From b2c278c91bc2a733dcb807d7eb7f0d3e7145d9c2 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 11 Dec 2015 19:28:44 +0100 Subject: set bookmark name to room subject if no subject has been set before --- src/main/java/eu/siacs/conversations/entities/Bookmark.java | 10 ++++++++++ .../java/eu/siacs/conversations/parser/MessageParser.java | 12 ++++++++++-- .../siacs/conversations/services/XmppConnectionService.java | 3 ++- .../eu/siacs/conversations/ui/ConferenceDetailsActivity.java | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java index 0210da24..acb4bf1a 100644 --- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java +++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java @@ -138,6 +138,16 @@ public class Bookmark extends Element implements ListItem { return this.getAttribute("name"); } + public boolean setBookmarkName(String name) { + String before = getBookmarkName(); + if (name != null && !name.equals(before)) { + this.setAttribute("name", name); + return true; + } else { + return false; + } + } + public void unregisterConversation() { if (this.mJoinedConversation != null) { this.mJoinedConversation.deregisterWithBookmark(); diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 49c3134c..d8190b70 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -14,6 +14,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; @@ -387,7 +388,7 @@ public class MessageParser extends AbstractParser implements message.setType(Message.TYPE_PRIVATE); } } - updateLastseen(packet,account,true); + updateLastseen(packet, account, true); boolean checkForDuplicates = query != null || (isTypeGroupChat && packet.hasChild("delay","urn:xmpp:delay")) || message.getType() == Message.TYPE_PRIVATE; @@ -458,7 +459,14 @@ public class MessageParser extends AbstractParser implements if (packet.hasChild("subject")) { if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { conversation.setHasMessagesLeftOnServer(conversation.countMessages() > 0); - conversation.getMucOptions().setSubject(packet.findChildContent("subject")); + String subject = packet.findChildContent("subject"); + conversation.getMucOptions().setSubject(subject); + final Bookmark bookmark = conversation.getBookmark(); + if (bookmark != null && bookmark.getBookmarkName() == null) { + if (bookmark.setBookmarkName(subject)) { + mXmppConnectionService.pushBookmarks(account); + } + } mXmppConnectionService.updateConversationUi(); return; } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index cb193167..3be56b04 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -250,9 +250,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa account.getRoster().clearPresences(); fetchRosterFromServer(account); fetchBookmarks(account); + mMessageArchiveService.executePendingQueries(account); sendPresence(account); connectMultiModeConversations(account); - mMessageArchiveService.executePendingQueries(account); mJingleConnectionManager.cancelInTransmission(); syncDirtyContacts(account); } @@ -1015,6 +1015,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } public void pushBookmarks(Account account) { + Log.d(Config.LOGTAG, account.getJid().toBareJid()+": pushing bookmarks"); IqPacket iqPacket = new IqPacket(IqPacket.TYPE.SET); Element query = iqPacket.query("jabber:iq:private"); Element storage = query.addChild("storage", "storage:bookmarks"); diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index adae7916..b3de28b3 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -420,6 +420,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers if (!mConversation.getJid().isBareJid()) { bookmark.setNick(mConversation.getJid().getResourcepart()); } + bookmark.setBookmarkName(mConversation.getMucOptions().getSubject()); bookmark.setAutojoin(true); account.getBookmarks().add(bookmark); xmppConnectionService.pushBookmarks(account); -- cgit v1.2.3