fixed #255 and made some other improvements to the subscription mgmt

This commit is contained in:
iNPUTmice 2014-07-11 13:52:27 +02:00
parent 8ebd14cef4
commit e7a0040ec5
5 changed files with 49 additions and 53 deletions

View File

@ -105,18 +105,6 @@
android:text="@string/receive_presence_updates"
android:textSize="14sp"
android:textColor="@color/primarytext" />
<TextView
android:id="@+id/ask_again"
android:paddingTop="8dp"
android:paddingLeft="32dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ask_again"
android:textColor="#33B5E5"
android:textSize="14sp"
android:visibility="gone"
/>
<TextView
style="@style/sectionHeader"
android:layout_width="wrap_content"

View File

@ -272,9 +272,11 @@ public class Contact implements ListItem {
} else if (subscription.equals("from")) {
this.resetOption(Contact.Options.TO);
this.setOption(Contact.Options.FROM);
this.resetOption(Contact.Options.PREEMPTIVE_GRANT);
} else if (subscription.equals("both")) {
this.setOption(Contact.Options.TO);
this.setOption(Contact.Options.FROM);
this.resetOption(Contact.Options.PREEMPTIVE_GRANT);
} else if (subscription.equals("none")) {
this.resetOption(Contact.Options.FROM);
this.resetOption(Contact.Options.TO);

View File

@ -90,8 +90,6 @@ public class PresenceParser extends AbstractParser {
} else if (type.equals("subscribe")) {
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
mXmppConnectionService.sendPresenceUpdatesTo(contact);
contact.setOption(Contact.Options.FROM);
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
if ((contact.getOption(Contact.Options.ASKING))
&& (!contact.getOption(Contact.Options.TO))) {
mXmppConnectionService

View File

@ -429,6 +429,7 @@ public class XmppConnectionService extends Service {
if (subscription.equals("remove")) {
contact.resetOption(Contact.Options.IN_ROSTER);
contact.resetOption(Contact.Options.DIRTY_DELETE);
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
} else {
contact.setOption(Contact.Options.IN_ROSTER);
contact.resetOption(Contact.Options.DIRTY_PUSH);
@ -516,7 +517,10 @@ public class XmppConnectionService extends Service {
}
}
if (wakeLock.isHeld()) {
try { wakeLock.release();} catch (RuntimeException re) {}
try {
wakeLock.release();
} catch (RuntimeException re) {
}
}
return START_STICKY;
}
@ -693,7 +697,8 @@ public class XmppConnectionService extends Service {
message.setStatus(Message.STATUS_WAITING);
} else if (conv.hasValidOtrSession()
&& conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
message.setPresence(conv.getOtrSession().getSessionID().getUserID());
message.setPresence(conv.getOtrSession().getSessionID()
.getUserID());
try {
packet = mMessageGenerator.generateOtrChat(message);
send = true;
@ -784,9 +789,11 @@ public class XmppConnectionService extends Service {
}
}
} else {
if (message.getConversation().getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
if (message.getConversation().getOtrSession()
.getSessionStatus() == SessionStatus.ENCRYPTED) {
if (message.getType() == Message.TYPE_TEXT) {
packet = mMessageGenerator.generateOtrChat(message,true);
packet = mMessageGenerator.generateOtrChat(message,
true);
} else if (message.getType() == Message.TYPE_IMAGE) {
mJingleConnectionManager.createNewConnection(message);
}
@ -795,7 +802,8 @@ public class XmppConnectionService extends Service {
} else if (message.getType() == Message.TYPE_TEXT) {
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
packet = mMessageGenerator.generateChat(message, true);
} else if ((message.getEncryption() == Message.ENCRYPTION_DECRYPTED)||(message.getEncryption() == Message.ENCRYPTION_PGP)) {
} else if ((message.getEncryption() == Message.ENCRYPTION_DECRYPTED)
|| (message.getEncryption() == Message.ENCRYPTION_PGP)) {
packet = mMessageGenerator.generatePgpChat(message, true);
}
} else if (message.getType() == Message.TYPE_IMAGE) {
@ -1087,10 +1095,13 @@ public class XmppConnectionService extends Service {
packet.addChild("x", "jabber:x:signed").setContent(sig);
}
if (conversation.getMessages().size() != 0) {
final SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",Locale.US);
final SimpleDateFormat mDateFormat = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = new Date(conversation.getLatestMessage().getTimeSent() + 1000);
x.addChild("history").setAttribute("since",mDateFormat.format(date));
Date date = new Date(
conversation.getLatestMessage().getTimeSent() + 1000);
x.addChild("history").setAttribute("since",
mDateFormat.format(date));
}
packet.addChild(x);
account.getXmppConnection().sendPresencePacket(packet);
@ -1221,11 +1232,13 @@ public class XmppConnectionService extends Service {
&& (msg.getEncryption() == Message.ENCRYPTION_OTR)) {
msg.setPresence(otrSession.getSessionID().getUserID());
if (msg.getType() == Message.TYPE_TEXT) {
MessagePacket outPacket = mMessageGenerator.generateOtrChat(msg,true);
MessagePacket outPacket = mMessageGenerator
.generateOtrChat(msg, true);
if (outPacket != null) {
msg.setStatus(Message.STATUS_SEND);
databaseBackend.updateMessage(msg);
account.getXmppConnection().sendMessagePacket(outPacket);
account.getXmppConnection()
.sendMessagePacket(outPacket);
}
} else if (msg.getType() == Message.TYPE_IMAGE) {
mJingleConnectionManager.createNewConnection(msg);
@ -1273,7 +1286,8 @@ public class XmppConnectionService extends Service {
if (contact.getOption(Contact.Options.ASKING)) {
requestPresenceUpdatesFrom(contact);
}
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)
&& contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
Log.d("xmppService", "contact had pending subscription");
sendPresenceUpdatesTo(contact);
}
@ -1281,6 +1295,7 @@ public class XmppConnectionService extends Service {
}
public void deleteContactOnServer(Contact contact) {
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
contact.resetOption(Contact.Options.DIRTY_PUSH);
contact.setOption(Contact.Options.DIRTY_DELETE);
Account account = contact.getAccount();
@ -1480,7 +1495,8 @@ public class XmppConnectionService extends Service {
public void replyWithNotAcceptable(Account account, MessagePacket packet) {
if (account.getStatus() == Account.STATUS_ONLINE) {
MessagePacket error = this.mMessageGenerator.generateNotAcceptable(packet);
MessagePacket error = this.mMessageGenerator
.generateNotAcceptable(packet);
account.getXmppConnection().sendMessagePacket(error);
}
}

View File

@ -47,7 +47,6 @@ public class ContactDetailsActivity extends XmppActivity {
private TextView contactJidTv;
private TextView accountJidTv;
private TextView status;
private TextView askAgain;
private TextView lastseen;
private CheckBox send;
private CheckBox receive;
@ -115,7 +114,6 @@ public class ContactDetailsActivity extends XmppActivity {
lastseen = (TextView) findViewById(R.id.details_lastseen);
send = (CheckBox) findViewById(R.id.details_send_presence);
receive = (CheckBox) findViewById(R.id.details_receive_presence);
askAgain = (TextView) findViewById(R.id.ask_again);
badge = (QuickContactBadge) findViewById(R.id.details_contact_badge);
keys = (LinearLayout) findViewById(R.id.details_contact_keys);
getActionBar().setHomeButtonEnabled(true);
@ -174,6 +172,8 @@ public class ContactDetailsActivity extends XmppActivity {
setTitle(contact.getDisplayName());
if (contact.getOption(Contact.Options.FROM)) {
send.setChecked(true);
} else if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)){
send.setChecked(false);
} else {
send.setText(R.string.preemptively_grant);
if (contact
@ -187,17 +187,6 @@ public class ContactDetailsActivity extends XmppActivity {
receive.setChecked(true);
} else {
receive.setText(R.string.ask_for_presence_updates);
askAgain.setVisibility(View.VISIBLE);
askAgain.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), getString(R.string.asked_for_presence_updates),
Toast.LENGTH_SHORT).show();
xmppConnectionService.requestPresenceUpdatesFrom(contact);
}
});
if (contact.getOption(Contact.Options.ASKING)) {
receive.setChecked(true);
} else {
@ -317,8 +306,7 @@ public class ContactDetailsActivity extends XmppActivity {
updated = true;
}
} else {
if (contact
.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
if (!send.isChecked()) {
if (online) {
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
@ -328,8 +316,12 @@ public class ContactDetailsActivity extends XmppActivity {
} else {
if (send.isChecked()) {
if (online) {
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
xmppConnectionService.sendPresenceUpdatesTo(contact);
} else {
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
}
}
updated = true;
}
}