Skip to content

Commit 2c8fafc

Browse files
committed
fix 添加消息去重
1 parent 33018bb commit 2c8fafc

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

android/messagelist/src/main/java/cn/jiguang/imui/messages/MsgListAdapter.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,18 @@ private class Wrapper<DATA> {
374374
* @param messages message to be add
375375
* @param scrollToBottom if true scroll list to bottom
376376
*/
377-
public void addToStart(List<MESSAGE> messages, boolean scrollToBottom) {
377+
public void addToStart(List<MESSAGE> messages, boolean scrollToBottom, boolean check) {
378378
boolean first = mItems.isEmpty();
379379
updateShowTimeItem(messages, first, true);
380380
for (int i = 0; i < messages.size(); i++) {//3 2 1
381381
MESSAGE message = messages.get(i);
382382

383+
if (check) {
384+
int position = getMessagePositionById(message.getMsgId());
385+
if (position >= 0) {
386+
continue;
387+
}
388+
}
383389
mItems.add(0, new Wrapper<>(message));
384390
notifyItemRangeInserted(0, 1);
385391
addImage(message, false);
@@ -520,10 +526,10 @@ public void updateMessage(String oldId, MESSAGE newMessage) {
520526
if (mLayoutManager != null) {
521527
mLayoutManager.requestLayout();
522528
}
523-
}else {
529+
} else {
524530
List<MESSAGE> list = new ArrayList<>();
525531
list.add(newMessage);
526-
addToStart(list,true);
532+
addToStart(list, true, false);
527533
}
528534

529535
}

android/src/main/java/cn/jiguang/imui/messagelist/ReactMsgListManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void loadAvatarImage(ImageView avatarImageView, String string) {
127127
return;
128128
}
129129
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
130-
if(reactContext.getCurrentActivity().isDestroyed()){
130+
if (reactContext.getCurrentActivity().isDestroyed()) {
131131
return;
132132
}
133133
}
@@ -392,7 +392,7 @@ public void setInitList(MessageList messageList, ReadableArray messages) {
392392
RCTMessage rctMessage = configMessage(messages.getMap(i));
393393
list.add(rctMessage);
394394
}
395-
mAdapter.addToStart(list, true);
395+
mAdapter.addToStart(list, true, false);
396396
}
397397
}
398398

@@ -508,7 +508,7 @@ public void onReceive(Context context, Intent intent) {
508508
activity.runOnUiThread(new Runnable() {
509509
@Override
510510
public void run() {
511-
mAdapter.addToStart(list, false);
511+
mAdapter.addToStart(list, false, true);
512512
}
513513
});
514514
}

0 commit comments

Comments
 (0)