diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index e65a518a1..4704fa191 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -259,7 +259,53 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite } resp.Id2ResultList = append(resp.Id2ResultList, &resultNode) } - + var haveConUserID []string + conversations, err := imdb.GetConversationsByConversationIDMultipleOwner(okUserIDList, utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)) + for _, v := range conversations { + haveConUserID = append(haveConUserID, v.OwnerUserID) + } + var reqPb pbUser.SetConversationReq + var c pbUser.Conversation + for _, v := range conversations { + reqPb.OperationID = req.OperationID + c.OwnerUserID = v.OwnerUserID + c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType) + c.RecvMsgOpt = v.RecvMsgOpt + c.ConversationType = constant.GroupChatType + c.GroupID = req.GroupID + c.IsPinned = v.IsPinned + c.AttachedInfo = v.AttachedInfo + c.IsPrivateChat = v.IsPrivateChat + c.GroupAtType = v.GroupAtType + c.IsNotInGroup = false + c.Ex = v.Ex + reqPb.Conversation = &c + 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.OwnerUserID) + } else { + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v.OwnerUserID) + } + } + for _, v := range utils.DifferenceString(haveConUserID, okUserIDList) { + reqPb.OperationID = req.OperationID + c.OwnerUserID = v + c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType) + c.ConversationType = constant.GroupChatType + c.GroupID = req.GroupID + c.IsNotInGroup = false + reqPb.Conversation = &c + 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) + } else { + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v) + } + } chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, req.Reason, okUserIDList) resp.ErrCode = 0 log.NewInfo(req.OperationID, "InviteUserToGroup rpc return ", resp.String()) @@ -379,9 +425,28 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou okUserIDList = append(okUserIDList, v) } - err = db.DB.DelGroupMember(req.GroupID, v) + //err = db.DB.DelGroupMember(req.GroupID, v) + //if err != nil { + // log.NewError(req.OperationID, "DelGroupMember failed ", err.Error(), req.GroupID, v) + //} + } + var reqPb pbUser.SetConversationReq + var c pbUser.Conversation + for _, v := range okUserIDList { + reqPb.OperationID = req.OperationID + c.OwnerUserID = v + c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType) + c.ConversationType = constant.GroupChatType + c.GroupID = req.GroupID + c.IsNotInGroup = true + reqPb.Conversation = &c + 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, "DelGroupMember failed ", err.Error(), req.GroupID, v) + log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error(), v) + } else { + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v) } } chat.MemberKickedNotification(req, okUserIDList) @@ -502,6 +567,38 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), member) return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + var reqPb pbUser.SetConversationReq + reqPb.OperationID = req.OperationID + var c pbUser.Conversation + conversation, err := imdb.GetConversation(req.FromUserID, utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)) + if err != nil { + c.OwnerUserID = req.FromUserID + c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType) + c.ConversationType = constant.GroupChatType + c.GroupID = req.GroupID + c.IsNotInGroup = false + } else { + c.OwnerUserID = conversation.OwnerUserID + c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType) + c.RecvMsgOpt = conversation.RecvMsgOpt + c.ConversationType = constant.GroupChatType + c.GroupID = req.GroupID + c.IsPinned = conversation.IsPinned + c.AttachedInfo = conversation.AttachedInfo + c.IsPrivateChat = conversation.IsPrivateChat + c.GroupAtType = conversation.GroupAtType + c.IsNotInGroup = false + c.Ex = conversation.Ex + } + reqPb.Conversation = &c + 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.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String()) + } chat.GroupApplicationAcceptedNotification(req) chat.MemberEnterNotification(req) } else if req.HandleResult == constant.GroupResponseRefuse { @@ -591,7 +688,7 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) 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.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String()) } chat.MemberQuitNotification(req) log.NewInfo(req.OperationID, "rpc QuitGroup return ", pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}) @@ -914,6 +1011,25 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo OperationID: req.OperationID, OpUserID: req.OpUserId, } + var reqPb pbUser.SetConversationReq + var c pbUser.Conversation + for _, v := range resp.Success { + reqPb.OperationID = req.OperationID + c.OwnerUserID = v + c.ConversationID = utils.GetConversationIDBySessionType(req.GroupId, constant.GroupChatType) + c.ConversationType = constant.GroupChatType + c.GroupID = req.GroupId + c.IsNotInGroup = true + reqPb.Conversation = &c + 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) + } else { + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v) + } + } chat.MemberKickedNotification(reqKick, resp.Success) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "success: ", resp.Success) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "failed: ", resp.Failed) @@ -1026,7 +1142,7 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou 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) + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v.UserID) } } chat.GroupDismissedNotification(req) 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 5d1a08035..af7c15311 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 @@ -384,7 +384,7 @@ func GetConversation(OwnerUserID, conversationID string) (db.Conversation, error err = dbConn.Model(&db.Conversation{ OwnerUserID: OwnerUserID, ConversationID: conversationID, - }).Find(&conversation).Error + }).Take(&conversation).Error return conversation, err } @@ -397,3 +397,12 @@ func GetConversations(OwnerUserID string, conversationIDs []string) ([]db.Conver err = dbConn.Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error return conversations, err } +func GetConversationsByConversationIDMultipleOwner(OwnerUserIDList []string, conversationID string) ([]db.Conversation, error) { + var conversations []db.Conversation + dbConn, err := db.DB.MysqlDB.DefaultGormDB() + if err != nil { + return conversations, err + } + err = dbConn.Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error + return conversations, err +} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 8f0b52d72..52cb1bf2e 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -77,6 +77,44 @@ func Difference(slice1, slice2 []uint32) []uint32 { } return n } + +//Get the intersection of two slices +func IntersectString(slice1, slice2 []string) []string { + m := make(map[string]bool) + n := make([]string, 0) + for _, v := range slice1 { + m[v] = true + } + for _, v := range slice2 { + flag, _ := m[v] + if flag { + n = append(n, v) + } + } + return n +} + +//Get the diff of two slices +func DifferenceString(slice1, slice2 []string) []string { + m := make(map[string]bool) + n := make([]string, 0) + inter := IntersectString(slice1, slice2) + for _, v := range inter { + m[v] = true + } + for _, v := range slice1 { + if !m[v] { + n = append(n, v) + } + } + + for _, v := range slice2 { + if !m[v] { + n = append(n, v) + } + } + return n +} func OperationIDGenerator() string { return strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10) }