Skip to content

Commit

Permalink
refactor: remove batchListener. (#729)
Browse files Browse the repository at this point in the history
* refactor: remove batchListener.

* comment update version file workflows.

* restore code.

* revert workflow file.

* fix: update to correct msgListener.

---------

Co-authored-by: OpenIM-Gordon <[email protected]>
  • Loading branch information
mo3et and FGadvancer authored Nov 14, 2024
1 parent a5324fa commit b5bce6b
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 58 deletions.
16 changes: 4 additions & 12 deletions internal/conversation_msg/conversation_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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))}})
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions open_im_sdk/em.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 0 additions & 4 deletions open_im_sdk/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 0 additions & 10 deletions open_im_sdk/userRelated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 0 additions & 5 deletions open_im_sdk_callback/callback_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions wasm/event_listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 0 additions & 6 deletions wasm/wasm_wrapper/wasm_init_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -80,7 +75,6 @@ func (s *SetListener) setCustomBusinessListener() {
func (s *SetListener) SetAllListener() {
s.setConversationListener()
s.setAdvancedMsgListener()
s.setBatchMessageListener()
s.setFriendListener()
s.setGroupListener()
s.setUserListener()
Expand Down

0 comments on commit b5bce6b

Please sign in to comment.