diff --git a/internal/conversation_msg/conversation_msg.go b/internal/conversation_msg/conversation_msg.go index e47d1067b..a13edfb6e 100644 --- a/internal/conversation_msg/conversation_msg.go +++ b/internal/conversation_msg/conversation_msg.go @@ -660,7 +660,7 @@ func isContainRevokedList(target string, List []*sdk_struct.MessageRevoked) (boo func (c *Conversation) newMessage(ctx context.Context, newMessagesList sdk_struct.NewMsgList, cc, nc map[string]*model_struct.LocalConversation) { sort.Sort(newMessagesList) - if c.IsBackground.Load() { + if c.GetBackground() { u, err := c.user.GetSelfUserInfo(ctx) if err != nil { log.ZWarn(ctx, "GetSelfUserInfo err", err) diff --git a/internal/interaction/long_conn_mgr.go b/internal/interaction/long_conn_mgr.go index b108b8e1e..d39ada520 100644 --- a/internal/interaction/long_conn_mgr.go +++ b/internal/interaction/long_conn_mgr.go @@ -31,7 +31,6 @@ import ( "strconv" "strings" "sync" - "sync/atomic" "time" "github.com/OpenIMSDK/protocol/sdkws" @@ -94,7 +93,9 @@ type LongConnMgr struct { Syncer *WsRespAsyn encoder Encoder compressor Compressor - IsBackground atomic.Bool + + mutex sync.Mutex + IsBackground bool // write conn lock connWrite *sync.Mutex } @@ -489,8 +490,9 @@ func (c *LongConnMgr) reConn(ctx context.Context, num *int) (needRecon bool, err c.w.Lock() c.connStatus = Connecting c.w.Unlock() - url := fmt.Sprintf("%s?sendID=%s&token=%s&platformID=%d&operationID=%s&isBackground=%t", ccontext.Info(ctx).WsAddr(), - ccontext.Info(ctx).UserID(), ccontext.Info(ctx).Token(), ccontext.Info(ctx).PlatformID(), ccontext.Info(ctx).OperationID(), c.IsBackground.Load()) + url := fmt.Sprintf("%s?sendID=%s&token=%s&platformID=%d&operationID=%s&isBackground=%t", + ccontext.Info(ctx).WsAddr(), ccontext.Info(ctx).UserID(), ccontext.Info(ctx).Token(), + ccontext.Info(ctx).PlatformID(), ccontext.Info(ctx).OperationID(), c.GetBackground()) if c.IsCompression { url += fmt.Sprintf("&compression=%s", "gzip") } @@ -565,6 +567,13 @@ func (c *LongConnMgr) Close(ctx context.Context) { } } +func (c *LongConnMgr) GetBackground() bool { + c.mutex.Lock() + defer c.mutex.Unlock() + return c.IsBackground +} func (c *LongConnMgr) SetBackground(isBackground bool) { - c.IsBackground.Store(isBackground) + c.mutex.Lock() + defer c.mutex.Unlock() + c.IsBackground = isBackground }