leave/join on bookmark modifactions

This commit is contained in:
Daniel Gultsch 2019-09-28 10:16:29 +02:00
parent f26e0720c6
commit 94c592f213
2 changed files with 35 additions and 22 deletions

View file

@ -239,9 +239,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (item != null) { if (item != null) {
final Bookmark bookmark = Bookmark.parseFromItem(item, account); final Bookmark bookmark = Bookmark.parseFromItem(item, account);
if (bookmark != null) { if (bookmark != null) {
//TODO find conversation mXmppConnectionService.processModifiedBookmark(bookmark);
account.putBookmark(bookmark);
//TODO handle autojoin
} }
} }
if (retract != null) { if (retract != null) {
@ -249,6 +247,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (id != null) { if (id != null) {
account.removeBookmark(id); account.removeBookmark(id);
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": deleted bookmark for "+id); Log.d(Config.LOGTAG,account.getJid().asBareJid()+": deleted bookmark for "+id);
mXmppConnectionService.processDeletedBookmark(account, id);
} }
} }
} else { } else {

View file

@ -1592,34 +1592,48 @@ public class XmppConnectionService extends Service {
final boolean synchronizeWithBookmarks = synchronizeWithBookmarks(); final boolean synchronizeWithBookmarks = synchronizeWithBookmarks();
for (Bookmark bookmark : bookmarks.values()) { for (Bookmark bookmark : bookmarks.values()) {
previousBookmarks.remove(bookmark.getJid().asBareJid()); previousBookmarks.remove(bookmark.getJid().asBareJid());
Conversation conversation = find(bookmark); processModifiedBookmark(bookmark, pep, synchronizeWithBookmarks);
if (conversation != null) {
if (conversation.getMode() != Conversation.MODE_MULTI) {
continue;
}
bookmark.setConversation(conversation);
if (pep && synchronizeWithBookmarks && !bookmark.autojoin()) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": archiving conference ("+conversation.getJid()+") after receiving pep");
archiveConversation(conversation, false);
}
} else if (synchronizeWithBookmarks && bookmark.autojoin()) {
conversation = findOrCreateConversation(account, bookmark.getFullJid(), true, true, false);
bookmark.setConversation(conversation);
}
} }
if (pep && synchronizeWithBookmarks) { if (pep && synchronizeWithBookmarks) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + previousBookmarks.size() + " bookmarks have been removed"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + previousBookmarks.size() + " bookmarks have been removed");
for (Jid jid : previousBookmarks) { for (Jid jid : previousBookmarks) {
final Conversation conversation = find(account, jid); processDeletedBookmark(account, jid);
if (conversation != null && conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": archiving destroyed conference ("+conversation.getJid()+") after receiving pep");
archiveConversation(conversation, false);
}
} }
} }
account.setBookmarks(bookmarks); account.setBookmarks(bookmarks);
} }
public void processDeletedBookmark(Account account, Jid jid) {
final Conversation conversation = find(account, jid);
if (conversation != null && conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": archiving destroyed conference ("+conversation.getJid()+") after receiving pep");
archiveConversation(conversation, false);
}
}
private void processModifiedBookmark(Bookmark bookmark, final boolean pep, final boolean synchronizeWithBookmarks) {
final Account account = bookmark.getAccount();
Conversation conversation = find(bookmark);
if (conversation != null) {
if (conversation.getMode() != Conversation.MODE_MULTI) {
return;
}
bookmark.setConversation(conversation);
if (pep && synchronizeWithBookmarks && !bookmark.autojoin()) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": archiving conference ("+conversation.getJid()+") after receiving pep");
archiveConversation(conversation, false);
}
} else if (synchronizeWithBookmarks && bookmark.autojoin()) {
conversation = findOrCreateConversation(account, bookmark.getFullJid(), true, true, false);
bookmark.setConversation(conversation);
}
}
public void processModifiedBookmark(Bookmark bookmark) {
final boolean synchronizeWithBookmarks = synchronizeWithBookmarks();
processModifiedBookmark(bookmark, true, synchronizeWithBookmarks);
}
public void createBookmark(final Account account, final Bookmark bookmark) { public void createBookmark(final Account account, final Bookmark bookmark) {
account.putBookmark(bookmark); account.putBookmark(bookmark);
final XmppConnection connection = account.getXmppConnection(); final XmppConnection connection = account.getXmppConnection();