From 8e6430625cd5b6a2bda5fe4d2af8f66a39eb6f14 Mon Sep 17 00:00:00 2001 From: Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Fri, 13 Oct 2023 11:45:40 +0800 Subject: [PATCH] fix: single chat unread status change. (#1171) * fix: to start im or chat, ZooKeeper must be started first. * fix: msg gateway start output err info Signed-off-by: Gordon <1432970085@qq.com> * fix: msg gateway start output err info Signed-off-by: Gordon <1432970085@qq.com> * chore: package path changes Signed-off-by: withchao <993506633@qq.com> * fix: go mod update Signed-off-by: Gordon <1432970085@qq.com> * fix: token update Signed-off-by: Gordon <1432970085@qq.com> * chore: package path changes Signed-off-by: withchao <993506633@qq.com> * chore: package path changes Signed-off-by: withchao <993506633@qq.com> * fix: token update Signed-off-by: Gordon <1432970085@qq.com> * fix: token update Signed-off-by: Gordon <1432970085@qq.com> * fix: token update Signed-off-by: Gordon <1432970085@qq.com> * fix: token update Signed-off-by: Gordon <1432970085@qq.com> * fix: token update Signed-off-by: Gordon <1432970085@qq.com> * fix: token update Signed-off-by: Gordon <1432970085@qq.com> * fix: get all userID Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: msggateway add online status call Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: log change Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: log change Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * chore: network mode change Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * feat: add api of get server time Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * feat: remove go work sum Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix: pull message add isRead field Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: check msg-transfer script Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: script update Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: start don't kill old process Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix: check component Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: pull message set isRead only message come from single. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix: multiple gateway kick user each other. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: multiple gateway kick user each other. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: multiple gateway kick user each other. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: multiple gateway kick user each other. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: multiple gateway kick user each other. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: multiple gateway kick user each other. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix: multiple gateway kick user each other. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: add ex field to update group info. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * cicd: robot automated Change * cicd: robot automated Change * refactor: change project module name. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: change project module name. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: change project module name. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * cicd: robot automated Change * test: for pressure test. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * test: for pressure test. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * test: for pressure test. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * test: message log. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * cicd: robot automated Change * fxi: component check output valid info. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fxi: component check output valid info. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * test: send message test log. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * cicd: robot automated Change * cicd: robot automated Change * test: remove info log. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * feat: api of send message add sendTime field. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * fix: add callback for update user's info. * cicd: robot automated Change * fix: change callback command name. * cicd: robot automated Change * fix: single chat unread status change. * fix: single chat unread status change. * fix: single chat unread status change. * fix: user status change. * cicd: robot automated Change * fix: user status change. * fix: user status change. * fix: user status change. * cicd: robot automated Change * fix: ws close when user logout. --------- Signed-off-by: Gordon <1432970085@qq.com> Signed-off-by: withchao <993506633@qq.com> Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: withchao <993506633@qq.com> Co-authored-by: Xinwei Xiong <3293172751NSS@gmail.com> Co-authored-by: FGadvancer --- go.mod | 2 +- go.sum | 4 +- internal/msggateway/client.go | 10 +- internal/rpc/msg/as_read.go | 70 ++++++--- internal/rpc/user/user.go | 36 +++-- pkg/common/db/cache/user.go | 148 ++++++++++-------- pkg/common/db/controller/user.go | 6 +- pkg/common/db/unrelation/user.go | 12 +- pkg/rpcclient/user.go | 5 +- tools/component/component.go | 3 +- tools/data-conversion/chat/chat.go | 8 +- tools/data-conversion/chat/v2/admin.go | 38 ++--- tools/data-conversion/chat/v2/chat.go | 90 +++++------ tools/data-conversion/openim/common/config.go | 12 +- tools/data-conversion/openim/msg.go | 14 +- tools/data-conversion/openim/mysql.go | 8 +- tools/data-conversion/openim/mysql/cmd.go | 8 +- .../openim/mysql/conversion/conversion.go | 1 + .../openim/mysql/v2/model_struct.go | 16 +- tools/data-conversion/utils/find_insert.go | 5 +- 20 files changed, 279 insertions(+), 217 deletions(-) diff --git a/go.mod b/go.mod index b179b3f5d1..de3adee481 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require github.com/google/uuid v1.3.1 require ( github.com/IBM/sarama v1.41.2 - github.com/OpenIMSDK/protocol v0.0.24 + github.com/OpenIMSDK/protocol v0.0.25 github.com/OpenIMSDK/tools v0.0.14 github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible github.com/go-redis/redis v6.15.9+incompatible diff --git a/go.sum b/go.sum index ee49432e9b..6fcc8ebfd6 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/IBM/sarama v1.41.2 h1:ZDBZfGPHAD4uuAtSv4U22fRZBgst0eEwGFzLj0fb85c= github.com/IBM/sarama v1.41.2/go.mod h1:xdpu7sd6OE1uxNdjYTSKUfY8FaKkJES9/+EyjSgiGQk= -github.com/OpenIMSDK/protocol v0.0.24 h1:wk/S0GOGVh8mBbpmjKxSsyYMhyBazdn/ZcS9VqXfT24= -github.com/OpenIMSDK/protocol v0.0.24/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= +github.com/OpenIMSDK/protocol v0.0.25 h1:AtB0Ia5LO26oqPoPJDIS4UMH3Wb2li96fMgfzI2cr4I= +github.com/OpenIMSDK/protocol v0.0.25/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= github.com/OpenIMSDK/tools v0.0.14 h1:WLof/+WxyPyRST+QkoTKubYCiV73uCLiL8pgnpH/yKQ= github.com/OpenIMSDK/tools v0.0.14/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI= github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= diff --git a/internal/msggateway/client.go b/internal/msggateway/client.go index 739fa9688d..b1eaaf057f 100644 --- a/internal/msggateway/client.go +++ b/internal/msggateway/client.go @@ -207,8 +207,8 @@ func (c *Client) handleMessage(message []byte) error { binaryReq.ReqIdentifier, ) } - c.replyMessage(ctx, &binaryReq, messageErr, resp) - return nil + + return c.replyMessage(ctx, &binaryReq, messageErr, resp) } func (c *Client) setAppBackgroundStatus(ctx context.Context, req Req) ([]byte, error) { @@ -229,7 +229,7 @@ func (c *Client) close() { c.longConnServer.UnRegister(c) } -func (c *Client) replyMessage(ctx context.Context, binaryReq *Req, err error, resp []byte) { +func (c *Client) replyMessage(ctx context.Context, binaryReq *Req, err error, resp []byte) error { errResp := apiresp.ParseError(err) mReply := Resp{ ReqIdentifier: binaryReq.ReqIdentifier, @@ -244,6 +244,10 @@ func (c *Client) replyMessage(ctx context.Context, binaryReq *Req, err error, re if err != nil { log.ZWarn(ctx, "wireBinaryMsg replyMessage", err, "resp", mReply.String()) } + if binaryReq.ReqIdentifier == WsLogoutMsg { + return errors.New("user logout") + } + return nil } func (c *Client) PushMessage(ctx context.Context, msgData *sdkws.MsgData) error { diff --git a/internal/rpc/msg/as_read.go b/internal/rpc/msg/as_read.go index 656849d1c2..c31cd02dd4 100644 --- a/internal/rpc/msg/as_read.go +++ b/internal/rpc/msg/as_read.go @@ -81,7 +81,8 @@ func (m *msgServer) SetConversationHasReadSeq( if err := m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq); err != nil { return nil, err } - if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID, req.UserID, nil, req.HasReadSeq); err != nil { + if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID, + req.UserID, nil, req.HasReadSeq); err != nil { return } return &msg.SetConversationHasReadSeqResp{}, nil @@ -119,7 +120,8 @@ func (m *msgServer) MarkMsgsAsRead( return } } - if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, m.conversationAndGetRecvID(conversation, req.UserID), req.Seqs, hasReadSeq); err != nil { + if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, + m.conversationAndGetRecvID(conversation, req.UserID), req.Seqs, hasReadSeq); err != nil { return } return &msg.MarkMsgsAsReadResp{}, nil @@ -131,44 +133,61 @@ func (m *msgServer) MarkConversationAsRead( ) (resp *msg.MarkConversationAsReadResp, err error) { conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID) if err != nil { - return + return nil, err } hasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID) if err != nil && errs.Unwrap(err) != redis.Nil { - return + return nil, err } - log.ZDebug(ctx, "MarkConversationAsRead", "hasReadSeq", hasReadSeq, "req.HasReadSeq", req.HasReadSeq) var seqs []int64 - if len(req.Seqs) == 0 { + + log.ZDebug(ctx, "MarkConversationAsRead", "hasReadSeq", hasReadSeq, + "req.HasReadSeq", req.HasReadSeq) + if conversation.ConversationType == constant.SingleChatType { for i := hasReadSeq + 1; i <= req.HasReadSeq; i++ { seqs = append(seqs, i) } - } else { - seqs = req.Seqs - } - if len(seqs) > 0 { - log.ZDebug(ctx, "MarkConversationAsRead", "seqs", seqs, "conversationID", req.ConversationID) - if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, seqs); err != nil { - return + + if len(seqs) > 0 { + log.ZDebug(ctx, "MarkConversationAsRead", "seqs", seqs, "conversationID", req.ConversationID) + if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, seqs); err != nil { + return nil, err + } } - } - if req.HasReadSeq > hasReadSeq { - err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq) - if err != nil { - return + if req.HasReadSeq > hasReadSeq { + err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq) + if err != nil { + return nil, err + } + hasReadSeq = req.HasReadSeq } - hasReadSeq = req.HasReadSeq - } - if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, m.conversationAndGetRecvID(conversation, req.UserID), seqs, hasReadSeq); err != nil { - return + if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, + m.conversationAndGetRecvID(conversation, req.UserID), seqs, hasReadSeq); err != nil { + return nil, err + } + + } else if conversation.ConversationType == constant.SuperGroupChatType { + if req.HasReadSeq > hasReadSeq { + err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq) + if err != nil { + return nil, err + } + hasReadSeq = req.HasReadSeq + } + if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID, + req.UserID, seqs, hasReadSeq); err != nil { + return nil, err + } + } + return &msg.MarkConversationAsReadResp{}, nil } func (m *msgServer) sendMarkAsReadNotification( ctx context.Context, conversationID string, - sesstionType int32, + sessionType int32, sendID, recvID string, seqs []int64, hasReadSeq int64, @@ -179,6 +198,9 @@ func (m *msgServer) sendMarkAsReadNotification( Seqs: seqs, HasReadSeq: hasReadSeq, } - m.notificationSender.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips) + err := m.notificationSender.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sessionType, tips) + if err != nil { + log.ZWarn(ctx, "send has read Receipt err", err) + } return nil } diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index d22715f0c0..f2ceb3beb0 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -289,7 +289,8 @@ func (s *userServer) SubscribeOrCancelUsersStatus(ctx context.Context, req *pbus } // GetUserStatus Get the online status of the user. -func (s *userServer) GetUserStatus(ctx context.Context, req *pbuser.GetUserStatusReq) (resp *pbuser.GetUserStatusResp, err error) { +func (s *userServer) GetUserStatus(ctx context.Context, req *pbuser.GetUserStatusReq) (resp *pbuser.GetUserStatusResp, + err error) { onlineStatusList, err := s.UserDatabase.GetUserStatus(ctx, req.UserIDs) if err != nil { return nil, err @@ -298,31 +299,32 @@ func (s *userServer) GetUserStatus(ctx context.Context, req *pbuser.GetUserStatu } // SetUserStatus Synchronize user's online status. -func (s *userServer) SetUserStatus(ctx context.Context, req *pbuser.SetUserStatusReq) (resp *pbuser.SetUserStatusResp, err error) { - err = s.UserDatabase.SetUserStatus(ctx, req.StatusList) +func (s *userServer) SetUserStatus(ctx context.Context, req *pbuser.SetUserStatusReq) (resp *pbuser.SetUserStatusResp, + err error) { + err = s.UserDatabase.SetUserStatus(ctx, req.UserID, req.Status, req.PlatformID) if err != nil { return nil, err } - for _, value := range req.StatusList { - list, err := s.UserDatabase.GetSubscribedList(ctx, value.UserID) - if err != nil { - return nil, err - } - for _, userID := range list { - tips := &sdkws.UserStatusChangeTips{ - FromUserID: value.UserID, - ToUserID: userID, - Status: value.Status, - PlatformID: value.PlatformIDs[0], - } - s.userNotificationSender.UserStatusChangeNotification(ctx, tips) + list, err := s.UserDatabase.GetSubscribedList(ctx, req.UserID) + if err != nil { + return nil, err + } + for _, userID := range list { + tips := &sdkws.UserStatusChangeTips{ + FromUserID: req.UserID, + ToUserID: userID, + Status: req.Status, + PlatformID: req.PlatformID, } + s.userNotificationSender.UserStatusChangeNotification(ctx, tips) } + return &pbuser.SetUserStatusResp{}, nil } // GetSubscribeUsersStatus Get the online status of subscribers. -func (s *userServer) GetSubscribeUsersStatus(ctx context.Context, req *pbuser.GetSubscribeUsersStatusReq) (*pbuser.GetSubscribeUsersStatusResp, error) { +func (s *userServer) GetSubscribeUsersStatus(ctx context.Context, + req *pbuser.GetSubscribeUsersStatusReq) (*pbuser.GetSubscribeUsersStatusResp, error) { userList, err := s.UserDatabase.GetAllSubscribeList(ctx, req.UserID) if err != nil { return nil, err diff --git a/pkg/common/db/cache/user.go b/pkg/common/db/cache/user.go index 8c270c6e47..5fb0fdde62 100644 --- a/pkg/common/db/cache/user.go +++ b/pkg/common/db/cache/user.go @@ -21,6 +21,8 @@ import ( "strconv" "time" + "github.com/OpenIMSDK/tools/log" + "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/user" @@ -51,7 +53,7 @@ type UserCache interface { GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error) DelUsersGlobalRecvMsgOpt(userIDs ...string) UserCache GetUserStatus(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error) - SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error + SetUserStatus(ctx context.Context, userID string, status, platformID int32) error } type UserCacheRedis struct { @@ -198,95 +200,107 @@ func (u *UserCacheRedis) GetUserStatus(ctx context.Context, userIDs []string) ([ return nil, errs.Wrap(err) } onlineStatus.UserID = userID + onlineStatus.Status = constant.Online res = append(res, &onlineStatus) } return res, nil } // SetUserStatus Set the user status and save it in redis. -func (u *UserCacheRedis) SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error { - for _, status := range list { - var isNewKey int64 - UserIDNum := crc32.ChecksumIEEE([]byte(status.UserID)) - modKey := strconv.Itoa(int(UserIDNum % statusMod)) - key := olineStatusKey + modKey - jsonData, err := json.Marshal(status) - if err != nil { +func (u *UserCacheRedis) SetUserStatus(ctx context.Context, userID string, status, platformID int32) error { + UserIDNum := crc32.ChecksumIEEE([]byte(userID)) + modKey := strconv.Itoa(int(UserIDNum % statusMod)) + key := olineStatusKey + modKey + log.ZDebug(ctx, "SetUserStatus args", "userID", userID, "status", status, + "platformID", platformID, "modKey", modKey, "key", key) + isNewKey, err := u.rdb.Exists(ctx, key).Result() + if err != nil { + return errs.Wrap(err) + } + if isNewKey == 0 { + if status == constant.Online { + onlineStatus := user.OnlineStatus{ + UserID: userID, + Status: constant.Online, + PlatformIDs: []int32{platformID}, + } + jsonData, err := json.Marshal(onlineStatus) + if err != nil { + return errs.Wrap(err) + } + _, err = u.rdb.HSet(ctx, key, userID, string(jsonData)).Result() + if err != nil { + return errs.Wrap(err) + } + u.rdb.Expire(ctx, key, userOlineStatusExpireTime) + return nil + } + } + + isNil := false + result, err := u.rdb.HGet(ctx, key, userID).Result() + if err != nil { + if err == redis.Nil { + isNil = true + } else { return errs.Wrap(err) } - isNewKey, err = u.rdb.Exists(ctx, key).Result() + } + + if status == constant.Offline { + if isNil { + log.ZWarn(ctx, "this user not online,maybe trigger order not right", + err, "userStatus", status) + return nil + } + var onlineStatus user.OnlineStatus + err = json.Unmarshal([]byte(result), &onlineStatus) if err != nil { return errs.Wrap(err) } - if isNewKey == 0 { - _, err = u.rdb.HSet(ctx, key, status.UserID, string(jsonData)).Result() + var newPlatformIDs []int32 + for _, val := range onlineStatus.PlatformIDs { + if val != platformID { + newPlatformIDs = append(newPlatformIDs, val) + } + } + if newPlatformIDs == nil { + _, err = u.rdb.HDel(ctx, key, userID).Result() if err != nil { return errs.Wrap(err) } - u.rdb.Expire(ctx, key, userOlineStatusExpireTime) } else { - result, err := u.rdb.HGet(ctx, key, status.UserID).Result() + onlineStatus.PlatformIDs = newPlatformIDs + newjsonData, err := json.Marshal(&onlineStatus) if err != nil { return errs.Wrap(err) } - var onlineStatus user.OnlineStatus - err = json.Unmarshal([]byte(result), &onlineStatus) + _, err = u.rdb.HSet(ctx, key, userID, string(newjsonData)).Result() if err != nil { return errs.Wrap(err) } - onlineStatus.UserID = status.UserID - if status.Status == constant.Offline { - var newPlatformIDs []int32 - for _, val := range onlineStatus.PlatformIDs { - if val != status.PlatformIDs[0] { - newPlatformIDs = append(newPlatformIDs, val) - } - } - if newPlatformIDs == nil { - onlineStatus.Status = constant.Offline - onlineStatus.PlatformIDs = []int32{} - newjsonData, err := json.Marshal(&onlineStatus) - if err != nil { - return errs.Wrap(err) - } - _, err = u.rdb.HSet(ctx, key, status.UserID, string(newjsonData)).Result() - if err != nil { - return errs.Wrap(err) - } - } else { - onlineStatus.PlatformIDs = newPlatformIDs - newjsonData, err := json.Marshal(&onlineStatus) - if err != nil { - return errs.Wrap(err) - } - _, err = u.rdb.HSet(ctx, key, status.UserID, string(newjsonData)).Result() - if err != nil { - return errs.Wrap(err) - } - } - } else { - onlineStatus.Status = constant.Online - // Judging whether to be kicked out. - flag := false - for _, val := range onlineStatus.PlatformIDs { - if val == status.PlatformIDs[0] { - flag = true - break - } - } - if !flag { - onlineStatus.PlatformIDs = append(onlineStatus.PlatformIDs, status.PlatformIDs[0]) - } - newjsonData, err := json.Marshal(&onlineStatus) - if err != nil { - return errs.Wrap(err) - } - _, err = u.rdb.HSet(ctx, key, status.UserID, string(newjsonData)).Result() - if err != nil { - return errs.Wrap(err) - } + } + } else { + var onlineStatus user.OnlineStatus + if !isNil { + err = json.Unmarshal([]byte(result), &onlineStatus) + if err != nil { + return errs.Wrap(err) } } + onlineStatus.Status = constant.Online + onlineStatus.UserID = userID + onlineStatus.PlatformIDs = append(onlineStatus.PlatformIDs, platformID) + newjsonData, err := json.Marshal(&onlineStatus) + if err != nil { + return errs.Wrap(err) + } + _, err = u.rdb.HSet(ctx, key, userID, string(newjsonData)).Result() + if err != nil { + return errs.Wrap(err) + } + } + return nil } diff --git a/pkg/common/db/controller/user.go b/pkg/common/db/controller/user.go index ab86cfd27a..9c6fdc5c47 100644 --- a/pkg/common/db/controller/user.go +++ b/pkg/common/db/controller/user.go @@ -64,7 +64,7 @@ type UserDatabase interface { // GetUserStatus Get the online status of the user GetUserStatus(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error) // SetUserStatus Set the user status and store the user status in redis - SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error + SetUserStatus(ctx context.Context, userID string, status, platformID int32) error } type userDatabase struct { @@ -217,6 +217,6 @@ func (u *userDatabase) GetUserStatus(ctx context.Context, userIDs []string) ([]* } // SetUserStatus Set the user status and save it in redis. -func (u *userDatabase) SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error { - return u.cache.SetUserStatus(ctx, list) +func (u *userDatabase) SetUserStatus(ctx context.Context, userID string, status, platformID int32) error { + return u.cache.SetUserStatus(ctx, userID, status, platformID) } diff --git a/pkg/common/db/unrelation/user.go b/pkg/common/db/unrelation/user.go index 777f27386d..4b4a78c795 100644 --- a/pkg/common/db/unrelation/user.go +++ b/pkg/common/db/unrelation/user.go @@ -163,7 +163,11 @@ func (u *UserMongoDriver) GetAllSubscribeList(ctx context.Context, userID string bson.M{"user_id": SubscriptionPrefix + userID}) err = cursor.Decode(&user) if err != nil { - return nil, errs.Wrap(err) + if err == mongo.ErrNoDocuments { + return []string{}, nil + } else { + return nil, errs.Wrap(err) + } } return user.UserIDList, nil } @@ -176,7 +180,11 @@ func (u *UserMongoDriver) GetSubscribedList(ctx context.Context, userID string) bson.M{"user_id": SubscribedPrefix + userID}) err = cursor.Decode(&user) if err != nil { - return nil, errs.Wrap(err) + if err == mongo.ErrNoDocuments { + return []string{}, nil + } else { + return nil, errs.Wrap(err) + } } return user.UserIDList, nil } diff --git a/pkg/rpcclient/user.go b/pkg/rpcclient/user.go index 6929b4fd9c..c40d957270 100644 --- a/pkg/rpcclient/user.go +++ b/pkg/rpcclient/user.go @@ -173,6 +173,9 @@ func (u *UserRpcClient) GetAllUserIDs(ctx context.Context, pageNumber, showNumbe // SetUserStatus sets the status for a user based on the provided user ID, status, and platform ID. func (u *UserRpcClient) SetUserStatus(ctx context.Context, userID string, status int32, platformID int) error { - _, err := u.Client.SetUserStatus(ctx, &user.SetUserStatusReq{StatusList: []*user.OnlineStatus{{UserID: userID, Status: status, PlatformIDs: []int32{int32(platformID)}}}}) + _, err := u.Client.SetUserStatus(ctx, &user.SetUserStatusReq{ + UserID: userID, + Status: status, PlatformID: int32(platformID), + }) return err } diff --git a/tools/component/component.go b/tools/component/component.go index 9aecfa7041..c995da5f12 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -129,11 +129,10 @@ func exactIP(urll string) string { if strings.HasSuffix(host, ":") { host = host[0 : len(host)-1] } - + return host } - func checkMysql() error { var sqlDB *sql.DB defer func() { diff --git a/tools/data-conversion/chat/chat.go b/tools/data-conversion/chat/chat.go index c71da3dc1d..77c62ee1fd 100644 --- a/tools/data-conversion/chat/chat.go +++ b/tools/data-conversion/chat/chat.go @@ -2,12 +2,14 @@ package main import ( "fmt" - "github.com/openimsdk/open-im-server/v3/tools/data-conversion/chat/conversion" - "github.com/openimsdk/open-im-server/v3/tools/data-conversion/utils" + "log" + "gorm.io/driver/mysql" "gorm.io/gorm" "gorm.io/gorm/logger" - "log" + + "github.com/openimsdk/open-im-server/v3/tools/data-conversion/chat/conversion" + "github.com/openimsdk/open-im-server/v3/tools/data-conversion/utils" ) func main() { diff --git a/tools/data-conversion/chat/v2/admin.go b/tools/data-conversion/chat/v2/admin.go index 4e23e19c26..7bc1b6c1bf 100644 --- a/tools/data-conversion/chat/v2/admin.go +++ b/tools/data-conversion/chat/v2/admin.go @@ -6,45 +6,45 @@ import ( // AppVersion pc端版本管理 type AppVersion struct { - Version string `gorm:"column:version;size:64" json:"version"` + Version string `gorm:"column:version;size:64" json:"version"` Type int `gorm:"column:type;primary_key" json:"type"` - UpdateTime int `gorm:"column:update_time" json:"update_time"` - ForceUpdate bool `gorm:"column:force_update" json:"force_update"` - FileName string `gorm:"column:file_name" json:"file_name"` - YamlName string `gorm:"column:yaml_name" json:"yaml_name"` - UpdateLog string `gorm:"column:update_log" json:"update_log"` + UpdateTime int `gorm:"column:update_time" json:"update_time"` + ForceUpdate bool `gorm:"column:force_update" json:"force_update"` + FileName string `gorm:"column:file_name" json:"file_name"` + YamlName string `gorm:"column:yaml_name" json:"yaml_name"` + UpdateLog string `gorm:"column:update_log" json:"update_log"` } // Admin 后台管理员 type Admin struct { Account string `gorm:"column:account;primary_key;type:char(64)" json:"account"` - Password string `gorm:"column:Password;type:char(64)" json:"password"` - FaceURL string `gorm:"column:FaceURL;type:char(64)" json:"faceURL"` - Nickname string `gorm:"column:Nickname;type:char(64)" json:"nickname"` - UserID string `gorm:"column:UserID;type:char(64)" json:"userID"` //openIM userID - Level int32 `gorm:"column:level;default:1" json:"level"` - CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + Password string `gorm:"column:Password;type:char(64)" json:"password"` + FaceURL string `gorm:"column:FaceURL;type:char(64)" json:"faceURL"` + Nickname string `gorm:"column:Nickname;type:char(64)" json:"nickname"` + UserID string `gorm:"column:UserID;type:char(64)" json:"userID"` //openIM userID + Level int32 `gorm:"column:level;default:1" json:"level"` + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` } // RegisterAddFriend 注册时默认好友 type RegisterAddFriend struct { UserID string `gorm:"column:user_id;primary_key;type:char(64)" json:"userID"` - CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` } // RegisterAddGroup 注册时默认群组 type RegisterAddGroup struct { GroupID string `gorm:"column:group_id;primary_key;type:char(64)" json:"userID"` - CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` } // ClientInitConfig 系统相关配置项 type ClientInitConfig struct { - DiscoverPageURL string `gorm:"column:discover_page_url;size:128" json:"discoverPageURL"` - OrdinaryUserAddFriend int32 `gorm:"column:ordinary_user_add_friend; default:1" json:"ordinaryUserAddFriend"` - BossUserID string `gorm:"column:boss_user_id;type:char(64)" json:"bossUserID"` - AdminURL string `gorm:"column:admin_url;type:char(128)" json:"adminURL"` - AllowSendMsgNotFriend int32 `gorm:"column:allow_send_msg_not_friend;default:1" json:"allowSendMsgNotFriend"` + DiscoverPageURL string `gorm:"column:discover_page_url;size:128" json:"discoverPageURL"` + OrdinaryUserAddFriend int32 `gorm:"column:ordinary_user_add_friend; default:1" json:"ordinaryUserAddFriend"` + BossUserID string `gorm:"column:boss_user_id;type:char(64)" json:"bossUserID"` + AdminURL string `gorm:"column:admin_url;type:char(128)" json:"adminURL"` + AllowSendMsgNotFriend int32 `gorm:"column:allow_send_msg_not_friend;default:1" json:"allowSendMsgNotFriend"` NeedInvitationCodeRegister int32 `gorm:"column:need_invitation_code_register;default:0" json:"needInvitationCodeRegister"` } diff --git a/tools/data-conversion/chat/v2/chat.go b/tools/data-conversion/chat/v2/chat.go index 100e2566fe..6690e110be 100644 --- a/tools/data-conversion/chat/v2/chat.go +++ b/tools/data-conversion/chat/v2/chat.go @@ -7,89 +7,89 @@ import ( // Register 注册信息表 type Register struct { UserID string `gorm:"column:user_id;primary_key;type:char(64)" json:"userID"` - DeviceID string `gorm:"column:device_id;type:varchar(255)" json:"deviceID"` - IP string `gorm:"column:ip;type:varchar(32)" json:"ip"` - Platform string `gorm:"column:platform;type:varchar(32)" json:"platform"` - AccountType string `gorm:"column:account_type;type:varchar(32)" json:"accountType"` //email phone account - Mode string `gorm:"column:mode;type:varchar(32)"` //user admin - CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + DeviceID string `gorm:"column:device_id;type:varchar(255)" json:"deviceID"` + IP string `gorm:"column:ip;type:varchar(32)" json:"ip"` + Platform string `gorm:"column:platform;type:varchar(32)" json:"platform"` + AccountType string `gorm:"column:account_type;type:varchar(32)" json:"accountType"` //email phone account + Mode string `gorm:"column:mode;type:varchar(32)"` //user admin + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` } // Account 账号密码表 type Account struct { UserID string `gorm:"column:user_id;primary_key;type:char(64)" json:"userID"` - Password string `gorm:"column:password;type:varchar(255)" json:"password"` - CreateTime time.Time `gorm:"column:create_time" json:"createTime"` - ChangeTime time.Time `gorm:"column:change_time" json:"changeTime"` + Password string `gorm:"column:password;type:varchar(255)" json:"password"` + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + ChangeTime time.Time `gorm:"column:change_time" json:"changeTime"` OperatorUserID string `gorm:"column:operator_user_id;type:varchar(64)" json:"operatorUserID"` } // Attribute 用户属性表 type Attribute struct { UserID string `gorm:"column:user_id;primary_key;type:char(64)" json:"userID"` - Account string `gorm:"column:account;type:char(64)" json:"account"` - PhoneNumber string `gorm:"column:phone_number;type:varchar(32)" json:"phoneNumber"` - AreaCode string `gorm:"column:area_code;type:varchar(8)" json:"areaCode"` - Email string `gorm:"column:email;type:varchar(64)" json:"email"` - Nickname string `gorm:"column:nickname;type:varchar(64)" json:"nickname"` - FaceURL string `gorm:"column:face_url;type:varchar(255)" json:"faceURL"` - Gender int32 `gorm:"column:gender" json:"gender"` - Birth uint32 `gorm:"column:birth" json:"birth"` - CreateTime time.Time `gorm:"column:create_time" json:"createTime"` - ChangeTime time.Time `gorm:"column:change_time" json:"changeTime"` - BirthTime time.Time `gorm:"column:birth_time" json:"birthTime"` - Level int32 `gorm:"column:level;default:1" json:"level"` - AllowVibration int32 `gorm:"column:allow_vibration;default:1" json:"allowVibration"` - AllowBeep int32 `gorm:"column:allow_beep;default:1" json:"allowBeep"` - AllowAddFriend int32 `gorm:"column:allow_add_friend;default:1" json:"allowAddFriend"` + Account string `gorm:"column:account;type:char(64)" json:"account"` + PhoneNumber string `gorm:"column:phone_number;type:varchar(32)" json:"phoneNumber"` + AreaCode string `gorm:"column:area_code;type:varchar(8)" json:"areaCode"` + Email string `gorm:"column:email;type:varchar(64)" json:"email"` + Nickname string `gorm:"column:nickname;type:varchar(64)" json:"nickname"` + FaceURL string `gorm:"column:face_url;type:varchar(255)" json:"faceURL"` + Gender int32 `gorm:"column:gender" json:"gender"` + Birth uint32 `gorm:"column:birth" json:"birth"` + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + ChangeTime time.Time `gorm:"column:change_time" json:"changeTime"` + BirthTime time.Time `gorm:"column:birth_time" json:"birthTime"` + Level int32 `gorm:"column:level;default:1" json:"level"` + AllowVibration int32 `gorm:"column:allow_vibration;default:1" json:"allowVibration"` + AllowBeep int32 `gorm:"column:allow_beep;default:1" json:"allowBeep"` + AllowAddFriend int32 `gorm:"column:allow_add_friend;default:1" json:"allowAddFriend"` } // 封号表 type ForbiddenAccount struct { UserID string `gorm:"column:user_id;index:userID;primary_key;type:char(64)" json:"userID"` - CreateTime time.Time `gorm:"column:create_time" json:"createTime"` - Reason string `gorm:"column:reason;type:varchar(255)" json:"reason"` - OperatorUserID string `gorm:"column:operator_user_id;type:varchar(255)" json:"operatorUserID"` + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + Reason string `gorm:"column:reason;type:varchar(255)" json:"reason"` + OperatorUserID string `gorm:"column:operator_user_id;type:varchar(255)" json:"operatorUserID"` } // 用户登录信息表 type UserLoginRecord struct { - UserID string `gorm:"column:user_id;size:64" json:"userID"` - LoginTime time.Time `gorm:"column:login_time" json:"loginTime"` - IP string `gorm:"column:ip;type:varchar(32)" json:"ip"` + UserID string `gorm:"column:user_id;size:64" json:"userID"` + LoginTime time.Time `gorm:"column:login_time" json:"loginTime"` + IP string `gorm:"column:ip;type:varchar(32)" json:"ip"` DeviceID string `gorm:"column:device_id;type:varchar(255)" json:"deviceID"` - Platform string `gorm:"column:platform;type:varchar(32)" json:"platform"` + Platform string `gorm:"column:platform;type:varchar(32)" json:"platform"` } // 禁止ip登录 注册 type IPForbidden struct { IP string `gorm:"column:ip;primary_key;type:char(32)" json:"ip"` - LimitRegister int32 `gorm:"column:limit_register" json:"limitRegister"` - LimitLogin int32 `gorm:"column:limit_login" json:"limitLogin"` - CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + LimitRegister int32 `gorm:"column:limit_register" json:"limitRegister"` + LimitLogin int32 `gorm:"column:limit_login" json:"limitLogin"` + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` } // 限制userID只能在某些ip登录 type LimitUserLoginIP struct { UserID string `gorm:"column:user_id;primary_key;type:char(64)" json:"userID"` - IP string `gorm:"column:ip;primary_key;type:char(32)" json:"ip"` - CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + IP string `gorm:"column:ip;primary_key;type:char(32)" json:"ip"` + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` } // 邀请码被注册使用 type InvitationRegister struct { InvitationCode string `gorm:"column:invitation_code;primary_key;type:char(32)" json:"invitationCode"` - CreateTime time.Time `gorm:"column:create_time" json:"createTime"` - UsedByUserID string `gorm:"column:user_id;index:userID;type:char(64)" json:"usedByUserID"` + CreateTime time.Time `gorm:"column:create_time" json:"createTime"` + UsedByUserID string `gorm:"column:user_id;index:userID;type:char(64)" json:"usedByUserID"` } type SignalRecord struct { - FileName string `gorm:"column:file_name;primary_key;type:char(128)" json:"fileName"` + FileName string `gorm:"column:file_name;primary_key;type:char(128)" json:"fileName"` MediaType string `gorm:"column:media_type;type:char(64);index:media_type_index" json:"mediaType"` - RoomType string `gorm:"column:room_type;type:char(20)" json:"roomType"` - SenderID string `gorm:"column:sender_id;type:char(64);index:sender_id_index" json:"senderID"` - RecvID string `gorm:"column:recv_id;type:char(64);index:recv_id_index" json:"recvID"` - GroupID string `gorm:"column:group_id;type:char(64)" json:"groupID"` - DownloadURL string `gorm:"column:download_url;type:text" json:"downloadURL"` - CreateTime time.Time `gorm:"create_time;index:create_time_index" json:"createTime"` + RoomType string `gorm:"column:room_type;type:char(20)" json:"roomType"` + SenderID string `gorm:"column:sender_id;type:char(64);index:sender_id_index" json:"senderID"` + RecvID string `gorm:"column:recv_id;type:char(64);index:recv_id_index" json:"recvID"` + GroupID string `gorm:"column:group_id;type:char(64)" json:"groupID"` + DownloadURL string `gorm:"column:download_url;type:text" json:"downloadURL"` + CreateTime time.Time `gorm:"create_time;index:create_time_index" json:"createTime"` } diff --git a/tools/data-conversion/openim/common/config.go b/tools/data-conversion/openim/common/config.go index ddfe779ccc..e2bd14a051 100644 --- a/tools/data-conversion/openim/common/config.go +++ b/tools/data-conversion/openim/common/config.go @@ -16,7 +16,7 @@ package common // =================================== V2 ===================================== // MySQL -// V2 +// V2. const ( UsernameV2 = "root" PasswordV2 = "openIM" @@ -24,7 +24,7 @@ const ( DatabaseV2 = "openIM_v2" ) -// V2 chat +// V2 chat. const ( ChatUsernameV2 = "root" ChatPasswordV2 = "openIM" @@ -32,14 +32,14 @@ const ( ChatDatabaseV2 = "admin_chat" ) -// Kafka +// Kafka. const ( Topic = "ws2ms_chat" KafkaAddr = "121.5.182.23:9092" ) // =================================== V3 ===================================== -// V3 +// V3. const ( UsernameV3 = "root" PasswordV3 = "openIM123" @@ -47,7 +47,7 @@ const ( DatabaseV3 = "openIM_v3" ) -// V3 chat +// V3 chat. const ( ChatUsernameV3 = "root" ChatPasswordV3 = "openIM123" @@ -55,7 +55,7 @@ const ( ChatDatabaseV3 = "openim_enterprise" ) -// Zookeeper +// Zookeeper. const ( ZkAddr = "43.134.63.160:12181" ZKSchema = "openim" diff --git a/tools/data-conversion/openim/msg.go b/tools/data-conversion/openim/msg.go index dc526e1bb0..338fbf1116 100644 --- a/tools/data-conversion/openim/msg.go +++ b/tools/data-conversion/openim/msg.go @@ -3,20 +3,22 @@ package main import ( "context" "encoding/json" + "log" + "sync" + "sync/atomic" + "time" + "github.com/IBM/sarama" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/mw" "github.com/golang/protobuf/proto" - "github.com/openimsdk/open-im-server/v3/pkg/apistruct" - pbmsg "github.com/openimsdk/open-im-server/v3/tools/data-conversion/openim/proto/msg" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "log" - "sync" - "sync/atomic" - "time" + + "github.com/openimsdk/open-im-server/v3/pkg/apistruct" + pbmsg "github.com/openimsdk/open-im-server/v3/tools/data-conversion/openim/proto/msg" ) func main() { diff --git a/tools/data-conversion/openim/mysql.go b/tools/data-conversion/openim/mysql.go index 6cffae8e6e..8992e12c4d 100644 --- a/tools/data-conversion/openim/mysql.go +++ b/tools/data-conversion/openim/mysql.go @@ -16,12 +16,14 @@ package main import ( "fmt" - "github.com/openimsdk/open-im-server/v3/tools/data-conversion/openim/mysql/conversion" - "github.com/openimsdk/open-im-server/v3/tools/data-conversion/utils" + "log" + "gorm.io/driver/mysql" "gorm.io/gorm" "gorm.io/gorm/logger" - "log" + + "github.com/openimsdk/open-im-server/v3/tools/data-conversion/openim/mysql/conversion" + "github.com/openimsdk/open-im-server/v3/tools/data-conversion/utils" ) func main() { diff --git a/tools/data-conversion/openim/mysql/cmd.go b/tools/data-conversion/openim/mysql/cmd.go index 76e39210bd..924b0a206e 100644 --- a/tools/data-conversion/openim/mysql/cmd.go +++ b/tools/data-conversion/openim/mysql/cmd.go @@ -2,12 +2,14 @@ package mysql import ( "fmt" - "github.com/openimsdk/open-im-server/v3/tools/data-conversion/openim/mysql/conversion" - "github.com/openimsdk/open-im-server/v3/tools/data-conversion/utils" + "log" + "gorm.io/driver/mysql" "gorm.io/gorm" "gorm.io/gorm/logger" - "log" + + "github.com/openimsdk/open-im-server/v3/tools/data-conversion/openim/mysql/conversion" + "github.com/openimsdk/open-im-server/v3/tools/data-conversion/utils" ) func Cmd() { diff --git a/tools/data-conversion/openim/mysql/conversion/conversion.go b/tools/data-conversion/openim/mysql/conversion/conversion.go index b0e22f696b..298eefb50f 100644 --- a/tools/data-conversion/openim/mysql/conversion/conversion.go +++ b/tools/data-conversion/openim/mysql/conversion/conversion.go @@ -2,6 +2,7 @@ package conversion import ( "github.com/OpenIMSDK/protocol/constant" + v3 "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation" v2 "github.com/openimsdk/open-im-server/v3/tools/data-conversion/openim/mysql/v2" "github.com/openimsdk/open-im-server/v3/tools/data-conversion/utils" diff --git a/tools/data-conversion/openim/mysql/v2/model_struct.go b/tools/data-conversion/openim/mysql/v2/model_struct.go index c9fafc4b0a..9da33f2a5f 100644 --- a/tools/data-conversion/openim/mysql/v2/model_struct.go +++ b/tools/data-conversion/openim/mysql/v2/model_struct.go @@ -29,19 +29,19 @@ func (FriendRequest) TableName() string { } type Group struct { - GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"` - GroupName string `gorm:"column:name;size:255" json:"groupName"` - Notification string `gorm:"column:notification;size:255" json:"notification"` - Introduction string `gorm:"column:introduction;size:255" json:"introduction"` - FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"` + GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"` + GroupName string `gorm:"column:name;size:255" json:"groupName"` + Notification string `gorm:"column:notification;size:255" json:"notification"` + Introduction string `gorm:"column:introduction;size:255" json:"introduction"` + FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"` CreateTime time.Time `gorm:"column:create_time;index:create_time"` - Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"` + Ex string `gorm:"column:ex" json:"ex;size:1024"` Status int32 `gorm:"column:status"` CreatorUserID string `gorm:"column:creator_user_id;size:64"` GroupType int32 `gorm:"column:group_type"` NeedVerification int32 `gorm:"column:need_verification"` - LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"` - ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"` + LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"` + ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"` NotificationUpdateTime time.Time `gorm:"column:notification_update_time"` NotificationUserID string `gorm:"column:notification_user_id;size:64"` } diff --git a/tools/data-conversion/utils/find_insert.go b/tools/data-conversion/utils/find_insert.go index 5fe0fbfde6..4789cd554b 100644 --- a/tools/data-conversion/utils/find_insert.go +++ b/tools/data-conversion/utils/find_insert.go @@ -2,11 +2,12 @@ package utils import ( "fmt" - "gorm.io/gorm" - "gorm.io/gorm/schema" "log" "sync" "sync/atomic" + + "gorm.io/gorm" + "gorm.io/gorm/schema" ) func FindAndInsert[V2 any, V3 schema.Tabler](v2db *gorm.DB, v3db *gorm.DB, fn func(V2) (V3, bool)) (string, error) {