Skip to content

Commit

Permalink
merge conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
wangchuxiao-dev committed Feb 11, 2022
2 parents fc9f268 + ffeedf5 commit d6281a2
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 11 deletions.
5 changes: 3 additions & 2 deletions internal/conversation_msg/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (c *Conversation) SyncConversations(operationID string) {
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
}
conversationsOnServer:= common.TransferToLocalConversation(svrList)
conversationsOnServer := common.TransferToLocalConversation(svrList)
aInBNot, bInANot, sameA, sameB := common.CheckConversationListDiff(conversationsOnServer, conversationsOnLocal)
log.NewInfo(operationID, "diff ", aInBNot, bInANot, sameA, sameB)

Expand Down Expand Up @@ -274,6 +274,7 @@ func (c *Conversation) markC2CMessageAsRead(callback open_im_sdk_callback.Base,
c.initBasicInfo(&s, constant.UserMsgType, constant.HasReadReceipt, operationID)
s.Content = sourceMsgIDList
options := make(map[string]bool, 2)
//If there is an error, the coroutine ends, so judgment is not required
resp, _ := c.internalSendMessage(callback, &s, userID, "", operationID, &server_api_params.OfflinePushInfo{}, false, options)
s.ServerMsgID = resp.ServerMsgID
s.SendTime = resp.SendTime
Expand Down Expand Up @@ -376,4 +377,4 @@ func (c *Conversation) DoNotification(msg *server_api_params.MsgData) {
go func() {
c.setConversationNotification(msg, operationID)
}()
}
}
1 change: 1 addition & 0 deletions internal/conversation_msg/conversation_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ func (c *Conversation) doUpdateConversation(c2v common.Cmd2Value) {

case constant.UnreadCountSetZero:
if err := c.db.UpdateColumnsConversation(node.ConID, map[string]interface{}{"unread_count": 0}); err != nil {
log.Error("internal", "UpdateColumnsConversation err", err.Error())
} else {
totalUnreadCount, err := c.db.GetTotalUnreadMsgCount()
if err == nil {
Expand Down
18 changes: 16 additions & 2 deletions internal/conversation_msg/open_im_sdk_conversation_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ func (c *Conversation) MarkC2CMessageAsRead(callback open_im_sdk_callback.Base,
log.NewInfo(operationID, "MarkC2CMessageAsRead args: ", userID, msgIDList)
var unmarshalParams sdk_params_callback.MarkC2CMessageAsReadParams
common.JsonUnmarshalCallback(msgIDList, &unmarshalParams, callback, operationID)
if len(msgIDList) == 0 {
if len(unmarshalParams) == 0 {
conversationID := c.GetConversationIDBySessionType(userID, constant.SingleChatType)
_ = common.TriggerCmdUpdateConversation(common.UpdateConNode{ConID: conversationID, Action: constant.UnreadCountSetZero}, c.ch)
_ = common.TriggerCmdUpdateConversation(common.UpdateConNode{ConID: conversationID, Action: constant.ConChange, Args: []string{conversationID}}, c.ch)
Expand Down Expand Up @@ -1023,6 +1023,21 @@ func (c *Conversation) InsertGroupMessageToLocalStorage(callback open_im_sdk_cal

}

func (c *Conversation) SetConversationStatus(callback open_im_sdk_callback.Base, operationID string, userID string, status int) {
if callback == nil {
log.Error(operationID, "callback is nil")
return
}
fName := utils.GetSelfFuncName()
go func() {
log.NewInfo(operationID, fName, "args: ", userID, status)
//var unmarshalParams sdk.SetConversationStatusParams
//common.JsonUnmarshalAndArgsValidate(userIDRemark, &unmarshalParams, callback, operationID)
//f.setConversationStatus(unmarshalParams, callback, operationID)
//callback.OnSuccess(utils.StructToJsonString(sdk.SetFriendRemarkCallback))
//log.NewInfo(operationID, fName, " callback: ", utils.StructToJsonString(sdk.SetFriendRemarkCallback))
}()
}

//func (c *Conversation) FindMessages(callback common.Base, messageIDList string) {
// go func() {
Expand Down Expand Up @@ -1108,4 +1123,3 @@ func (c *Conversation) GetConversationIDBySessionType(sourceID string, sessionTy
}
return ""
}

4 changes: 3 additions & 1 deletion internal/interaction/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func (u *Heartbeat) Run() {
select {
case r := <-u.cmdCh:
if r.Cmd == constant.CmdLogout {
log.Warn("", "recv logout cmd, Goexit...")
log.Warn(operationID, "recv logout cmd, close conn, set logout state, Goexit...")
u.SetLoginState(constant.Logout)
u.CloseConn()
runtime.Goexit()
}
log.Warn(operationID, "other cmd...", r.Cmd)
Expand Down
12 changes: 9 additions & 3 deletions internal/interaction/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,24 @@ func (w *Ws) reConnSleep(operationID string, sleep int32) {
}

func (w *Ws) ReadData() {
isErrorOccurred := false
for {
isErrorOccurred := false
operationID := utils.OperationIDGenerator()
if isErrorOccurred {
select {
case r := <-w.cmdCh:
if r.Cmd == constant.CmdLogout {
log.Info(operationID, "recv CmdLogout, return, close conn")
w.SetLoginState(constant.Logout)
// w.CloseConn()
return
}
log.Warn(operationID, "other cmd ...", r.Cmd)
case <-time.After(time.Microsecond * time.Duration(100)):
log.Warn(operationID, "timeout(ms)... ", 100)
}
}

isErrorOccurred = false
if w.WsConn.conn == nil {
log.Error(operationID, "conn == nil, ReConn")
w.reConnSleep(operationID, 1)
Expand All @@ -130,9 +132,13 @@ func (w *Ws) ReadData() {
msgType, message, err := w.WsConn.conn.ReadMessage()
if err != nil {
isErrorOccurred = true
if w.loginState == constant.Logout {
log.Error(operationID, "loginState logout ")
continue
}
if w.WsConn.IsFatalError(err) {
log.Error(operationID, "IsFatalError ", err.Error(), "ReConn")
w.reConnSleep(operationID, 1)
w.reConnSleep(operationID, 5)
} else {
log.Warn(operationID, "timeout failed ", err.Error())
}
Expand Down
1 change: 1 addition & 0 deletions internal/login/init_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (u *LoginMgr) logout(callback open_im_sdk_callback.Base, operationID string
if err != nil {
log.Error(operationID, "TriggerCmdLogout failed ", err.Error())
}

timeout := 5
retryTimes := 0
log.Info(operationID, "send to svr logout ...", u.loginUserID)
Expand Down
4 changes: 4 additions & 0 deletions open_im_sdk/open_im_sdk_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func SetSelfInfo(callback open_im_sdk_callback.Base, operationID string, userInf
userForSDK.User().SetSelfInfo(callback, userInfo, operationID)
}

func GetSelfUserInfo(callback open_im_sdk_callback.Base, operationID string) {
userForSDK.User().GetSelfUserInfo(callback, operationID)
}

//////////////////////////group//////////////////////////////////////////
func SetGroupListener(callback open_im_sdk_callback.OnGroupListener) {
if callback == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/data_model_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ type LocalUser struct {
Birth uint32 `gorm:"column:birth" json:"birth"`
Email string `gorm:"column:email;type:varchar(64)" json:"email"`
CreateTime uint32 `gorm:"column:create_time" json:"createTime"`
AppMangerLevel int32 `gorm:"column:app_manger_level" json:"appMangerLevel"`
AppMangerLevel int32 `gorm:"column:app_manger_level" json:"-"`
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
}

Expand Down
7 changes: 5 additions & 2 deletions ws_wrapper/ws_local_server/ws_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"github.com/gorilla/websocket"
utils2 "open_im_sdk/pkg/utils"
"open_im_sdk/sdk_struct"
"open_im_sdk/ws_wrapper/utils"
"reflect"
Expand Down Expand Up @@ -80,8 +81,10 @@ func DelUserRouter(uid string) {
defer UserRouteRwLock.Unlock()
urm, ok := UserRouteMap[uid]
if ok {
wrapSdkLog("DelUserRouter logout, UnInitSDK ", uid)
urm.wsRouter.LogoutNoCallback(uid, "0")
operationID := utils2.OperationIDGenerator()
wrapSdkLog("DelUserRouter logout, UnInitSDK ", uid, operationID)

urm.wsRouter.LogoutNoCallback(uid, operationID)
urm.wsRouter.UnInitSDK()
} else {
wrapSdkLog("no found UserRouteMap: ", uid)
Expand Down

0 comments on commit d6281a2

Please sign in to comment.