diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-01-27 22:03:15 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-01-27 22:03:15 +0100 |
commit | 7ba79653b17284ac5d6c2e8ca6287dad1cc9bb06 (patch) | |
tree | b7b9d90751fdae65e75993adf75b4622b6627748 /src/main/java/de/pixart/messenger | |
parent | ff1b7567d122aaa22a191f0fc7a1cc270bd57a0e (diff) |
improvements for self messages
* fix omemo in group chats w/o participants
* don't create two axolotl messages when messaging self
* fix read marker for self messages
Diffstat (limited to 'src/main/java/de/pixart/messenger')
5 files changed, 25 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java index 6721a7975..cece60c5a 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java @@ -334,6 +334,10 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } private Set<XmppAxolotlSession> findSessionsForConversation(Conversation conversation) { + if (conversation.getContact().isSelf()) { + //will be added in findOwnSessions() + return Collections.emptySet(); + } HashSet<XmppAxolotlSession> sessions = new HashSet<>(); for (Jid jid : conversation.getAcceptedCryptoTargets()) { sessions.addAll(this.sessions.getAll(getAddressForJid(jid).getName()).values()); @@ -1179,7 +1183,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } public boolean trustedSessionVerified(final Conversation conversation) { - Set<XmppAxolotlSession> sessions = findSessionsForConversation(conversation); + final Set<XmppAxolotlSession> sessions = new HashSet<>(); + sessions.addAll(findSessionsForConversation(conversation)); sessions.addAll(findOwnSessions()); boolean verified = false; for (XmppAxolotlSession session : sessions) { @@ -1213,7 +1218,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { @Nullable private boolean buildHeader(XmppAxolotlMessage axolotlMessage, Conversation c) { Set<XmppAxolotlSession> remoteSessions = findSessionsForConversation(c); - final boolean acceptEmpty = c.getMode() == Conversation.MODE_MULTI && c.getMucOptions().getUserCount() == 0; + final boolean acceptEmpty = (c.getMode() == Conversation.MODE_MULTI && c.getMucOptions().getUserCount() == 0) || c.getContact().isSelf(); Collection<XmppAxolotlSession> ownSessions = findOwnSessions(); if (remoteSessions.isEmpty() && !acceptEmpty) { return false; diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 5c5f5634c..d9a12392e 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -208,7 +208,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public boolean setOutgoingChatState(ChatState state) { - if (mode == MODE_SINGLE || (isPrivateAndNonAnonymous() && getNextCounterpart() == null)) { + if (mode == MODE_SINGLE && !getContact().isSelf() || (isPrivateAndNonAnonymous() && getNextCounterpart() == null)) { if (this.mOutgoingChatState != state) { this.mOutgoingChatState = state; return true; diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index 8c55c57c4..1e087b69b 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -649,7 +649,7 @@ public class Message extends AbstractEntity { public boolean trusted() { Contact contact = this.getContact(); - return (status > STATUS_RECEIVED || (contact != null && contact.mutualPresenceSubscription())); + return status > STATUS_RECEIVED || (contact != null && (contact.mutualPresenceSubscription() || contact.isSelf())); } public boolean fixCounterpart() { diff --git a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java index 4be56b79f..cc641a3b8 100644 --- a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java @@ -36,10 +36,11 @@ public class MessageGenerator extends AbstractGenerator { Conversation conversation = message.getConversation(); Account account = conversation.getAccount(); MessagePacket packet = new MessagePacket(); + final boolean isWithSelf = conversation.getContact().isSelf(); if (conversation.getMode() == Conversation.MODE_SINGLE) { packet.setTo(message.getCounterpart()); packet.setType(MessagePacket.TYPE_CHAT); - if (this.mXmppConnectionService.indicateReceived()) { + if (this.mXmppConnectionService.indicateReceived() && !isWithSelf) { packet.addChild("request", "urn:xmpp:receipts"); } } else if (message.getType() == Message.TYPE_PRIVATE) { diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java index bbc9d05bb..82810bc1c 100644 --- a/src/main/java/de/pixart/messenger/parser/MessageParser.java +++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java @@ -581,6 +581,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece && replacedMessage.getStatus() == Message.STATUS_RECEIVED && (replacedMessage.trusted() || replacedMessage.getType() == Message.TYPE_PRIVATE) && remoteMsgId != null + && !selfAddressed && !isTypeGroupChat) { processMessageReceipts(account, packet, query); } @@ -658,6 +659,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece && message.getStatus() == Message.STATUS_RECEIVED && (message.trusted() || message.getType() == Message.TYPE_PRIVATE) && remoteMsgId != null + && !selfAddressed && !isTypeGroupChat) { processMessageReceipts(account, packet, query); } @@ -783,11 +785,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (displayed != null) { final String id = displayed.getAttribute("id"); final Jid sender = displayed.getAttributeAsJid("sender"); - if (packet.fromAccount(account)) { - Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid()); - if (conversation != null && (query == null || query.isCatchup())) { - mXmppConnectionService.markRead(conversation); - } + if (packet.fromAccount(account) && !selfAddressed) { + dismissNotification(account, counterpart, query); } else if (isTypeGroupChat) { Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid()); if (conversation != null && id != null && sender != null) { @@ -820,6 +819,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece mXmppConnectionService.markMessage(message, Message.STATUS_SEND_DISPLAYED); message = message.prev(); } + if (displayedMessage != null && selfAddressed) { + dismissNotification(account, counterpart, query); + } } } @@ -837,6 +839,13 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } } + private void dismissNotification(Account account, Jid counterpart, MessageArchiveService.Query query) { + Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid()); + if (conversation != null && (query == null || query.isCatchup())) { + mXmppConnectionService.markRead(conversation); //TODO only mark messages read that are older than timestamp + } + } + private static Jid getTrueCounterpart(Element mucUserElement, Jid fallback) { final Element item = mucUserElement == null ? null : mucUserElement.findChild("item"); Jid result = item == null ? null : item.getAttributeAsJid("jid"); |