Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode

 Conflicts:
	internal/rpc/group/group.go
	pkg/common/db/relation/user_model_k.go
test-errcode
wangchuxiao 2 years ago
commit 5b8f66404c

@ -5,7 +5,7 @@ import (
relation "Open_IM/pkg/common/db/mysql"
"Open_IM/pkg/common/tools"
pbGroup "Open_IM/pkg/proto/group"
sdk "Open_IM/pkg/proto/sdk_ws"
sdk_ws "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"math/big"
@ -40,10 +40,22 @@ func getDBGroupMember(ctx context.Context, groupID, userID string) (dbGroupMembe
return dbGroupMember, nil
}
func getUsersInfo(ctx context.Context, userIDs []string) ([]*sdk.UserInfo, error) {
func getUsersInfo(ctx context.Context, userIDs []string) ([]*sdk_ws.UserInfo, error) {
return nil, nil
}
func getUserMap(ctx context.Context, userIDs []string) (map[string]*sdk_ws.UserInfo, error) {
users, err := getUsersInfo(ctx, userIDs)
if err != nil {
return nil, err
}
userMap := make(map[string]*sdk_ws.UserInfo)
for i, user := range users {
userMap[user.UserID] = users[i]
}
return userMap, nil
}
func genGroupID(ctx context.Context, groupID string) string {
if groupID != "" {
return groupID

@ -15,7 +15,6 @@ import (
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/common/tools"
"Open_IM/pkg/common/trace_log"
"Open_IM/pkg/common/tracelog"
cp "Open_IM/internal/utils"
"Open_IM/pkg/getcdv3"
@ -26,13 +25,12 @@ import (
"Open_IM/pkg/utils"
"context"
"errors"
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"net"
"strconv"
"strings"
"time"
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/wrapperspb"
"gorm.io/gorm"
@ -260,139 +258,128 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
groupNode.NotificationUpdateTime = group.NotificationUpdateTime.UnixMilli()
resp.GroupList = append(resp.GroupList, &groupNode)
}
resp.Total = uint32(len(resp.GroupList))
resp.Total = int32(len(resp.GroupList))
return resp, nil
}
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.InviteUserToGroupReq) (*pbGroup.InviteUserToGroupResp, error) {
resp := &pbGroup.InviteUserToGroupResp{}
opUserID := tools.OpUserID(ctx)
if err := token_verify.CheckManagerUserID(ctx, opUserID); err != nil {
if err := relation.CheckIsExistGroupMember(ctx, req.GroupID, opUserID); err != nil {
return nil, err
}
if len(req.InvitedUserIDList) == 0 {
return nil, constant.ErrArgs.Wrap("user empty")
}
if utils.IsDuplicateID(req.InvitedUserIDList) {
return nil, constant.ErrArgs.Wrap("userID duplicate")
}
groupInfo, err := (*relation.Group)(nil).Take(ctx, req.GroupID)
group, err := s.GroupInterface.TakeGroupByID(ctx, req.GroupID)
if err != nil {
return nil, err
}
if groupInfo.Status == constant.GroupStatusDismissed {
return nil, utils.Wrap(constant.ErrDismissedAlready, "")
if group.Status == constant.GroupStatusDismissed {
return nil, constant.ErrDismissedAlready.Wrap()
}
if groupInfo.NeedVerification == constant.AllNeedVerification &&
!relation.IsGroupOwnerAdmin(req.GroupID, tools.OpUserID(ctx)) && !token_verify.IsManagerUserID(tools.OpUserID(ctx)) {
joinReq := pbGroup.JoinGroupReq{}
for _, v := range req.InvitedUserIDList {
var groupRequest relation.GroupRequest
groupRequest.UserID = v
groupRequest.GroupID = req.GroupID
groupRequest.JoinSource = constant.JoinByInvitation
groupRequest.InviterUserID = tools.OpUserID(ctx)
err = relation.InsertIntoGroupRequest(groupRequest)
if err != nil {
var resultNode pbGroup.Id2Result
resultNode.Result = -1
resultNode.UserID = v
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue
} else {
var resultNode pbGroup.Id2Result
resultNode.Result = 0
resultNode.UserID = v
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
joinReq.GroupID = req.GroupID
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
chat.JoinGroupApplicationNotification(ctx, &joinReq)
}
members, err := s.GroupInterface.GetGroupMemberList(ctx, group.GroupID)
if err != nil {
return nil, err
}
memberMap := make(map[string]*relation.GroupMember)
for i, member := range members {
memberMap[member.GroupID] = members[i]
}
for _, userID := range req.InvitedUserIDList {
if _, ok := memberMap[userID]; ok {
return nil, constant.ErrArgs.Wrap("user in group " + userID)
}
return resp, nil
}
if err := s.DelGroupAndUserCache(ctx, req.GroupID, req.InvitedUserIDList); err != nil {
userMap, err := getUserMap(ctx, req.InvitedUserIDList)
if err != nil {
return nil, err
}
//from User: invite: applicant
//to user: invite: invited
var okUserIDList []string
if groupInfo.GroupType != constant.SuperGroup {
for _, v := range req.InvitedUserIDList {
var resultNode pbGroup.Id2Result
resultNode.UserID = v
resultNode.Result = 0
toUserInfo, err := relation.GetUserByUserID(v)
if err != nil {
tracelog.SetCtxInfo(ctx, "GetUserByUserID", err, "userID", v)
resultNode.Result = -1
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue
}
if relation.IsExistGroupMember(req.GroupID, v) {
tracelog.SetCtxInfo(ctx, "IsExistGroupMember", err, "groupID", req.GroupID, "userID", v)
resultNode.Result = -1
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue
}
var toInsertInfo relation.GroupMember
utils.CopyStructFields(&toInsertInfo, toUserInfo)
toInsertInfo.GroupID = req.GroupID
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
toInsertInfo.OperatorUserID = tools.OpUserID(ctx)
toInsertInfo.InviterUserID = tools.OpUserID(ctx)
toInsertInfo.JoinSource = constant.JoinByInvitation
if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), &toInsertInfo, groupInfo.Ex); err != nil {
return nil, err
}
err = relation.InsertIntoGroupMember(toInsertInfo)
if err != nil {
tracelog.SetCtxInfo(ctx, "InsertIntoGroupMember", err, "args", toInsertInfo)
resultNode.Result = -1
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue
for _, userID := range req.InvitedUserIDList {
if _, ok := userMap[userID]; !ok {
return nil, constant.ErrUserIDNotFound.Wrap(userID)
}
}
if group.NeedVerification == constant.AllNeedVerification {
if !token_verify.IsAppManagerUid(ctx) {
opUserID := tools.OpUserID(ctx)
member, ok := memberMap[opUserID]
if ok {
return nil, constant.ErrNoPermission.Wrap("not in group")
}
okUserIDList = append(okUserIDList, v)
err = db.DB.AddGroupMember(req.GroupID, toUserInfo.UserID)
if err != nil {
tracelog.SetCtxInfo(ctx, "AddGroupMember", err, "groupID", req.GroupID, "userID", toUserInfo.UserID)
if !(member.RoleLevel == constant.GroupOwner || member.RoleLevel == constant.GroupAdmin) {
var requests []*relation.GroupRequest
for _, userID := range req.InvitedUserIDList {
requests = append(requests, &relation.GroupRequest{
UserID: userID,
GroupID: req.GroupID,
JoinSource: constant.JoinByInvitation,
InviterUserID: opUserID,
})
}
if err := s.GroupInterface.CreateGroupRequest(ctx, requests); err != nil {
return nil, err
}
for _, request := range requests {
chat.JoinGroupApplicationNotification(ctx, &pbGroup.JoinGroupReq{
GroupID: request.GroupID,
ReqMessage: request.ReqMsg,
JoinSource: request.JoinSource,
InviterUserID: request.InviterUserID,
})
}
return resp, nil
}
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
}
} else {
okUserIDList = req.InvitedUserIDList
if err := db.DB.AddUserToSuperGroup(req.GroupID, req.InvitedUserIDList); err != nil {
}
if group.GroupType == constant.SuperGroup {
if err := s.GroupInterface.AddUserToSuperGroup(ctx, req.GroupID, req.InvitedUserIDList); err != nil {
return nil, err
}
}
if groupInfo.GroupType != constant.SuperGroup {
chat.MemberInvitedNotification(tools.OperationID(ctx), req.GroupID, tools.OpUserID(ctx), req.Reason, okUserIDList)
for _, userID := range req.InvitedUserIDList {
chat.SuperGroupNotification(tools.OperationID(ctx), userID, userID)
}
} else {
var groupMembers []*relation.GroupMember
for _, userID := range req.InvitedUserIDList {
if err := rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, userID); err != nil {
tracelog.SetCtxInfo(ctx, "DelJoinedSuperGroupIDListFromCache", err, "userID", userID)
user := userMap[userID]
var member relation.GroupMember
utils.CopyStructFields(&member, user)
member.GroupID = req.GroupID
member.RoleLevel = constant.GroupOrdinaryUsers
member.OperatorUserID = tools.OpUserID(ctx)
member.InviterUserID = tools.OpUserID(ctx)
member.JoinSource = constant.JoinByInvitation
if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), &member, group.Ex); err != nil {
return nil, err
}
groupMembers = append(groupMembers, &member)
}
for _, v := range req.InvitedUserIDList {
chat.SuperGroupNotification(tools.OperationID(ctx), v, v)
if err := s.GroupInterface.CreateGroupMember(ctx, groupMembers); err != nil {
return nil, err
}
chat.MemberInvitedNotification(tools.OperationID(ctx), req.GroupID, tools.OpUserID(ctx), req.Reason, req.InvitedUserIDList)
}
return resp, nil
}
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) {
resp := &pbGroup.GetGroupAllMemberResp{}
groupInfo, err := rocksCache.GetGroupInfoFromCache(ctx, req.GroupID)
group, err := s.GroupInterface.TakeGroupByID(ctx, req.GroupID)
if err != nil {
return nil, err
}
if groupInfo.GroupType != constant.SuperGroup {
memberList, err := rocksCache.GetGroupMembersInfoFromCache(ctx, req.Count, req.Offset, req.GroupID)
if group.GroupType != constant.SuperGroup {
members, err := s.GroupInterface.GetGroupMemberList(ctx, req.GroupID)
if err != nil {
return nil, err
}
for _, v := range memberList {
var userIDs []string
for _, member := range members {
userIDs = append(userIDs, member.UserID)
}
for _, member := range members {
var node open_im_sdk.GroupMemberFullInfo
cp.GroupMemberDBCopyOpenIM(&node, v)
utils.CopyStructFields(&node, member)
resp.MemberList = append(resp.MemberList, &node)
}
}
@ -401,12 +388,10 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGroupMemberListReq) (*pbGroup.GetGroupMemberListResp, error) {
resp := &pbGroup.GetGroupMemberListResp{}
memberList, err := relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
memberList, err := s.GroupInterface.GetGroupMemberFilterList(ctx, req.GroupID, req.Filter, req.NextSeq, 30)
if err != nil {
return nil, err
}
for _, v := range memberList {
var node open_im_sdk.GroupMemberFullInfo
utils.CopyStructFields(&node, &v)
@ -481,23 +466,23 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
kickedInfo, err := rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, v)
if err != nil {
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
tracelog.SetCtxInfo(ctx, "GetGroupMemberInfoFromCache", err, "groupID", req.GroupID, "userID", v)
trace_log.SetCtxInfo(ctx, "GetGroupMemberInfoFromCache", err, "groupID", req.GroupID, "userID", v)
continue
}
if kickedInfo.RoleLevel == constant.GroupAdmin && opFlag == 3 {
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
tracelog.SetCtxInfo(ctx, "", nil, "msg", "is constant.GroupAdmin, can't kicked", "groupID", req.GroupID, "userID", v)
trace_log.SetCtxInfo(ctx, "", nil, "msg", "is constant.GroupAdmin, can't kicked", "groupID", req.GroupID, "userID", v)
continue
}
if kickedInfo.RoleLevel == constant.GroupOwner && opFlag != 1 {
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
tracelog.SetCtxInfo(ctx, "", nil, "msg", "is constant.GroupOwner, can't kicked", "groupID", req.GroupID, "userID", v)
trace_log.SetCtxInfo(ctx, "", nil, "msg", "is constant.GroupOwner, can't kicked", "groupID", req.GroupID, "userID", v)
continue
}
err = relation.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, v)
tracelog.SetCtxInfo(ctx, "RemoveGroupMember", err, "groupID", req.GroupID, "userID", v)
trace_log.SetCtxInfo(ctx, "RemoveGroupMember", err, "groupID", req.GroupID, "userID", v)
if err != nil {
log.NewError(tools.OperationID(ctx), "RemoveGroupMember failed ", err.Error(), req.GroupID, v)
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
@ -522,7 +507,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
}
client := pbUser.NewUserClient(etcdConn)
respPb, err := client.SetConversation(context.Background(), &reqPb)
tracelog.SetCtxInfo(ctx, "SetConversation", err, "req", &reqPb, "resp", respPb)
trace_log.SetCtxInfo(ctx, "SetConversation", err, "req", &reqPb, "resp", respPb)
}
} else {
okUserIDList = req.KickedUserIDList
@ -534,14 +519,14 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
if groupInfo.GroupType != constant.SuperGroup {
for _, userID := range okUserIDList {
if err := rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, userID); err != nil {
tracelog.SetCtxInfo(ctx, "DelGroupMemberInfoFromCache", err, "groupID", req.GroupID, "userID", userID)
trace_log.SetCtxInfo(ctx, "DelGroupMemberInfoFromCache", err, "groupID", req.GroupID, "userID", userID)
}
}
chat.MemberKickedNotification(req, okUserIDList)
} else {
for _, userID := range okUserIDList {
if err = rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, userID); err != nil {
tracelog.SetCtxInfo(ctx, "DelGroupMemberInfoFromCache", err, "userID", userID)
trace_log.SetCtxInfo(ctx, "DelGroupMemberInfoFromCache", err, "userID", userID)
}
}
go func() {
@ -556,15 +541,14 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetGroupMembersInfoReq) (*pbGroup.GetGroupMembersInfoResp, error) {
resp := &pbGroup.GetGroupMembersInfoResp{}
resp.MemberList = []*open_im_sdk.GroupMemberFullInfo{}
for _, userID := range req.MemberList {
groupMember, err := rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, userID)
if err != nil {
return nil, err
}
members, err := s.GroupInterface.GetGroupMemberListByUserID(ctx, req.GroupID, req.MemberList)
if err != nil {
return nil, err
}
for _, member := range members {
var memberNode open_im_sdk.GroupMemberFullInfo
utils.CopyStructFields(&memberNode, groupMember)
memberNode.JoinTime = int32(groupMember.JoinTime.Unix())
utils.CopyStructFields(&memberNode, member)
memberNode.JoinTime = member.JoinTime.UnixMilli()
resp.MemberList = append(resp.MemberList, &memberNode)
}
return resp, nil
@ -600,7 +584,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.
return nil, err
}
var errResult error
tracelog.SetCtxInfo(ctx, "GetRecvGroupApplicationList", nil, " FromUserID: ", req.FromUserID, "GroupApplicationList: ", reply)
trace_log.SetCtxInfo(ctx, "GetRecvGroupApplicationList", nil, " FromUserID: ", req.FromUserID, "GroupApplicationList: ", reply)
for _, v := range reply {
node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}}
err := FillGroupInfoByGroupID(tools.OperationID(ctx), v.GroupID, node.GroupInfo)
@ -610,7 +594,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.
}
continue
}
tracelog.SetCtxInfo(ctx, "FillGroupInfoByGroupID ", nil, " groupID: ", v.GroupID, " groupInfo: ", node.GroupInfo)
trace_log.SetCtxInfo(ctx, "FillGroupInfoByGroupID ", nil, " groupID: ", v.GroupID, " groupInfo: ", node.GroupInfo)
err = FillPublicUserInfoByUserID(tools.OperationID(ctx), v.UserID, node.UserInfo)
if err != nil {
errResult = err
@ -622,7 +606,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.
if errResult != nil && len(resp.GroupRequestList) == 0 {
return nil, err
}
tracelog.SetRpcRespInfo(ctx, utils.GetSelfFuncName(), resp.String())
trace_log.SetRpcRespInfo(ctx, utils.GetSelfFuncName(), resp.String())
return resp, nil
}
@ -645,7 +629,7 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
func CheckPermission(ctx context.Context, groupID string, userID string) (err error) {
defer func() {
tracelog.SetCtxInfo(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID)
trace_log.SetCtxInfo(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID)
}()
if !token_verify.IsManagerUserID(userID) && !relation.IsGroupOwnerAdmin(groupID, userID) {
return utils.Wrap(constant.ErrNoPermission, utils.GetSelfFuncName())
@ -765,7 +749,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
}
client := pbUser.NewUserClient(etcdConn)
respPb, err := client.SetConversation(context.Background(), &reqPb)
tracelog.SetCtxInfo(ctx, "SetConversation", err, "req", reqPb, "resp", respPb)
trace_log.SetCtxInfo(ctx, "SetConversation", err, "req", reqPb, "resp", respPb)
chat.MemberEnterDirectlyNotification(req.GroupID, tools.OpUserID(ctx), tools.OperationID(ctx))
return resp, nil
} else {
@ -933,7 +917,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
}
nClient := pbConversation.NewConversationClient(nEtcdConn)
conversationReply, err := nClient.ModifyConversationField(context.Background(), &conversationReq)
tracelog.SetCtxInfo(ctx, "ModifyConversationField", err, "req", &conversationReq, "resp", conversationReply)
trace_log.SetCtxInfo(ctx, "ModifyConversationField", err, "req", &conversationReq, "resp", conversationReply)
}
return resp, nil
}
@ -1006,14 +990,14 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbGroup.GetGroupsReq)
} else {
groups, count, err := relation.GetGroupsByName(req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
tracelog.SetCtxInfo(ctx, "GetGroupsByName", err, "GroupName", req.GroupName, "PageNumber", req.Pagination.PageNumber, "ShowNumber", req.Pagination.ShowNumber)
trace_log.SetCtxInfo(ctx, "GetGroupsByName", err, "GroupName", req.GroupName, "PageNumber", req.Pagination.PageNumber, "ShowNumber", req.Pagination.ShowNumber)
}
for _, v := range groups {
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(group.GroupInfo, v)
groupMember, err := relation.GetGroupOwnerInfoByGroupID(v.GroupID)
if err != nil {
tracelog.SetCtxInfo(ctx, "GetGroupOwnerInfoByGroupID", err, "GroupID", v.GroupID)
trace_log.SetCtxInfo(ctx, "GetGroupOwnerInfoByGroupID", err, "GroupID", v.GroupID)
continue
}
group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix())
@ -1062,12 +1046,12 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGrou
node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}}
group, err := relation.GetGroupInfoByGroupID(groupReq.GroupID)
if err != nil {
tracelog.SetCtxInfo(ctx, "GetGroupInfoByGroupID", err, "GroupID", groupReq.GroupID)
trace_log.SetCtxInfo(ctx, "GetGroupInfoByGroupID", err, "GroupID", groupReq.GroupID)
continue
}
user, err := relation.GetUserByUserID(groupReq.UserID)
if err != nil {
tracelog.SetCtxInfo(ctx, "GetUserByUserID", err, "UserID", groupReq.UserID)
trace_log.SetCtxInfo(ctx, "GetUserByUserID", err, "UserID", groupReq.UserID)
continue
}
cp.GroupRequestDBCopyOpenIM(&node, &groupReq)
@ -1103,7 +1087,7 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
if groupInfo.GroupType != constant.SuperGroup {
memberList, err := relation.GetGroupMemberListByGroupID(req.GroupID)
if err != nil {
tracelog.SetCtxInfo(ctx, "GetGroupMemberListByGroupID", err, "groupID", req.GroupID)
trace_log.SetCtxInfo(ctx, "GetGroupMemberListByGroupID", err, "groupID", req.GroupID)
}
//modify quitter conversation info
var reqPb pbUser.SetConversationReq
@ -1119,7 +1103,7 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
client := pbUser.NewUserClient(etcdConn)
respPb, err := client.SetConversation(context.Background(), &reqPb)
tracelog.SetCtxInfo(ctx, "SetConversation", err, "req", &reqPb, "resp", respPb)
trace_log.SetCtxInfo(ctx, "SetConversation", err, "req", &reqPb, "resp", respPb)
}
err = relation.DeleteGroupMemberByGroupID(req.GroupID)
if err != nil {
@ -1382,7 +1366,7 @@ func (s *groupServer) GetGroupAbstractInfo(ctx context.Context, req *pbGroup.Get
}
func (s *groupServer) DelGroupAndUserCache(ctx context.Context, groupID string, userIDList []string) error {
operationID := tracelog.GetOperationID(ctx)
operationID := trace_log.GetOperationID(ctx)
if groupID != "" {
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImCacheName)
if err != nil {

@ -25,13 +25,13 @@ func getFromToUserNickname(fromUserID, toUserID string) (string, string, error)
return from.Nickname, to.Nickname, nil
}
func friendNotification(commID *pbFriend.CommID, contentType int32, m proto.Message) {
log.Info(commID.OperationID, utils.GetSelfFuncName(), "args: ", commID, contentType)
func friendNotification(operationID, fromUserID, toUserID string, contentType int32, m proto.Message) {
log.Info(operationID, utils.GetSelfFuncName(), "args: ", commID, contentType)
var err error
var tips open_im_sdk.TipsComm
tips.Detail, err = proto.Marshal(m)
if err != nil {
log.Error(commID.OperationID, "Marshal failed ", err.Error(), m.String())
log.Error(operationID, "Marshal failed ", err.Error(), m.String())
return
}
@ -43,9 +43,9 @@ func friendNotification(commID *pbFriend.CommID, contentType int32, m proto.Mess
tips.JsonDetail, _ = marshaler.MarshalToString(m)
fromUserNickname, toUserNickname, err := getFromToUserNickname(commID.FromUserID, commID.ToUserID)
fromUserNickname, toUserNickname, err := getFromToUserNickname(fromUserID, toUserID)
if err != nil {
log.Error(commID.OperationID, "getFromToUserNickname failed ", err.Error(), commID.FromUserID, commID.ToUserID)
log.Error(operationID, "getFromToUserNickname failed ", err.Error(), fromUserID, toUserID)
return
}
cn := config.Config.Notification
@ -71,20 +71,20 @@ func friendNotification(commID *pbFriend.CommID, contentType int32, m proto.Mess
case constant.FriendInfoUpdatedNotification:
tips.DefaultTips = cn.FriendInfoUpdated.DefaultTips.Tips + toUserNickname
default:
log.Error(commID.OperationID, "contentType failed ", contentType)
log.Error(operationID, "contentType failed ", contentType)
return
}
var n NotificationMsg
n.SendID = commID.FromUserID
n.RecvID = commID.ToUserID
n.SendID = fromUserID
n.RecvID = toUserID
n.ContentType = contentType
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = commID.OperationID
n.OperationID = operationID
n.Content, err = proto.Marshal(&tips)
if err != nil {
log.Error(commID.OperationID, "Marshal failed ", err.Error(), tips.String())
log.Error(operationID, "Marshal failed ", err.Error(), tips.String())
return
}
Notification(&n)
@ -160,7 +160,7 @@ func BlackDeletedNotification(req *pbFriend.RemoveBlacklistReq) {
friendNotification(req.CommID, constant.BlackDeletedNotification, &blackDeletedTips)
}
//send to myself
// send to myself
func UserInfoUpdatedNotification(operationID, opUserID string, changedUserID string) {
selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: changedUserID}
commID := pbFriend.CommID{FromUserID: opUserID, ToUserID: changedUserID, OpUserID: opUserID, OperationID: operationID}
@ -169,6 +169,5 @@ func UserInfoUpdatedNotification(operationID, opUserID string, changedUserID str
func FriendInfoUpdatedNotification(operationID, changedUserID string, needNotifiedUserID string, opUserID string) {
selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: changedUserID}
commID := pbFriend.CommID{FromUserID: opUserID, ToUserID: needNotifiedUserID, OpUserID: opUserID, OperationID: operationID}
friendNotification(&commID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips)
friendNotification(operationID, opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips)
}

@ -11,13 +11,12 @@ import (
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/common/tools"
"Open_IM/pkg/getcdv3"
pbConversation "Open_IM/pkg/proto/conversation"
pbFriend "Open_IM/pkg/proto/friend"
sdkws "Open_IM/pkg/proto/sdk_ws"
pbGroup "Open_IM/pkg/proto/group"
pbUser "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils"
"context"
"errors"
"github.com/golang/protobuf/ptypes/wrappers"
"net"
"strconv"
"strings"
@ -26,7 +25,6 @@ import (
utils2 "Open_IM/internal/utils"
"google.golang.org/grpc"
"gorm.io/gorm"
)
type userServer struct {
@ -62,7 +60,7 @@ func NewUserServer(port int) *userServer {
}
func (s *userServer) Run() {
log.NewInfo("0", "rpc user start...")
log.NewInfo("", "rpc user start...")
listenIP := ""
if config.Config.ListenIP == "" {
@ -77,7 +75,7 @@ func (s *userServer) Run() {
if err != nil {
panic("listening err:" + err.Error() + s.rpcRegisterName)
}
log.NewInfo("0", "listen network success, address ", address, listener)
log.NewInfo("", "listen network success, address ", address, listener)
defer listener.Close()
//grpc server
var grpcOpts []grpc.ServerOption
@ -102,329 +100,72 @@ func (s *userServer) Run() {
log.Error("", "GetLocalIP failed ", err.Error())
}
}
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10, "")
if err != nil {
log.NewError("0", "RegisterEtcd failed ", err.Error(), s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName)
log.NewError("", "RegisterEtcd failed ", err.Error(), s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName)
panic(utils.Wrap(err, "register user module rpc to etcd err"))
}
err = srv.Serve(listener)
if err != nil {
log.NewError("0", "Serve failed ", err.Error())
log.NewError("", "Serve failed ", err.Error())
return
}
log.NewInfo("0", "rpc user success")
log.NewInfo("", "rpc user success")
}
func syncPeerUserConversation(conversation *pbConversation.Conversation, operationID string) error {
peerUserConversation := imdb.Conversation{
OwnerUserID: conversation.UserID,
ConversationID: utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType),
ConversationType: constant.SingleChatType,
UserID: conversation.OwnerUserID,
GroupID: "",
RecvMsgOpt: 0,
UnreadCount: 0,
DraftTextTime: 0,
IsPinned: false,
IsPrivateChat: conversation.IsPrivateChat,
AttachedInfo: "",
Ex: "",
}
err := imdb.PeerUserSetConversation(peerUserConversation)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
return err
}
chat.ConversationSetPrivateNotification(operationID, conversation.OwnerUserID, conversation.UserID, conversation.IsPrivateChat)
return nil
}
func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.BatchSetConversationsReq) (*pbUser.BatchSetConversationsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
if req.NotificationType == 0 {
req.NotificationType = constant.ConversationOptChangeNotification
}
resp := &pbUser.BatchSetConversationsResp{}
for _, v := range req.Conversations {
conversation := imdb.Conversation{}
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}
return resp, nil
}
isUpdate, err := imdb.SetConversation(conversation)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
resp.Failed = append(resp.Failed, v.ConversationID)
continue
}
if isUpdate {
err = rocksCache.DelConversationFromCache(v.OwnerUserID, v.ConversationID)
} else {
err = rocksCache.DelUserConversationIDListFromCache(v.OwnerUserID)
}
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), v.ConversationID, v.OwnerUserID)
}
resp.Success = append(resp.Success, v.ConversationID)
// if is set private msg operationthen peer user need to sync and set tips\
if v.ConversationType == constant.SingleChatType && req.NotificationType == constant.ConversationPrivateChatNotification {
if err := syncPeerUserConversation(v, req.OperationID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error())
}
}
}
chat.ConversationChangeNotification(req.OperationID, req.OwnerUserID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
func (s *userServer) GetAllConversations(ctx context.Context, req *pbUser.GetAllConversationsReq) (*pbUser.GetAllConversationsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetAllConversationsResp{Conversations: []*pbConversation.Conversation{}}
conversations, err := rocksCache.GetUserAllConversationList(req.OwnerUserID)
log.NewDebug(req.OperationID, "conversations: ", conversations)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversations error", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
if err = utils.CopyStructFields(&resp.Conversations, conversations); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields error", err.Error())
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
func (s *userServer) GetConversation(ctx context.Context, req *pbUser.GetConversationReq) (*pbUser.GetConversationResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetConversationResp{Conversation: &pbConversation.Conversation{}}
conversation, err := rocksCache.GetConversationFromCache(req.OwnerUserID, req.ConversationID)
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "conversation", conversation)
func (s *userServer) SyncJoinedGroupMemberFaceURL(ctx context.Context, userID string, faceURL string, operationID string, opUserID string) {
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImFriendName)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversation error", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
if err := utils.CopyStructFields(resp.Conversation, &conversation); err != nil {
log.Debug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields error", conversation, err.Error())
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
func (s *userServer) GetConversations(ctx context.Context, req *pbUser.GetConversationsReq) (*pbUser.GetConversationsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetConversationsResp{Conversations: []*pbConversation.Conversation{}}
conversations, err := rocksCache.GetConversationsFromCache(req.OwnerUserID, req.ConversationIDs)
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "conversations", conversations)
client := pbGroup.NewGroupClient(etcdConn)
newReq := &pbGroup.GetJoinedGroupListReq{FromUserID: userID}
rpcResp, err := client.GetJoinedGroupList(ctx, newReq)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversations error", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
if err := utils.CopyStructFields(&resp.Conversations, conversations); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", conversations, err.Error())
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConversationReq) (*pbUser.SetConversationResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.SetConversationResp{}
if req.NotificationType == 0 {
req.NotificationType = constant.ConversationOptChangeNotification
}
if req.Conversation.ConversationType == constant.GroupChatType {
groupInfo, err := imdb.GetGroupInfoByGroupID(req.Conversation.GroupID)
for _, group := range rpcResp.Groups {
req := &pbGroup.SetGroupMemberInfoReq{GroupID: group.GroupID, UserID: userID, FaceURL: &wrappers.StringValue{Value: faceURL}}
_, err := client.SetGroupMemberInfo(ctx, req)
if err != nil {
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.Conversation.GroupID, err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
if groupInfo.Status == constant.GroupStatusDismissed && !req.Conversation.IsNotInGroup {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "group status is dismissed", groupInfo)
errMsg := "group status is dismissed"
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}
return resp, nil
}
}
var conversation imdb.Conversation
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req.Conversation, err.Error())
}
if err := db.DB.SetSingleConversationRecvMsgOpt(req.Conversation.OwnerUserID, req.Conversation.ConversationID, req.Conversation.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}
return resp, nil
}
isUpdate, err := imdb.SetConversation(conversation)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
if isUpdate {
err = rocksCache.DelConversationFromCache(req.Conversation.OwnerUserID, req.Conversation.ConversationID)
} else {
err = rocksCache.DelUserConversationIDListFromCache(req.Conversation.OwnerUserID)
}
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.Conversation.ConversationID, req.Conversation.OwnerUserID)
}
// notification
if req.Conversation.ConversationType == constant.SingleChatType && req.NotificationType == constant.ConversationPrivateChatNotification {
//sync peer user conversation if conversation is singleChatType
if err := syncPeerUserConversation(req.Conversation, req.OperationID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
} else {
chat.ConversationChangeNotification(req.OperationID, req.Conversation.OwnerUserID)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOptReq) (*pbUser.SetRecvMsgOptResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.SetRecvMsgOptResp{}
var conversation imdb.Conversation
if err := utils.CopyStructFields(&conversation, req); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req, err.Error())
}
if err := db.DB.SetSingleConversationRecvMsgOpt(req.OwnerUserID, req.ConversationID, req.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}
return resp, nil
}
stringList := strings.Split(req.ConversationID, "_")
if len(stringList) > 1 {
switch stringList[0] {
case "single":
conversation.UserID = stringList[1]
conversation.ConversationType = constant.SingleChatType
case "group":
conversation.GroupID = stringList[1]
conversation.ConversationType = constant.GroupChatType
return
}
chat.GroupMemberInfoSetNotification(operationID, opUserID, group.GroupID, userID)
}
isUpdate, err := imdb.SetRecvMsgOpt(conversation)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
if isUpdate {
err = rocksCache.DelConversationFromCache(conversation.OwnerUserID, conversation.ConversationID)
} else {
err = rocksCache.DelUserConversationIDListFromCache(conversation.OwnerUserID)
}
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), conversation.ConversationID, err.Error())
}
chat.ConversationChangeNotification(req.OperationID, req.OwnerUserID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
func (s *userServer) GetAllUserID(_ context.Context, req *pbUser.GetAllUserIDReq) (*pbUser.GetAllUserIDResp, error) {
log.NewInfo(req.OperationID, "GetAllUserID args ", req.String())
if !token_verify.IsManagerUserID(req.OpUserID) {
log.NewError(req.OperationID, "IsManagerUserID false ", req.OpUserID)
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
}
uidList, err := imdb.SelectAllUserID()
func (s *userServer) SyncJoinedGroupMemberNickname(ctx context.Context, userID string, newNickname, oldNickname string, operationID string, opUserID string) {
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImFriendName)
if err != nil {
log.NewError(req.OperationID, "SelectAllUserID false ", err.Error())
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
} else {
log.NewInfo(req.OperationID, "GetAllUserID rpc return ", pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{}, UserIDList: uidList})
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{}, UserIDList: uidList}, nil
return
}
}
func (s *userServer) SyncJoinedGroupMemberFaceURL(userID string, faceURL string, operationID string, opUserID string) {
joinedGroupIDList, err := rocksCache.GetJoinedGroupIDListFromCache(userID)
client := pbGroup.NewGroupClient(etcdConn)
newReq := &pbGroup.GetJoinedGroupListReq{FromUserID: userID}
rpcResp, err := client.GetJoinedGroupList(ctx, newReq)
if err != nil {
log.NewWarn(operationID, "GetJoinedGroupIDListByUserID failed ", userID, err.Error())
return
}
for _, groupID := range joinedGroupIDList {
groupMemberInfo := imdb.GroupMember{UserID: userID, GroupID: groupID, FaceURL: faceURL}
if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo)
continue
}
//if err := rocksCache.DelAllGroupMembersInfoFromCache(groupID); err != nil {
// log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID)
// continue
//}
if err := rocksCache.DelGroupMemberInfoFromCache(groupID, userID); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID, userID)
continue
}
chat.GroupMemberInfoSetNotification(operationID, opUserID, groupID, userID)
req := pbGroup.GetUserInGroupMembersReq{UserID: userID}
for _, group := range rpcResp.Groups {
req.GroupIDs = append(req.GroupIDs, group.GroupID)
}
}
func (s *userServer) SyncJoinedGroupMemberNickname(userID string, newNickname, oldNickname string, operationID string, opUserID string) {
joinedGroupIDList, err := imdb.GetJoinedGroupIDListByUserID(userID)
resp, err := client.GetUserInGroupMembers(ctx, &req)
if err != nil {
log.NewWarn(operationID, "GetJoinedGroupIDListByUserID failed ", userID, err.Error())
return
}
for _, v := range joinedGroupIDList {
member, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(v, userID)
if err != nil {
log.NewWarn(operationID, "GetGroupMemberInfoByGroupIDAndUserID failed ", err.Error(), v, userID)
continue
}
if member.Nickname == oldNickname {
groupMemberInfo := imdb.GroupMember{UserID: userID, GroupID: v, Nickname: newNickname}
if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo)
continue
for _, v := range resp.Members {
if v.Nickname == oldNickname {
req := pbGroup.SetGroupMemberNicknameReq{Nickname: newNickname, GroupID: v.GroupID, UserID: v.UserID}
_, err := client.SetGroupMemberNickname(ctx, &req)
if err != nil {
return
}
//if err := rocksCache.DelAllGroupMembersInfoFromCache(v); err != nil {
// log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), v)
// continue
//}
if err := rocksCache.DelGroupMemberInfoFromCache(v, userID); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), v)
}
chat.GroupMemberInfoSetNotification(operationID, opUserID, v, userID)
chat.GroupMemberInfoSetNotification(operationID, opUserID, v.GroupID, userID)
}
}
}
func (s *userServer) AddUser(ctx context.Context, req *pbUser.AddUserReq) (*pbUser.AddUserResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.AddUserResp{CommonResp: &pbUser.CommonResp{}}
err := imdb.AddUser(req.UserInfo.UserID, req.UserInfo.PhoneNumber, req.UserInfo.Nickname, req.UserInfo.Email, req.UserInfo.Gender, req.UserInfo.FaceURL, req.UserInfo.BirthStr)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddUser", err.Error(), req.String())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
return resp, nil
}
func (s *userServer) GetUsersInfo(ctx context.Context, req *pbUser.GetUsersInfoReq) (*pbUser.GetUsersInfoResp, error) {
resp := &pbUser.GetUsersInfoResp{}
users, err := s.Find(ctx, req.UserIDs)
@ -447,7 +188,6 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
if err != nil {
return nil, err
}
oldNickname := ""
if req.UserInfo.Nickname != "" {
u, err := s.Take(ctx, req.UserInfo.UserID)
@ -456,7 +196,6 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
}
oldNickname = u.Nickname
}
user, err := utils2.NewPBUser(req.UserInfo).Convert()
if err != nil {
return nil, err
@ -469,36 +208,26 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
if err != nil {
return nil, err
}
client := pbFriend.NewFriendClient(etcdConn)
newReq := &pbFriend.GetFriendListReq{
CommID: &pbFriend.CommID{OperationID: req.OperationID, FromUserID: req.UserInfo.UserID, OpUserID: req.OpUserID},
}
newReq := &pbFriend.GetFriendListReq{UserID: req.UserInfo.UserID}
rpcResp, err := client.GetFriendList(context.Background(), newReq)
if err != nil {
log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq)
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: 500, ErrMsg: err.Error()}}, nil
}
for _, v := range rpcResp.FriendInfoList {
log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, v.FriendUser.UserID)
// chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, v.FriendUser.UserID)
chat.FriendInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, v.FriendUser.UserID, req.OpUserID)
}
if err := rocksCache.DelUserInfoFromCache(user.UserID); err != nil {
log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq)
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
return nil, err
}
//chat.UserInfoUpdatedNotification(req.OperationID, req.OpUserID, req.UserInfo.UserID)
chat.UserInfoUpdatedNotification(req.OperationID, req.OpUserID, req.UserInfo.UserID)
log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID)
go func() {
for _, v := range rpcResp.FriendInfoList {
chat.FriendInfoUpdatedNotification(tools.OperationID(ctx), req.UserInfo.UserID, v.FriendUser.UserID, tools.OpUserID(ctx))
}
}()
chat.UserInfoUpdatedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.UserInfo.UserID)
if req.UserInfo.FaceURL != "" {
s.SyncJoinedGroupMemberFaceURL(req.UserInfo.UserID, req.UserInfo.FaceURL, req.OperationID, req.OpUserID)
s.SyncJoinedGroupMemberFaceURL(ctx, req.UserInfo.UserID, req.UserInfo.FaceURL, tools.OperationID(ctx), tools.OpUserID(ctx))
}
if req.UserInfo.Nickname != "" {
s.SyncJoinedGroupMemberNickname(req.UserInfo.UserID, req.UserInfo.Nickname, oldNickname, req.OperationID, req.OpUserID)
s.SyncJoinedGroupMemberNickname(ctx, req.UserInfo.UserID, req.UserInfo.Nickname, oldNickname, tools.OperationID(ctx), tools.OpUserID(ctx))
}
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
return &resp, nil
}
func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.SetGlobalRecvMessageOptReq) (*pbUser.SetGlobalRecvMessageOptResp, error) {
@ -559,74 +288,48 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
}
if req.UserName != "" {
usersDB, err = imdb.GetUserByName(req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
usersDB, total, err := s.GetByName(ctx, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
return resp, nil
return nil, err
}
resp.TotalNums, err = imdb.GetUsersCount(req.UserName)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.UserName, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
resp.Total = int32(total)
for _, v := range usersDB {
u1, err := utils2.NewDBUser(v).Convert()
if err != nil {
return nil, err
}
resp.Users = append(resp.Users, u1)
}
return &resp, nil
} else if req.Content != "" {
var count int64
usersDB, count, err = imdb.GetUsersByNameAndID(req.Content, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsers failed", req.Pagination.ShowNumber, req.Pagination.PageNumber, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.TotalNums = int32(count)
}
else {
usersDB, err = imdb.GetUsers(req.Pagination.ShowNumber, req.Pagination.PageNumber)
usersDB, total, err := s.GetByNameAndID(ctx, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsers failed", req.Pagination.ShowNumber, req.Pagination.PageNumber, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
return nil, err
}
resp.TotalNums, err = imdb.GetTotalUserNum()
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
resp.Total = int32(total)
for _, v := range usersDB {
u1, err := utils2.NewDBUser(v).Convert()
if err != nil {
return nil, err
}
resp.Users = append(resp.Users, u1)
}
}
for _, userDB := range usersDB {
var user sdkws.UserInfo
utils.CopyStructFields(&user, userDB)
user.CreateTime = uint32(userDB.CreateTime.Unix())
user.BirthStr = utils.TimeToString(userDB.Birth)
resp.UserList = append(resp.UserList, &pbUser.CmsUser{User: &user})
return &resp, nil
}
var userIDList []string
for _, v := range resp.UserList {
userIDList = append(userIDList, v.User.UserID)
}
isBlockUser, err := imdb.UsersIsBlock(userIDList)
usersDB, total, err := s.Get(ctx, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userIDList)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
return nil, err
}
for _, v := range resp.UserList {
if utils.IsContain(v.User.UserID, isBlockUser) {
v.IsBlock = true
resp.Total = int32(total)
for _, userDB := range usersDB {
u, err := utils2.NewDBUser(userDB).Convert()
if err != nil {
return nil, err
}
resp.Users = append(resp.Users, u)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
return &resp, nil
}

@ -281,7 +281,7 @@ func (pb *PBUser) Convert() (*relation.User, error) {
func (db *DBUser) Convert() (*sdk.UserInfo, error) {
dst := &sdk.UserInfo{}
utils.CopyStructFields(dst, db)
dst.CreateTime = uint32(db.CreateTime.Unix())
dst.CreateTime = db.CreateTime.Unix()
dst.Birthday = db.Birth.Unix()
return dst, nil
}

@ -18,17 +18,73 @@ type GroupInterface interface {
DeleteGroupByIDs(ctx context.Context, groupIDs []string) error
TakeGroupByID(ctx context.Context, groupID string) (group *relation.Group, err error)
GetJoinedGroupList(ctx context.Context, userID string) ([]*relation.Group, error)
GetGroupMemberList(ctx context.Context, groupID string) ([]*relation.GroupMember, error)
GetGroupMemberListByUserID(ctx context.Context, groupID string, userIDs []string) ([]*relation.GroupMember, error)
GetGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation.GroupMember, error) // relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
GetGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
GetGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error)
CreateGroupMember(ctx context.Context, groupMember []*relation.GroupMember) error
CreateGroupRequest(ctx context.Context, requests []*relation.GroupRequest) error
//mongo
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
}
var _ GroupInterface = (*GroupController)(nil)
type GroupController struct {
database GroupDataBaseInterface
}
func (g *GroupController) GetJoinedGroupList(ctx context.Context, userID string) ([]*relation.Group, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) GetGroupMemberList(ctx context.Context, groupID string) ([]*relation.GroupMember, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) GetGroupMemberListByUserID(ctx context.Context, groupID string, userIDs []string) ([]*relation.GroupMember, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) GetGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation.GroupMember, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) GetGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) GetGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) CreateGroupMember(ctx context.Context, groupMember []*relation.GroupMember) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) CreateGroupRequest(ctx context.Context, requests []*relation.GroupRequest) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
//TODO implement me
panic("implement me")
}
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupInterface {
groupController := &GroupController{database: newGroupDatabase(db, rdb, mgoDB)}
return groupController

@ -12,7 +12,9 @@ type UserInterface interface {
Take(ctx context.Context, userID string) (user *relation.User, err error)
Update(ctx context.Context, users []*relation.User) (err error)
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, err error)
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
}
type UserController struct {
@ -34,10 +36,15 @@ func (u *UserController) Update(ctx context.Context, users []*relation.User) (er
func (u *UserController) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
return u.database.UpdateByMap(ctx, userID, args)
}
func (u *UserController) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, err error) {
func (u *UserController) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
return u.database.GetByName(ctx, userName, showNumber, pageNumber)
}
func (u *UserController) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
return u.database.GetByNameAndID(ctx, content, showNumber, pageNumber)
}
func (u *UserController) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
return u.database.Get(ctx, showNumber, pageNumber)
}
func NewUserController(db *gorm.DB) UserInterface {
controller := &UserController{database: newUserDatabase(db)}
return controller
@ -49,7 +56,9 @@ type UserDatabaseInterface interface {
Take(ctx context.Context, userID string) (user *relation.User, err error)
Update(ctx context.Context, users []*relation.User) (err error)
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, err error)
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
Get(ctx context.Context, showNumber, pageNumber int32) (users []*User, count int64, err error)
}
type UserDatabase struct {
@ -80,6 +89,12 @@ func (u *UserDatabase) Update(ctx context.Context, users []*relation.User) (err
func (u *UserDatabase) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
return u.sqlDB.UpdateByMap(ctx, userID, args)
}
func (u *UserDatabase) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, err error) {
func (u *UserDatabase) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
return u.sqlDB.GetByName(ctx, userName, showNumber, pageNumber)
}
func (u *UserDatabase) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
return u.sqlDB.GetByNameAndID(ctx, content, showNumber, pageNumber)
}
func (u *UserDatabase) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
return u.sqlDB.Get(ctx, showNumber, pageNumber)
}

@ -71,10 +71,37 @@ func (u *User) Take(ctx context.Context, userID string) (user *User, err error)
return user, err
}
func (u *User) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*User, err error) {
func (u *User) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*User, count int64, err error) {
defer func() {
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userName", userName, "showNumber", showNumber, "pageNumber", pageNumber, "users", users, "count", count)
}()
err = u.DB.Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber * pageNumber)).Find(&users).Error
if err != nil {
return nil, 0, utils.Wrap(err, "")
}
return users, count, utils.Wrap(u.DB.Where(" name like ? ", fmt.Sprintf("%%%s%%", userName)).Count(&count).Error, "")
}
func (u *User) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*User, count int64, err error) {
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userName", userName, "showNumber", showNumber, "pageNumber", pageNumber, "users", users)
}()
err = u.DB.Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
return users, utils.Wrap(err, "")
db := u.DB.Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content)
if err := db.Count(&count).Error; err != nil {
return nil, 0, utils.Wrap(err, "")
}
err = utils.Wrap(db.Limit(int(showNumber)).Offset(int(showNumber*pageNumber)).Find(&users).Error, "")
return
}
func (u *User) Get(ctx context.Context, showNumber, pageNumber int32) (users []*User, count int64, err error) {
defer func() {
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "showNumber", showNumber, "pageNumber", pageNumber, "users", users, "count", count)
}()
err = u.DB.Model(u).Count(&count).Error
if err != nil {
return nil, 0, utils.Wrap(err, "")
}
err = utils.Wrap(u.DB.Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&users).Error, "")
return
}

@ -173,6 +173,10 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
return constant.ErrIdentity.Wrap(utils.GetSelfFuncName())
}
func IsAppManagerUid(ctx context.Context) bool {
return utils.IsContain(tools.OpUserID(ctx), config.Config.Manager.AppManagerUid)
}
func CheckAdmin(ctx context.Context) error {
if utils.IsContain(tools.OpUserID(ctx), config.Config.Manager.AppManagerUid) {
return nil

@ -1,160 +0,0 @@
package utils
import (
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/token_verify"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"math/rand"
"strconv"
"time"
)
func OperationIDGenerator() string {
return strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10)
}
func FriendOpenIMCopyDB(dst *imdb.Friend, src *open_im_sdk.FriendInfo) {
utils.CopyStructFields(dst, src)
dst.FriendUserID = src.FriendUser.UserID
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime))
}
func FriendDBCopyOpenIM(dst *open_im_sdk.FriendInfo, src *imdb.Friend) error {
utils.CopyStructFields(dst, src)
user, err := imdb.GetUserByUserID(src.FriendUserID)
if err != nil {
return utils.Wrap(err, "")
}
utils.CopyStructFields(dst.FriendUser, user)
dst.CreateTime = uint32(src.CreateTime.Unix())
if dst.FriendUser == nil {
dst.FriendUser = &open_im_sdk.UserInfo{}
}
dst.FriendUser.CreateTime = uint32(user.CreateTime.Unix())
return nil
}
func FriendRequestOpenIMCopyDB(dst *imdb.FriendRequest, src *open_im_sdk.FriendRequest) {
utils.CopyStructFields(dst, src)
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime))
dst.HandleTime = utils.UnixSecondToTime(int64(src.HandleTime))
}
func FriendRequestDBCopyOpenIM(dst *open_im_sdk.FriendRequest, src *imdb.FriendRequest) error {
utils.CopyStructFields(dst, src)
user, err := imdb.GetUserByUserID(src.FromUserID)
if err != nil {
return utils.Wrap(err, "")
}
dst.FromNickname = user.Nickname
dst.FromFaceURL = user.FaceURL
dst.FromGender = user.Gender
user, err = imdb.GetUserByUserID(src.ToUserID)
if err != nil {
return utils.Wrap(err, "")
}
dst.ToNickname = user.Nickname
dst.ToFaceURL = user.FaceURL
dst.ToGender = user.Gender
dst.CreateTime = uint32(src.CreateTime.Unix())
dst.HandleTime = uint32(src.HandleTime.Unix())
return nil
}
func BlackOpenIMCopyDB(dst *imdb.Black, src *open_im_sdk.BlackInfo) {
utils.CopyStructFields(dst, src)
dst.BlockUserID = src.BlackUserInfo.UserID
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime))
}
func BlackDBCopyOpenIM(dst *open_im_sdk.BlackInfo, src *imdb.Black) error {
utils.CopyStructFields(dst, src)
dst.CreateTime = uint32(src.CreateTime.Unix())
user, err := imdb.GetUserByUserID(src.BlockUserID)
if err != nil {
return utils.Wrap(err, "")
}
utils.CopyStructFields(dst.BlackUserInfo, user)
return nil
}
func GroupOpenIMCopyDB(dst *imdb.Group, src *open_im_sdk.GroupInfo) {
utils.CopyStructFields(dst, src)
}
func GroupDBCopyOpenIM(dst *open_im_sdk.GroupInfo, src *imdb.Group) error {
utils.CopyStructFields(dst, src)
user, err := imdb.GetGroupOwnerInfoByGroupID(src.GroupID)
if err != nil {
return utils.Wrap(err, "")
}
dst.OwnerUserID = user.UserID
memberCount, err := imdb.GetGroupMemberNumByGroupID(src.GroupID)
dst.MemberCount = uint32(memberCount)
if err != nil {
return utils.Wrap(err, "")
}
dst.CreateTime = uint32(src.CreateTime.Unix())
dst.NotificationUpdateTime = uint32(src.NotificationUpdateTime.Unix())
if src.NotificationUpdateTime.Unix() < 0 {
dst.NotificationUpdateTime = 0
}
return nil
}
func GroupMemberOpenIMCopyDB(dst *imdb.GroupMember, src *open_im_sdk.GroupMemberFullInfo) {
utils.CopyStructFields(dst, src)
}
func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src *imdb.GroupMember) error {
utils.CopyStructFields(dst, src)
if token_verify.IsManagerUserID(src.UserID) {
u, err := imdb.GetUserByUserID(src.UserID)
if err != nil {
return utils.Wrap(err, "")
}
utils.CopyStructFields(dst, u)
dst.AppMangerLevel = 1
}
dst.JoinTime = int32(src.JoinTime.Unix())
if src.JoinTime.Unix() < 0 {
dst.JoinTime = 0
return nil
}
dst.MuteEndTime = uint32(src.MuteEndTime.Unix())
if dst.MuteEndTime < uint32(time.Now().Unix()) {
dst.MuteEndTime = 0
}
return nil
}
func GroupRequestOpenIMCopyDB(dst *imdb.GroupRequest, src *open_im_sdk.GroupRequest) {
utils.CopyStructFields(dst, src)
}
func GroupRequestDBCopyOpenIM(dst *open_im_sdk.GroupRequest, src *imdb.GroupRequest) {
utils.CopyStructFields(dst, src)
dst.ReqTime = uint32(src.ReqTime.Unix())
dst.HandleTime = uint32(src.HandledTime.Unix())
}
func UserOpenIMCopyDB(dst *imdb.User, src *open_im_sdk.UserInfo) {
utils.CopyStructFields(dst, src)
dst.Birth, _ = utils.TimeStringToTime(src.BirthStr)
dst.CreateTime = utils.UnixSecondToTime(int64(src.CreateTime))
}
func UserDBCopyOpenIM(dst *open_im_sdk.UserInfo, src *imdb.User) {
utils.CopyStructFields(dst, src)
dst.CreateTime = uint32(src.CreateTime.Unix())
//dst.Birth = uint32(src.Birth.Unix())
dst.BirthStr = utils.TimeToString(src.Birth)
}
func UserDBCopyOpenIMPublicUser(dst *open_im_sdk.PublicUserInfo, src *imdb.User) {
utils.CopyStructFields(dst, src)
}

File diff suppressed because it is too large Load Diff

@ -4,21 +4,20 @@ option go_package = "Open_IM/pkg/proto/friend;friend";
package friend;
message GetFriendsInfoReq{
string ToUserID = 1;
string FromUserID = 2;
string fromUserID = 1;
repeated string toUserIDs = 2;
}
message GetFriendInfoResp{
message GetFriendsInfoResp{
repeated server_api_params.FriendInfo FriendInfoList = 1;
}
message AddFriendReq{
string ToUserID = 1;
string FromUserID = 2;
string ReqMsg = 3;
string fromUserID = 1;
string toUserID = 2;
string reqMsg = 3;
}
message AddFriendResp{
server_api_params.CommonResp commonResp = 1;
}
@ -31,115 +30,131 @@ message ImportFriendResp{
}
message GetFriendApplyListReq{
string ToUserID = 1;
string FromUserID = 2;
message GetToFriendApplyListReq{
string userID = 1;
server_api_params.RequestPagination pagination = 2;
}
message GetFriendApplyListResp{
message GetToFriendApplyListResp{
repeated server_api_params.FriendRequest FriendRequestList = 1;
int32 total = 2;
}
message GetFriendListReq{
string ToUserID = 1;
string FromUserID = 2;
server_api_params.RequestPagination pagination = 1;
string userID = 2;
}
message GetFriendListResp{
repeated server_api_params.FriendInfo FriendInfoList = 1;
int32 total = 2;
}
message AddBlacklistReq{
string ToUserID = 1;
string FromUserID = 2;
string fromUserID = 1;
string toUserID = 2;
}
message AddBlacklistResp{
}
message RemoveBlacklistReq{
string ToUserID = 1;
string FromUserID = 2;
string fromUserID = 1;
string toUserID = 2;
}
message RemoveBlacklistResp{
}
message GetBlacklistReq{
string FromUserID = 1;
string userID = 1;
server_api_params.RequestPagination pagination = 2;
}
message GetBlacklistResp{
repeated server_api_params.PublicUserInfo BlackUserInfoList = 1;
int32 total = 2;
}
message IsFriendReq{
string ToUserID = 1;
string FromUserID = 2;
string fromUserID = 1;
string toUserID = 2;
}
message IsFriendResp{
bool Response = 1;
bool Response = 1;
}
message IsInBlackListReq{
string ToUserID = 1;
string FromUserID = 2;
string fromUserID = 1;
string toUserID = 2;
}
message IsInBlackListResp{
bool Response = 1;
bool Response = 1;
}
message DeleteFriendReq{
string ToUserID = 1;
string FromUserID = 2;
string fromUserID = 1;
string toUserID = 2;
}
message DeleteFriendResp{
}
//process
message AddFriendResponseReq{
string ToUserID = 1;
string FromUserID = 2;
message FriendApplyResponseReq{
string fromUserID = 1;
string toUserID = 2;
int32 handleResult = 3;
string handleMsg = 4;
}
message AddFriendResponseResp{
message FriendApplyResponseResp{
}
message SetFriendRemarkReq{
string ToUserID = 1;
string FromUserID = 2;
string Remark = 3;
string fromUserID = 1;
string toUserID = 2;
string remark = 3;
}
message SetFriendRemarkResp{
}
message GetSelfApplyListReq{
string ToUserID = 1;
string FromUserID = 2;
message GetFromFriendApplyListReq{
string userID = 1;
server_api_params.RequestPagination pagination = 2;
}
message GetSelfApplyListResp{
repeated server_api_params.FriendRequest FriendRequestList = 1;
message GetFromFriendApplyListResp{
repeated server_api_params.FriendRequest friendRequestList = 1;
int32 total = 2;
}
service friend{
//
rpc addFriend(AddFriendReq) returns(AddFriendResp);
rpc getFriendApplyList(GetFriendApplyListReq) returns(GetFriendApplyListResp);
rpc getSelfApplyList(GetSelfApplyListReq) returns(GetSelfApplyListResp);
//
rpc getToFriendApplyList(GetToFriendApplyListReq) returns(GetToFriendApplyListResp);
//
rpc getFromFriendApplyList(GetFromFriendApplyListReq) returns(GetFromFriendApplyListResp);
//
rpc getFriendList(GetFriendListReq) returns(GetFriendListResp);
//
rpc addBlacklist(AddBlacklistReq) returns(AddBlacklistResp);
//
rpc removeBlacklist(RemoveBlacklistReq) returns(RemoveBlacklistResp);
//
rpc isFriend(IsFriendReq) returns(IsFriendResp);
//
rpc isInBlackList(IsInBlackListReq) returns(IsInBlackListResp);
//
rpc getBlacklist(GetBlacklistReq) returns(GetBlacklistResp);
//
rpc deleteFriend(DeleteFriendReq) returns(DeleteFriendResp);
rpc addFriendResponse(AddFriendResponseReq) returns(AddFriendResponseResp);
//
rpc friendApplyResponse(FriendApplyResponseReq) returns(FriendApplyResponseResp);
//
rpc setFriendRemark(SetFriendRemarkReq) returns(SetFriendRemarkResp);
//
rpc importFriend(ImportFriendReq) returns(ImportFriendResp);
//
rpc getFriendsInfo(GetFriendsInfoReq) returns (GetFriendsInfoResp);
}

File diff suppressed because it is too large Load Diff

@ -10,18 +10,18 @@ message CreateGroupReq{
repeated string initMemberList = 1;
server_api_params.GroupInfo groupInfo = 2;
repeated string adminUserIDs = 3;
string ownerUserID = 5; //owner
string ownerUserID = 4; //owner
}
message CreateGroupResp{
server_api_params.GroupInfo groupInfo = 3;
server_api_params.GroupInfo groupInfo = 1;
}
message GetGroupsInfoReq{
repeated string groupIDList = 1;
repeated string groupIDs = 1;
}
message GetGroupsInfoResp{
repeated server_api_params.GroupInfo groupInfoList = 3;
repeated server_api_params.GroupInfo groupInfos = 1;
}
@ -34,11 +34,11 @@ message SetGroupInfoResp{
message GetGroupApplicationListReq {
server_api_params.RequestPagination pagination = 1;
string fromUserID = 3; //owner or admin
string fromUserID = 2; //owner or admin
}
message GetGroupApplicationListResp {
int32 total = 1;
repeated server_api_params.GroupRequest groupRequestList = 3;
repeated server_api_params.GroupRequest groupRequests = 2;
}
message GetUserReqApplicationListReq{
@ -48,7 +48,7 @@ message GetUserReqApplicationListReq{
message GetUserReqApplicationListResp{
int32 total = 1;
repeated server_api_params.GroupRequest groupRequestList = 2;
repeated server_api_params.GroupRequest groupRequests = 2;
}
@ -64,18 +64,18 @@ message TransferGroupOwnerResp{
message JoinGroupReq{
string groupID = 1;
string reqMessage = 2;
int32 joinSource = 5;
string inviterUserID = 6;
int32 joinSource = 3;
string inviterUserID = 4;
}
message JoinGroupResp{
}
message GroupApplicationResponseReq{
string groupID = 3;
string fromUserID = 4; //
string handledMsg = 5;
int32 handleResult = 6;
string groupID = 1;
string fromUserID = 2; //
string handledMsg = 3;
int32 handleResult = 4;
}
message GroupApplicationResponseResp{
@ -93,13 +93,13 @@ message QuitGroupResp{
message GetGroupMemberListReq {
string groupID = 1;
int32 filter = 4;
server_api_params.RequestPagination pagination = 2;
int32 filter = 2;
server_api_params.RequestPagination pagination = 4;
}
message GetGroupMemberListResp {
int32 total = 1;
repeated server_api_params.GroupMemberFullInfo memberList = 3;
repeated server_api_params.GroupMemberFullInfo members = 2;
}
@ -109,7 +109,7 @@ message GetGroupMembersInfoReq {
}
message GetGroupMembersInfoResp {
repeated server_api_params.GroupMemberFullInfo memberList = 3;
repeated server_api_params.GroupMemberFullInfo members = 1;
}
message KickGroupMemberReq {
@ -129,14 +129,14 @@ message GetJoinedGroupListReq {
}
message GetJoinedGroupListResp{
int32 total = 1;
repeated server_api_params.GroupInfo groupList = 3;
repeated server_api_params.GroupInfo groups = 2;
}
message InviteUserToGroupReq {
string groupID = 3;
string reason = 4;
repeated string invitedUserIDList = 5;
string groupID = 1;
string reason = 2;
repeated string invitedUserIDs = 3;
}
message InviteUserToGroupResp {
@ -145,11 +145,10 @@ message InviteUserToGroupResp {
message GetGroupAllMemberReq {
string groupID = 1;
int32 offset = 4;
int32 count = 5;
server_api_params.RequestPagination pagination = 2;
}
message GetGroupAllMemberResp {
repeated server_api_params.GroupMemberFullInfo memberList = 3;
repeated server_api_params.GroupMemberFullInfo members = 1;
}
message CMSGroup {
@ -167,7 +166,7 @@ message GetGroupsReq {
message GetGroupsResp {
repeated CMSGroup groups = 1;
int32 GroupNum = 3;
int32 GroupNum = 2;
}
message GetGroupMemberReq {
@ -187,7 +186,7 @@ message GetGroupMembersCMSResp {
}
message DismissGroupReq{
string groupID = 3;
string groupID = 1;
}
message DismissGroupResp{
@ -195,9 +194,9 @@ message DismissGroupResp{
message MuteGroupMemberReq{
string groupID = 3;
string userID = 4;
uint32 mutedSeconds = 5;
string groupID = 1;
string userID = 2;
uint32 mutedSeconds = 3;
}
message MuteGroupMemberResp{
@ -206,8 +205,8 @@ message MuteGroupMemberResp{
message CancelMuteGroupMemberReq{
string groupID = 3;
string userID = 4;
string groupID = 1;
string userID = 2;
}
message CancelMuteGroupMemberResp{
@ -215,7 +214,7 @@ message CancelMuteGroupMemberResp{
message MuteGroupReq{
string groupID = 3;
string groupID = 1;
}
message MuteGroupResp{
@ -224,7 +223,7 @@ message MuteGroupResp{
message CancelMuteGroupReq{
string groupID = 3;
string groupID = 1;
}
message CancelMuteGroupResp{
@ -236,7 +235,7 @@ message CancelMuteGroupResp{
message SetGroupMemberNicknameReq{
string groupID = 1;
string nickname = 2;
string userID = 5;
string userID = 3;
}
message SetGroupMemberNicknameResp{
}
@ -248,24 +247,24 @@ message GetJoinedSuperGroupListReq {
message GetJoinedSuperGroupListResp {
int32 total = 1;
repeated server_api_params.GroupInfo groupList = 3;
repeated server_api_params.GroupInfo groups = 2;
}
message GetSuperGroupsInfoReq {
repeated string groupIDList = 1;
repeated string groupIDs = 1;
}
message GetSuperGroupsInfoResp {
repeated server_api_params.GroupInfo groupInfoList = 3;
repeated server_api_params.GroupInfo groupInfos = 1;
}
message SetGroupMemberInfoReq{
string groupID = 1;
string userID = 2;
google.protobuf.StringValue nickname = 5;
google.protobuf.StringValue faceURL = 6;
google.protobuf.Int32Value roleLevel = 7;
google.protobuf.StringValue ex = 8;
google.protobuf.StringValue nickname = 3;
google.protobuf.StringValue faceURL = 4;
google.protobuf.Int32Value roleLevel = 5;
google.protobuf.StringValue ex = 6;
}
message SetGroupMemberInfoResp{
@ -286,6 +285,13 @@ message GetGroupAbstractInfoResp{
repeated GroupAbstractInfo groupAbstractInfos = 1;
}
message getUserInGroupMembersReq {
string userID = 1;
repeated string groupIDs = 2;
}
message getUserInGroupMembersResp{
repeated server_api_params.GroupMemberFullInfo members = 1;
}
service group{
//
@ -317,30 +323,32 @@ service group{
//
rpc inviteUserToGroup(InviteUserToGroupReq) returns (InviteUserToGroupResp);
rpc GetGroups(GetGroupsReq) returns(GetGroupsResp);
rpc GetGroupMembersCMS(GetGroupMembersCMSReq) returns(GetGroupMembersCMSResp);
rpc getGroups(GetGroupsReq) returns(GetGroupsResp);
rpc getGroupMembersCMS(GetGroupMembersCMSReq) returns(GetGroupMembersCMSResp);
//
rpc DismissGroup(DismissGroupReq) returns(DismissGroupResp);
rpc dismissGroup(DismissGroupReq) returns(DismissGroupResp);
//
rpc MuteGroupMember(MuteGroupMemberReq) returns(MuteGroupMemberResp);
rpc muteGroupMember(MuteGroupMemberReq) returns(MuteGroupMemberResp);
//
rpc CancelMuteGroupMember(CancelMuteGroupMemberReq) returns(CancelMuteGroupMemberResp);
rpc cancelMuteGroupMember(CancelMuteGroupMemberReq) returns(CancelMuteGroupMemberResp);
//
rpc MuteGroup(MuteGroupReq) returns(MuteGroupResp);
rpc muteGroup(MuteGroupReq) returns(MuteGroupResp);
//
rpc CancelMuteGroup(CancelMuteGroupReq) returns(CancelMuteGroupResp);
rpc cancelMuteGroup(CancelMuteGroupReq) returns(CancelMuteGroupResp);
//
rpc GetJoinedSuperGroupList(GetJoinedSuperGroupListReq) returns (GetJoinedSuperGroupListResp);
rpc getJoinedSuperGroupList(GetJoinedSuperGroupListReq) returns (GetJoinedSuperGroupListResp);
//
rpc GetSuperGroupsInfo(GetSuperGroupsInfoReq) returns (GetSuperGroupsInfoResp);
rpc getSuperGroupsInfo(GetSuperGroupsInfoReq) returns (GetSuperGroupsInfoResp);
//
rpc SetGroupMemberNickname(SetGroupMemberNicknameReq) returns (SetGroupMemberNicknameResp);
rpc setGroupMemberNickname(SetGroupMemberNicknameReq) returns (SetGroupMemberNicknameResp);
//
rpc SetGroupMemberInfo(SetGroupMemberInfoReq) returns (SetGroupMemberInfoResp);
rpc setGroupMemberInfo(SetGroupMemberInfoReq) returns (SetGroupMemberInfoResp);
//hash
rpc GetGroupAbstractInfo(GetGroupAbstractInfoReq) returns (GetGroupAbstractInfoResp);
rpc getGroupAbstractInfo(GetGroupAbstractInfoReq) returns (GetGroupAbstractInfoResp);
//
rpc getUserInGroupMembers(getUserInGroupMembersReq) returns (getUserInGroupMembersResp);
}

Loading…
Cancel
Save