mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
fix Pb2String
This commit is contained in:
parent
46c3b5a6ea
commit
c96ccfc7f5
@ -1,7 +1,6 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"Open_IM/internal/fault_tolerant"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
utils2 "Open_IM/pkg/utils"
|
||||
|
@ -13,8 +13,8 @@ import (
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
cp "Open_IM/pkg/common/utils"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"github.com/OpenIMSDK/getcdv3"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
@ -567,21 +567,14 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
|
||||
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (resp *pbGroup.GetGroupAllMemberResp, err error) {
|
||||
resp = &pbGroup.GetGroupAllMemberResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), nil, "req", req.String(), "resp", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
groupInfo, err := rocksCache.GetGroupInfoFromCache(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
memberList, err := rocksCache.GetGroupMembersInfoFromCache(ctx, req.Count, req.Offset, req.GroupID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range memberList {
|
||||
var node open_im_sdk.GroupMemberFullInfo
|
||||
@ -589,7 +582,7 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
|
||||
resp.MemberList = append(resp.MemberList, &node)
|
||||
}
|
||||
}
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGroupMemberListReq) (resp *pbGroup.GetGroupMemberListResp, err error) {
|
||||
@ -723,7 +716,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
c.GroupID = req.GroupID
|
||||
c.IsNotInGroup = true
|
||||
reqPb.Conversation = &c
|
||||
etcdConn, err := utils.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
|
||||
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
@ -774,8 +767,7 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
|
||||
for _, userID := range req.MemberList {
|
||||
groupMember, err := rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, userID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
var memberNode open_im_sdk.GroupMemberFullInfo
|
||||
utils.CopyStructFields(&memberNode, groupMember)
|
||||
@ -1027,7 +1019,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
c.IsNotInGroup = false
|
||||
c.UpdateUnreadCountTime = utils.GetCurrentTimestampByMill()
|
||||
reqPb.Conversation = &c
|
||||
etcdConn, err := utils.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
|
||||
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
@ -1167,8 +1159,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
m := make(map[string]interface{})
|
||||
m["need_verification"] = req.GroupInfoForSet.NeedVerification.Value
|
||||
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if req.GroupInfoForSet.LookMemberInfo != nil {
|
||||
@ -1176,8 +1167,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
m := make(map[string]interface{})
|
||||
m["look_member_info"] = req.GroupInfoForSet.LookMemberInfo.Value
|
||||
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if req.GroupInfoForSet.ApplyMemberFriend != nil {
|
||||
@ -1185,8 +1175,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
m := make(map[string]interface{})
|
||||
m["apply_member_friend"] = req.GroupInfoForSet.ApplyMemberFriend.Value
|
||||
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
||||
constant.SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
//only administrators can set group information
|
||||
@ -1197,13 +1186,11 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
groupInfo.NotificationUpdateTime = time.Now()
|
||||
}
|
||||
if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupInfoForSet.GroupID); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
err = imdb.SetGroupInfo(groupInfo)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if changedType != 0 {
|
||||
chat.GroupInfoSetNotification(req.OperationID, req.OpUserID, req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification)
|
||||
@ -1211,10 +1198,10 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
if req.GroupInfoForSet.Notification != "" {
|
||||
//get group member user id
|
||||
getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupInfoForSet.GroupID}
|
||||
etcdConn, err := utils.GetConn(ctx, config.Config.RpcRegisterName.OpenImCacheName)
|
||||
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImCacheName)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return+
|
||||
}
|
||||
client := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := client.GetGroupMemberIDListFromCache(ctx, getGroupMemberIDListFromCacheReq)
|
||||
@ -1238,7 +1225,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
conversationReq.FieldType = constant.FieldGroupAtType
|
||||
conversation.GroupAtType = constant.GroupNotification
|
||||
conversationReq.UserIDList = cacheResp.UserIDList
|
||||
nEtcdConn, err := utils.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName)
|
||||
nEtcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
@ -1269,31 +1256,26 @@ func (s *groupServer) TransferGroupOwner(ctx context.Context, req *pbGroup.Trans
|
||||
}
|
||||
|
||||
if req.OldOwnerUserID == req.NewOwnerUserID {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
err = rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, req.NewOwnerUserID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
err = rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, req.OldOwnerUserID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groupMemberInfo := imdb.GroupMember{GroupID: req.GroupID, UserID: req.OldOwnerUserID, RoleLevel: constant.GroupOrdinaryUsers}
|
||||
err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
groupMemberInfo = imdb.GroupMember{GroupID: req.GroupID, UserID: req.NewOwnerUserID, RoleLevel: constant.GroupOwner}
|
||||
err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupOwnerTransferredNotification(req)
|
||||
return
|
||||
@ -1305,32 +1287,24 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbGroup.GetGroupsReq)
|
||||
Groups: []*pbGroup.CMSGroup{},
|
||||
Pagination: &open_im_sdk.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber},
|
||||
}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
if req.GroupID != "" {
|
||||
groupInfoDB, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp, nil
|
||||
}
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
resp.GroupNum = 1
|
||||
groupInfo := &open_im_sdk.GroupInfo{}
|
||||
utils.CopyStructFields(groupInfo, groupInfoDB)
|
||||
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
memberNum, err := imdb.GetGroupMembersCount(req.GroupID, "")
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
groupInfo.MemberCount = uint32(memberNum)
|
||||
groupInfo.CreateTime = uint32(groupInfoDB.CreateTime.Unix())
|
||||
@ -1355,25 +1329,18 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbGroup.GetGroupsReq)
|
||||
}
|
||||
resp.GroupNum = int32(count)
|
||||
}
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGroupMembersCMSReq) (resp *pbGroup.GetGroupMembersCMSResp, _ error) {
|
||||
resp = &pbGroup.GetGroupMembersCMSResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
groupMembers, err := imdb.GetGroupMembersByGroupIdCMS(req.GroupID, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
groupMembersCount, err := imdb.GetGroupMembersCount(req.GroupID, req.UserName)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
log.NewInfo(req.OperationID, groupMembersCount)
|
||||
resp.MemberNums = int32(groupMembersCount)
|
||||
@ -1388,20 +1355,14 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGr
|
||||
CurrentPage: req.Pagination.PageNumber,
|
||||
ShowNumber: req.Pagination.ShowNumber,
|
||||
}
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGroup.GetUserReqApplicationListReq) (resp *pbGroup.GetUserReqApplicationListResp, _ error) {
|
||||
resp = &pbGroup.GetUserReqApplicationListResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
groupRequests, err := imdb.GetUserReqGroupByUserID(req.UserID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
for _, groupReq := range groupRequests {
|
||||
node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}}
|
||||
@ -1420,39 +1381,29 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGrou
|
||||
cp.GroupDBCopyOpenIM(node.GroupInfo, group)
|
||||
resp.GroupRequestList = append(resp.GroupRequestList, &node)
|
||||
}
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGroupReq) (resp *pbGroup.DismissGroupResp, _ error) {
|
||||
func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGroupReq) (resp *pbGroup.DismissGroupResp, err error) {
|
||||
resp = &pbGroup.DismissGroupResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
|
||||
constant.SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||
return
|
||||
return nil, utils.Wrap(constant.ErrNoPermission, "")
|
||||
}
|
||||
|
||||
if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupID); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if err := s.DelGroupAndUserCache(ctx, req.GroupID, nil); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err := imdb.OperateGroupStatus(req.GroupID, constant.GroupStatusDismissed)
|
||||
err = imdb.OperateGroupStatus(req.GroupID, constant.GroupStatusDismissed)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID)
|
||||
@ -1470,28 +1421,26 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
|
||||
c.GroupID = req.GroupID
|
||||
c.IsNotInGroup = true
|
||||
reqPb.Conversation = &c
|
||||
etcdConn, err := utils.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
|
||||
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
trace_log.SetContextInfo(ctx, "SetConversation", err, "req", &reqPb, "resp", respPb)
|
||||
}
|
||||
err = imdb.DeleteGroupMemberByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupDismissedNotification(req)
|
||||
} else {
|
||||
err = db.DB.DeleteSuperGroup(req.GroupID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGroupMemberReq) (resp *pbGroup.MuteGroupMemberResp, _ error) {
|
||||
func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGroupMemberReq) (resp *pbGroup.MuteGroupMemberResp, err error) {
|
||||
resp = &pbGroup.MuteGroupMemberResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
@ -1500,108 +1449,79 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou
|
||||
}()
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if opFlag == 0 {
|
||||
constant.SetErrorForResp(constant.ErrNoPermission, resp.CommonResp)
|
||||
return
|
||||
return nil, utils.Wrap(constant.ErrNoPermission, "")
|
||||
}
|
||||
|
||||
mutedInfo, err := rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, req.UserID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if mutedInfo.RoleLevel == constant.GroupOwner && opFlag != 1 {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if mutedInfo.RoleLevel == constant.GroupAdmin && opFlag == 3 {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, req.UserID); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
groupMemberInfo := imdb.GroupMember{GroupID: req.GroupID, UserID: req.UserID}
|
||||
groupMemberInfo.MuteEndTime = time.Unix(int64(time.Now().Second())+int64(req.MutedSeconds), time.Now().UnixNano())
|
||||
err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupMemberMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, req.MutedSeconds)
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.CancelMuteGroupMemberReq) (resp *pbGroup.CancelMuteGroupMemberResp, _ error) {
|
||||
func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.CancelMuteGroupMemberReq) (resp *pbGroup.CancelMuteGroupMemberResp, err error) {
|
||||
resp = &pbGroup.CancelMuteGroupMemberResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if opFlag == 0 {
|
||||
constant.SetErrorForResp(constant.ErrNoPermission, resp.CommonResp)
|
||||
return
|
||||
return nil, utils.Wrap(constant.ErrNoPermission, "")
|
||||
}
|
||||
|
||||
mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.UserID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if mutedInfo.RoleLevel == constant.GroupOwner && opFlag != 1 {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if mutedInfo.RoleLevel == constant.GroupAdmin && opFlag == 3 {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if err := rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, req.UserID); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groupMemberInfo := imdb.GroupMember{GroupID: req.GroupID, UserID: req.UserID}
|
||||
groupMemberInfo.MuteEndTime = time.Unix(0, 0)
|
||||
err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupMemberCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq) (resp *pbGroup.MuteGroupResp, _ error) {
|
||||
func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq) (resp *pbGroup.MuteGroupResp, err error) {
|
||||
resp = &pbGroup.MuteGroupResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
}
|
||||
if opFlag == 0 {
|
||||
//errMsg := req.OperationID + "opFlag == 0 " + req.GroupID + req.OpUserID
|
||||
//log.Error(req.OperationID, errMsg)
|
||||
//return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
|
||||
constant.SetErrorForResp(constant.ErrNoPermission, resp.CommonResp)
|
||||
return
|
||||
return nil, utils.Wrap(constant.ErrNoPermission, "")
|
||||
}
|
||||
|
||||
//mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.UserID)
|
||||
@ -1618,35 +1538,28 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq)
|
||||
// return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
|
||||
//}
|
||||
if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupID); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = imdb.OperateGroupStatus(req.GroupID, constant.GroupStatusMuted)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chat.GroupMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMuteGroupReq) (resp *pbGroup.CancelMuteGroupResp, _ error) {
|
||||
func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMuteGroupReq) (resp *pbGroup.CancelMuteGroupResp, err error) {
|
||||
resp = &pbGroup.CancelMuteGroupResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if opFlag == 0 {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
//mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.)
|
||||
//if err != nil {
|
||||
@ -1663,28 +1576,20 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu
|
||||
//}
|
||||
log.Debug(req.OperationID, "UpdateGroupInfoDefaultZero ", req.GroupID, map[string]interface{}{"status": constant.GroupOk})
|
||||
if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupID); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
err = imdb.UpdateGroupInfoDefaultZero(req.GroupID, map[string]interface{}{"status": constant.GroupOk})
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.SetGroupMemberNicknameReq) (resp *pbGroup.SetGroupMemberNicknameResp, _ error) {
|
||||
func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.SetGroupMemberNicknameReq) (resp *pbGroup.SetGroupMemberNicknameResp, err error) {
|
||||
resp = &pbGroup.SetGroupMemberNicknameResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
constant.SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||
return
|
||||
return nil, utils.Wrap(constant.ErrNoPermission, "")
|
||||
}
|
||||
cbReq := &pbGroup.SetGroupMemberInfoReq{
|
||||
GroupID: req.GroupID,
|
||||
@ -1694,8 +1599,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S
|
||||
Nickname: &wrapperspb.StringValue{Value: req.Nickname},
|
||||
}
|
||||
if err := CallbackBeforeSetGroupMemberInfo(ctx, cbReq); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
nickName := cbReq.Nickname.Value
|
||||
groupMemberInfo := imdb.GroupMember{}
|
||||
@ -1704,8 +1608,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S
|
||||
if nickName == "" {
|
||||
userNickname, err := imdb.GetUserNameByUserID(groupMemberInfo.UserID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
groupMemberInfo.Nickname = userNickname
|
||||
} else {
|
||||
@ -1713,32 +1616,23 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S
|
||||
}
|
||||
|
||||
if err := rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, req.UserID); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfoReq) (resp *pbGroup.SetGroupMemberInfoResp, _ error) {
|
||||
func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfoReq) (resp *pbGroup.SetGroupMemberInfoResp, err error) {
|
||||
resp = &pbGroup.SetGroupMemberInfoResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
if err := rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, req.UserID); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if err := CallbackBeforeSetGroupMemberInfo(ctx, req); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
groupMember := imdb.GroupMember{
|
||||
GroupID: req.GroupID,
|
||||
@ -1760,8 +1654,7 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
|
||||
m["ex"] = nil
|
||||
}
|
||||
if err := imdb.UpdateGroupMemberInfoByMap(groupMember, m); err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if req.RoleLevel != nil {
|
||||
switch req.RoleLevel.Value {
|
||||
@ -1775,26 +1668,19 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
|
||||
} else {
|
||||
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
}
|
||||
return
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupAbstractInfo(ctx context.Context, req *pbGroup.GetGroupAbstractInfoReq) (resp *pbGroup.GetGroupAbstractInfoResp, _ error) {
|
||||
func (s *groupServer) GetGroupAbstractInfo(ctx context.Context, req *pbGroup.GetGroupAbstractInfoReq) (resp *pbGroup.GetGroupAbstractInfoResp, err error) {
|
||||
resp = &pbGroup.GetGroupAbstractInfoResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||
trace_log.ShowLog(ctx)
|
||||
}()
|
||||
hashCode, err := rocksCache.GetGroupMemberListHashFromCache(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
resp.GroupMemberListHash = hashCode
|
||||
num, err := rocksCache.GetGroupMemberNumFromCache(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
resp.GroupMemberNumber = int32(num)
|
||||
return resp, nil
|
||||
@ -1803,7 +1689,7 @@ func (s *groupServer) GetGroupAbstractInfo(ctx context.Context, req *pbGroup.Get
|
||||
func (s *groupServer) DelGroupAndUserCache(ctx context.Context, groupID string, userIDList []string) error {
|
||||
operationID := trace_log.GetOperationID(ctx)
|
||||
if groupID != "" {
|
||||
etcdConn, err := utils.GetConn(ctx, config.Config.RpcRegisterName.OpenImCacheName)
|
||||
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImCacheName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ import (
|
||||
|
||||
func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbGroup.GetJoinedSuperGroupListResp{CommonResp: &pbGroup.CommonResp{}}
|
||||
groupIDList, err := rocksCache.GetJoinedSuperGroupListFromCache(req.UserID)
|
||||
resp := &pbGroup.GetJoinedSuperGroupListResp{CommonResp: &commonPb.CommonResp{}}
|
||||
groupIDList, err := rocksCache.GetJoinedSuperGroupListFromCache(ctx, req.UserID)
|
||||
if err != nil {
|
||||
if err == redis.Nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroupByUserID nil ", err.Error(), req.UserID)
|
||||
@ -27,7 +27,7 @@ func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.
|
||||
return resp, nil
|
||||
}
|
||||
for _, groupID := range groupIDList {
|
||||
groupInfoFromCache, err := rocksCache.GetGroupInfoFromCache(groupID)
|
||||
groupInfoFromCache, err := rocksCache.GetGroupInfoFromCache(ctx, groupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupInfoByGroupID failed", groupID, err.Error())
|
||||
continue
|
||||
@ -36,7 +36,7 @@ func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.
|
||||
if err := utils.CopyStructFields(groupInfo, groupInfoFromCache); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
groupMemberIDList, err := rocksCache.GetGroupMemberIDListFromCache(groupID)
|
||||
groupMemberIDList, err := rocksCache.GetGroupMemberIDListFromCache(ctx, groupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroup failed", groupID, err.Error())
|
||||
continue
|
||||
@ -48,12 +48,12 @@ func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetSuperGroupsInfo(_ context.Context, req *pbGroup.GetSuperGroupsInfoReq) (resp *pbGroup.GetSuperGroupsInfoResp, err error) {
|
||||
func (s *groupServer) GetSuperGroupsInfo(ctx context.Context, req *pbGroup.GetSuperGroupsInfoReq) (resp *pbGroup.GetSuperGroupsInfoResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbGroup.GetSuperGroupsInfoResp{CommonResp: &pbGroup.CommonResp{}}
|
||||
resp = &pbGroup.GetSuperGroupsInfoResp{CommonResp: &commonPb.CommonResp{}}
|
||||
groupsInfoList := make([]*commonPb.GroupInfo, 0)
|
||||
for _, groupID := range req.GroupIDList {
|
||||
groupInfoFromRedis, err := rocksCache.GetGroupInfoFromCache(groupID)
|
||||
groupInfoFromRedis, err := rocksCache.GetGroupInfoFromCache(ctx, groupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupID)
|
||||
continue
|
||||
|
@ -51,7 +51,8 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackRes
|
||||
}
|
||||
//utils.CopyStructFields(req, msg.MsgData)
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSendSingleMsgCommand, req, resp, config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackTimeOut); err != nil {
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSendSingleMsgCommand,
|
||||
req, resp, config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackTimeOut, &config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackFailedContinue); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
if !config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackFailedContinue {
|
||||
@ -79,7 +80,8 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp
|
||||
}
|
||||
resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: &callbackResp}
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackAfterSendSingleMsgCommand, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil {
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackAfterSendSingleMsgCommand,
|
||||
req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut, &config.Config.Callback.CallbackAfterSendSingleMsg.CallbackFailedContinue); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
return callbackResp
|
||||
@ -101,7 +103,8 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp
|
||||
}
|
||||
resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: &callbackResp}
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSendGroupMsgCommand, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil {
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSendGroupMsgCommand,
|
||||
req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut, &config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue {
|
||||
@ -129,7 +132,8 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp
|
||||
}
|
||||
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: &callbackResp}
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackAfterSendGroupMsgCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackAfterSendGroupMsgCommand, req, resp,
|
||||
config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut, nil); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
return callbackResp
|
||||
@ -150,7 +154,8 @@ func callbackMsgModify(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp {
|
||||
}
|
||||
resp := &cbApi.CallbackMsgModifyCommandResp{CommonCallbackResp: &callbackResp}
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackMsgModifyCommand, req, resp, config.Config.Callback.CallbackMsgModify.CallbackTimeOut); err != nil {
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackMsgModifyCommand, req, resp,
|
||||
config.Config.Callback.CallbackMsgModify.CallbackTimeOut, &config.Config.Callback.CallbackMsgModify.CallbackFailedContinue); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
if !config.Config.Callback.CallbackMsgModify.CallbackFailedContinue {
|
||||
|
@ -15,21 +15,21 @@ func (rpc *rpcChat) ClearMsg(_ context.Context, req *pbChat.ClearMsgReq) (*pbCha
|
||||
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.UserID) {
|
||||
errMsg := "No permission" + req.OpUserID + req.UserID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "CleanUpOneUserAllMsgFromRedis args", req.UserID)
|
||||
err := db.DB.CleanUpOneUserAllMsgFromRedis(req.UserID, req.OperationID)
|
||||
if err != nil {
|
||||
errMsg := "CleanUpOneUserAllMsgFromRedis failed " + err.Error() + req.OperationID + req.UserID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "CleanUpUserMsgFromMongo args", req.UserID)
|
||||
err = db.DB.CleanUpUserMsgFromMongo(req.UserID, req.OperationID)
|
||||
if err != nil {
|
||||
errMsg := "CleanUpUserMsgFromMongo failed " + err.Error() + req.OperationID + req.UserID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
resp := pbChat.ClearMsgResp{ErrCode: 0}
|
||||
@ -42,14 +42,14 @@ func (rpc *rpcChat) SetMsgMinSeq(_ context.Context, req *pbChat.SetMsgMinSeqReq)
|
||||
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.UserID) {
|
||||
errMsg := "No permission" + req.OpUserID + req.UserID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
if req.GroupID == "" {
|
||||
err := db.DB.SetUserMinSeq(req.UserID, req.MinSeq)
|
||||
if err != nil {
|
||||
errMsg := "SetUserMinSeq failed " + err.Error() + req.OperationID + req.UserID + utils.Uint32ToString(req.MinSeq)
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
return &pbChat.SetMsgMinSeqResp{}, nil
|
||||
}
|
||||
@ -57,7 +57,7 @@ func (rpc *rpcChat) SetMsgMinSeq(_ context.Context, req *pbChat.SetMsgMinSeqReq)
|
||||
if err != nil {
|
||||
errMsg := "SetGroupUserMinSeq failed " + err.Error() + req.OperationID + req.GroupID + req.UserID + utils.Uint32ToString(req.MinSeq)
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
return &pbChat.SetMsgMinSeqResp{}, nil
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
commonPb "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
commonPb "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"time"
|
||||
@ -30,27 +30,27 @@ func (rpc *rpcChat) DelMsgList(_ context.Context, req *commonPb.DelMsgListReq) (
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
func (rpc *rpcChat) DelSuperGroupMsg(_ context.Context, req *msg.DelSuperGroupMsgReq) (*msg.DelSuperGroupMsgResp, error) {
|
||||
func (rpc *rpcChat) DelSuperGroupMsg(ctx context.Context, req *msg.DelSuperGroupMsgReq) (*msg.DelSuperGroupMsgResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
if !token_verify.CheckAccess(req.OpUserID, req.UserID) {
|
||||
if !token_verify.CheckAccess(ctx, req.OpUserID, req.UserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.UserID)
|
||||
return &msg.DelSuperGroupMsgResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
return &msg.DelSuperGroupMsgResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: constant.ErrNoPermission.ErrMsg}, nil
|
||||
}
|
||||
resp := &msg.DelSuperGroupMsgResp{}
|
||||
groupMaxSeq, err := db.DB.GetGroupMaxSeq(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupMaxSeq false ", req.OpUserID, req.UserID,req.GroupID)
|
||||
log.NewError(req.OperationID, "GetGroupMaxSeq false ", req.OpUserID, req.UserID, req.GroupID)
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
err = db.DB.SetGroupUserMinSeq(req.GroupID,req.UserID, groupMaxSeq)
|
||||
err = db.DB.SetGroupUserMinSeq(req.GroupID, req.UserID, groupMaxSeq)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SetGroupUserMinSeq false ", req.OpUserID, req.UserID,req.GroupID)
|
||||
log.NewError(req.OperationID, "SetGroupUserMinSeq false ", req.OpUserID, req.UserID, req.GroupID)
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
@ -87,7 +88,7 @@ func messageReactionSender(operationID, sendID string, sourceID string, sessionT
|
||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||
pbData.MsgData.GroupID = sourceID
|
||||
}
|
||||
etcdConn, err := utils.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
|
||||
etcdConn, err := getcdv3.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ func callbackSetMessageReactionExtensions(setReq *msg.SetMessageReactionExtensio
|
||||
}
|
||||
resp := &cbApi.CallbackBeforeSetMessageReactionExtResp{CommonCallbackResp: &callbackResp}
|
||||
defer log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSetMessageReactionExtensionCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSetMessageReactionExtensionCommand,
|
||||
req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut, nil); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
}
|
||||
@ -52,7 +53,8 @@ func callbackDeleteMessageReactionExtensions(setReq *msg.DeleteMessageListReacti
|
||||
}
|
||||
resp := &cbApi.CallbackDeleteMessageReactionExtResp{CommonCallbackResp: &callbackResp}
|
||||
defer log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeDeleteMessageReactionExtensionsCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeDeleteMessageReactionExtensionsCommand,
|
||||
req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut, nil); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ func (rpc *rpcChat) SetSendMsgStatus(_ context.Context, req *pbMsg.SetSendMsgSta
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
|
||||
if err := db.DB.SetSendMsgStatus(req.Status, req.OperationID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.ErrCode = constant.ErrDatabase.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
cacheRpc "Open_IM/pkg/proto/cache"
|
||||
pbConversation "Open_IM/pkg/proto/conversation"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
@ -129,7 +130,7 @@ func (rpc *rpcChat) messageVerification(ctx context.Context, data *pbChat.SendMs
|
||||
}
|
||||
log.NewDebug(data.OperationID, *config.Config.MessageVerify.FriendVerify)
|
||||
reqGetBlackIDListFromCache := &cacheRpc.GetBlackIDListFromCacheReq{UserID: data.MsgData.RecvID, OperationID: data.OperationID}
|
||||
etcdConn, err := utils.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
etcdConn, err := getcdv3.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
if err != nil {
|
||||
errMsg := data.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(data.OperationID, errMsg)
|
||||
@ -152,7 +153,7 @@ func (rpc *rpcChat) messageVerification(ctx context.Context, data *pbChat.SendMs
|
||||
log.NewDebug(data.OperationID, *config.Config.MessageVerify.FriendVerify)
|
||||
if *config.Config.MessageVerify.FriendVerify {
|
||||
reqGetFriendIDListFromCache := &cacheRpc.GetFriendIDListFromCacheReq{UserID: data.MsgData.RecvID, OperationID: data.OperationID}
|
||||
etcdConn, err := utils.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
etcdConn, err := getcdv3.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
if err != nil {
|
||||
errMsg := data.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(data.OperationID, errMsg)
|
||||
@ -176,7 +177,7 @@ func (rpc *rpcChat) messageVerification(ctx context.Context, data *pbChat.SendMs
|
||||
return true, 0, "", nil
|
||||
}
|
||||
case constant.GroupChatType:
|
||||
userIDList, err := utils2.GetGroupMemberUserIDList(data.MsgData.GroupID, data.OperationID)
|
||||
userIDList, err := utils2.GetGroupMemberUserIDList(ctx, data.MsgData.GroupID, data.OperationID)
|
||||
if err != nil {
|
||||
errMsg := data.OperationID + err.Error()
|
||||
log.NewError(data.OperationID, errMsg)
|
||||
@ -250,7 +251,7 @@ func (rpc *rpcChat) messageVerification(ctx context.Context, data *pbChat.SendMs
|
||||
if groupInfo.GroupType == constant.SuperGroup {
|
||||
return true, 0, "", nil
|
||||
} else {
|
||||
userIDList, err := utils2.GetGroupMemberUserIDList(data.MsgData.GroupID, data.OperationID)
|
||||
userIDList, err := utils2.GetGroupMemberUserIDList(ctx, data.MsgData.GroupID, data.OperationID)
|
||||
if err != nil {
|
||||
errMsg := data.OperationID + err.Error()
|
||||
log.NewError(data.OperationID, errMsg)
|
||||
@ -485,13 +486,13 @@ func (rpc *rpcChat) SendMsg(ctx context.Context, pb *pbChat.SendMsgReq) (*pbChat
|
||||
wg.Add(1)
|
||||
tmp := valueCopy(pb)
|
||||
// go rpc.sendMsgToGroup(v[i*split:(i+1)*split], *pb, k, &sendTag, &wg)
|
||||
go rpc.sendMsgToGroupOptimization(v[i*split:(i+1)*split], tmp, k, &sendTag, &wg)
|
||||
go rpc.sendMsgToGroupOptimization(ctx, v[i*split:(i+1)*split], tmp, k, &sendTag, &wg)
|
||||
}
|
||||
if remain > 0 {
|
||||
wg.Add(1)
|
||||
tmp := valueCopy(pb)
|
||||
// go rpc.sendMsgToGroup(v[split*(len(v)/split):], *pb, k, &sendTag, &wg)
|
||||
go rpc.sendMsgToGroupOptimization(v[split*(len(v)/split):], tmp, k, &sendTag, &wg)
|
||||
go rpc.sendMsgToGroupOptimization(ctx, v[split*(len(v)/split):], tmp, k, &sendTag, &wg)
|
||||
}
|
||||
}
|
||||
log.Debug(pb.OperationID, "send msg cost time22 ", time.Since(t1), pb.MsgData.ClientMsgID, "uidList : ", len(addUidList))
|
||||
@ -538,7 +539,7 @@ func (rpc *rpcChat) SendMsg(ctx context.Context, pb *pbChat.SendMsgReq) (*pbChat
|
||||
conversationReq.UserIDList = pb.MsgData.AtUserIDList
|
||||
conversation.GroupAtType = constant.AtMe
|
||||
}
|
||||
etcdConn, err := utils.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName)
|
||||
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName)
|
||||
if err != nil {
|
||||
errMsg := pb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(pb.OperationID, errMsg)
|
||||
@ -615,7 +616,7 @@ func (rpc *rpcChat) SendMsg(ctx context.Context, pb *pbChat.SendMsgReq) (*pbChat
|
||||
}
|
||||
msgToMQSingle.MsgData = pb.MsgData
|
||||
log.NewInfo(msgToMQSingle.OperationID, msgToMQSingle)
|
||||
err1 := rpc.sendMsgToWriter(&msgToMQSingle, msgToMQSingle.MsgData.GroupID, constant.OnlineStatus)
|
||||
err1 := rpc.sendMsgToWriter(ctx, &msgToMQSingle, msgToMQSingle.MsgData.GroupID, constant.OnlineStatus)
|
||||
if err1 != nil {
|
||||
log.NewError(msgToMQSingle.OperationID, "kafka send msg err:RecvID", msgToMQSingle.MsgData.RecvID, msgToMQSingle.String())
|
||||
promePkg.PromeInc(promePkg.WorkSuperGroupChatMsgProcessFailedCounter)
|
||||
@ -639,7 +640,7 @@ func (rpc *rpcChat) sendMsgToWriter(ctx context.Context, m *pbChat.MsgDataToMQ,
|
||||
case constant.OnlineStatus:
|
||||
if m.MsgData.ContentType == constant.SignalingNotification {
|
||||
rpcPushMsg := pbPush.PushMsgReq{OperationID: m.OperationID, MsgData: m.MsgData, PushToUserID: key}
|
||||
grpcConn, err := utils.GetConn(ctx, config.Config.RpcRegisterName.OpenImPushName)
|
||||
grpcConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImPushName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1103,7 +1104,7 @@ func valueCopy(pb *pbChat.SendMsgReq) *pbChat.SendMsgReq {
|
||||
return &pbChat.SendMsgReq{Token: pb.Token, OperationID: pb.OperationID, MsgData: &msgData}
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) sendMsgToGroup(list []string, pb pbChat.SendMsgReq, status string, sendTag *bool, wg *sync.WaitGroup) {
|
||||
func (rpc *rpcChat) sendMsgToGroup(ctx context.Context, list []string, pb pbChat.SendMsgReq, status string, sendTag *bool, wg *sync.WaitGroup) {
|
||||
// log.Debug(pb.OperationID, "split userID ", list)
|
||||
offlinePushInfo := sdk_ws.OfflinePushInfo{}
|
||||
if pb.MsgData.OfflinePushInfo != nil {
|
||||
@ -1126,7 +1127,7 @@ func (rpc *rpcChat) sendMsgToGroup(list []string, pb pbChat.SendMsgReq, status s
|
||||
if isSend {
|
||||
msgToMQGroup.MsgData = groupPB.MsgData
|
||||
// log.Debug(groupPB.OperationID, "sendMsgToWriter, ", v, groupID, msgToMQGroup.String())
|
||||
err := rpc.sendMsgToWriter(&msgToMQGroup, v, status)
|
||||
err := rpc.sendMsgToWriter(ctx, &msgToMQGroup, v, status)
|
||||
if err != nil {
|
||||
log.NewError(msgToMQGroup.OperationID, "kafka send msg err:UserId", v, msgToMQGroup.String())
|
||||
} else {
|
||||
@ -1139,7 +1140,7 @@ func (rpc *rpcChat) sendMsgToGroup(list []string, pb pbChat.SendMsgReq, status s
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) sendMsgToGroupOptimization(list []string, groupPB *pbChat.SendMsgReq, status string, sendTag *bool, wg *sync.WaitGroup) {
|
||||
func (rpc *rpcChat) sendMsgToGroupOptimization(ctx context.Context, list []string, groupPB *pbChat.SendMsgReq, status string, sendTag *bool, wg *sync.WaitGroup) {
|
||||
msgToMQGroup := pbChat.MsgDataToMQ{Token: groupPB.Token, OperationID: groupPB.OperationID, MsgData: groupPB.MsgData}
|
||||
tempOptions := make(map[string]bool, 1)
|
||||
for k, v := range groupPB.MsgData.Options {
|
||||
@ -1158,7 +1159,7 @@ func (rpc *rpcChat) sendMsgToGroupOptimization(list []string, groupPB *pbChat.Se
|
||||
log.Error(msgToMQGroup.OperationID, "sendMsgToGroupOptimization userID nil ", msgToMQGroup.String())
|
||||
continue
|
||||
}
|
||||
err := rpc.sendMsgToWriter(&msgToMQGroup, v, status)
|
||||
err := rpc.sendMsgToWriter(ctx, &msgToMQGroup, v, status)
|
||||
if err != nil {
|
||||
log.NewError(msgToMQGroup.OperationID, "kafka send msg err:UserId", v, msgToMQGroup.String())
|
||||
} else {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbCache "Open_IM/pkg/proto/cache"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@ -59,7 +60,7 @@ func GetGroupMemberUserIDListHashFromRemote(ctx context.Context, groupID string)
|
||||
|
||||
func GetGroupMemberUserIDListFromRemote(groupID string, operationID string) ([]string, error) {
|
||||
getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: operationID, GroupID: groupID}
|
||||
etcdConn, err := utils.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
etcdConn, err := getcdv3.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ var (
|
||||
ErrOwnerNotAllowedQuit = ErrInfo{OwnerNotAllowedQuitError, "OwnerNotAllowedQuitError", ""}
|
||||
ErrRegisteredAlready = ErrInfo{RegisteredAlreadyError, "RegisteredAlreadyError", ""}
|
||||
ErrGroupTypeNotSupport = ErrInfo{GroupTypeNotSupport, "", ""}
|
||||
ErrGroupNoOwner = ErrInfo{GroupNoOwner, "ErrGroupNoOwner", ""}
|
||||
|
||||
ErrDefaultOther = ErrInfo{DefaultOtherError, "DefaultOtherError", ""}
|
||||
ErrData = ErrInfo{DataError, "DataError", ""}
|
||||
@ -65,6 +66,9 @@ var (
|
||||
ErrTokenDifferentUserID = ErrInfo{TokenDifferentUserIDError, "TokenDifferentUserIDError", ""}
|
||||
|
||||
ErrMessageHasReadDisable = ErrInfo{MessageHasReadDisable, "MessageHasReadDisable", ""}
|
||||
|
||||
ErrDB = ErrDatabase
|
||||
ErrSendLimit = ErrInternalServer
|
||||
)
|
||||
|
||||
func NewErrNetwork(err error) error {
|
||||
@ -185,6 +189,7 @@ const (
|
||||
DismissedAlreadyError = 93004 //群组已经解散
|
||||
OwnerNotAllowedQuitError = 93004 //群主不能退群
|
||||
GroupTypeNotSupport = 93005
|
||||
GroupNoOwner = 93006
|
||||
)
|
||||
|
||||
// 用户错误码
|
||||
|
@ -1,14 +1,18 @@
|
||||
package im_mysql_model
|
||||
|
||||
import "Open_IM/pkg/common/db"
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var InitConfigDB *gorm.DB
|
||||
|
||||
func SetClientInitConfig(m map[string]interface{}) error {
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Model(&ClientInitConfig{}).Where("1=1").Updates(m)
|
||||
result := InitConfigDB.Model(&ClientInitConfig{}).Where("1=1").Updates(m)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&ClientInitConfig{}).Create(m).Error
|
||||
err := InitConfigDB.Model(&ClientInitConfig{}).Create(m).Error
|
||||
return err
|
||||
}
|
||||
|
||||
@ -17,6 +21,6 @@ func SetClientInitConfig(m map[string]interface{}) error {
|
||||
|
||||
func GetClientInitConfig() (ClientInitConfig, error) {
|
||||
var config ClientInitConfig
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&ClientInitConfig{}).First(&config).Error
|
||||
err := InitConfigDB.Model(&ClientInitConfig{}).First(&config).Error
|
||||
return config, err
|
||||
}
|
||||
|
@ -1,42 +1,61 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var ConversationDB *gorm.DB
|
||||
|
||||
type Conversation struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;type:char(128)" json:"OwnerUserID"`
|
||||
ConversationID string `gorm:"column:conversation_id;primary_key;type:char(128)" json:"conversationID"`
|
||||
ConversationType int32 `gorm:"column:conversation_type" json:"conversationType"`
|
||||
UserID string `gorm:"column:user_id;type:char(64)" json:"userID"`
|
||||
GroupID string `gorm:"column:group_id;type:char(128)" json:"groupID"`
|
||||
RecvMsgOpt int32 `gorm:"column:recv_msg_opt" json:"recvMsgOpt"`
|
||||
UnreadCount int32 `gorm:"column:unread_count" json:"unreadCount"`
|
||||
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"`
|
||||
BurnDuration int32 `gorm:"column:burn_duration;default:30" json:"burnDuration"`
|
||||
GroupAtType int32 `gorm:"column:group_at_type" json:"groupAtType"`
|
||||
IsNotInGroup bool `gorm:"column:is_not_in_group" json:"isNotInGroup"`
|
||||
UpdateUnreadCountTime int64 `gorm:"column:update_unread_count_time" json:"updateUnreadCountTime"`
|
||||
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
|
||||
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
}
|
||||
|
||||
func (Conversation) TableName() string {
|
||||
return "conversations"
|
||||
}
|
||||
|
||||
func SetConversation(conversation Conversation) (bool, error) {
|
||||
var isUpdate bool
|
||||
newConversation := conversation
|
||||
if db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Create(&conversation).Error
|
||||
if ConversationDB.Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
return isUpdate, ConversationDB.Model(&Conversation{}).Create(&conversation).Error
|
||||
// if exist, then update record
|
||||
} else {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
|
||||
//force update
|
||||
isUpdate = true
|
||||
return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
return isUpdate, ConversationDB.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
Updates(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
|
||||
}
|
||||
}
|
||||
func SetOneConversation(conversation Conversation) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Create(&conversation).Error
|
||||
return ConversationDB.Model(&Conversation{}).Create(&conversation).Error
|
||||
|
||||
}
|
||||
|
||||
func PeerUserSetConversation(conversation Conversation) error {
|
||||
newConversation := conversation
|
||||
if db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Create(&conversation).Error
|
||||
if ConversationDB.Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
return ConversationDB.Model(&Conversation{}).Create(&conversation).Error
|
||||
// if exist, then update record
|
||||
}
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
|
||||
//force update
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
return ConversationDB.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
Updates(map[string]interface{}{"is_private_chat": conversation.IsPrivateChat}).Error
|
||||
|
||||
}
|
||||
@ -44,32 +63,30 @@ func PeerUserSetConversation(conversation Conversation) error {
|
||||
func SetRecvMsgOpt(conversation Conversation) (bool, error) {
|
||||
var isUpdate bool
|
||||
newConversation := conversation
|
||||
if db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Create(&conversation).Error
|
||||
if ConversationDB.Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
return isUpdate, ConversationDB.Model(&Conversation{}).Create(&conversation).Error
|
||||
// if exist, then update record
|
||||
} else {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
|
||||
//force update
|
||||
isUpdate = true
|
||||
return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
return isUpdate, ConversationDB.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error
|
||||
}
|
||||
}
|
||||
|
||||
func GetUserAllConversations(ownerUserID string) ([]Conversation, error) {
|
||||
var conversations []Conversation
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
|
||||
err := ConversationDB.Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
func GetMultipleUserConversationByConversationID(ownerUserIDList []string, conversationID string) ([]Conversation, error) {
|
||||
var conversations []Conversation
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error
|
||||
err := ConversationDB.Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
func GetExistConversationUserIDList(ownerUserIDList []string, conversationID string) ([]string, error) {
|
||||
var resultArr []string
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where(" owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Pluck("owner_user_id", &resultArr).Error
|
||||
err := ConversationDB.Table("conversations").Where(" owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Pluck("owner_user_id", &resultArr).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -78,29 +95,29 @@ func GetExistConversationUserIDList(ownerUserIDList []string, conversationID str
|
||||
|
||||
func GetConversation(OwnerUserID, conversationID string) (Conversation, error) {
|
||||
var conversation Conversation
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error
|
||||
err := ConversationDB.Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error
|
||||
return conversation, err
|
||||
}
|
||||
|
||||
func GetConversations(OwnerUserID string, conversationIDs []string) ([]Conversation, error) {
|
||||
var conversations []Conversation
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
|
||||
err := ConversationDB.Model(&Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
|
||||
func GetConversationsByConversationIDMultipleOwner(OwnerUserIDList []string, conversationID string) ([]Conversation, error) {
|
||||
var conversations []Conversation
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error
|
||||
err := ConversationDB.Model(&Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
|
||||
func UpdateColumnsConversations(ownerUserIDList []string, conversationID string, args map[string]interface{}) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error
|
||||
return ConversationDB.Model(&Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error
|
||||
|
||||
}
|
||||
|
||||
func GetConversationIDListByUserID(userID string) ([]string, error) {
|
||||
var IDList []string
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&Conversation{}).Where("owner_user_id=?", userID).Pluck("conversation_id", &IDList).Error
|
||||
err := ConversationDB.Model(&Conversation{}).Where("owner_user_id=?", userID).Pluck("conversation_id", &IDList).Error
|
||||
return IDList, err
|
||||
}
|
||||
|
@ -1,21 +1,31 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"errors"
|
||||
|
||||
_ "gorm.io/gorm"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var RegisterDB *gorm.DB
|
||||
|
||||
type Register struct {
|
||||
Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"`
|
||||
Password string `gorm:"column:password;type:varchar(255)" json:"password"`
|
||||
Ex string `gorm:"column:ex;size:1024" json:"ex"`
|
||||
UserID string `gorm:"column:user_id;type:varchar(255)" json:"userID"`
|
||||
AreaCode string `gorm:"column:area_code;type:varchar(255)"`
|
||||
InvitationCode string `gorm:"column:invitation_code;type:varchar(255)"`
|
||||
RegisterIP string `gorm:"column:register_ip;type:varchar(255)"`
|
||||
}
|
||||
|
||||
func GetRegister(account, areaCode, userID string) (*Register, error) {
|
||||
var r Register
|
||||
return &r, db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("user_id = ? and user_id != ? or account = ? or account =? and area_code=?",
|
||||
return &r, RegisterDB.Table("registers").Where("user_id = ? and user_id != ? or account = ? or account =? and area_code=?",
|
||||
userID, "", account, account, areaCode).Take(&r).Error
|
||||
}
|
||||
|
||||
func GetRegisterInfo(userID string) (*Register, error) {
|
||||
var r Register
|
||||
return &r, db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("user_id = ?", userID).Take(&r).Error
|
||||
return &r, RegisterDB.Table("registers").Where("user_id = ?", userID).Take(&r).Error
|
||||
}
|
||||
|
||||
func SetPassword(account, password, ex, userID, areaCode, ip string) error {
|
||||
@ -27,20 +37,20 @@ func SetPassword(account, password, ex, userID, areaCode, ip string) error {
|
||||
RegisterIP: ip,
|
||||
AreaCode: areaCode,
|
||||
}
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("registers").Create(&r).Error
|
||||
return RegisterDB.Table("registers").Create(&r).Error
|
||||
}
|
||||
|
||||
func ResetPassword(account, password string) error {
|
||||
r := Register{
|
||||
Password: password,
|
||||
}
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("account = ?", account).Updates(&r).Error
|
||||
return RegisterDB.Table("registers").Where("account = ?", account).Updates(&r).Error
|
||||
}
|
||||
|
||||
func GetRegisterAddFriendList(showNumber, pageNumber int32) ([]string, error) {
|
||||
var IDList []string
|
||||
var err error
|
||||
model := db.DB.MysqlDB.DefaultGormDB().Model(&RegisterAddFriend{})
|
||||
model := RegisterDB.Model(&RegisterAddFriend{})
|
||||
if showNumber == 0 {
|
||||
err = model.Pluck("user_id", &IDList).Error
|
||||
} else {
|
||||
@ -54,7 +64,7 @@ func AddUserRegisterAddFriendIDList(userIDList ...string) error {
|
||||
for _, v := range userIDList {
|
||||
list = append(list, RegisterAddFriend{UserID: v})
|
||||
}
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Create(list)
|
||||
result := RegisterDB.Create(list)
|
||||
if int(result.RowsAffected) < len(userIDList) {
|
||||
return errors.New("some line insert failed")
|
||||
}
|
||||
@ -67,18 +77,18 @@ func ReduceUserRegisterAddFriendIDList(userIDList ...string) error {
|
||||
for _, v := range userIDList {
|
||||
list = append(list, RegisterAddFriend{UserID: v})
|
||||
}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Delete(list).Error
|
||||
err := RegisterDB.Delete(list).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteAllRegisterAddFriendIDList() error {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Where("1 = 1").Delete(&RegisterAddFriend{}).Error
|
||||
err := RegisterDB.Where("1 = 1").Delete(&RegisterAddFriend{}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUserIPLimit(userID string) (UserIpLimit, error) {
|
||||
var limit UserIpLimit
|
||||
limit.UserID = userID
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Take(&limit).Error
|
||||
err := RegisterDB.Model(&UserIpLimit{}).Take(&limit).Error
|
||||
return limit, err
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
var AppDB *gorm.DB
|
||||
|
||||
func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error {
|
||||
updateTime := int(time.Now().Unix())
|
||||
app := AppVersion{
|
||||
@ -16,13 +18,13 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, y
|
||||
ForceUpdate: forceUpdate,
|
||||
UpdateLog: updateLog,
|
||||
}
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Model(AppVersion{}).Where("type = ?", appType).Updates(map[string]interface{}{"force_update": forceUpdate,
|
||||
result := AppDB.Model(AppVersion{}).Where("type = ?", appType).Updates(map[string]interface{}{"force_update": forceUpdate,
|
||||
"version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType, "update_log": updateLog})
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Create(&app).Error
|
||||
err := AppDB.Create(&app).Error
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -30,5 +32,5 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, y
|
||||
|
||||
func GetNewestVersion(appType int) (*AppVersion, error) {
|
||||
app := AppVersion{}
|
||||
return &app, db.DB.MysqlDB.DefaultGormDB().Model(AppVersion{}).First(&app, appType).Error
|
||||
return &app, AppDB.Model(AppVersion{}).First(&app, appType).Error
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func InsertToFriend(toInsertFollow *Friend) error {
|
||||
toInsertFollow.CreateTime = time.Now()
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Create(toInsertFollow).Error
|
||||
err := FriendDB.Table("friends").Create(toInsertFollow).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -17,7 +16,7 @@ func InsertToFriend(toInsertFollow *Friend) error {
|
||||
|
||||
func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*Friend, error) {
|
||||
var friend Friend
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error
|
||||
err := FriendDB.Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -28,7 +27,7 @@ func GetFriendListByUserID(OwnerUserID string) ([]Friend, error) {
|
||||
var friends []Friend
|
||||
var x Friend
|
||||
x.OwnerUserID = OwnerUserID
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error
|
||||
err := FriendDB.Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -37,7 +36,7 @@ func GetFriendListByUserID(OwnerUserID string) ([]Friend, error) {
|
||||
|
||||
func GetFriendIDListByUserID(OwnerUserID string) ([]string, error) {
|
||||
var friendIDList []string
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Pluck("friend_user_id", &friendIDList).Error
|
||||
err := FriendDB.Table("friends").Where("owner_user_id=?", OwnerUserID).Pluck("friend_user_id", &friendIDList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -45,11 +44,11 @@ func GetFriendIDListByUserID(OwnerUserID string) ([]string, error) {
|
||||
}
|
||||
|
||||
func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Exec("update friends set remark=? where owner_user_id=? and friend_user_id=?", Remark, OwnerUserID, FriendUserID).Error
|
||||
return FriendDB.Exec("update friends set remark=? where owner_user_id=? and friend_user_id=?", Remark, OwnerUserID, FriendUserID).Error
|
||||
}
|
||||
|
||||
func DeleteSingleFriendInfo(OwnerUserID, FriendUserID string) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(Friend{}).Error
|
||||
return FriendDB.Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(Friend{}).Error
|
||||
}
|
||||
|
||||
type FriendUser struct {
|
||||
@ -58,7 +57,7 @@ type FriendUser struct {
|
||||
}
|
||||
|
||||
func GetUserFriendsCMS(ownerUserID, friendUserName string, pageNumber, showNumber int32) (friendUserList []*FriendUser, count int64, err error) {
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("friends").
|
||||
db := FriendDB.Table("friends").
|
||||
Select("friends.*, users.name").
|
||||
Where("friends.owner_user_id=?", ownerUserID).Limit(int(showNumber)).
|
||||
Joins("left join users on friends.friend_user_id = users.user_id").
|
||||
@ -75,7 +74,7 @@ func GetUserFriendsCMS(ownerUserID, friendUserName string, pageNumber, showNumbe
|
||||
|
||||
func GetFriendByIDCMS(ownerUserID, friendUserID string) (friendUser *FriendUser, err error) {
|
||||
friendUser = &FriendUser{}
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("friends").
|
||||
err = FriendDB.Table("friends").
|
||||
Select("friends.*, users.name").
|
||||
Where("friends.owner_user_id=? and friends.friend_user_id=?", ownerUserID, friendUserID).
|
||||
Joins("left join users on friends.friend_user_id = users.user_id").
|
||||
|
@ -1,7 +1,6 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@ -25,7 +24,7 @@ func (*Friend) Create(ctx context.Context, friends []*Friend) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
err = utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Create(&friends).Error, "")
|
||||
err = utils.Wrap(FriendDB.Create(&friends).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
@ -33,7 +32,7 @@ func (*Friend) Delete(ctx context.Context, ownerUserID string, friendUserIDs []s
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs)
|
||||
}()
|
||||
err = utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("owner_user_id = ? and friend_user_id in (?)", ownerUserID, friendUserIDs).Delete(&Friend{}).Error, "")
|
||||
err = utils.Wrap(FriendDB.Where("owner_user_id = ? and friend_user_id in (?)", ownerUserID, friendUserIDs).Delete(&Friend{}).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
@ -41,27 +40,27 @@ func (*Friend) UpdateByMap(ctx context.Context, ownerUserID string, args map[str
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(FriendDB.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (*Friend) Update(ctx context.Context, friends []*Friend) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Updates(&friends).Error, "")
|
||||
return utils.Wrap(FriendDB.Updates(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (*Friend) Find(ctx context.Context, ownerUserID string) (friends []*Friend, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
err = utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
err = utils.Wrap(FriendDB.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
return friends, err
|
||||
}
|
||||
|
||||
func (*Friend) Take(ctx context.Context, ownerUserID, friendUserID string) (group *Group, err error) {
|
||||
group = &Group{}
|
||||
defer trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "group", *group)
|
||||
err = utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(group).Error, "")
|
||||
err = utils.Wrap(FriendDB.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(group).Error, "")
|
||||
return group, err
|
||||
}
|
||||
|
@ -1,27 +1,33 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
//type FriendRequest struct {
|
||||
// FromUserID string `gorm:"column:from_user_id;primaryKey;"`
|
||||
// ToUserID string `gorm:"column:to_user_id;primaryKey;"`
|
||||
// HandleResult int32 `gorm:"column:handle_result"`
|
||||
// ReqMessage string `gorm:"column:req_message"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// HandlerUserID string `gorm:"column:handler_user_id"`
|
||||
// HandleMsg string `gorm:"column:handle_msg"`
|
||||
// HandleTime time.Time `gorm:"column:handle_time"`
|
||||
// Ex string `gorm:"column:ex"`
|
||||
//}
|
||||
var FriendRequestDB *gorm.DB
|
||||
|
||||
type FriendRequest struct {
|
||||
FromUserID string `gorm:"column:from_user_id;primary_key;size:64"`
|
||||
ToUserID string `gorm:"column:to_user_id;primary_key;size:64"`
|
||||
HandleResult int32 `gorm:"column:handle_result"`
|
||||
ReqMsg string `gorm:"column:req_msg;size:255"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
HandlerUserID string `gorm:"column:handler_user_id;size:64"`
|
||||
HandleMsg string `gorm:"column:handle_msg;size:255"`
|
||||
HandleTime time.Time `gorm:"column:handle_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
func (FriendRequest) TableName() string {
|
||||
return "friend_requests"
|
||||
}
|
||||
|
||||
// who apply to add me
|
||||
func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]FriendRequest, error) {
|
||||
var usersInfo []FriendRequest
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error
|
||||
err := FriendRequestDB.Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -31,7 +37,7 @@ func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]FriendRequest
|
||||
// I apply to add somebody
|
||||
func GetSendFriendApplicationListByUserID(FromUserID string) ([]FriendRequest, error) {
|
||||
var usersInfo []FriendRequest
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error
|
||||
err := FriendRequestDB.Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -41,7 +47,7 @@ func GetSendFriendApplicationListByUserID(FromUserID string) ([]FriendRequest, e
|
||||
// FromUserId apply to add ToUserID
|
||||
func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*FriendRequest, error) {
|
||||
var friendRequest FriendRequest
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error
|
||||
err := FriendRequestDB.Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -50,12 +56,12 @@ func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*FriendReque
|
||||
|
||||
func UpdateFriendApplication(friendRequest *FriendRequest) error {
|
||||
friendRequest.CreateTime = time.Now()
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
||||
return FriendRequestDB.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
||||
friendRequest.FromUserID, friendRequest.ToUserID).Updates(&friendRequest).Error
|
||||
}
|
||||
|
||||
func InsertFriendApplication(friendRequest *FriendRequest, args map[string]interface{}) error {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Create(friendRequest).Error; err == nil {
|
||||
if err := FriendRequestDB.Table("friend_requests").Create(friendRequest).Error; err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -67,7 +73,7 @@ func InsertFriendApplication(friendRequest *FriendRequest, args map[string]inter
|
||||
|
||||
friendRequest.CreateTime = time.Now()
|
||||
args["create_time"] = friendRequest.CreateTime
|
||||
u := db.DB.MysqlDB.DefaultGormDB().Model(friendRequest).Updates(args)
|
||||
u := FriendRequestDB.Model(friendRequest).Updates(args)
|
||||
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
||||
// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
|
||||
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
||||
@ -82,7 +88,7 @@ func InsertFriendApplication(friendRequest *FriendRequest, args map[string]inter
|
||||
if friendRequest.HandleTime.Unix() < 0 {
|
||||
friendRequest.HandleTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Create(friendRequest).Error
|
||||
err := FriendRequestDB.Table("friend_requests").Create(friendRequest).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@ -11,18 +10,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
//type GroupMember struct {
|
||||
// GroupID string `gorm:"column:group_id;primaryKey;"`
|
||||
// UserID string `gorm:"column:user_id;primaryKey;"`
|
||||
// NickName string `gorm:"column:nickname"`
|
||||
// FaceUrl string `gorm:"user_group_face_url"`
|
||||
// RoleLevel int32 `gorm:"column:role_level"`
|
||||
// JoinTime time.Time `gorm:"column:join_time"`
|
||||
// JoinSource int32 `gorm:"column:join_source"`
|
||||
// OperatorUserID string `gorm:"column:operator_user_id"`
|
||||
// Ex string `gorm:"column:ex"`
|
||||
//}
|
||||
|
||||
var GroupMemberDB *gorm.DB
|
||||
|
||||
type GroupMember struct {
|
||||
@ -44,26 +31,26 @@ func (g *GroupMember) Create(ctx context.Context, groupMemberList []*GroupMember
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupMemberList", groupMemberList)
|
||||
}()
|
||||
return utils.Wrap(g.DB.Create(&groupMemberList).Error, "")
|
||||
return utils.Wrap(GroupMemberDB.Create(&groupMemberList).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMember) Delete(ctx context.Context, groupMembers []*GroupMember) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers)
|
||||
}()
|
||||
return utils.Wrap(g.DB.Delete(groupMembers).Error, "")
|
||||
return utils.Wrap(GroupMemberDB.Delete(groupMembers).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMember) UpdateByMap(ctx context.Context, groupID string, userID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(g.DB.Model(&GroupMember{}).Where("group_id = ? and user_id = ?", groupID, userID).Updates(args).Error, "")
|
||||
return utils.Wrap(GroupMemberDB.Model(&GroupMember{}).Where("group_id = ? and user_id = ?", groupID, userID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMember) Update(ctx context.Context, groupMembers []*GroupMember) (err error) {
|
||||
defer func() { trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers) }()
|
||||
return utils.Wrap(g.DB.Updates(&groupMembers).Error, "")
|
||||
return utils.Wrap(GroupMemberDB.Updates(&groupMembers).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMember) Find(ctx context.Context, groupMembers []*GroupMember) (groupList []*GroupMember, err error) {
|
||||
@ -74,7 +61,7 @@ func (g *GroupMember) Find(ctx context.Context, groupMembers []*GroupMember) (gr
|
||||
for _, groupMember := range groupMembers {
|
||||
where = append(where, []interface{}{groupMember.GroupID, groupMember.UserID})
|
||||
}
|
||||
err = utils.Wrap(g.DB.Where("(group_id, user_id) in ?", where).Find(&groupList).Error, "")
|
||||
err = utils.Wrap(GroupMemberDB.Where("(group_id, user_id) in ?", where).Find(&groupList).Error, "")
|
||||
return groupList, err
|
||||
}
|
||||
|
||||
@ -83,7 +70,7 @@ func (g *GroupMember) Take(ctx context.Context, groupID string, userID string) (
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupMember", *groupMember)
|
||||
}()
|
||||
groupMember = &GroupMember{}
|
||||
return groupMember, utils.Wrap(g.DB.Where("group_id = ? and user_id = ?", groupID, userID).Take(groupMember).Error, "")
|
||||
return groupMember, utils.Wrap(GroupMemberDB.Where("group_id = ? and user_id = ?", groupID, userID).Take(groupMember).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMember) TakeOwnerInfo(ctx context.Context, groupID string) (groupMember *GroupMember, err error) {
|
||||
@ -91,7 +78,7 @@ func (g *GroupMember) TakeOwnerInfo(ctx context.Context, groupID string) (groupM
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMember", *groupMember)
|
||||
}()
|
||||
groupMember = &GroupMember{}
|
||||
err = g.DB.Where("group_id = ? and role_level = ?", groupID, constant.GroupOwner).Take(groupMember).Error
|
||||
err = GroupMemberDB.Where("group_id = ? and role_level = ?", groupID, constant.GroupOwner).Take(groupMember).Error
|
||||
return groupMember, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
@ -183,7 +170,7 @@ func UpdateGroupMemberInfoByMap(groupMemberInfo GroupMember, m map[string]interf
|
||||
|
||||
func GetOwnerManagerByGroupID(groupID string) ([]GroupMember, error) {
|
||||
var groupMemberList []GroupMember
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
|
||||
err := GroupMemberDB.Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -192,7 +179,7 @@ func GetOwnerManagerByGroupID(groupID string) ([]GroupMember, error) {
|
||||
|
||||
func GetGroupMemberNumByGroupID(groupID string) (int64, error) {
|
||||
var number int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Count(&number).Error
|
||||
err := GroupMemberDB.Table("group_members").Where("group_id=?", groupID).Count(&number).Error
|
||||
if err != nil {
|
||||
return 0, utils.Wrap(err, "")
|
||||
}
|
||||
@ -209,12 +196,12 @@ func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) {
|
||||
return &v, nil
|
||||
}
|
||||
}
|
||||
return nil, utils.Wrap(constant.ErrNoGroupOwner, "")
|
||||
return nil, utils.Wrap(constant.ErrGroupNoOwner, "")
|
||||
}
|
||||
|
||||
func IsExistGroupMember(groupID, userID string) bool {
|
||||
var number int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
err := GroupMemberDB.Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@ -276,7 +263,7 @@ func IsGroupOwnerAdmin(groupID, UserID string) bool {
|
||||
|
||||
func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) {
|
||||
var groupMembers []GroupMember
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
|
||||
err := GroupMemberDB.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -285,33 +272,12 @@ func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pa
|
||||
|
||||
func GetGroupMembersCount(groupID, userName string) (int64, error) {
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
|
||||
if err := GroupMemberDB.Table("group_members").Where("group_id=?", groupID).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
|
||||
return count, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func UpdateGroupMemberInfoDefaultZero(groupMemberInfo GroupMember, args map[string]interface{}) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error
|
||||
return GroupMemberDB.Model(groupMemberInfo).Updates(args).Error
|
||||
}
|
||||
|
||||
//
|
||||
//func SelectGroupList(groupID string) ([]string, error) {
|
||||
// var groupUserID string
|
||||
// var groupList []string
|
||||
// dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
// if err != nil {
|
||||
// return groupList, err
|
||||
// }
|
||||
//
|
||||
// rows, err := dbConn.Model(&GroupMember{}).Where("group_id = ?", groupID).Select("user_id").Rows()
|
||||
// if err != nil {
|
||||
// return groupList, err
|
||||
// }
|
||||
// defer rows.Close()
|
||||
// for rows.Next() {
|
||||
// rows.Scan(&groupUserID)
|
||||
// groupList = append(groupList, groupUserID)
|
||||
// }
|
||||
// return groupList, nil
|
||||
//}
|
||||
|
@ -2,26 +2,12 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
|
||||
"time"
|
||||
)
|
||||
|
||||
//type Group struct {
|
||||
// GroupID string `gorm:"column:group_id;primaryKey;"`
|
||||
// GroupName string `gorm:"column:name"`
|
||||
// Introduction string `gorm:"column:introduction"`
|
||||
// Notification string `gorm:"column:notification"`
|
||||
// FaceUrl string `gorm:"column:face_url"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// Status int32 `gorm:"column:status"`
|
||||
// CreatorUserID string `gorm:"column:creator_user_id"`
|
||||
// GroupType int32 `gorm:"column:group_type"`
|
||||
// Ex string `gorm:"column:ex"`
|
||||
//}
|
||||
|
||||
func InsertIntoGroup(groupInfo Group) error {
|
||||
if groupInfo.GroupName == "" {
|
||||
groupInfo.GroupName = "Group Chat"
|
||||
@ -31,7 +17,7 @@ func InsertIntoGroup(groupInfo Group) error {
|
||||
if groupInfo.NotificationUpdateTime.Unix() < 0 {
|
||||
groupInfo.NotificationUpdateTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Create(groupInfo).Error
|
||||
err := GroupDB.Create(groupInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -40,18 +26,18 @@ func InsertIntoGroup(groupInfo Group) error {
|
||||
|
||||
func TakeGroupInfoByGroupID(groupID string) (*Group, error) {
|
||||
var groupInfo Group
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupID).Take(&groupInfo).Error
|
||||
err := GroupDB.Where("group_id=?", groupID).Take(&groupInfo).Error
|
||||
return &groupInfo, err
|
||||
}
|
||||
|
||||
func GetGroupInfoByGroupID(groupID string) (*Group, error) {
|
||||
var groupInfo Group
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupID).Take(&groupInfo).Error
|
||||
err := GroupDB.Where("group_id=?", groupID).Take(&groupInfo).Error
|
||||
return &groupInfo, err
|
||||
}
|
||||
|
||||
func SetGroupInfo(groupInfo Group) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupInfo.GroupID).Updates(&groupInfo).Error
|
||||
return GroupDB.Where("group_id=?", groupInfo.GroupID).Updates(&groupInfo).Error
|
||||
}
|
||||
|
||||
type GroupWithNum struct {
|
||||
@ -62,7 +48,7 @@ type GroupWithNum struct {
|
||||
func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]GroupWithNum, int64, error) {
|
||||
var groups []GroupWithNum
|
||||
var count int64
|
||||
sql := db.DB.MysqlDB.DefaultGormDB().Table("groups").Select("groups.*, (select count(*) from group_members where group_members.group_id=groups.group_id) as num").
|
||||
sql := GroupDB.Select("groups.*, (select count(*) from group_members where group_members.group_id=groups.group_id) as num").
|
||||
Where(" name like ? and status != ?", fmt.Sprintf("%%%s%%", groupName), constant.GroupStatusDismissed)
|
||||
if err := sql.Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
@ -73,7 +59,7 @@ func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]GroupWit
|
||||
|
||||
func GetGroups(pageNumber, showNumber int) ([]GroupWithNum, error) {
|
||||
var groups []GroupWithNum
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Select("groups.*, (select count(*) from group_members where group_members.group_id=groups.group_id) as num").
|
||||
if err := GroupDB.Select("groups.*, (select count(*) from group_members where group_members.group_id=groups.group_id) as num").
|
||||
Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil {
|
||||
return groups, err
|
||||
}
|
||||
@ -93,19 +79,19 @@ func OperateGroupStatus(groupId string, groupStatus int32) error {
|
||||
|
||||
func GetGroupsCountNum(group Group) (int32, error) {
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(" name like ? ", fmt.Sprintf("%%%s%%", group.GroupName)).Count(&count).Error; err != nil {
|
||||
if err := GroupDB.Where(" name like ? ", fmt.Sprintf("%%%s%%", group.GroupName)).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int32(count), nil
|
||||
}
|
||||
|
||||
func UpdateGroupInfoDefaultZero(groupID string, args map[string]interface{}) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id = ? ", groupID).Updates(args).Error
|
||||
return GroupDB.Where("group_id = ? ", groupID).Updates(args).Error
|
||||
}
|
||||
|
||||
func GetGroupIDListByGroupType(groupType int) ([]string, error) {
|
||||
var groupIDList []string
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_type = ? ", groupType).Pluck("group_id", &groupIDList).Error; err != nil {
|
||||
if err := GroupDB.Where("group_type = ? ", groupType).Pluck("group_id", &groupIDList).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groupIDList, nil
|
||||
|
@ -1,13 +1,15 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
var GroupDB *gorm.DB
|
||||
|
||||
type Group struct {
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
|
||||
GroupName string `gorm:"column:name;size:255" json:"groupName"`
|
||||
@ -24,13 +26,14 @@ type Group struct {
|
||||
ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
|
||||
NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
|
||||
NotificationUserID string `gorm:"column:notification_user_id;size:64"`
|
||||
GroupDB *gorm.DB
|
||||
}
|
||||
|
||||
func (*Group) Create(ctx context.Context, groups []*Group) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
}()
|
||||
err = utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Create(&groups).Error, "")
|
||||
err = utils.Wrap(GroupDB.Create(&groups).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
@ -38,28 +41,28 @@ func (*Group) Delete(ctx context.Context, groupIDs []string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs)
|
||||
}()
|
||||
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("group_id in (?)", groupIDs).Delete(&Group{}).Error, "")
|
||||
return utils.Wrap(GroupDB.Where("group_id in (?)", groupIDs).Delete(&Group{}).Error, "")
|
||||
}
|
||||
|
||||
func (*Group) UpdateByMap(ctx context.Context, groupID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("group_id = ?", groupID).Updates(args).Error, "")
|
||||
return utils.Wrap(GroupDB.Where("group_id = ?", groupID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (*Group) Update(ctx context.Context, groups []*Group) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
}()
|
||||
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Updates(&groups).Error, "")
|
||||
return utils.Wrap(GroupDB.Updates(&groups).Error, "")
|
||||
}
|
||||
|
||||
func (*Group) Find(ctx context.Context, groupIDs []string) (groupList []*Group, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupIDList", groupIDs, "groupList", groupList)
|
||||
}()
|
||||
err = utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("group_id in (?)", groupIDs).Find(&groupList).Error, "")
|
||||
err = utils.Wrap(GroupDB.Where("group_id in (?)", groupIDs).Find(&groupList).Error, "")
|
||||
return groupList, err
|
||||
}
|
||||
|
||||
@ -68,6 +71,6 @@ func (*Group) Take(ctx context.Context, groupID string) (group *Group, err error
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", *group)
|
||||
}()
|
||||
err = utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("group_id = ?", groupID).Take(group).Error, "")
|
||||
err = utils.Wrap(GroupDB.Where("group_id = ?", groupID).Take(group).Error, "")
|
||||
return group, err
|
||||
}
|
||||
|
@ -1,12 +1,5 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
//type GroupRequest struct {
|
||||
// UserID string `gorm:"column:user_id;primaryKey;"`
|
||||
// GroupID string `gorm:"column:group_id;primaryKey;"`
|
||||
@ -26,27 +19,27 @@ import (
|
||||
// return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
|
||||
//}
|
||||
|
||||
func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
||||
if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
u := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo)
|
||||
if u.RowsAffected != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
toInsertInfo.ReqTime = time.Now()
|
||||
if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Create(&toInsertInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
//func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
// DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
||||
// if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
// toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
// }
|
||||
// u := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo)
|
||||
// if u.RowsAffected != 0 {
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// toInsertInfo.ReqTime = time.Now()
|
||||
// if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
// toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
// }
|
||||
//
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Create(&toInsertInfo).Error
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
|
||||
//func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
|
||||
// var groupRequest GroupRequest
|
||||
@ -71,29 +64,29 @@ func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
//}
|
||||
|
||||
// received
|
||||
func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
|
||||
var groupRequestList []GroupRequest
|
||||
memberList, err := GetGroupMemberListByUserID(userID)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, utils.GetSelfFuncName())
|
||||
}
|
||||
for _, v := range memberList {
|
||||
if v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
list, err := GetGroupRequestByGroupID(v.GroupID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
groupRequestList = append(groupRequestList, list...)
|
||||
}
|
||||
}
|
||||
return groupRequestList, nil
|
||||
}
|
||||
|
||||
func GetUserReqGroupByUserID(userID string) ([]GroupRequest, error) {
|
||||
var groupRequestList []GroupRequest
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||
return groupRequestList, err
|
||||
}
|
||||
//func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
|
||||
// var groupRequestList []GroupRequest
|
||||
// memberList, err := GetGroupMemberListByUserID(userID)
|
||||
// if err != nil {
|
||||
// return nil, utils.Wrap(err, utils.GetSelfFuncName())
|
||||
// }
|
||||
// for _, v := range memberList {
|
||||
// if v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
// list, err := GetGroupRequestByGroupID(v.GroupID)
|
||||
// if err != nil {
|
||||
// continue
|
||||
// }
|
||||
// groupRequestList = append(groupRequestList, list...)
|
||||
// }
|
||||
// }
|
||||
// return groupRequestList, nil
|
||||
//}
|
||||
//
|
||||
//func GetUserReqGroupByUserID(userID string) ([]GroupRequest, error) {
|
||||
// var groupRequestList []GroupRequest
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||
// return groupRequestList, err
|
||||
//}
|
||||
|
||||
//
|
||||
//func GroupApplicationResponse(pb *group.GroupApplicationResponseReq) (*group.CommonResp, error) {
|
||||
|
@ -2,13 +2,15 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
var GroupRequestDB *gorm.DB
|
||||
|
||||
type GroupRequest struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
@ -27,28 +29,28 @@ func (*GroupRequest) Create(ctx context.Context, groupRequests []*GroupRequest)
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Create(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
return utils.Wrap(GroupRequestDB.Create(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) Delete(ctx context.Context, groupRequests []*GroupRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Delete(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
return utils.Wrap(GroupRequestDB.Delete(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) UpdateByMap(ctx context.Context, groupID string, userID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("group_id = ? and user_id = ? ", groupID, userID).Updates(args).Error, utils.GetSelfFuncName())
|
||||
return utils.Wrap(GroupRequestDB.Where("group_id = ? and user_id = ? ", groupID, userID).Updates(args).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) Update(ctx context.Context, groupRequests []*GroupRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Updates(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
return utils.Wrap(GroupRequestDB.Updates(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) Find(ctx context.Context, groupRequests []*GroupRequest) (resultGroupRequests []*GroupRequest, err error) {
|
||||
@ -59,7 +61,7 @@ func (*GroupRequest) Find(ctx context.Context, groupRequests []*GroupRequest) (r
|
||||
for _, groupMember := range groupRequests {
|
||||
where = append(where, []interface{}{groupMember.GroupID, groupMember.UserID})
|
||||
}
|
||||
return resultGroupRequests, utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("(group_id, user_id) in ?", where).Find(&resultGroupRequests).Error, utils.GetSelfFuncName())
|
||||
return resultGroupRequests, utils.Wrap(GroupRequestDB.Where("(group_id, user_id) in ?", where).Find(&resultGroupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) Take(ctx context.Context, groupID string, userID string) (groupRequest *GroupRequest, err error) {
|
||||
@ -67,7 +69,7 @@ func (*GroupRequest) Take(ctx context.Context, groupID string, userID string) (g
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID, "groupRequest", *groupRequest)
|
||||
}()
|
||||
return groupRequest, utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("group_id = ? and user_id = ? ", groupID, userID).Take(groupRequest).Error, utils.GetSelfFuncName())
|
||||
return groupRequest, utils.Wrap(GroupRequestDB.Where("group_id = ? and user_id = ? ", groupID, userID).Take(groupRequest).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
//func UpdateGroupRequest(groupRequest GroupRequest) error {
|
||||
@ -82,7 +84,7 @@ func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
u := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo)
|
||||
u := GroupRequestDB.Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo)
|
||||
if u.RowsAffected != 0 {
|
||||
return nil
|
||||
}
|
||||
@ -92,7 +94,7 @@ func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Create(&toInsertInfo).Error
|
||||
err := GroupRequestDB.Create(&toInsertInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -101,7 +103,7 @@ func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
|
||||
func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
|
||||
var groupRequest GroupRequest
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||
err := GroupRequestDB.Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -109,12 +111,12 @@ func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, e
|
||||
}
|
||||
|
||||
func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(GroupRequest{}).Error
|
||||
return GroupRequestDB.Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(GroupRequest{}).Error
|
||||
}
|
||||
|
||||
func GetGroupRequestByGroupID(groupID string) ([]GroupRequest, error) {
|
||||
var groupRequestList []GroupRequest
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
|
||||
err := GroupRequestDB.Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -142,7 +144,7 @@ func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
|
||||
|
||||
func GetUserReqGroupByUserID(userID string) ([]GroupRequest, error) {
|
||||
var groupRequestList []GroupRequest
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||
err := GroupRequestDB.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||
return groupRequestList, err
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,22 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
var InvitationDB *gorm.DB
|
||||
|
||||
type Invitation struct {
|
||||
InvitationCode string `gorm:"column:invitation_code;primary_key;type:varchar(32)"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
UserID string `gorm:"column:user_id;index:userID"`
|
||||
LastTime time.Time `gorm:"column:last_time"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成邀请码
|
||||
*/
|
||||
@ -24,7 +34,7 @@ func BatchCreateInvitationCodes(CodeNums int, CodeLen int) ([]string, error) {
|
||||
invitation.LastTime = time.Now()
|
||||
invitation.Status = 0
|
||||
invitation.UserID = ""
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("invitations").Create(&invitation)
|
||||
result := InvitationDB.Table("invitations").Create(&invitation)
|
||||
if result.Error != nil {
|
||||
continue
|
||||
}
|
||||
@ -41,7 +51,7 @@ func BatchCreateInvitationCodes(CodeNums int, CodeLen int) ([]string, error) {
|
||||
*/
|
||||
func CheckInvitationCode(code string) error {
|
||||
var invitationCode Invitation
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("invitations").Where("invitation_code=?", code).Take(&invitationCode).Error
|
||||
err := InvitationDB.Table("invitations").Where("invitation_code=?", code).Take(&invitationCode).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -62,7 +72,7 @@ func TryLockInvitationCode(Code string, UserID string) bool {
|
||||
Data["user_id"] = UserID
|
||||
Data["status"] = 1
|
||||
Data["last_time"] = time.Now()
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("invitations").Where("invitation_code=? and user_id=? and status=?", Code, "", 0).Updates(Data)
|
||||
result := InvitationDB.Table("invitations").Where("invitation_code=? and user_id=? and status=?", Code, "", 0).Updates(Data)
|
||||
if result.Error != nil {
|
||||
return false
|
||||
}
|
||||
@ -75,7 +85,7 @@ func TryLockInvitationCode(Code string, UserID string) bool {
|
||||
func FinishInvitationCode(Code string, UserId string) bool {
|
||||
Data := make(map[string]interface{}, 0)
|
||||
Data["status"] = 2
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("invitations").Where("invitation_code=? and user_id=? and status=?", Code, UserId, 1).Updates(Data)
|
||||
result := InvitationDB.Table("invitations").Where("invitation_code=? and user_id=? and status=?", Code, UserId, 1).Updates(Data)
|
||||
if result.Error != nil {
|
||||
return false
|
||||
}
|
||||
@ -86,7 +96,7 @@ func GetInvitationCode(code string) (*Invitation, error) {
|
||||
invitation := &Invitation{
|
||||
InvitationCode: code,
|
||||
}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(invitation).Find(invitation).Error
|
||||
err := InvitationDB.Model(invitation).Find(invitation).Error
|
||||
return invitation, err
|
||||
}
|
||||
|
||||
@ -103,7 +113,7 @@ func CreateRandomString(strlen int) string {
|
||||
|
||||
func GetInvitationCodes(showNumber, pageNumber, status int32) ([]Invitation, int64, error) {
|
||||
var invitationList []Invitation
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Model(Invitation{}).Where("status=?", status)
|
||||
db := InvitationDB.Model(Invitation{}).Where("status=?", status)
|
||||
var count int64
|
||||
err := db.Count(&count).Error
|
||||
err = db.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).
|
||||
|
@ -1,17 +1,42 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var IPDB *gorm.DB
|
||||
|
||||
type UserIpRecord struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
CreateIp string `gorm:"column:create_ip;size:15"`
|
||||
LastLoginTime time.Time `gorm:"column:last_login_time"`
|
||||
LastLoginIp string `gorm:"column:last_login_ip;size:15"`
|
||||
LoginTimes int32 `gorm:"column:login_times"`
|
||||
}
|
||||
|
||||
// ip limit login
|
||||
type IpLimit struct {
|
||||
Ip string `gorm:"column:ip;primary_key;size:15"`
|
||||
LimitRegister int32 `gorm:"column:limit_register;size:1"`
|
||||
LimitLogin int32 `gorm:"column:limit_login;size:1"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
LimitTime time.Time `gorm:"column:limit_time"`
|
||||
}
|
||||
|
||||
// ip login
|
||||
type UserIpLimit struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Ip string `gorm:"column:ip;primary_key;size:15"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
}
|
||||
|
||||
func IsLimitRegisterIp(RegisterIp string) (bool, error) {
|
||||
//如果已经存在则限制
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("ip_limits").Where("ip=? and limit_register=? and limit_time>now()", RegisterIp, 1).Count(&count).Error; err != nil {
|
||||
if err := IPDB.Table("ip_limits").Where("ip=? and limit_register=? and limit_time>now()", RegisterIp, 1).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
@ -20,7 +45,7 @@ func IsLimitRegisterIp(RegisterIp string) (bool, error) {
|
||||
func IsLimitLoginIp(LoginIp string) (bool, error) {
|
||||
//如果已经存在则限制
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("ip_limits").Where("ip=? and limit_login=? and limit_time>now()", LoginIp, 1).Count(&count).Error; err != nil {
|
||||
if err := IPDB.Table("ip_limits").Where("ip=? and limit_login=? and limit_time>now()", LoginIp, 1).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
@ -29,14 +54,14 @@ func IsLimitLoginIp(LoginIp string) (bool, error) {
|
||||
func IsLimitUserLoginIp(userID string, loginIp string) (limit bool, err error) {
|
||||
//如果已经存在则放行
|
||||
var count int64
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("user_ip_limits").Where("user_id=?", userID).Count(&count)
|
||||
result := IPDB.Table("user_ip_limits").Where("user_id=?", userID).Count(&count)
|
||||
if err := result.Error; err != nil {
|
||||
return true, err
|
||||
}
|
||||
if count < 1 {
|
||||
return false, nil
|
||||
}
|
||||
result = db.DB.MysqlDB.DefaultGormDB().Table("user_ip_limits").Where("user_id=? and ip = ?", userID, loginIp).Count(&count)
|
||||
result = IPDB.Table("user_ip_limits").Where("user_id=? and ip = ?", userID, loginIp).Count(&count)
|
||||
if err := result.Error; err != nil {
|
||||
return true, err
|
||||
}
|
||||
@ -46,56 +71,56 @@ func IsLimitUserLoginIp(userID string, loginIp string) (limit bool, err error) {
|
||||
|
||||
func QueryIPLimits(ip string) (*IpLimit, error) {
|
||||
var ipLimit IpLimit
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&IpLimit{}).Where("ip=?", ip).First(&ipLimit).Error
|
||||
err := IPDB.Model(&IpLimit{}).Where("ip=?", ip).First(&ipLimit).Error
|
||||
return &ipLimit, err
|
||||
}
|
||||
|
||||
func QueryUserIPLimits(ip string) ([]UserIpLimit, error) {
|
||||
var ips []UserIpLimit
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Where("ip=?", ip).Find(&ips).Error
|
||||
err := IPDB.Model(&UserIpLimit{}).Where("ip=?", ip).Find(&ips).Error
|
||||
return ips, err
|
||||
}
|
||||
|
||||
func InsertOneIntoIpLimits(ipLimits IpLimit) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&IpLimit{}).Create(ipLimits).Error
|
||||
return IPDB.Model(&IpLimit{}).Create(ipLimits).Error
|
||||
}
|
||||
|
||||
func DeleteOneFromIpLimits(ip string) error {
|
||||
ipLimits := &IpLimit{Ip: ip}
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(ipLimits).Where("ip=?", ip).Delete(ipLimits).Error
|
||||
return IPDB.Model(ipLimits).Where("ip=?", ip).Delete(ipLimits).Error
|
||||
}
|
||||
|
||||
func GetIpLimitsLoginByUserID(userID string) ([]UserIpLimit, error) {
|
||||
var ips []UserIpLimit
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Where("user_id=?", userID).Find(&ips).Error
|
||||
err := IPDB.Model(&UserIpLimit{}).Where("user_id=?", userID).Find(&ips).Error
|
||||
return ips, err
|
||||
}
|
||||
|
||||
func InsertUserIpLimitsLogin(userIp *UserIpLimit) error {
|
||||
userIp.CreateTime = time.Now()
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Create(userIp).Error
|
||||
return IPDB.Model(&UserIpLimit{}).Create(userIp).Error
|
||||
}
|
||||
|
||||
func DeleteUserIpLimitsLogin(userID, ip string) error {
|
||||
userIp := UserIpLimit{UserID: userID, Ip: ip}
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&UserIpLimit{}).Delete(&userIp).Error
|
||||
return IPDB.Model(&UserIpLimit{}).Delete(&userIp).Error
|
||||
}
|
||||
|
||||
func GetRegisterUserNum(ip string) ([]string, error) {
|
||||
var userIDList []string
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&Register{}).Where("register_ip=?", ip).Pluck("user_id", &userIDList).Error
|
||||
err := IPDB.Model(&Register{}).Where("register_ip=?", ip).Pluck("user_id", &userIDList).Error
|
||||
return userIDList, err
|
||||
}
|
||||
|
||||
func InsertIpRecord(userID, createIp string) error {
|
||||
record := &UserIpRecord{UserID: userID, CreateIp: createIp, LastLoginTime: time.Now(), LoginTimes: 1}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpRecord{}).Create(record).Error
|
||||
err := IPDB.Model(&UserIpRecord{}).Create(record).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateIpReocord(userID, ip string) (err error) {
|
||||
record := &UserIpRecord{UserID: userID, LastLoginIp: ip, LastLoginTime: time.Now()}
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Model(&UserIpRecord{}).Where("user_id=?", userID).Updates(record).Update("login_times", gorm.Expr("login_times+?", 1))
|
||||
result := IPDB.Model(&UserIpRecord{}).Where("user_id=?", userID).Updates(record).Update("login_times", gorm.Expr("login_times+?", 1))
|
||||
if result.Error != nil {
|
||||
return utils.Wrap(result.Error, "")
|
||||
}
|
||||
|
@ -2,12 +2,37 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ChatLogDB *gorm.DB
|
||||
|
||||
type ChatLog struct {
|
||||
ServerMsgID string `gorm:"column:server_msg_id;primary_key;type:char(64)" json:"serverMsgID"`
|
||||
ClientMsgID string `gorm:"column:client_msg_id;type:char(64)" json:"clientMsgID"`
|
||||
SendID string `gorm:"column:send_id;type:char(64);index:send_id,priority:2" json:"sendID"`
|
||||
RecvID string `gorm:"column:recv_id;type:char(64);index:recv_id,priority:2" json:"recvID"`
|
||||
SenderPlatformID int32 `gorm:"column:sender_platform_id" json:"senderPlatformID"`
|
||||
SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"`
|
||||
SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255);" json:"senderFaceURL"`
|
||||
SessionType int32 `gorm:"column:session_type;index:session_type,priority:2;index:session_type_alone" json:"sessionType"`
|
||||
MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
|
||||
ContentType int32 `gorm:"column:content_type;index:content_type,priority:2;index:content_type_alone" json:"contentType"`
|
||||
Content string `gorm:"column:content;type:varchar(3000)" json:"content"`
|
||||
Status int32 `gorm:"column:status" json:"status"`
|
||||
SendTime time.Time `gorm:"column:send_time;index:sendTime;index:content_type,priority:1;index:session_type,priority:1;index:recv_id,priority:1;index:send_id,priority:1" json:"sendTime"`
|
||||
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
|
||||
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
}
|
||||
|
||||
func (ChatLog) TableName() string {
|
||||
return "chat_logs"
|
||||
}
|
||||
|
||||
func GetChatLog(chatLog *ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []ChatLog, error) {
|
||||
mdb := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
|
||||
mdb := ChatLogDB.Table("chat_logs")
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
mdb = mdb.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
|
@ -4,23 +4,23 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Register struct {
|
||||
Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"`
|
||||
Password string `gorm:"column:password;type:varchar(255)" json:"password"`
|
||||
Ex string `gorm:"column:ex;size:1024" json:"ex"`
|
||||
UserID string `gorm:"column:user_id;type:varchar(255)" json:"userID"`
|
||||
AreaCode string `gorm:"column:area_code;type:varchar(255)"`
|
||||
InvitationCode string `gorm:"column:invitation_code;type:varchar(255)"`
|
||||
RegisterIP string `gorm:"column:register_ip;type:varchar(255)"`
|
||||
}
|
||||
//type Register struct {
|
||||
// Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"`
|
||||
// Password string `gorm:"column:password;type:varchar(255)" json:"password"`
|
||||
// Ex string `gorm:"column:ex;size:1024" json:"ex"`
|
||||
// UserID string `gorm:"column:user_id;type:varchar(255)" json:"userID"`
|
||||
// AreaCode string `gorm:"column:area_code;type:varchar(255)"`
|
||||
// InvitationCode string `gorm:"column:invitation_code;type:varchar(255)"`
|
||||
// RegisterIP string `gorm:"column:register_ip;type:varchar(255)"`
|
||||
//}
|
||||
|
||||
type Invitation struct {
|
||||
InvitationCode string `gorm:"column:invitation_code;primary_key;type:varchar(32)"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
UserID string `gorm:"column:user_id;index:userID"`
|
||||
LastTime time.Time `gorm:"column:last_time"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
}
|
||||
//type Invitation struct {
|
||||
// InvitationCode string `gorm:"column:invitation_code;primary_key;type:varchar(32)"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// UserID string `gorm:"column:user_id;index:userID"`
|
||||
// LastTime time.Time `gorm:"column:last_time"`
|
||||
// Status int32 `gorm:"column:status"`
|
||||
//}
|
||||
|
||||
// message FriendInfo{
|
||||
// string OwnerUserID = 1;
|
||||
@ -54,21 +54,21 @@ type Invitation struct {
|
||||
// string Ex = 9;
|
||||
// }
|
||||
// open_im_sdk.FriendRequest(nickname, farce url ...) != imdb.FriendRequest
|
||||
type FriendRequest struct {
|
||||
FromUserID string `gorm:"column:from_user_id;primary_key;size:64"`
|
||||
ToUserID string `gorm:"column:to_user_id;primary_key;size:64"`
|
||||
HandleResult int32 `gorm:"column:handle_result"`
|
||||
ReqMsg string `gorm:"column:req_msg;size:255"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
HandlerUserID string `gorm:"column:handler_user_id;size:64"`
|
||||
HandleMsg string `gorm:"column:handle_msg;size:255"`
|
||||
HandleTime time.Time `gorm:"column:handle_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
func (FriendRequest) TableName() string {
|
||||
return "friend_requests"
|
||||
}
|
||||
//type FriendRequest struct {
|
||||
// FromUserID string `gorm:"column:from_user_id;primary_key;size:64"`
|
||||
// ToUserID string `gorm:"column:to_user_id;primary_key;size:64"`
|
||||
// HandleResult int32 `gorm:"column:handle_result"`
|
||||
// ReqMsg string `gorm:"column:req_msg;size:255"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// HandlerUserID string `gorm:"column:handler_user_id;size:64"`
|
||||
// HandleMsg string `gorm:"column:handle_msg;size:255"`
|
||||
// HandleTime time.Time `gorm:"column:handle_time"`
|
||||
// Ex string `gorm:"column:ex;size:1024"`
|
||||
//}
|
||||
//
|
||||
//func (FriendRequest) TableName() string {
|
||||
// return "friend_requests"
|
||||
//}
|
||||
|
||||
// message GroupInfo{
|
||||
// string GroupID = 1;
|
||||
@ -170,45 +170,45 @@ func (FriendRequest) TableName() string {
|
||||
// int64 CreateTime = 10;
|
||||
// int32 AppMangerLevel = 11;
|
||||
// open_im_sdk.User == imdb.User
|
||||
type User struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
FaceURL string `gorm:"column:face_url;size:255"`
|
||||
Gender int32 `gorm:"column:gender"`
|
||||
PhoneNumber string `gorm:"column:phone_number;size:32"`
|
||||
Birth time.Time `gorm:"column:birth"`
|
||||
Email string `gorm:"column:email;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
//type User struct {
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// Nickname string `gorm:"column:name;size:255"`
|
||||
// FaceURL string `gorm:"column:face_url;size:255"`
|
||||
// Gender int32 `gorm:"column:gender"`
|
||||
// PhoneNumber string `gorm:"column:phone_number;size:32"`
|
||||
// Birth time.Time `gorm:"column:birth"`
|
||||
// Email string `gorm:"column:email;size:64"`
|
||||
// Ex string `gorm:"column:ex;size:1024"`
|
||||
// CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
// AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
// GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
//
|
||||
// status int32 `gorm:"column:status"`
|
||||
//}
|
||||
|
||||
status int32 `gorm:"column:status"`
|
||||
}
|
||||
|
||||
type UserIpRecord struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
CreateIp string `gorm:"column:create_ip;size:15"`
|
||||
LastLoginTime time.Time `gorm:"column:last_login_time"`
|
||||
LastLoginIp string `gorm:"column:last_login_ip;size:15"`
|
||||
LoginTimes int32 `gorm:"column:login_times"`
|
||||
}
|
||||
|
||||
// ip limit login
|
||||
type IpLimit struct {
|
||||
Ip string `gorm:"column:ip;primary_key;size:15"`
|
||||
LimitRegister int32 `gorm:"column:limit_register;size:1"`
|
||||
LimitLogin int32 `gorm:"column:limit_login;size:1"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
LimitTime time.Time `gorm:"column:limit_time"`
|
||||
}
|
||||
|
||||
// ip login
|
||||
type UserIpLimit struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Ip string `gorm:"column:ip;primary_key;size:15"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
}
|
||||
//type UserIpRecord struct {
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// CreateIp string `gorm:"column:create_ip;size:15"`
|
||||
// LastLoginTime time.Time `gorm:"column:last_login_time"`
|
||||
// LastLoginIp string `gorm:"column:last_login_ip;size:15"`
|
||||
// LoginTimes int32 `gorm:"column:login_times"`
|
||||
//}
|
||||
//
|
||||
//// ip limit login
|
||||
//type IpLimit struct {
|
||||
// Ip string `gorm:"column:ip;primary_key;size:15"`
|
||||
// LimitRegister int32 `gorm:"column:limit_register;size:1"`
|
||||
// LimitLogin int32 `gorm:"column:limit_login;size:1"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// LimitTime time.Time `gorm:"column:limit_time"`
|
||||
//}
|
||||
//
|
||||
//// ip login
|
||||
//type UserIpLimit struct {
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// Ip string `gorm:"column:ip;primary_key;size:15"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
//}
|
||||
|
||||
// message BlackInfo{
|
||||
// string OwnerUserID = 1;
|
||||
@ -219,64 +219,64 @@ type UserIpLimit struct {
|
||||
// string Ex = 7;
|
||||
// }
|
||||
// open_im_sdk.BlackInfo(BlackUserInfo) != imdb.Black (BlockUserID)
|
||||
type Black struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
BlockUserID string `gorm:"column:block_user_id;primary_key;size:64"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
//type Black struct {
|
||||
// OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
// BlockUserID string `gorm:"column:block_user_id;primary_key;size:64"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// AddSource int32 `gorm:"column:add_source"`
|
||||
// OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
// Ex string `gorm:"column:ex;size:1024"`
|
||||
//}
|
||||
|
||||
type ChatLog struct {
|
||||
ServerMsgID string `gorm:"column:server_msg_id;primary_key;type:char(64)" json:"serverMsgID"`
|
||||
ClientMsgID string `gorm:"column:client_msg_id;type:char(64)" json:"clientMsgID"`
|
||||
SendID string `gorm:"column:send_id;type:char(64);index:send_id,priority:2" json:"sendID"`
|
||||
RecvID string `gorm:"column:recv_id;type:char(64);index:recv_id,priority:2" json:"recvID"`
|
||||
SenderPlatformID int32 `gorm:"column:sender_platform_id" json:"senderPlatformID"`
|
||||
SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"`
|
||||
SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255);" json:"senderFaceURL"`
|
||||
SessionType int32 `gorm:"column:session_type;index:session_type,priority:2;index:session_type_alone" json:"sessionType"`
|
||||
MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
|
||||
ContentType int32 `gorm:"column:content_type;index:content_type,priority:2;index:content_type_alone" json:"contentType"`
|
||||
Content string `gorm:"column:content;type:varchar(3000)" json:"content"`
|
||||
Status int32 `gorm:"column:status" json:"status"`
|
||||
SendTime time.Time `gorm:"column:send_time;index:sendTime;index:content_type,priority:1;index:session_type,priority:1;index:recv_id,priority:1;index:send_id,priority:1" json:"sendTime"`
|
||||
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
|
||||
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
}
|
||||
//type ChatLog struct {
|
||||
// ServerMsgID string `gorm:"column:server_msg_id;primary_key;type:char(64)" json:"serverMsgID"`
|
||||
// ClientMsgID string `gorm:"column:client_msg_id;type:char(64)" json:"clientMsgID"`
|
||||
// SendID string `gorm:"column:send_id;type:char(64);index:send_id,priority:2" json:"sendID"`
|
||||
// RecvID string `gorm:"column:recv_id;type:char(64);index:recv_id,priority:2" json:"recvID"`
|
||||
// SenderPlatformID int32 `gorm:"column:sender_platform_id" json:"senderPlatformID"`
|
||||
// SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"`
|
||||
// SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255);" json:"senderFaceURL"`
|
||||
// SessionType int32 `gorm:"column:session_type;index:session_type,priority:2;index:session_type_alone" json:"sessionType"`
|
||||
// MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
|
||||
// ContentType int32 `gorm:"column:content_type;index:content_type,priority:2;index:content_type_alone" json:"contentType"`
|
||||
// Content string `gorm:"column:content;type:varchar(3000)" json:"content"`
|
||||
// Status int32 `gorm:"column:status" json:"status"`
|
||||
// SendTime time.Time `gorm:"column:send_time;index:sendTime;index:content_type,priority:1;index:session_type,priority:1;index:recv_id,priority:1;index:send_id,priority:1" json:"sendTime"`
|
||||
// CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
|
||||
// Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
//}
|
||||
//
|
||||
//func (ChatLog) TableName() string {
|
||||
// return "chat_logs"
|
||||
//}
|
||||
|
||||
func (ChatLog) TableName() string {
|
||||
return "chat_logs"
|
||||
}
|
||||
//type BlackList struct {
|
||||
// UserId string `gorm:"column:uid"`
|
||||
// BeginDisableTime time.Time `gorm:"column:begin_disable_time"`
|
||||
// EndDisableTime time.Time `gorm:"column:end_disable_time"`
|
||||
//}
|
||||
//type Conversation struct {
|
||||
// OwnerUserID string `gorm:"column:owner_user_id;primary_key;type:char(128)" json:"OwnerUserID"`
|
||||
// ConversationID string `gorm:"column:conversation_id;primary_key;type:char(128)" json:"conversationID"`
|
||||
// ConversationType int32 `gorm:"column:conversation_type" json:"conversationType"`
|
||||
// UserID string `gorm:"column:user_id;type:char(64)" json:"userID"`
|
||||
// GroupID string `gorm:"column:group_id;type:char(128)" json:"groupID"`
|
||||
// RecvMsgOpt int32 `gorm:"column:recv_msg_opt" json:"recvMsgOpt"`
|
||||
// UnreadCount int32 `gorm:"column:unread_count" json:"unreadCount"`
|
||||
// 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"`
|
||||
// BurnDuration int32 `gorm:"column:burn_duration;default:30" json:"burnDuration"`
|
||||
// GroupAtType int32 `gorm:"column:group_at_type" json:"groupAtType"`
|
||||
// IsNotInGroup bool `gorm:"column:is_not_in_group" json:"isNotInGroup"`
|
||||
// UpdateUnreadCountTime int64 `gorm:"column:update_unread_count_time" json:"updateUnreadCountTime"`
|
||||
// AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
|
||||
// Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
//}
|
||||
|
||||
type BlackList struct {
|
||||
UserId string `gorm:"column:uid"`
|
||||
BeginDisableTime time.Time `gorm:"column:begin_disable_time"`
|
||||
EndDisableTime time.Time `gorm:"column:end_disable_time"`
|
||||
}
|
||||
type Conversation struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;type:char(128)" json:"OwnerUserID"`
|
||||
ConversationID string `gorm:"column:conversation_id;primary_key;type:char(128)" json:"conversationID"`
|
||||
ConversationType int32 `gorm:"column:conversation_type" json:"conversationType"`
|
||||
UserID string `gorm:"column:user_id;type:char(64)" json:"userID"`
|
||||
GroupID string `gorm:"column:group_id;type:char(128)" json:"groupID"`
|
||||
RecvMsgOpt int32 `gorm:"column:recv_msg_opt" json:"recvMsgOpt"`
|
||||
UnreadCount int32 `gorm:"column:unread_count" json:"unreadCount"`
|
||||
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"`
|
||||
BurnDuration int32 `gorm:"column:burn_duration;default:30" json:"burnDuration"`
|
||||
GroupAtType int32 `gorm:"column:group_at_type" json:"groupAtType"`
|
||||
IsNotInGroup bool `gorm:"column:is_not_in_group" json:"isNotInGroup"`
|
||||
UpdateUnreadCountTime int64 `gorm:"column:update_unread_count_time" json:"updateUnreadCountTime"`
|
||||
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
|
||||
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
}
|
||||
|
||||
func (Conversation) TableName() string {
|
||||
return "conversations"
|
||||
}
|
||||
//func (Conversation) TableName() string {
|
||||
// return "conversations"
|
||||
//}
|
||||
|
||||
type Department struct {
|
||||
DepartmentID string `gorm:"column:department_id;primary_key;size:64" json:"departmentID"`
|
||||
|
@ -1,29 +1,30 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
var OrgDB *gorm.DB
|
||||
|
||||
func CreateDepartment(department *Department) error {
|
||||
department.CreateTime = time.Now()
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("departments").Create(department).Error
|
||||
return OrgDB.Table("departments").Create(department).Error
|
||||
}
|
||||
|
||||
func GetDepartment(departmentID string) (*Department, error) {
|
||||
var department Department
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Find(&department).Error
|
||||
err := OrgDB.Table("departments").Where("department_id=?", departmentID).Find(&department).Error
|
||||
return &department, err
|
||||
}
|
||||
|
||||
func UpdateDepartment(department *Department, args map[string]interface{}) error {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil {
|
||||
if err := OrgDB.Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if args != nil {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", department.DepartmentID).Updates(args).Error
|
||||
return OrgDB.Table("departments").Where("department_id=?", department.DepartmentID).Updates(args).Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -32,9 +33,9 @@ func GetSubDepartmentList(departmentID string) ([]Department, error) {
|
||||
var departmentList []Department
|
||||
var err error
|
||||
if departmentID == "-1" {
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Find(&departmentList).Error
|
||||
err = OrgDB.Table("departments").Find(&departmentList).Error
|
||||
} else {
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("parent_id=?", departmentID).Find(&departmentList).Error
|
||||
err = OrgDB.Table("departments").Where("parent_id=?", departmentID).Find(&departmentList).Error
|
||||
}
|
||||
|
||||
return departmentList, err
|
||||
@ -42,10 +43,10 @@ func GetSubDepartmentList(departmentID string) ([]Department, error) {
|
||||
|
||||
func DeleteDepartment(departmentID string) error {
|
||||
var err error
|
||||
if err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Delete(Department{}).Error; err != nil {
|
||||
if err = OrgDB.Table("departments").Where("department_id=?", departmentID).Delete(Department{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Delete(DepartmentMember{}).Error; err != nil {
|
||||
if err = OrgDB.Table("department_members").Where("department_id=?", departmentID).Delete(DepartmentMember{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -53,72 +54,72 @@ func DeleteDepartment(departmentID string) error {
|
||||
|
||||
func CreateOrganizationUser(organizationUser *OrganizationUser) error {
|
||||
organizationUser.CreateTime = time.Now()
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Create(organizationUser).Error
|
||||
return OrgDB.Table("organization_users").Create(organizationUser).Error
|
||||
}
|
||||
|
||||
func GetOrganizationUser(userID string) (error, *OrganizationUser) {
|
||||
organizationUser := OrganizationUser{}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error
|
||||
err := OrgDB.Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error
|
||||
return err, &organizationUser
|
||||
}
|
||||
|
||||
func GetOrganizationUsers(userIDList []string) ([]*OrganizationUser, error) {
|
||||
var organizationUserList []*OrganizationUser
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id in (?)", userIDList).Find(&organizationUserList).Error
|
||||
err := OrgDB.Table("organization_users").Where("user_id in (?)", userIDList).Find(&organizationUserList).Error
|
||||
return organizationUserList, err
|
||||
}
|
||||
|
||||
func UpdateOrganizationUser(organizationUser *OrganizationUser, args map[string]interface{}) error {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil {
|
||||
if err := OrgDB.Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if args != nil {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(args).Error
|
||||
return OrgDB.Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(args).Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateDepartmentMember(departmentMember *DepartmentMember) error {
|
||||
departmentMember.CreateTime = time.Now()
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Create(departmentMember).Error
|
||||
return OrgDB.Table("department_members").Create(departmentMember).Error
|
||||
}
|
||||
|
||||
func GetUserInDepartment(userID string) (error, []DepartmentMember) {
|
||||
var departmentMemberList []DepartmentMember
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error
|
||||
err := OrgDB.Where("user_id=?", userID).Find(&departmentMemberList).Error
|
||||
return err, departmentMemberList
|
||||
}
|
||||
|
||||
func UpdateUserInDepartment(departmentMember *DepartmentMember, args map[string]interface{}) error {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
|
||||
if err := OrgDB.Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
|
||||
Updates(departmentMember).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if args != nil {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
|
||||
return OrgDB.Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
|
||||
Updates(args).Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteUserInDepartment(departmentID, userID string) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentID, userID).Delete(DepartmentMember{}).Error
|
||||
return OrgDB.Table("department_members").Where("department_id=? AND user_id=?", departmentID, userID).Delete(DepartmentMember{}).Error
|
||||
}
|
||||
|
||||
func DeleteUserInAllDepartment(userID string) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Delete(DepartmentMember{}).Error
|
||||
return OrgDB.Table("department_members").Where("user_id=?", userID).Delete(DepartmentMember{}).Error
|
||||
}
|
||||
|
||||
func DeleteOrganizationUser(OrganizationUserID string) error {
|
||||
if err := DeleteUserInAllDepartment(OrganizationUserID); err != nil {
|
||||
return err
|
||||
}
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(OrganizationUser{}).Error
|
||||
return OrgDB.Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(OrganizationUser{}).Error
|
||||
}
|
||||
|
||||
func GetDepartmentMemberUserIDList(departmentID string) (error, []string) {
|
||||
var departmentMemberList []DepartmentMember
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Take(&departmentMemberList).Error
|
||||
err := OrgDB.Table("department_members").Where("department_id=?", departmentID).Take(&departmentMemberList).Error
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
@ -133,9 +134,9 @@ func GetDepartmentMemberList(departmentID string) ([]DepartmentMember, error) {
|
||||
var departmentMemberList []DepartmentMember
|
||||
var err error
|
||||
if departmentID == "-1" {
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Find(&departmentMemberList).Error
|
||||
err = OrgDB.Table("department_members").Find(&departmentMemberList).Error
|
||||
} else {
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Find(&departmentMemberList).Error
|
||||
err = OrgDB.Table("department_members").Where("department_id=?", departmentID).Find(&departmentMemberList).Error
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@ -147,12 +148,12 @@ func GetDepartmentMemberList(departmentID string) ([]DepartmentMember, error) {
|
||||
func GetAllOrganizationUserID() (error, []string) {
|
||||
var OrganizationUser OrganizationUser
|
||||
var result []string
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&OrganizationUser).Pluck("user_id", &result).Error, result
|
||||
return OrgDB.Model(&OrganizationUser).Pluck("user_id", &result).Error, result
|
||||
}
|
||||
|
||||
func GetDepartmentMemberNum(departmentID string) (error, uint32) {
|
||||
var number int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Count(&number).Error
|
||||
err := OrgDB.Table("department_members").Where("department_id=?", departmentID).Count(&number).Error
|
||||
if err != nil {
|
||||
return utils.Wrap(err, ""), 0
|
||||
}
|
||||
@ -162,7 +163,7 @@ func GetDepartmentMemberNum(departmentID string) (error, uint32) {
|
||||
|
||||
func GetSubDepartmentNum(departmentID string) (error, uint32) {
|
||||
var number int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("parent_id=?", departmentID).Count(&number).Error
|
||||
err := OrgDB.Table("departments").Where("parent_id=?", departmentID).Count(&number).Error
|
||||
if err != nil {
|
||||
return utils.Wrap(err, ""), 0
|
||||
}
|
||||
@ -171,12 +172,12 @@ func GetSubDepartmentNum(departmentID string) (error, uint32) {
|
||||
|
||||
func SetDepartmentRelatedGroupID(groupID, departmentID string) error {
|
||||
department := &Department{RelatedGroupID: groupID}
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Updates(department).Error
|
||||
return OrgDB.Model(&department).Where("department_id=?", departmentID).Updates(department).Error
|
||||
}
|
||||
|
||||
func GetDepartmentRelatedGroupIDList(departmentIDList []string) ([]string, error) {
|
||||
var groupIDList []string
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id IN (?) ", departmentIDList).Pluck("related_group_id", &groupIDList).Error
|
||||
err := OrgDB.Table("departments").Where("department_id IN (?) ", departmentIDList).Pluck("related_group_id", &groupIDList).Error
|
||||
return groupIDList, err
|
||||
}
|
||||
|
||||
@ -184,7 +185,7 @@ func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*Department, err
|
||||
var department Department
|
||||
var parentDepartment Department
|
||||
//var parentID string
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error
|
||||
err := OrgDB.Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
@ -210,7 +211,7 @@ func GetDepartmentParent(departmentID string, dbConn *gorm.DB, parentIDList *[]s
|
||||
}
|
||||
|
||||
func GetDepartmentParentIDList(departmentID string) ([]string, error) {
|
||||
dbConn := db.DB.MysqlDB.DefaultGormDB()
|
||||
dbConn := OrgDB
|
||||
var parentIDList []string
|
||||
err := GetDepartmentParent(departmentID, dbConn, &parentIDList)
|
||||
return parentIDList, err
|
||||
@ -218,6 +219,6 @@ func GetDepartmentParentIDList(departmentID string) ([]string, error) {
|
||||
|
||||
func GetRandomDepartmentID() (string, error) {
|
||||
department := &Department{}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(department).Order("RAND()").Where("related_group_id != ? AND department_id != ? AND department_type = ?", "", "0", 1).First(department).Error
|
||||
err := OrgDB.Model(department).Order("RAND()").Where("related_group_id != ? AND department_id != ? AND department_type = ?", "", "0", 1).First(department).Error
|
||||
return department.DepartmentID, err
|
||||
}
|
||||
|
@ -2,61 +2,60 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetActiveUserNum(from, to time.Time) (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("count(distinct(send_id))").Where("send_time >= ? and send_time <= ?", from, to).Count(&num).Error
|
||||
err := ChatLogDB.Table("chat_logs").Select("count(distinct(send_id))").Where("send_time >= ? and send_time <= ?", from, to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetIncreaseUserNum(from, to time.Time) (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
err := UserDB.Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetTotalUserNum() (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Count(&num).Error
|
||||
err := UserDB.Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetTotalUserNumByDate(to time.Time) (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("create_time <= ?", to).Count(&num).Error
|
||||
err := UserDB.Where("create_time <= ?", to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetPrivateMessageNum(from, to time.Time) (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
|
||||
err := ChatLogDB.Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetGroupMessageNum(from, to time.Time) (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
|
||||
err := ChatLogDB.Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetIncreaseGroupNum(from, to time.Time) (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
err := GroupDB.Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetTotalGroupNum() (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Count(&num).Error
|
||||
err := GroupDB.Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetGroupNum(to time.Time) (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("create_time <= ?", to).Count(&num).Error
|
||||
err := GroupDB.Where("create_time <= ?", to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
@ -68,12 +67,12 @@ type activeGroup struct {
|
||||
|
||||
func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
|
||||
var activeGroups []*activeGroup
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("recv_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.GroupChatType, constant.SuperGroupChatType}).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
|
||||
err := ChatLogDB.Select("recv_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.GroupChatType, constant.SuperGroupChatType}).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
|
||||
for _, activeGroup := range activeGroups {
|
||||
group := Group{
|
||||
GroupID: activeGroup.Id,
|
||||
}
|
||||
db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id= ? ", group.GroupID).Find(&group)
|
||||
GroupDB.Where("group_id= ? ", group.GroupID).Find(&group)
|
||||
activeGroup.Name = group.GroupName
|
||||
}
|
||||
return activeGroups, err
|
||||
@ -87,12 +86,12 @@ type activeUser struct {
|
||||
|
||||
func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
|
||||
var activeUsers []*activeUser
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("send_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, constant.SingleChatType).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
|
||||
err := ChatLogDB.Select("send_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, constant.SingleChatType).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
|
||||
for _, activeUser := range activeUsers {
|
||||
user := User{
|
||||
UserID: activeUser.ID,
|
||||
}
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user).Error
|
||||
err = UserDB.Select("user_id, name").Find(&user).Error
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
@ -1,42 +1,44 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
func InsertInToUserBlackList(ctx context.Context, black db.Black) (err error) {
|
||||
var BlackDB *gorm.DB
|
||||
|
||||
type Black struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
BlockUserID string `gorm:"column:block_user_id;primary_key;size:64"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
func InsertInToUserBlackList(ctx context.Context, black Black) (err error) {
|
||||
defer trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "black", black)
|
||||
black.CreateTime = time.Now()
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("blacks").Create(black).Error
|
||||
err = BlackDB.Create(black).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// type Black struct {
|
||||
// OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
|
||||
// BlockUserID string `gorm:"column:block_user_id;primaryKey;"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// AddSource int32 `gorm:"column:add_source"`
|
||||
// OperatorUserID int32 `gorm:"column:operator_user_id"`
|
||||
// Ex string `gorm:"column:ex"`
|
||||
// }
|
||||
|
||||
func CheckBlack(ownerUserID, blockUserID string) error {
|
||||
var black db.Black
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error
|
||||
var black Black
|
||||
return BlackDB.Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error
|
||||
}
|
||||
|
||||
func RemoveBlackList(ownerUserID, blockUserID string) error {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(db.Black{}).Error
|
||||
err := BlackDB.Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(Black{}).Error
|
||||
return utils.Wrap(err, "RemoveBlackList failed")
|
||||
}
|
||||
|
||||
func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) {
|
||||
var blackListUsersInfo []db.Black
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error
|
||||
func GetBlackListByUserID(ownerUserID string) ([]Black, error) {
|
||||
var blackListUsersInfo []Black
|
||||
err := BlackDB.Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -45,7 +47,7 @@ func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) {
|
||||
|
||||
func GetBlackIDListByUserID(ownerUserID string) ([]string, error) {
|
||||
var blackIDList []string
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error
|
||||
err := BlackDB.Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -3,13 +3,40 @@ package im_mysql_model
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
BlackListDB *gorm.DB
|
||||
UserDB *gorm.DB
|
||||
)
|
||||
|
||||
type BlackList struct {
|
||||
UserId string `gorm:"column:uid"`
|
||||
BeginDisableTime time.Time `gorm:"column:begin_disable_time"`
|
||||
EndDisableTime time.Time `gorm:"column:end_disable_time"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
FaceURL string `gorm:"column:face_url;size:255"`
|
||||
Gender int32 `gorm:"column:gender"`
|
||||
PhoneNumber string `gorm:"column:phone_number;size:32"`
|
||||
Birth time.Time `gorm:"column:birth"`
|
||||
Email string `gorm:"column:email;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
|
||||
status int32 `gorm:"column:status"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
for k, v := range config.Config.Manager.AppManagerUid {
|
||||
_, err := GetUserByUserID(v)
|
||||
@ -42,7 +69,7 @@ func UserRegister(user User) error {
|
||||
if user.Birth.Unix() < 0 {
|
||||
user.Birth = utils.UnixSecondToTime(0)
|
||||
}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user).Error
|
||||
err := UserDB.Table("users").Create(&user).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -51,13 +78,13 @@ func UserRegister(user User) error {
|
||||
|
||||
func GetAllUser() ([]User, error) {
|
||||
var userList []User
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Find(&userList).Error
|
||||
err := UserDB.Table("users").Find(&userList).Error
|
||||
return userList, err
|
||||
}
|
||||
|
||||
func TakeUserByUserID(userID string) (*User, error) {
|
||||
var user User
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error
|
||||
err := UserDB.Table("users").Where("user_id=?", userID).Take(&user).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -66,7 +93,7 @@ func TakeUserByUserID(userID string) (*User, error) {
|
||||
|
||||
func GetUserByUserID(userID string) (*User, error) {
|
||||
var user User
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error
|
||||
err := UserDB.Table("users").Where("user_id=?", userID).Take(&user).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -75,13 +102,13 @@ func GetUserByUserID(userID string) (*User, error) {
|
||||
|
||||
func GetUsersByUserIDList(userIDList []string) ([]*User, error) {
|
||||
var userList []*User
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id in (?)", userIDList).Find(&userList).Error
|
||||
err := UserDB.Table("users").Where("user_id in (?)", userIDList).Find(&userList).Error
|
||||
return userList, err
|
||||
}
|
||||
|
||||
func GetUserNameByUserID(userID string) (string, error) {
|
||||
var user User
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Select("name").Where("user_id=?", userID).First(&user).Error
|
||||
err := UserDB.Table("users").Select("name").Where("user_id=?", userID).First(&user).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -89,17 +116,17 @@ func GetUserNameByUserID(userID string) (string, error) {
|
||||
}
|
||||
|
||||
func UpdateUserInfo(user User) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(&user).Error
|
||||
return UserDB.Where("user_id=?", user.UserID).Updates(&user).Error
|
||||
}
|
||||
|
||||
func UpdateUserInfoByMap(user User, m map[string]interface{}) error {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(m).Error
|
||||
err := UserDB.Where("user_id=?", user.UserID).Updates(m).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func SelectAllUserID() ([]string, error) {
|
||||
var resultArr []string
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Pluck("user_id", &resultArr).Error
|
||||
err := UserDB.Pluck("user_id", &resultArr).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -108,7 +135,7 @@ func SelectAllUserID() ([]string, error) {
|
||||
|
||||
func SelectSomeUserID(userIDList []string) ([]string, error) {
|
||||
var resultArr []string
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id IN (?) ", userIDList).Pluck("user_id", &resultArr).Error
|
||||
err := UserDB.Pluck("user_id", &resultArr).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -117,7 +144,7 @@ func SelectSomeUserID(userIDList []string) ([]string, error) {
|
||||
|
||||
func GetUsers(showNumber, pageNumber int32) ([]User, error) {
|
||||
var users []User
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
|
||||
err := UserDB.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
|
||||
if err != nil {
|
||||
return users, err
|
||||
}
|
||||
@ -140,13 +167,13 @@ func AddUser(userID string, phoneNumber string, name string, email string, gende
|
||||
Ex: "",
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user)
|
||||
result := UserDB.Create(&user)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
func UserIsBlock(userId string) (bool, error) {
|
||||
var user BlackList
|
||||
rows := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
|
||||
rows := BlackListDB.Where("uid=?", userId).First(&user).RowsAffected
|
||||
if rows >= 1 {
|
||||
return user.EndDisableTime.After(time.Now()), nil
|
||||
}
|
||||
@ -154,7 +181,7 @@ func UserIsBlock(userId string) (bool, error) {
|
||||
}
|
||||
|
||||
func UsersIsBlock(userIDList []string) (inBlockUserIDList []string, err error) {
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid in (?) and end_disable_time > now()", userIDList).Pluck("uid", &inBlockUserIDList).Error
|
||||
err = BlackListDB.Where("uid in (?) and end_disable_time > now()", userIDList).Pluck("uid", &inBlockUserIDList).Error
|
||||
return inBlockUserIDList, err
|
||||
}
|
||||
|
||||
@ -171,9 +198,9 @@ func BlockUser(userID, endDisableTime string) error {
|
||||
return errors.New("endDisableTime is before now")
|
||||
}
|
||||
var blockUser BlackList
|
||||
db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userID).First(&blockUser)
|
||||
BlackListDB.Where("uid=?", userID).First(&blockUser)
|
||||
if blockUser.UserId != "" {
|
||||
db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
|
||||
BlackListDB.Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
|
||||
return nil
|
||||
}
|
||||
blockUser = BlackList{
|
||||
@ -181,12 +208,12 @@ func BlockUser(userID, endDisableTime string) error {
|
||||
BeginDisableTime: time.Now(),
|
||||
EndDisableTime: end,
|
||||
}
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Create(&blockUser).Error
|
||||
err = BlackListDB.Create(&blockUser).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func UnBlockUser(userID string) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userID).Delete(&BlackList{}).Error
|
||||
return BlackListDB.Where("uid=?", userID).Delete(&BlackList{}).Error
|
||||
}
|
||||
|
||||
type BlockUserInfo struct {
|
||||
@ -200,13 +227,13 @@ func GetBlockUserByID(userId string) (BlockUserInfo, error) {
|
||||
blockUser := BlackList{
|
||||
UserId: userId,
|
||||
}
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil {
|
||||
if err := BlackListDB.Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil {
|
||||
return blockUserInfo, err
|
||||
}
|
||||
user := User{
|
||||
UserID: blockUser.UserId,
|
||||
}
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Find(&user).Error; err != nil {
|
||||
if err := BlackListDB.Find(&user).Error; err != nil {
|
||||
return blockUserInfo, err
|
||||
}
|
||||
blockUserInfo.User.UserID = user.UserID
|
||||
@ -224,12 +251,12 @@ func GetBlockUserByID(userId string) (BlockUserInfo, error) {
|
||||
func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
|
||||
var blockUserInfos []BlockUserInfo
|
||||
var blockUsers []BlackList
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&blockUsers).Error; err != nil {
|
||||
if err := BlackListDB.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&blockUsers).Error; err != nil {
|
||||
return blockUserInfos, err
|
||||
}
|
||||
for _, blockUser := range blockUsers {
|
||||
var user User
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil {
|
||||
if err := UserDB.Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil {
|
||||
blockUserInfos = append(blockUserInfos, BlockUserInfo{
|
||||
User: User{
|
||||
UserID: user.UserID,
|
||||
@ -250,14 +277,14 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
|
||||
|
||||
func GetUserByName(userName string, showNumber, pageNumber int32) ([]User, error) {
|
||||
var users []User
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
|
||||
err := UserDB.Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
|
||||
return users, err
|
||||
}
|
||||
|
||||
func GetUsersByNameAndID(content string, showNumber, pageNumber int32) ([]User, int64, error) {
|
||||
var users []User
|
||||
var count int64
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content)
|
||||
db := UserDB.Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content)
|
||||
if err := db.Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@ -266,10 +293,10 @@ func GetUsersByNameAndID(content string, showNumber, pageNumber int32) ([]User,
|
||||
}
|
||||
|
||||
func GetUserIDsByEmailAndID(phoneNumber, email string) ([]string, error) {
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("users")
|
||||
if phoneNumber == "" && email == "" {
|
||||
return nil, nil
|
||||
}
|
||||
db := UserDB
|
||||
if phoneNumber != "" {
|
||||
db = db.Where("phone_number = ? ", phoneNumber)
|
||||
}
|
||||
@ -283,7 +310,7 @@ func GetUserIDsByEmailAndID(phoneNumber, email string) ([]string, error) {
|
||||
|
||||
func GetUsersCount(userName string) (int32, error) {
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like ? ", fmt.Sprintf("%%%s%%", userName)).Count(&count).Error; err != nil {
|
||||
if err := UserDB.Where(" name like ? ", fmt.Sprintf("%%%s%%", userName)).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int32(count), nil
|
||||
@ -291,7 +318,7 @@ func GetUsersCount(userName string) (int32, error) {
|
||||
|
||||
func GetBlockUsersNumCount() (int32, error) {
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Model(&BlackList{}).Count(&count).Error; err != nil {
|
||||
if err := BlackListDB.Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int32(count), nil
|
||||
|
@ -1,7 +1,41 @@
|
||||
package getcdv3
|
||||
|
||||
import "google.golang.org/grpc"
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"context"
|
||||
"github.com/OpenIMSDK/getcdv3"
|
||||
"google.golang.org/grpc"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func GetDefaultConn(arg1, arg2, arg3, arg4 string) *grpc.ClientConn {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetConn(ctx context.Context, serviceName string) (conn *grpc.ClientConn, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, "GetConn", err, "serviceName", serviceName)
|
||||
}()
|
||||
conn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","),
|
||||
serviceName, trace_log.GetOperationID(ctx), config.Config.Etcd.UserName, config.Config.Etcd.Password)
|
||||
if conn == nil {
|
||||
return nil, constant.ErrRpcConn
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func GetDefaultGatewayConn4Unique(schema, addr, operationID string) []*grpc.ClientConn {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RegisterEtcd(schema, etcdAddr, myHost string, myPort int, serviceName string, ttl int, operationID string) error {
|
||||
return getcdv3.RegisterEtcd(schema, etcdAddr, myHost, myPort, serviceName, ttl, operationID)
|
||||
}
|
||||
|
||||
var Conn4UniqueList []*grpc.ClientConn
|
||||
var Conn4UniqueListMtx sync.RWMutex
|
||||
var IsUpdateStart bool
|
||||
var IsUpdateStartMtx sync.RWMutex
|
||||
|
@ -1 +0,0 @@
|
||||
package utils
|
@ -2,31 +2,16 @@ package utils
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/getcdv3"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"gopkg.in/yaml.v3"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetConn(ctx context.Context, serviceName string) (conn *grpc.ClientConn, err error) {
|
||||
defer func() {
|
||||
trace_log.SetContextInfo(ctx, "GetConn", err, "serviceName", serviceName)
|
||||
}()
|
||||
conn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","),
|
||||
serviceName, trace_log.GetOperationID(ctx), config.Config.Etcd.UserName, config.Config.Etcd.Password)
|
||||
if conn == nil {
|
||||
return nil, constant.ErrRpcConn
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func registerConf(key, conf string) {
|
||||
etcdAddr := strings.Join(config.Config.Etcd.EtcdAddr, ",")
|
||||
cli, err := clientv3.New(clientv3.Config{
|
||||
|
Loading…
x
Reference in New Issue
Block a user