diff --git a/ring-android/app/src/main/java/cx/ring/service/LocalService.java b/ring-android/app/src/main/java/cx/ring/service/LocalService.java index c781219917793f3bc3e0fc51a4d9529f375d3d96..f2e9a3aa893881a0f46493eb1acef02d76c43351 100644 --- a/ring-android/app/src/main/java/cx/ring/service/LocalService.java +++ b/ring-android/app/src/main/java/cx/ring/service/LocalService.java @@ -900,7 +900,6 @@ public class LocalService extends Service implements Observer<DaemonEvent> { @Override protected Map<String, Conversation> doInBackground(Void... params) { - final Map<String, Conversation> ret = new HashMap<>(); try { final List<HistoryCall> history = mHistoryService.getAll(); final List<HistoryText> historyTexts = mHistoryService.getAllTextMessages(); @@ -911,7 +910,7 @@ public class LocalService extends Service implements Observer<DaemonEvent> { CallContact contact = getCreateContact(call.getContactID(), call.getContactKey(), call.getNumber()); Map.Entry<String, Conversation> merge = null; - for (Map.Entry<String, Conversation> ce : ret.entrySet()) { + for (Map.Entry<String, Conversation> ce : conversations.entrySet()) { Conversation conversation = ce.getValue(); if ((contact.getId() > 0 && contact.getId() == conversation.getContact().getId()) || conversation.getContact().hasNumber(call.getNumber())) { merge = ce; @@ -922,25 +921,25 @@ public class LocalService extends Service implements Observer<DaemonEvent> { Conversation conversation = merge.getValue(); if (conversation.getContact().getId() <= 0 && contact.getId() > 0) { conversation.setContact(contact); - ret.remove(merge.getKey()); - ret.put(contact.getIds().get(0), conversation); + conversations.remove(merge.getKey()); + conversations.put(contact.getIds().get(0), conversation); } conversation.addHistoryCall(call); continue; } String key = contact.getIds().get(0); - if (ret.containsKey(key)) { - ret.get(key).addHistoryCall(call); + if (conversations.containsKey(key)) { + conversations.get(key).addHistoryCall(call); } else { Conversation conversation = new Conversation(contact); conversation.addHistoryCall(call); - ret.put(key, conversation); + conversations.put(key, conversation); } } for (HistoryText htext : historyTexts) { CallContact contact = getCreateContact(htext.getContactID(), htext.getContactKey(), htext.getNumber()); - Tuple<HistoryEntry, HistoryCall> p = findHistoryByCallId(ret, htext.getCallId()); + Tuple<HistoryEntry, HistoryCall> p = findHistoryByCallId(conversations, htext.getCallId()); if (contact == null && p != null) { contact = p.first.getContact(); @@ -960,12 +959,14 @@ public class LocalService extends Service implements Observer<DaemonEvent> { } String key = contact.getIds().get(0); - if (ret.containsKey(key)) { - ret.get(key).addTextMessage(msg); + if (conversations.containsKey(key)) { + if (!conversations.get(key).getTextMessages().contains(msg)) { + conversations.get(key).addTextMessage(msg); + } } else { Conversation c = new Conversation(contact); c.addTextMessage(msg); - ret.put(key, c); + conversations.put(key, c); } } @@ -993,7 +994,7 @@ public class LocalService extends Service implements Observer<DaemonEvent> { Conversation conv = null; ArrayList<String> ids = contact.getIds(); for (String id : ids) { - conv = ret.get(id); + conv = conversations.get(id); if (conv != null) { break; } @@ -1003,24 +1004,24 @@ public class LocalService extends Service implements Observer<DaemonEvent> { } else { conv = new Conversation(contact); conv.addConference(conf); - ret.put(ids.get(0), conv); + conversations.put(ids.get(0), conv); } } } - for (Conversation c : ret.values()) { + for (Conversation c : conversations.values()) { Log.w(TAG, "Conversation : " + c.getContact().getId() + " " + c.getContact().getDisplayName() + " " + c.getLastNumberUsed(c.getLastAccountUsed()) + " " + c.getLastInteraction().toString()); } for (int i = 0; i < localContactCache.size(); i++) { CallContact contact = localContactCache.valueAt(i); String key = contact.getIds().get(0); - if (!ret.containsKey(key)) { - ret.put(key, new Conversation(contact)); + if (!conversations.containsKey(key)) { + conversations.put(key, new Conversation(contact)); } } } catch (Exception e) { Log.e(TAG, "ConversationLoader doInBackground", e); } - return ret; + return conversations; } } @@ -1089,13 +1090,13 @@ public class LocalService extends Service implements Observer<DaemonEvent> { mMessageNotificationBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(NotificationCompat.PRIORITY_HIGH) .setDefaults(NotificationCompat.DEFAULT_ALL) - .setSmallIcon(R.drawable.ic_ring_logo_white) - .setContentTitle(contact.getDisplayName()); - String[] split = contact.getDisplayName().split(":"); - if (split.length > 0) { - mLastBlockchainQuery = split[1]; - mAccountService.lookupAddress("", "", mLastBlockchainQuery); - } + .setSmallIcon(R.drawable.ic_ring_logo_white); + } + mMessageNotificationBuilder.setContentTitle(contact.getDisplayName()); + String[] split = contact.getDisplayName().split(":"); + if (split.length > 0) { + mLastBlockchainQuery = split[1]; + mAccountService.lookupAddress("", "", mLastBlockchainQuery); } Intent c_intent = new Intent(Intent.ACTION_VIEW) .setClass(this, ConversationActivity.class) diff --git a/ring-android/libringclient/src/main/java/cx/ring/model/TextMessage.java b/ring-android/libringclient/src/main/java/cx/ring/model/TextMessage.java index 466adad90943b9d9b413abf8b3341e3ef1c31e65..4871d30a4b16a04fef7f0d015965752e90968a58 100644 --- a/ring-android/libringclient/src/main/java/cx/ring/model/TextMessage.java +++ b/ring-android/libringclient/src/main/java/cx/ring/model/TextMessage.java @@ -212,4 +212,28 @@ public class TextMessage { mNotified = noti; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TextMessage that = (TextMessage) o; + + if (mTimestamp != that.mTimestamp) { + return false; + } + return mMessage.equals(that.mMessage); + + } + + @Override + public int hashCode() { + int result = (int) (mTimestamp ^ (mTimestamp >>> 32)); + result = 31 * result + mMessage.hashCode(); + return result; + } }