diff --git a/internal/api/auth/auth.go b/internal/api/auth/auth.go index abc909748..682ba4c30 100644 --- a/internal/api/auth/auth.go +++ b/internal/api/auth/auth.go @@ -93,6 +93,6 @@ func UserToken(c *gin.Context) { } resp := api.UserTokenResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}, UserToken: api.UserTokenInfo{UserID: req.FromUserID, Token: reply.Token, ExpiredTime: reply.ExpiredTime}} - log.NewInfo(req.OperationID, "UserRegister return ", resp) + log.NewInfo(req.OperationID, "UserToken return ", resp) c.JSON(http.StatusOK, resp) } diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index e71647d55..a6a5dadbc 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -13,6 +13,7 @@ import ( "Open_IM/pkg/grpc-etcdv3/getcdv3" pbGroup "Open_IM/pkg/proto/group" open_im_sdk "Open_IM/pkg/proto/sdk_ws" + pbUser "Open_IM/pkg/proto/user" "Open_IM/pkg/utils" "context" "net" @@ -576,6 +577,22 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) } chat.MemberQuitNotification(req) + //modify quitter conversation info + var reqPb pbUser.SetConversationReq + reqPb.OperationID = req.OperationID + reqPb.Conversation.OwnerUserID = req.OpUserID + reqPb.Conversation.ConversationID = utils.GetConversationIDBySessionType(req.OpUserID, constant.GroupChatType) + reqPb.Conversation.ConversationType = constant.GroupChatType + reqPb.Conversation.GroupID = req.GroupID + reqPb.Conversation.IsNotInGroup = true + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) + client := pbUser.NewUserClient(etcdConn) + respPb, err := client.SetConversation(context.Background(), &reqPb) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error()) + } else { + log.NewDebug(req.OpUserID, utils.GetSelfFuncName(), respPb.String()) + } log.NewInfo(req.OperationID, "rpc QuitGroup return ", pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}) return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil } @@ -988,13 +1005,35 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } chat.GroupDismissedNotification(req) - + memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID) + if err != nil { + log.NewError(req.OperationID, "GetGroupMemberListByGroupID failed,", err.Error(), req.GroupID) + } + //modify quitter conversation info + var reqPb pbUser.SetConversationReq + for _, v := range memberList { + reqPb.OperationID = req.OperationID + reqPb.Conversation.OwnerUserID = v.UserID + reqPb.Conversation.ConversationID = utils.GetConversationIDBySessionType(v.UserID, constant.GroupChatType) + reqPb.Conversation.ConversationType = constant.GroupChatType + reqPb.Conversation.GroupID = req.GroupID + reqPb.Conversation.IsNotInGroup = true + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) + client := pbUser.NewUserClient(etcdConn) + respPb, err := client.SetConversation(context.Background(), &reqPb) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error(), v.UserID) + } else { + log.NewDebug(req.OpUserID, utils.GetSelfFuncName(), respPb.String(), v.UserID) + } + } err = imdb.DeleteGroupMemberByGroupID(req.GroupID) if err != nil { log.NewError(req.OperationID, "DeleteGroupMemberByGroupID failed ", req.GroupID) return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil } diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 1234b2be9..e201719f7 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -75,7 +75,7 @@ func (s *userServer) Run() { func syncPeerUserConversation(conversation *pbUser.Conversation, operationID string) error { peerUserConversation := db.Conversation{ OwnerUserID: conversation.UserID, - ConversationID: "single_" + conversation.OwnerUserID, + ConversationID: utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType), ConversationType: constant.SingleChatType, UserID: conversation.OwnerUserID, GroupID: "", @@ -129,6 +129,7 @@ func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.Batc if err := utils.CopyStructFields(&conversation, v); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), v.String(), "CopyStructFields failed", err.Error()) } + //redis op if err := db.DB.SetSingleConversationRecvMsgOpt(req.OwnerUserID, v.ConversationID, v.RecvMsgOpt); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error()) resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} diff --git a/pkg/base_info/conversation_api_struct.go b/pkg/base_info/conversation_api_struct.go index 10b46f547..5e9d021f6 100644 --- a/pkg/base_info/conversation_api_struct.go +++ b/pkg/base_info/conversation_api_struct.go @@ -43,6 +43,8 @@ type Conversation struct { DraftTextTime int64 `json:"draftTextTime"` IsPinned bool `json:"isPinned" binding:"omitempty"` IsPrivateChat bool `json:"isPrivateChat"` + GroupAtType int32 `json:"groupAtType"` + IsNotInGroup bool `json:"isNotInGroup"` AttachedInfo string `json:"attachedInfo"` Ex string `json:"ex"` } diff --git a/pkg/common/db/model_struct.go b/pkg/common/db/model_struct.go index 9591050e0..9e50a8fc6 100644 --- a/pkg/common/db/model_struct.go +++ b/pkg/common/db/model_struct.go @@ -215,6 +215,8 @@ type Conversation struct { DraftTextTime int64 `gorm:"column:draft_text_time" json:"draftTextTime"` IsPinned bool `gorm:"column:is_pinned" json:"isPinned"` IsPrivateChat bool `gorm:"column:is_private_chat" json:"isPrivateChat"` + GroupAtType int32 `gorm:"column:group_at_type" json:"groupAtType"` + IsNotInGroup bool `gorm:"column:is_not_in_group" json:"isNotInGroup"` AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"` Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"` } diff --git a/pkg/common/db/mysql_model/im_mysql_model/user_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_model.go index 003b7afa7..5d1a08035 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/user_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_model.go @@ -321,7 +321,8 @@ func SetConversation(conversation db.Conversation) error { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") //force update return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID). - Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat}).Error + Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat, + "group_at_type": conversation.GroupAtType, "is_not_in_group": conversation.IsNotInGroup}).Error } } diff --git a/pkg/utils/strings.go b/pkg/utils/strings.go index 49d883f7c..a05ba927a 100644 --- a/pkg/utils/strings.go +++ b/pkg/utils/strings.go @@ -85,6 +85,8 @@ func GetConversationIDBySessionType(sourceID string, sessionType int) string { return "single_" + sourceID case constant.GroupChatType: return "group_" + sourceID + case constant.NotificationChatType: + return "notification_" + sourceID } return "" }