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
This commit is contained in:
parent
3e111e7f58
commit
be70eb5650
|
@ -335,6 +335,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());
|
||||
|
@ -1180,7 +1184,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) {
|
||||
|
@ -1214,7 +1219,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;
|
||||
|
|
|
@ -194,7 +194,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;
|
||||
|
|
|
@ -645,7 +645,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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -586,6 +586,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);
|
||||
}
|
||||
|
@ -663,6 +664,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);
|
||||
}
|
||||
|
@ -792,11 +794,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); //TODO only mark messages read that are older than timestamp
|
||||
}
|
||||
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) {
|
||||
|
@ -827,6 +826,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -844,6 +846,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");
|
||||
|
|
Loading…
Reference in a new issue