fixed #255 and made some other improvements to the subscription mgmt
This commit is contained in:
parent
8ebd14cef4
commit
e7a0040ec5
|
@ -105,18 +105,6 @@
|
||||||
android:text="@string/receive_presence_updates"
|
android:text="@string/receive_presence_updates"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:textColor="@color/primarytext" />
|
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
|
<TextView
|
||||||
style="@style/sectionHeader"
|
style="@style/sectionHeader"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -272,9 +272,11 @@ public class Contact implements ListItem {
|
||||||
} else if (subscription.equals("from")) {
|
} else if (subscription.equals("from")) {
|
||||||
this.resetOption(Contact.Options.TO);
|
this.resetOption(Contact.Options.TO);
|
||||||
this.setOption(Contact.Options.FROM);
|
this.setOption(Contact.Options.FROM);
|
||||||
|
this.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||||
} else if (subscription.equals("both")) {
|
} else if (subscription.equals("both")) {
|
||||||
this.setOption(Contact.Options.TO);
|
this.setOption(Contact.Options.TO);
|
||||||
this.setOption(Contact.Options.FROM);
|
this.setOption(Contact.Options.FROM);
|
||||||
|
this.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||||
} else if (subscription.equals("none")) {
|
} else if (subscription.equals("none")) {
|
||||||
this.resetOption(Contact.Options.FROM);
|
this.resetOption(Contact.Options.FROM);
|
||||||
this.resetOption(Contact.Options.TO);
|
this.resetOption(Contact.Options.TO);
|
||||||
|
|
|
@ -90,8 +90,6 @@ public class PresenceParser extends AbstractParser {
|
||||||
} else if (type.equals("subscribe")) {
|
} else if (type.equals("subscribe")) {
|
||||||
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
||||||
mXmppConnectionService.sendPresenceUpdatesTo(contact);
|
mXmppConnectionService.sendPresenceUpdatesTo(contact);
|
||||||
contact.setOption(Contact.Options.FROM);
|
|
||||||
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
||||||
if ((contact.getOption(Contact.Options.ASKING))
|
if ((contact.getOption(Contact.Options.ASKING))
|
||||||
&& (!contact.getOption(Contact.Options.TO))) {
|
&& (!contact.getOption(Contact.Options.TO))) {
|
||||||
mXmppConnectionService
|
mXmppConnectionService
|
||||||
|
|
|
@ -429,6 +429,7 @@ public class XmppConnectionService extends Service {
|
||||||
if (subscription.equals("remove")) {
|
if (subscription.equals("remove")) {
|
||||||
contact.resetOption(Contact.Options.IN_ROSTER);
|
contact.resetOption(Contact.Options.IN_ROSTER);
|
||||||
contact.resetOption(Contact.Options.DIRTY_DELETE);
|
contact.resetOption(Contact.Options.DIRTY_DELETE);
|
||||||
|
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||||
} else {
|
} else {
|
||||||
contact.setOption(Contact.Options.IN_ROSTER);
|
contact.setOption(Contact.Options.IN_ROSTER);
|
||||||
contact.resetOption(Contact.Options.DIRTY_PUSH);
|
contact.resetOption(Contact.Options.DIRTY_PUSH);
|
||||||
|
@ -516,7 +517,10 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (wakeLock.isHeld()) {
|
if (wakeLock.isHeld()) {
|
||||||
try { wakeLock.release();} catch (RuntimeException re) {}
|
try {
|
||||||
|
wakeLock.release();
|
||||||
|
} catch (RuntimeException re) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
@ -693,13 +697,14 @@ public class XmppConnectionService extends Service {
|
||||||
message.setStatus(Message.STATUS_WAITING);
|
message.setStatus(Message.STATUS_WAITING);
|
||||||
} else if (conv.hasValidOtrSession()
|
} else if (conv.hasValidOtrSession()
|
||||||
&& conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
|
&& conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
|
||||||
message.setPresence(conv.getOtrSession().getSessionID().getUserID());
|
message.setPresence(conv.getOtrSession().getSessionID()
|
||||||
|
.getUserID());
|
||||||
try {
|
try {
|
||||||
packet = mMessageGenerator.generateOtrChat(message);
|
packet = mMessageGenerator.generateOtrChat(message);
|
||||||
send = true;
|
send = true;
|
||||||
message.setStatus(Message.STATUS_SEND);
|
message.setStatus(Message.STATUS_SEND);
|
||||||
} catch (OtrException e) {
|
} catch (OtrException e) {
|
||||||
Log.e(LOGTAG,"error generating otr packet");
|
Log.e(LOGTAG, "error generating otr packet");
|
||||||
packet = null;
|
packet = null;
|
||||||
}
|
}
|
||||||
} else if (message.getPresence() == null) {
|
} else if (message.getPresence() == null) {
|
||||||
|
@ -784,9 +789,11 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (message.getConversation().getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
|
if (message.getConversation().getOtrSession()
|
||||||
|
.getSessionStatus() == SessionStatus.ENCRYPTED) {
|
||||||
if (message.getType() == Message.TYPE_TEXT) {
|
if (message.getType() == Message.TYPE_TEXT) {
|
||||||
packet = mMessageGenerator.generateOtrChat(message,true);
|
packet = mMessageGenerator.generateOtrChat(message,
|
||||||
|
true);
|
||||||
} else if (message.getType() == Message.TYPE_IMAGE) {
|
} else if (message.getType() == Message.TYPE_IMAGE) {
|
||||||
mJingleConnectionManager.createNewConnection(message);
|
mJingleConnectionManager.createNewConnection(message);
|
||||||
}
|
}
|
||||||
|
@ -794,9 +801,10 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
} else if (message.getType() == Message.TYPE_TEXT) {
|
} else if (message.getType() == Message.TYPE_TEXT) {
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
|
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
|
||||||
packet = mMessageGenerator.generateChat(message,true);
|
packet = mMessageGenerator.generateChat(message, true);
|
||||||
} else if ((message.getEncryption() == Message.ENCRYPTION_DECRYPTED)||(message.getEncryption() == Message.ENCRYPTION_PGP)) {
|
} else if ((message.getEncryption() == Message.ENCRYPTION_DECRYPTED)
|
||||||
packet = mMessageGenerator.generatePgpChat(message,true);
|
|| (message.getEncryption() == Message.ENCRYPTION_PGP)) {
|
||||||
|
packet = mMessageGenerator.generatePgpChat(message, true);
|
||||||
}
|
}
|
||||||
} else if (message.getType() == Message.TYPE_IMAGE) {
|
} else if (message.getType() == Message.TYPE_IMAGE) {
|
||||||
Presences presences = message.getConversation().getContact()
|
Presences presences = message.getConversation().getContact()
|
||||||
|
@ -1087,10 +1095,13 @@ public class XmppConnectionService extends Service {
|
||||||
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
||||||
}
|
}
|
||||||
if (conversation.getMessages().size() != 0) {
|
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"));
|
mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
Date date = new Date(conversation.getLatestMessage().getTimeSent() + 1000);
|
Date date = new Date(
|
||||||
x.addChild("history").setAttribute("since",mDateFormat.format(date));
|
conversation.getLatestMessage().getTimeSent() + 1000);
|
||||||
|
x.addChild("history").setAttribute("since",
|
||||||
|
mDateFormat.format(date));
|
||||||
}
|
}
|
||||||
packet.addChild(x);
|
packet.addChild(x);
|
||||||
account.getXmppConnection().sendPresencePacket(packet);
|
account.getXmppConnection().sendPresencePacket(packet);
|
||||||
|
@ -1221,11 +1232,13 @@ public class XmppConnectionService extends Service {
|
||||||
&& (msg.getEncryption() == Message.ENCRYPTION_OTR)) {
|
&& (msg.getEncryption() == Message.ENCRYPTION_OTR)) {
|
||||||
msg.setPresence(otrSession.getSessionID().getUserID());
|
msg.setPresence(otrSession.getSessionID().getUserID());
|
||||||
if (msg.getType() == Message.TYPE_TEXT) {
|
if (msg.getType() == Message.TYPE_TEXT) {
|
||||||
MessagePacket outPacket = mMessageGenerator.generateOtrChat(msg,true);
|
MessagePacket outPacket = mMessageGenerator
|
||||||
if (outPacket!=null) {
|
.generateOtrChat(msg, true);
|
||||||
|
if (outPacket != null) {
|
||||||
msg.setStatus(Message.STATUS_SEND);
|
msg.setStatus(Message.STATUS_SEND);
|
||||||
databaseBackend.updateMessage(msg);
|
databaseBackend.updateMessage(msg);
|
||||||
account.getXmppConnection().sendMessagePacket(outPacket);
|
account.getXmppConnection()
|
||||||
|
.sendMessagePacket(outPacket);
|
||||||
}
|
}
|
||||||
} else if (msg.getType() == Message.TYPE_IMAGE) {
|
} else if (msg.getType() == Message.TYPE_IMAGE) {
|
||||||
mJingleConnectionManager.createNewConnection(msg);
|
mJingleConnectionManager.createNewConnection(msg);
|
||||||
|
@ -1273,7 +1286,8 @@ public class XmppConnectionService extends Service {
|
||||||
if (contact.getOption(Contact.Options.ASKING)) {
|
if (contact.getOption(Contact.Options.ASKING)) {
|
||||||
requestPresenceUpdatesFrom(contact);
|
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");
|
Log.d("xmppService", "contact had pending subscription");
|
||||||
sendPresenceUpdatesTo(contact);
|
sendPresenceUpdatesTo(contact);
|
||||||
}
|
}
|
||||||
|
@ -1281,6 +1295,7 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteContactOnServer(Contact contact) {
|
public void deleteContactOnServer(Contact contact) {
|
||||||
|
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||||
contact.resetOption(Contact.Options.DIRTY_PUSH);
|
contact.resetOption(Contact.Options.DIRTY_PUSH);
|
||||||
contact.setOption(Contact.Options.DIRTY_DELETE);
|
contact.setOption(Contact.Options.DIRTY_DELETE);
|
||||||
Account account = contact.getAccount();
|
Account account = contact.getAccount();
|
||||||
|
@ -1480,32 +1495,33 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
public void replyWithNotAcceptable(Account account, MessagePacket packet) {
|
public void replyWithNotAcceptable(Account account, MessagePacket packet) {
|
||||||
if (account.getStatus() == Account.STATUS_ONLINE) {
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
||||||
MessagePacket error = this.mMessageGenerator.generateNotAcceptable(packet);
|
MessagePacket error = this.mMessageGenerator
|
||||||
|
.generateNotAcceptable(packet);
|
||||||
account.getXmppConnection().sendMessagePacket(error);
|
account.getXmppConnection().sendMessagePacket(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void syncRosterToDisk(final Account account) {
|
public void syncRosterToDisk(final Account account) {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
databaseBackend.writeRoster(account.getRoster());
|
databaseBackend.writeRoster(account.getRoster());
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getKnownHosts() {
|
public List<String> getKnownHosts() {
|
||||||
List<String> hosts = new ArrayList<String>();
|
List<String> hosts = new ArrayList<String>();
|
||||||
for(Account account : getAccounts()) {
|
for (Account account : getAccounts()) {
|
||||||
if (!hosts.contains(account.getServer())) {
|
if (!hosts.contains(account.getServer())) {
|
||||||
hosts.add(account.getServer());
|
hosts.add(account.getServer());
|
||||||
}
|
}
|
||||||
for(Contact contact : account.getRoster().getContacts()) {
|
for (Contact contact : account.getRoster().getContacts()) {
|
||||||
if (contact.showInRoster()) {
|
if (contact.showInRoster()) {
|
||||||
String server = contact.getServer();
|
String server = contact.getServer();
|
||||||
if (server!=null && !hosts.contains(server)) {
|
if (server != null && !hosts.contains(server)) {
|
||||||
hosts.add(server);
|
hosts.add(server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
private TextView contactJidTv;
|
private TextView contactJidTv;
|
||||||
private TextView accountJidTv;
|
private TextView accountJidTv;
|
||||||
private TextView status;
|
private TextView status;
|
||||||
private TextView askAgain;
|
|
||||||
private TextView lastseen;
|
private TextView lastseen;
|
||||||
private CheckBox send;
|
private CheckBox send;
|
||||||
private CheckBox receive;
|
private CheckBox receive;
|
||||||
|
@ -115,7 +114,6 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
lastseen = (TextView) findViewById(R.id.details_lastseen);
|
lastseen = (TextView) findViewById(R.id.details_lastseen);
|
||||||
send = (CheckBox) findViewById(R.id.details_send_presence);
|
send = (CheckBox) findViewById(R.id.details_send_presence);
|
||||||
receive = (CheckBox) findViewById(R.id.details_receive_presence);
|
receive = (CheckBox) findViewById(R.id.details_receive_presence);
|
||||||
askAgain = (TextView) findViewById(R.id.ask_again);
|
|
||||||
badge = (QuickContactBadge) findViewById(R.id.details_contact_badge);
|
badge = (QuickContactBadge) findViewById(R.id.details_contact_badge);
|
||||||
keys = (LinearLayout) findViewById(R.id.details_contact_keys);
|
keys = (LinearLayout) findViewById(R.id.details_contact_keys);
|
||||||
getActionBar().setHomeButtonEnabled(true);
|
getActionBar().setHomeButtonEnabled(true);
|
||||||
|
@ -174,6 +172,8 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
setTitle(contact.getDisplayName());
|
setTitle(contact.getDisplayName());
|
||||||
if (contact.getOption(Contact.Options.FROM)) {
|
if (contact.getOption(Contact.Options.FROM)) {
|
||||||
send.setChecked(true);
|
send.setChecked(true);
|
||||||
|
} else if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)){
|
||||||
|
send.setChecked(false);
|
||||||
} else {
|
} else {
|
||||||
send.setText(R.string.preemptively_grant);
|
send.setText(R.string.preemptively_grant);
|
||||||
if (contact
|
if (contact
|
||||||
|
@ -187,17 +187,6 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
receive.setChecked(true);
|
receive.setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
receive.setText(R.string.ask_for_presence_updates);
|
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)) {
|
if (contact.getOption(Contact.Options.ASKING)) {
|
||||||
receive.setChecked(true);
|
receive.setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -317,8 +306,7 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (contact
|
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
||||||
.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
|
||||||
if (!send.isChecked()) {
|
if (!send.isChecked()) {
|
||||||
if (online) {
|
if (online) {
|
||||||
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||||
|
@ -328,7 +316,11 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
} else {
|
} else {
|
||||||
if (send.isChecked()) {
|
if (send.isChecked()) {
|
||||||
if (online) {
|
if (online) {
|
||||||
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
|
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
||||||
|
xmppConnectionService.sendPresenceUpdatesTo(contact);
|
||||||
|
} else {
|
||||||
|
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue