only offer message correction for the very last message

This commit is contained in:
Daniel Gultsch 2016-02-17 16:51:36 +01:00
parent 3626e4b3a0
commit 59978e157c
4 changed files with 37 additions and 8 deletions

View file

@ -227,11 +227,18 @@ public class Conversation extends AbstractEntity implements Blockable {
return null; return null;
} }
public Message findMessageWithRemoteIdAndCounterpart(String id, Jid counterpart) { public Message findMessageWithRemoteIdAndCounterpart(String id, Jid counterpart, boolean received, boolean carbon) {
synchronized (this.messages) { synchronized (this.messages) {
for(Message message : this.messages) { for(int i = this.messages.size() - 1; i >= 0; --i) {
if(id.equals(message.getRemoteMsgId()) && counterpart.equals(message.getCounterpart())) { Message message = messages.get(i);
if (counterpart.equals(message.getCounterpart())
&& ((message.getStatus() == Message.STATUS_RECEIVED) == received)
&& (carbon == message.isCarbon() || received) ) {
if (id.equals(message.getRemoteMsgId())) {
return message; return message;
} else {
return null;
}
} }
} }
} }

View file

@ -428,6 +428,21 @@ public class Message extends AbstractEntity {
} }
} }
public boolean isLastCorrectableMessage() {
Message next = next();
while(next != null) {
if (next.isCorrectable()) {
return false;
}
next = next.next();
}
return isCorrectable();
}
private boolean isCorrectable() {
return getStatus() != STATUS_RECEIVED && !isCarbon();
}
public boolean mergeable(final Message message) { public boolean mergeable(final Message message) {
return message != null && return message != null &&
(message.getType() == Message.TYPE_TEXT && (message.getType() == Message.TYPE_TEXT &&

View file

@ -336,6 +336,7 @@ public class MessageParser extends AbstractParser implements
if (isTypeGroupChat) { if (isTypeGroupChat) {
if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) { if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) {
status = Message.STATUS_SEND_RECEIVED; status = Message.STATUS_SEND_RECEIVED;
isCarbon = true; //not really carbon but received from another resource
if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status)) { if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status)) {
return; return;
} else if (remoteMsgId == null || Config.IGNORE_ID_REWRITE_IN_MUC) { } else if (remoteMsgId == null || Config.IGNORE_ID_REWRITE_IN_MUC) {
@ -395,7 +396,10 @@ public class MessageParser extends AbstractParser implements
} }
if (replacementId != null && mXmppConnectionService.allowMessageCorrection()) { if (replacementId != null && mXmppConnectionService.allowMessageCorrection()) {
Message replacedMessage = conversation.findMessageWithRemoteIdAndCounterpart(replacementId, counterpart); Message replacedMessage = conversation.findMessageWithRemoteIdAndCounterpart(replacementId,
counterpart,
message.getStatus() == Message.STATUS_RECEIVED,
message.isCarbon());
if (replacedMessage != null) { if (replacedMessage != null) {
final boolean fingerprintsMatch = replacedMessage.getAxolotlFingerprint() == null final boolean fingerprintsMatch = replacedMessage.getAxolotlFingerprint() == null
|| replacedMessage.getAxolotlFingerprint().equals(message.getAxolotlFingerprint()); || replacedMessage.getAxolotlFingerprint().equals(message.getAxolotlFingerprint());

View file

@ -514,6 +514,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private void populateContextMenu(ContextMenu menu) { private void populateContextMenu(ContextMenu menu) {
final Message m = this.selectedMessage; final Message m = this.selectedMessage;
Message relevantForCorrection = m;
while(relevantForCorrection.mergeable(relevantForCorrection.next())) {
relevantForCorrection = relevantForCorrection.next();
}
if (m.getType() != Message.TYPE_STATUS) { if (m.getType() != Message.TYPE_STATUS) {
activity.getMenuInflater().inflate(R.menu.message_context, menu); activity.getMenuInflater().inflate(R.menu.message_context, menu);
menu.setHeaderTitle(R.string.message_options); menu.setHeaderTitle(R.string.message_options);
@ -530,9 +534,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
&& m.treatAsDownloadable() != Message.Decision.MUST) { && m.treatAsDownloadable() != Message.Decision.MUST) {
copyText.setVisible(true); copyText.setVisible(true);
} }
if (m.getType() == Message.TYPE_TEXT if (relevantForCorrection.getType() == Message.TYPE_TEXT
&& m.getStatus() != Message.STATUS_RECEIVED && relevantForCorrection.isLastCorrectableMessage()) {
&& !m.isCarbon()) {
correctMessage.setVisible(true); correctMessage.setVisible(true);
} }
if ((m.getType() != Message.TYPE_TEXT if ((m.getType() != Message.TYPE_TEXT