handle conference invites differently to deal with killed activities. fixes #1188

This commit is contained in:
Daniel Gultsch 2015-05-12 04:33:04 +02:00
parent 93e444ac3a
commit d3a6aa9f7a
4 changed files with 67 additions and 31 deletions

View file

@ -2108,6 +2108,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
public void invite(Conversation conversation, Jid contact) { public void invite(Conversation conversation, Jid contact) {
Log.d(Config.LOGTAG,conversation.getAccount().getJid().toBareJid()+": inviting "+contact+" to "+conversation.getJid().toBareJid());
MessagePacket packet = mMessageGenerator.invite(conversation, contact); MessagePacket packet = mMessageGenerator.invite(conversation, contact);
sendMessagePacket(conversation.getAccount(), packet); sendMessagePacket(conversation.getAccount(), packet);
} }

View file

@ -385,6 +385,10 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override @Override
void onBackendConnected() { void onBackendConnected() {
if (mPendingConferenceInvite != null) {
mPendingConferenceInvite.execute(this);
mPendingConferenceInvite = null;
}
if (getIntent().getAction().equals(ACTION_VIEW_MUC)) { if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
this.uuid = getIntent().getExtras().getString("uuid"); this.uuid = getIntent().getExtras().getString("uuid");
} }

View file

@ -901,6 +901,12 @@ public class ConversationActivity extends XmppActivity
void onBackendConnected() { void onBackendConnected() {
this.xmppConnectionService.getNotificationService().setIsInForeground(true); this.xmppConnectionService.getNotificationService().setIsInForeground(true);
updateConversationList(); updateConversationList();
if (mPendingConferenceInvite != null) {
mPendingConferenceInvite.execute(this);
mPendingConferenceInvite = null;
}
if (xmppConnectionService.getAccounts().size() == 0) { if (xmppConnectionService.getAccounts().size() == 0) {
if (!mRedirected) { if (!mRedirected) {
this.mRedirected = true; this.mRedirected = true;

View file

@ -113,6 +113,8 @@ public abstract class XmppActivity extends Activity {
} }
}; };
protected ConferenceInvite mPendingConferenceInvite = null;
protected void refreshUi() { protected void refreshUi() {
final long diff = SystemClock.elapsedRealtime() - mLastUiRefresh; final long diff = SystemClock.elapsedRealtime() - mLastUiRefresh;
@ -665,32 +667,13 @@ public abstract class XmppActivity extends Activity {
protected void onActivityResult(int requestCode, int resultCode, protected void onActivityResult(int requestCode, int resultCode,
final Intent data) { final Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_INVITE_TO_CONVERSATION if (requestCode == REQUEST_INVITE_TO_CONVERSATION && resultCode == RESULT_OK) {
&& resultCode == RESULT_OK) { mPendingConferenceInvite = ConferenceInvite.parse(data);
try { if (xmppConnectionServiceBound && mPendingConferenceInvite != null) {
String conversationUuid = data.getStringExtra("conversation"); mPendingConferenceInvite.execute(this);
Conversation conversation = xmppConnectionService mPendingConferenceInvite = null;
.findConversationByUuid(conversationUuid);
List<Jid> jids = new ArrayList<Jid>();
if (data.getBooleanExtra("multiple", false)) {
String[] toAdd = data.getStringArrayExtra("contacts");
for (String item : toAdd) {
jids.add(Jid.fromString(item));
}
} else { } else {
jids.add(Jid.fromString(data.getStringExtra("contact"))); Log.d(Config.LOGTAG,"putting invite on pending");
}
if (conversation.getMode() == Conversation.MODE_MULTI) {
for (Jid jid : jids) {
xmppConnectionService.invite(conversation, jid);
}
} else {
jids.add(conversation.getJid().toBareJid());
xmppConnectionService.createAdhocConference(conversation.getAccount(), jids, adhocCallback);
}
} catch (final InvalidJidException ignored) {
} }
} }
} }
@ -855,6 +838,48 @@ public abstract class XmppActivity extends Activity {
} }
} }
public static class ConferenceInvite {
private String uuid;
private List<Jid> jids = new ArrayList<>();
public static ConferenceInvite parse(Intent data) {
ConferenceInvite invite = new ConferenceInvite();
invite.uuid = data.getStringExtra("conversation");
if (invite.uuid == null) {
return null;
}
try {
if (data.getBooleanExtra("multiple", false)) {
String[] toAdd = data.getStringArrayExtra("contacts");
for (String item : toAdd) {
invite.jids.add(Jid.fromString(item));
}
} else {
invite.jids.add(Jid.fromString(data.getStringExtra("contact")));
}
} catch (final InvalidJidException ignored) {
return null;
}
return invite;
}
public void execute(XmppActivity activity) {
XmppConnectionService service = activity.xmppConnectionService;
Conversation conversation = service.findConversationByUuid(this.uuid);
if (conversation == null) {
return;
}
if (conversation.getMode() == Conversation.MODE_MULTI) {
for (Jid jid : jids) {
service.invite(conversation, jid);
}
} else {
jids.add(conversation.getJid().toBareJid());
service.createAdhocConference(conversation.getAccount(), jids, activity.adhocCallback);
}
}
}
public AvatarService avatarService() { public AvatarService avatarService() {
return xmppConnectionService.getAvatarService(); return xmppConnectionService.getAvatarService();
} }