aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-03-11 21:34:10 +0100
committersteckbrief <steckbrief@chefmail.de>2016-03-11 21:34:10 +0100
commit864bb77883b2f5d9f9122c102faa4af89d589653 (patch)
treec9d7b675da2b5eb38809dabdd599e43ff0acce3b /src/main/java/eu/siacs
parent8585231be2844ab794cfa63454b1013bae8502f6 (diff)
parentbfc5000b6aa3d401ad80e04c43a6671aa9c2c619 (diff)
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Conflicts: src/main/java/eu/siacs/conversations/entities/Message.java
Diffstat (limited to 'src/main/java/eu/siacs')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java6
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java103
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java40
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java12
-rw-r--r--src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java9
6 files changed, 25 insertions, 147 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java
index 75477d3e..4a9e83a3 100644
--- a/src/main/java/eu/siacs/conversations/entities/Conversation.java
+++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java
@@ -261,16 +261,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/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index 599afc93..f463da54 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -5,11 +5,8 @@ import android.database.Cursor;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Arrays;
-import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
-import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.MimeUtils;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.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/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index fb587817..c9fbf297 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/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/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index 369de781..3c45792f 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -637,7 +637,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/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index f9a82e11..b130df9b 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/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/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java b/src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java
index a5c5e2aa..08916206 100644
--- a/src/main/java/eu/siacs/conversations/ui/listeners/ConversationMoreMessagesLoadedListener.java
+++ b/src/main/java/eu/siacs/conversations/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;