aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-03-11 21:31:30 +0100
committersteckbrief <steckbrief@chefmail.de>2016-03-11 21:31:30 +0100
commitbfc5000b6aa3d401ad80e04c43a6671aa9c2c619 (patch)
treea662cf642e413d8dd7cc40ee1d647406bfe7e5c3 /src/main/java
parent27c9c0aa21e3ec1a5801f6c3279caf0cd4fe9248 (diff)
Fixes FS#139: Do not merge messages at all
Diffstat (limited to '')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Message.java103
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java40
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java12
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java9
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java3
8 files changed, 28 insertions, 149 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java b/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
index b822ef0e..3a4c3d4b 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
@@ -260,16 +260,12 @@ public class Conversation extends AbstractEntity implements Blockable {
return null;
}
+ // TODO Check if this is really necessary
public void populateWithMessages(final List<Message> messages) {
synchronized (this.messages) {
messages.clear();
messages.addAll(this.messages);
}
- for(Iterator<Message> iterator = messages.iterator(); iterator.hasNext();) {
- if (iterator.next().wasMergedIntoPrevious()) {
- iterator.remove();
- }
- }
}
@Override
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
index f1da885e..9fbfce54 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
@@ -5,11 +5,8 @@ import android.database.Cursor;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Arrays;
-import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
-import de.thedevstack.conversationsplus.utils.GeoHelper;
import de.thedevstack.conversationsplus.utils.MimeUtils;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -344,10 +341,6 @@ public class Message extends AbstractEntity {
this.carbon = carbon;
}
- public void setEdited(String edited) {
- this.edited = edited;
- }
-
public boolean edited() {
return this.edited != null;
}
@@ -356,10 +349,6 @@ public class Message extends AbstractEntity {
this.trueCounterpart = trueCounterpart;
}
- public Jid getTrueCounterpart() {
- return this.trueCounterpart;
- }
-
public Transferable getTransferable() {
return this.transferable;
}
@@ -391,8 +380,7 @@ public class Message extends AbstractEntity {
} else {
return this.remoteMsgId == null
&& this.counterpart.equals(message.getCounterpart())
- && body.equals(otherBody)
- && Math.abs(this.getTimeSent() - message.getTimeSent()) < Config.MESSAGE_MERGE_WINDOW * 1000;
+ && body.equals(otherBody);
}
}
}
@@ -425,95 +413,8 @@ 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) {
- return message != null &&
- (message.getType() == Message.TYPE_TEXT &&
- this.getTransferable() == null &&
- message.getTransferable() == null &&
- message.getEncryption() != Message.ENCRYPTION_PGP &&
- message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED &&
- this.getType() == message.getType() &&
- //this.getStatus() == message.getStatus() &&
- isStatusMergeable(this.getStatus(), message.getStatus()) &&
- this.getEncryption() == message.getEncryption() &&
- this.getCounterpart() != null &&
- this.getCounterpart().equals(message.getCounterpart()) &&
- this.edited() == message.edited() &&
- (message.getTimeSent() - this.getTimeSent()) <= (Config.MESSAGE_MERGE_WINDOW * 1000) &&
- !GeoHelper.isGeoUri(message.getBody()) &&
- !GeoHelper.isGeoUri(this.getBody()) &&
- message.treatAsDownloadable() == Decision.NEVER &&
- this.treatAsDownloadable() == Decision.NEVER &&
- !message.getBody().startsWith(ME_COMMAND) &&
- !this.getBody().startsWith(ME_COMMAND) &&
- this.isTrusted() == message.isTrusted()
- );
- }
-
- private static boolean isStatusMergeable(int a, int b) {
- return a == b || (
- (a == Message.STATUS_SEND_RECEIVED && b == Message.STATUS_UNSEND)
- || (a == Message.STATUS_SEND_RECEIVED && b == Message.STATUS_SEND)
- || (a == Message.STATUS_UNSEND && b == Message.STATUS_SEND)
- || (a == Message.STATUS_UNSEND && b == Message.STATUS_SEND_RECEIVED)
- || (a == Message.STATUS_SEND && b == Message.STATUS_UNSEND)
- || (a == Message.STATUS_SEND && b == Message.STATUS_SEND_RECEIVED)
- );
- }
-
- public String getMergedBody() {
- StringBuilder body = new StringBuilder(this.body);
- Message current = this;
- while(current.mergeable(current.next())) {
- current = current.next();
- body.append(MERGE_SEPARATOR);
- body.append(current.getBody());
- }
- return body.toString();
- }
-
public boolean hasMeCommand() {
- return getMergedBody().startsWith(ME_COMMAND);
- }
-
- public int getMergedStatus() {
- int status = this.status;
- Message current = this;
- while(current.mergeable(current.next())) {
- current = current.next();
- status = current.status;
- }
- return status;
- }
-
- public long getMergedTimeSent() {
- long time = this.timeSent;
- Message current = this;
- while(current.mergeable(current.next())) {
- current = current.next();
- time = current.timeSent;
- }
- return time;
- }
-
- public boolean wasMergedIntoPrevious() {
- Message prev = this.prev();
- return prev != null && prev.mergeable(this);
+ return getBody().startsWith(ME_COMMAND);
}
public boolean trusted() {
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
index 29910815..941aaae1 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
@@ -991,11 +991,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private void sendUnsentMessages(final Conversation conversation) {
conversation.findWaitingMessages(new Conversation.OnMessageFound() {
- @Override
- public void onMessageFound(Message message) {
- resendMessage(message, true);
- }
- });
+ @Override
+ public void onMessageFound(Message message) {
+ resendMessage(message, true);
+ }
+ });
}
public void resendMessage(final Message message, final boolean delay) {
@@ -2069,7 +2069,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (callback != null) {
callback.onConferenceConfigurationFetched(conversation);
}
- Log.d(Config.LOGTAG,account.getJid().toBareJid()+": fetched muc configuration for "+conversation.getJid().toBareJid()+" - "+features.toString());
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetched muc configuration for " + conversation.getJid().toBareJid() + " - " + features.toString());
updateConversationUi();
} else if (packet.getType() == IqPacket.TYPE.ERROR) {
if (callback != null) {
@@ -2235,9 +2235,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
final Account account = conversation.getAccount();
final Session otrSession = conversation.getOtrSession();
Logging.d(Config.LOGTAG,
- account.getJid().toBareJid() + " otr session established with "
- + conversation.getJid() + "/"
- + otrSession.getSessionID().getUserID());
+ account.getJid().toBareJid() + " otr session established with "
+ + conversation.getJid() + "/"
+ + otrSession.getSessionID().getUserID());
conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {
@Override
@@ -2275,7 +2275,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
packet.setFrom(account.getJid());
MessageGenerator.addMessageHints(packet);
packet.setAttribute("to", otrSession.getSessionID().getAccountID() + "/"
- + otrSession.getSessionID().getUserID());
+ + otrSession.getSessionID().getUserID());
try {
packet.setBody(otrSession
.transformSending(CryptoHelper.FILETRANSFER
@@ -2746,21 +2746,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void resendFailedMessages(final Message message) {
- final Collection<Message> messages = new ArrayList<>();
- Message current = message;
- while (current.getStatus() == Message.STATUS_SEND_FAILED) {
- messages.add(current);
- if (current.mergeable(current.next())) {
- current = current.next();
- } else {
- break;
- }
- }
- for (final Message msg : messages) {
- msg.setTime(System.currentTimeMillis());
- markMessage(msg, Message.STATUS_WAITING);
- this.resendMessage(msg, false);
- }
+ if (message.getStatus() == Message.STATUS_SEND_FAILED) {
+ message.setTime(System.currentTimeMillis());
+ markMessage(message, Message.STATUS_WAITING);
+ this.resendMessage(message, false);
+ }
}
public void clearConversationHistory(final Conversation conversation) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
index 44132ce3..e700d6e9 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
@@ -631,7 +631,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
private void copyText(Message message) {
- if (activity.copyTextToClipboard(message.getMergedBody(),
+ if (activity.copyTextToClipboard(message.getBody(),
R.string.message_text)) {
Toast.makeText(activity, R.string.message_copied_to_clipboard,
Toast.LENGTH_SHORT).show();
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
index cc6ea18c..1d8af20c 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
@@ -134,7 +134,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI
- && message.getMergedStatus() <= Message.STATUS_RECEIVED;
+ && message.getStatus() <= Message.STATUS_RECEIVED;
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getTransferable() != null) {
FileParams params = message.getFileParams();
if (params.size > (1.5 * 1024 * 1024)) {
@@ -146,7 +146,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
error = true;
}
}
- switch (message.getMergedStatus()) {
+ switch (message.getStatus()) {
case Message.STATUS_WAITING:
info = getContext().getString(R.string.waiting);
break;
@@ -218,7 +218,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
String formatedTime = UIHelper.readableTimeDifferenceFull(getContext(),
- message.getMergedTimeSent());
+ message.getTimeSent());
if (message.getStatus() <= Message.STATUS_RECEIVED) {
if ((filesize != null) && (info != null)) {
viewHolder.time.setText(formatedTime + " \u00B7 " + filesize +" \u00B7 " + info);
@@ -282,9 +282,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
final String nick = UIHelper.getMessageDisplayName(message);
String body;
try {
- body = message.getMergedBody().replaceAll("^" + Message.ME_COMMAND, nick + " ");
+ body = message.getBody().replaceAll("^" + Message.ME_COMMAND, nick + " ");
} catch (ArrayIndexOutOfBoundsException e) {
- body = message.getMergedBody();
+ body = message.getBody();
}
final SpannableString formattedBody = new SpannableString(body);
int i = body.indexOf(Message.MERGE_SEPARATOR);
@@ -533,7 +533,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.status_message.setVisibility(View.VISIBLE);
viewHolder.contact_picture.setVisibility(View.VISIBLE);
if (conversation.getMode() == Conversation.MODE_SINGLE) {
- viewHolder.contact_picture.setImageBitmap(AvatarService.getInstance().get(conversation.getContact(),
+ viewHolder.contact_picture.setImageBitmap(AvatarService.getInstance().get(conversation.getContact(),
activity.getPixel(32)));
viewHolder.contact_picture.setAlpha(0.5f);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
index 63ed8dc7..2e7e8354 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
@@ -175,6 +175,6 @@ public class MessageDetailsDialog extends AbstractAlertDialog {
*/
protected void displayMessageSentTime(View view, Message message) {
TextView timeSent = (TextView) view.findViewById(R.id.dlgMsgDetTimeSent);
- timeSent.setText(DateFormat.format("dd.MM.yyyy kk:mm:ss", new Date(message.getMergedTimeSent())));
+ timeSent.setText(DateFormat.format("dd.MM.yyyy kk:mm:ss", new Date(message.getTimeSent())));
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java
index 859a6069..8e2909ad 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationMoreMessagesLoadedListener.java
@@ -136,15 +136,6 @@ public class ConversationMoreMessagesLoadedListener implements XmppConnectionSer
for (int i = 0; i < messages.size(); ++i) {
if (uuid.equals(messages.get(i).getUuid())) {
return i;
- } else {
- Message next = messages.get(i);
- while(next != null && next.wasMergedIntoPrevious()) {
- if (uuid.equals(next.getUuid())) {
- return i;
- }
- next = next.next();
- }
-
}
}
return 0;
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
index 7afc3fa4..6a668938 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
@@ -11,9 +11,10 @@ import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.persistance.FileBackend;
/**
- * Created by tzur on 15.12.2015.
+ * Utility class to work with messages.
*/
public final class MessageUtil {
+
public static boolean wasHighlightedOrPrivate(final Message message) {
final String nick = message.getConversation().getMucOptions().getActualNick();
final Pattern highlight = generateNickHighlightPattern(nick);