From d84c243799c61f82ce52145c6ff302401c56dfa4 Mon Sep 17 00:00:00 2001 From: wangcongtao Date: Fri, 21 Feb 2020 11:45:12 +0800 Subject: [PATCH] opt --- .../com/mogo/connection/socket/SocketManager.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/foudations/mogo-connection/src/main/java/com/mogo/connection/socket/SocketManager.java b/foudations/mogo-connection/src/main/java/com/mogo/connection/socket/SocketManager.java index 3a2b0a47e8..48b58bbea9 100644 --- a/foudations/mogo-connection/src/main/java/com/mogo/connection/socket/SocketManager.java +++ b/foudations/mogo-connection/src/main/java/com/mogo/connection/socket/SocketManager.java @@ -74,6 +74,7 @@ public class SocketManager implements IMogoSocketManager, OnSocketReceiveCallbac private SocketConnManager mSocketConnManager; + private long mLastMsgId = Long.MAX_VALUE; @Override public void init( Context context, String appId ) { @@ -91,15 +92,17 @@ public class SocketManager implements IMogoSocketManager, OnSocketReceiveCallbac List< IMogoOnMessageListener > listeners = mListeners.get( msgType ); if ( listeners != null && !listeners.isEmpty() ) { Iterator< IMogoOnMessageListener > iterator = listeners.iterator(); + if ( msgId != 0 ) { //兼容老版本 + if ( mLastMsgId == msgId ) { // 避免消息重发 + return; + } + } + mLastMsgId = msgId; while ( iterator.hasNext() ) { IMogoOnMessageListener listener = iterator.next(); if ( listener != null ) { - Object obj = GsonUtil.objectFromJson( payload.getPayload().toStringUtf8(), listener.target() ); - if ( obj instanceof IMessageResponse ) { - ( ( IMessageResponse ) obj ).setMsgId( msgId ); - } Logger.d(TAG, "received msg == %s, msgId = %s", payload.getPayload().toStringUtf8(), msgId); - listener.onMsgReceived( obj ); + listener.onMsgReceived( GsonUtil.objectFromJson( payload.getPayload().toStringUtf8(), listener.target() ) ); } } }