From b5bce6b1dae3a3e464bf525e1d6301265405e4ef Mon Sep 17 00:00:00 2001 From: Monet Lee Date: Thu, 14 Nov 2024 16:38:01 +0800 Subject: [PATCH] refactor: remove batchListener. (#729) * refactor: remove batchListener. * comment update version file workflows. * restore code. * revert workflow file. * fix: update to correct msgListener. --------- Co-authored-by: OpenIM-Gordon <46924906+FGadvancer@users.noreply.github.com> --- internal/conversation_msg/conversation_msg.go | 16 ++++------------ open_im_sdk/em.go | 14 -------------- open_im_sdk/listener.go | 4 ---- open_im_sdk/userRelated.go | 10 ---------- open_im_sdk_callback/callback_client.go | 5 ----- wasm/event_listener/listener.go | 7 ------- wasm/wasm_wrapper/wasm_init_login.go | 6 ------ 7 files changed, 4 insertions(+), 58 deletions(-) diff --git a/internal/conversation_msg/conversation_msg.go b/internal/conversation_msg/conversation_msg.go index 219625a95..ebf2ffb39 100644 --- a/internal/conversation_msg/conversation_msg.go +++ b/internal/conversation_msg/conversation_msg.go @@ -56,7 +56,6 @@ type Conversation struct { ConversationListener func() open_im_sdk_callback.OnConversationListener msgListener func() open_im_sdk_callback.OnAdvancedMsgListener msgKvListener func() open_im_sdk_callback.OnMessageKvInfoListener - batchMsgListener func() open_im_sdk_callback.OnBatchMsgListener businessListener func() open_im_sdk_callback.OnCustomBusinessListener recvCH chan common.Cmd2Value loginUserID string @@ -88,10 +87,6 @@ func (c *Conversation) SetMsgKvListener(msgKvListener func() open_im_sdk_callbac c.msgKvListener = msgKvListener } -func (c *Conversation) SetBatchMsgListener(batchMsgListener func() open_im_sdk_callback.OnBatchMsgListener) { - c.batchMsgListener = batchMsgListener -} - func (c *Conversation) SetBusinessListener(businessListener func() open_im_sdk_callback.OnCustomBusinessListener) { c.businessListener = businessListener } @@ -436,11 +431,8 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) { } log.ZDebug(ctx, "before trigger msg", "cost time", time.Since(b).Seconds(), "len", len(allMsg)) - if c.batchMsgListener() != nil { - c.batchNewMessages(ctx, newMessages, conversationChangedSet, newConversationSet, onlineMap) - } else { - c.newMessage(ctx, newMessages, conversationChangedSet, newConversationSet, onlineMap) - } + c.newMessage(ctx, newMessages, conversationChangedSet, newConversationSet, onlineMap) + if len(newConversationSet) > 0 { c.doUpdateConversation(common.Cmd2Value{Value: common.UpdateConNode{Action: constant.NewConDirect, Args: utils.StructToJsonString(mapConversationToList(newConversationSet))}}) } @@ -760,7 +752,7 @@ func (c *Conversation) batchNewMessages(ctx context.Context, newMessagesList sdk } if len(needNotificationMsgList) != 0 { - c.batchMsgListener().OnRecvOfflineNewMessages(utils.StructToJsonString(needNotificationMsgList)) + c.msgListener().OnRecvOfflineNewMessage(utils.StructToJsonString(needNotificationMsgList)) } } else { // online for _, w := range newMessagesList { @@ -772,7 +764,7 @@ func (c *Conversation) batchNewMessages(ctx context.Context, newMessagesList sdk } if len(needNotificationMsgList) != 0 { - c.batchMsgListener().OnRecvNewMessages(utils.StructToJsonString(needNotificationMsgList)) + c.msgListener().OnRecvOnlineOnlyMessage(utils.StructToJsonString(needNotificationMsgList)) } } } diff --git a/open_im_sdk/em.go b/open_im_sdk/em.go index 1df7b452e..42116d7a4 100644 --- a/open_im_sdk/em.go +++ b/open_im_sdk/em.go @@ -241,20 +241,6 @@ func (e *emptyAdvancedMsgListener) OnMsgDeleted(message string) { log.ZWarn(e.ctx, "AdvancedMsgListener is not implemented", nil, "message", message) } -type emptyBatchMsgListener struct{} - -func newEmptyBatchMsgListener() *emptyBatchMsgListener { - return &emptyBatchMsgListener{} -} - -func (e *emptyBatchMsgListener) OnRecvNewMessages(messageList string) { - -} - -func (e *emptyBatchMsgListener) OnRecvOfflineNewMessages(messageList string) { - -} - type emptyUserListener struct { ctx context.Context } diff --git a/open_im_sdk/listener.go b/open_im_sdk/listener.go index a3011f4cd..c9f4a9711 100644 --- a/open_im_sdk/listener.go +++ b/open_im_sdk/listener.go @@ -30,10 +30,6 @@ func SetAdvancedMsgListener(listener open_im_sdk_callback.OnAdvancedMsgListener) listenerCall(UserForSDK.SetAdvancedMsgListener, listener) } -func SetBatchMsgListener(listener open_im_sdk_callback.OnBatchMsgListener) { - listenerCall(UserForSDK.SetBatchMsgListener, listener) -} - func SetUserListener(listener open_im_sdk_callback.OnUserListener) { listenerCall(UserForSDK.SetUserListener, listener) diff --git a/open_im_sdk/userRelated.go b/open_im_sdk/userRelated.go index 89cf4807a..4810dbfbf 100644 --- a/open_im_sdk/userRelated.go +++ b/open_im_sdk/userRelated.go @@ -107,7 +107,6 @@ type LoginMgr struct { friendshipListener open_im_sdk_callback.OnFriendshipListener conversationListener open_im_sdk_callback.OnConversationListener advancedMsgListener open_im_sdk_callback.OnAdvancedMsgListener - batchMsgListener open_im_sdk_callback.OnBatchMsgListener userListener open_im_sdk_callback.OnUserListener signalingListener open_im_sdk_callback.OnSignalingListener businessListener open_im_sdk_callback.OnCustomBusinessListener @@ -140,10 +139,6 @@ func (u *LoginMgr) AdvancedMsgListener() open_im_sdk_callback.OnAdvancedMsgListe return u.advancedMsgListener } -func (u *LoginMgr) BatchMsgListener() open_im_sdk_callback.OnBatchMsgListener { - return u.batchMsgListener -} - func (u *LoginMgr) UserListener() open_im_sdk_callback.OnUserListener { return u.userListener } @@ -215,10 +210,6 @@ func (u *LoginMgr) SetMessageKvInfoListener(messageKvInfoListener open_im_sdk_ca u.msgKvListener = messageKvInfoListener } -func (u *LoginMgr) SetBatchMsgListener(batchMsgListener open_im_sdk_callback.OnBatchMsgListener) { - u.batchMsgListener = batchMsgListener -} - func (u *LoginMgr) SetFriendshipListener(friendshipListener open_im_sdk_callback.OnFriendshipListener) { u.friendshipListener = friendshipListener } @@ -364,7 +355,6 @@ func (u *LoginMgr) setListener(ctx context.Context) { setListener(ctx, &u.groupListener, u.GroupListener, u.group.SetGroupListener, newEmptyGroupListener) setListener(ctx, &u.conversationListener, u.ConversationListener, u.conversation.SetConversationListener, newEmptyConversationListener) setListener(ctx, &u.advancedMsgListener, u.AdvancedMsgListener, u.conversation.SetMsgListener, newEmptyAdvancedMsgListener) - setListener(ctx, &u.batchMsgListener, u.BatchMsgListener, u.conversation.SetBatchMsgListener, nil) setListener(ctx, &u.businessListener, u.BusinessListener, u.conversation.SetBusinessListener, newEmptyCustomBusinessListener) } diff --git a/open_im_sdk_callback/callback_client.go b/open_im_sdk_callback/callback_client.go index 34fd02e40..671c20539 100644 --- a/open_im_sdk_callback/callback_client.go +++ b/open_im_sdk_callback/callback_client.go @@ -77,11 +77,6 @@ type OnAdvancedMsgListener interface { OnMsgEdited(message string) } -type OnBatchMsgListener interface { - OnRecvNewMessages(messageList string) - OnRecvOfflineNewMessages(messageList string) -} - type OnUserListener interface { OnSelfInfoUpdated(userInfo string) OnUserStatusChanged(userOnlineStatus string) diff --git a/wasm/event_listener/listener.go b/wasm/event_listener/listener.go index c188036eb..1d5aba5b4 100644 --- a/wasm/event_listener/listener.go +++ b/wasm/event_listener/listener.go @@ -312,13 +312,6 @@ func NewBatchMessageCallback(callback *js.Value) *BatchMessageCallback { return &BatchMessageCallback{CallbackWriter: NewEventData(callback)} } -func (b *BatchMessageCallback) OnRecvNewMessages(messageList string) { - b.CallbackWriter.SetEvent(utils.GetSelfFuncName()).SetData(messageList).SendMessage() -} -func (b *BatchMessageCallback) OnRecvOfflineNewMessages(messageList string) { - b.CallbackWriter.SetEvent(utils.GetSelfFuncName()).SetData(messageList).SendMessage() -} - type FriendCallback struct { CallbackWriter } diff --git a/wasm/wasm_wrapper/wasm_init_login.go b/wasm/wasm_wrapper/wasm_init_login.go index c5b1dd38a..90e6b4a87 100644 --- a/wasm/wasm_wrapper/wasm_init_login.go +++ b/wasm/wasm_wrapper/wasm_init_login.go @@ -48,11 +48,6 @@ func (s *SetListener) setAdvancedMsgListener() { open_im_sdk.SetAdvancedMsgListener(callback) } -func (s *SetListener) setBatchMessageListener() { - callback := event_listener.NewBatchMessageCallback(s.commonFunc) - open_im_sdk.SetBatchMsgListener(callback) -} - func (s *SetListener) setFriendListener() { callback := event_listener.NewFriendCallback(s.commonFunc) open_im_sdk.SetFriendListener(callback) @@ -80,7 +75,6 @@ func (s *SetListener) setCustomBusinessListener() { func (s *SetListener) SetAllListener() { s.setConversationListener() s.setAdvancedMsgListener() - s.setBatchMessageListener() s.setFriendListener() s.setGroupListener() s.setUserListener()