From eee5d885ba61b3476be7e89076f7836235626d92 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 22 Jan 2018 23:21:24 +0100 Subject: [PATCH] make chat markers opportunistic in private mucs --- .../crypto/axolotl/AxolotlService.java | 5 ++-- .../conversations/entities/Conversation.java | 28 ++++++++++--------- .../conversations/entities/MucOptions.java | 4 +++ .../generator/MessageGenerator.java | 3 +- .../conversations/parser/PresenceParser.java | 2 +- .../services/XmppConnectionService.java | 10 +++---- .../ui/ConversationFragment.java | 2 +- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 40d94310f..a202a4c66 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -788,12 +788,11 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } public boolean isConversationAxolotlCapable(Conversation conversation) { - return conversation.getMode() == Conversation.MODE_SINGLE || (conversation.getMucOptions().nonanonymous() && conversation.getMucOptions().membersOnly()); + return conversation.isSingleOrPrivateAndNonAnonymous(); } public Pair isConversationAxolotlCapableDetailed(Conversation conversation) { - if (conversation.getMode() == Conversation.MODE_SINGLE - || (conversation.getMucOptions().membersOnly() && conversation.getMucOptions().nonanonymous())) { + if (conversation.isSingleOrPrivateAndNonAnonymous()) { final List jids = getCryptoTargets(conversation); for (Jid jid : jids) { if (!hasAny(jid) && (!deviceIds.containsKey(jid) || deviceIds.get(jid).isEmpty())) { diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 7cf4618e3..1721a2d2c 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -194,15 +194,13 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public boolean setOutgoingChatState(ChatState state) { - if (mode == MODE_MULTI && (getNextCounterpart() != null || !isPnNA())) { - return false; - } - if (this.mOutgoingChatState != state) { - this.mOutgoingChatState = state; - return true; - } else { - return false; + if (mode == MODE_SINGLE || (isPrivateAndNonAnonymous() && getNextCounterpart() == null)) { + if (this.mOutgoingChatState != state) { + this.mOutgoingChatState = state; + return true; + } } + return false; } public ChatState getOutgoingChatState() { @@ -466,12 +464,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return unread; } - public Message getLatestMarkableMessage() { + public Message getLatestMarkableMessage(boolean isPrivateAndNonAnonymousMuc) { synchronized (this.messages) { for (int i = this.messages.size() - 1; i >= 0; --i) { final Message message = this.messages.get(i); if (message.getStatus() <= Message.STATUS_RECEIVED - && message.markable + && (message.markable || isPrivateAndNonAnonymousMuc) && message.getType() != Message.TYPE_PRIVATE) { return message.isRead() ? null : message; } @@ -697,8 +695,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl /** * short for is Private and Non-anonymous */ - private boolean isPnNA() { - return mode == MODE_SINGLE || (getMucOptions().membersOnly() && getMucOptions().nonanonymous()); + public boolean isSingleOrPrivateAndNonAnonymous() { + return mode == MODE_SINGLE || isPrivateAndNonAnonymous(); + } + + public boolean isPrivateAndNonAnonymous() { + return getMucOptions().isPrivateAndNonAnonymous(); } public synchronized MucOptions getMucOptions() { @@ -866,7 +868,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public boolean alwaysNotify() { - return mode == MODE_SINGLE || getBooleanAttribute(ATTRIBUTE_ALWAYS_NOTIFY, Config.ALWAYS_NOTIFY_BY_DEFAULT || isPnNA()); + return mode == MODE_SINGLE || getBooleanAttribute(ATTRIBUTE_ALWAYS_NOTIFY, Config.ALWAYS_NOTIFY_BY_DEFAULT || isPrivateAndNonAnonymous()); } public boolean setAttribute(String key, String value) { diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index 98eb444c3..3368ee830 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -424,6 +424,10 @@ public class MucOptions { return hasFeature("muc_nonanonymous"); } + public boolean isPrivateAndNonAnonymous() { + return membersOnly() && nonanonymous(); + } + public boolean persistent() { return hasFeature("muc_persistent"); } diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index 4539396b3..561697fba 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -53,8 +53,7 @@ public class MessageGenerator extends AbstractGenerator { packet.setTo(message.getCounterpart().toBareJid()); packet.setType(MessagePacket.TYPE_GROUPCHAT); } - if (conversation.getMode() == Conversation.MODE_SINGLE || - (conversation.getMucOptions().nonanonymous() && conversation.getMucOptions().membersOnly() && message.getType() != Message.TYPE_PRIVATE)) { + if (conversation.isSingleOrPrivateAndNonAnonymous() && message.getType() != Message.TYPE_PRIVATE) { packet.addChild("markable", "urn:xmpp:chat-markers:0"); } packet.setFrom(account.getJid()); diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index a4fb6db3f..ea555baac 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -78,7 +78,7 @@ public class PresenceParser extends AbstractParser implements } boolean isNew = mucOptions.updateUser(user); final AxolotlService axolotlService = conversation.getAccount().getAxolotlService(); - if (isNew && user.getRealJid() != null && mucOptions.membersOnly() && mucOptions.nonanonymous() && axolotlService.hasEmptyDeviceList(user.getRealJid())) { + if (isNew && user.getRealJid() != null && mucOptions.isPrivateAndNonAnonymous() && axolotlService.hasEmptyDeviceList(user.getRealJid())) { axolotlService.fetchDeviceIds(user.getRealJid()); } if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && mucOptions.autoPushConfiguration()) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index dcc57ea4f..293c71cf5 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2271,7 +2271,7 @@ public class XmppConnectionService extends Service { if (mucOptions.mamSupport()) { getMessageArchiveService().catchupMUC(conversation); } - if (mucOptions.membersOnly() && mucOptions.nonanonymous()) { + if (mucOptions.isPrivateAndNonAnonymous()) { fetchConferenceMembers(conversation); if (followedInvite && conversation.getBookmark() == null) { saveConversationAsBookmark(conversation, null); @@ -3432,15 +3432,15 @@ public class XmppConnectionService extends Service { } public void sendReadMarker(final Conversation conversation) { - final Message markable = conversation.getLatestMarkableMessage(); + final boolean isPrivateAndNonAnonymousMuc = conversation.getMode() == Conversation.MODE_MULTI && conversation.isPrivateAndNonAnonymous(); + final Message markable = conversation.getLatestMarkableMessage(isPrivateAndNonAnonymousMuc); if (this.markRead(conversation)) { updateConversationUi(); } if (confirmMessages() && markable != null - && markable.trusted() - && markable.getRemoteMsgId() != null - && markable.getType() != Message.TYPE_PRIVATE) { + && (markable.trusted() || isPrivateAndNonAnonymousMuc) + && markable.getRemoteMsgId() != null) { Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString()); Account account = conversation.getAccount(); final Jid to = markable.getCounterpart(); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 7ec358900..969281c9a 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1385,7 +1385,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa state = ChatState.PAUSED; users = conversation.getMucOptions().getUsersWithChatState(state, 5); } - if (mucOptions.membersOnly() && mucOptions.nonanonymous()) { + if (mucOptions.isPrivateAndNonAnonymous()) { for (int i = this.messageList.size() - 1; i >= 0; --i) { final Set markersForMessage = messageList.get(i).getReadByMarkers(); final List shownMarkers = new ArrayList<>();