|
|
@ -1,50 +1,183 @@
|
|
|
|
package group
|
|
|
|
package group
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"Open_IM/internal/push/content_struct"
|
|
|
|
"Open_IM/internal/rpc/chat"
|
|
|
|
"Open_IM/internal/push/logic"
|
|
|
|
|
|
|
|
"Open_IM/pkg/common/config"
|
|
|
|
"Open_IM/pkg/common/config"
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/db"
|
|
|
|
"Open_IM/pkg/common/db"
|
|
|
|
"Open_IM/pkg/common/token_verify"
|
|
|
|
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
|
|
|
pbChat "Open_IM/pkg/proto/chat"
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
|
|
|
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
|
|
|
|
"Open_IM/pkg/common/token_verify"
|
|
|
|
|
|
|
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
|
|
|
pbGroup "Open_IM/pkg/proto/group"
|
|
|
|
pbGroup "Open_IM/pkg/proto/group"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type groupServer struct {
|
|
|
|
|
|
|
|
rpcPort int
|
|
|
|
|
|
|
|
rpcRegisterName string
|
|
|
|
|
|
|
|
etcdSchema string
|
|
|
|
|
|
|
|
etcdAddr []string
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewGroupServer(port int) *groupServer {
|
|
|
|
|
|
|
|
log.NewPrivateLog("group")
|
|
|
|
|
|
|
|
return &groupServer{
|
|
|
|
|
|
|
|
rpcPort: port,
|
|
|
|
|
|
|
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
|
|
|
|
|
|
|
etcdSchema: config.Config.Etcd.EtcdSchema,
|
|
|
|
|
|
|
|
etcdAddr: config.Config.Etcd.EtcdAddr,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *groupServer) Run() {
|
|
|
|
|
|
|
|
log.Info("", "", "rpc group init....")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ip := utils.ServerIP
|
|
|
|
|
|
|
|
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
|
|
|
|
|
|
|
//listener network
|
|
|
|
|
|
|
|
listener, err := net.Listen("tcp", registerAddress)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.InfoByArgs("listen network failed,err=%s", err.Error())
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("", "", "listen network success, address = %s", registerAddress)
|
|
|
|
|
|
|
|
defer listener.Close()
|
|
|
|
|
|
|
|
//grpc server
|
|
|
|
|
|
|
|
srv := grpc.NewServer()
|
|
|
|
|
|
|
|
defer srv.GracefulStop()
|
|
|
|
|
|
|
|
//Service registers with etcd
|
|
|
|
|
|
|
|
pbGroup.RegisterGroupServer(srv, s)
|
|
|
|
|
|
|
|
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.ErrorByArgs("get etcd failed,err=%s", err.Error())
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
err = srv.Serve(listener)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.ErrorByArgs("listen rpc_group error,err=%s", err.Error())
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("", "", "rpc create group init success")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (*pbGroup.CreateGroupResp, error) {
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "CreateGroup, args=%s", req.String())
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
groupId string
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
//Parse token, to find current user information
|
|
|
|
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "ParseToken failed, ", err.Error(), req.String())
|
|
|
|
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Time stamp + MD5 to generate group chat id
|
|
|
|
|
|
|
|
groupId = utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10))
|
|
|
|
|
|
|
|
err = im_mysql_model.InsertIntoGroup(groupId, req.GroupName, req.Introduction, req.Notification, req.FaceUrl, req.Ext)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), req.String())
|
|
|
|
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrCreateGroup.ErrCode, ErrMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isManagerFlag := 0
|
|
|
|
|
|
|
|
tokenUid := claims.UID
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if utils.IsContain(tokenUid, config.Config.Manager.AppManagerUid) {
|
|
|
|
|
|
|
|
isManagerFlag = 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
us, err := im_mysql_model.FindUserByUID(claims.UID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error("", req.OperationID, "find userInfo failed", err.Error())
|
|
|
|
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrCreateGroup.ErrCode, ErrMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isManagerFlag == 0 {
|
|
|
|
|
|
|
|
//Add the group owner to the group first, otherwise the group creation will fail
|
|
|
|
|
|
|
|
err = im_mysql_model.InsertIntoGroupMember(groupId, claims.UID, us.Nickname, us.FaceUrl, constant.GroupOwner)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error("", req.OperationID, "create group chat failed,err=%s", err.Error())
|
|
|
|
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrCreateGroup.ErrCode, ErrMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = db.DB.AddGroupMember(groupId, claims.UID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "AddGroupMember failed ", err.Error(), groupId, claims.UID)
|
|
|
|
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrCreateGroup.ErrCode, ErrMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Binding group id and member id
|
|
|
|
|
|
|
|
for _, user := range req.MemberList {
|
|
|
|
|
|
|
|
us, err := im_mysql_model.FindUserByUID(user.Uid)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), user.Uid)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
err = im_mysql_model.InsertIntoGroupMember(groupId, user.Uid, us.Nickname, us.FaceUrl, user.SetRole)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.ErrorByArgs("InsertIntoGroupMember failed", user.Uid, groupId, err.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
err = db.DB.AddGroupMember(groupId, user.Uid)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isManagerFlag == 1 {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
group, err := im_mysql_model.FindGroupInfoByGroupId(groupId)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed ", err.Error(), groupId)
|
|
|
|
|
|
|
|
return &pbGroup.CreateGroupResp{GroupID: groupId}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
memberList, err := im_mysql_model.FindGroupMemberListByGroupId(groupId)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "FindGroupMemberListByGroupId failed ", err.Error(), groupId)
|
|
|
|
|
|
|
|
return &pbGroup.CreateGroupResp{GroupID: groupId}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
chat.GroupCreatedNotification(req.OperationID, us, group, memberList)
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "GroupCreatedNotification, rpc CreateGroup success return ", groupId)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return &pbGroup.CreateGroupResp{GroupID: groupId}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJoinedGroupListReq) (*pbGroup.GetJoinedGroupListResp, error) {
|
|
|
|
func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJoinedGroupListReq) (*pbGroup.GetJoinedGroupListResp, error) {
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
|
|
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
|
|
|
return &pbGroup.GetJoinedGroupListResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
|
|
|
log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
|
|
|
|
|
|
|
|
|
|
|
joinedGroupList, err := imdb.GetJoinedGroupIdListByMemberId(claims.UID)
|
|
|
|
joinedGroupList, err := imdb.GetJoinedGroupIdListByMemberId(claims.UID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error(claims.UID, req.OperationID, "GetJoinedGroupIdListByMemberId failed, err: ", err.Error())
|
|
|
|
log.Error(claims.UID, req.OperationID, "GetJoinedGroupIdListByMemberId failed, err: ", err.Error())
|
|
|
|
return &pbGroup.GetJoinedGroupListResp{ErrorCode: constant.ErrParam.ErrCode, ErrorMsg: constant.ErrParam.ErrMsg}, nil
|
|
|
|
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrParam.ErrCode, ErrorMsg: constant.ErrParam.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var resp pbGroup.GetJoinedGroupListResp
|
|
|
|
var resp pbGroup.GetJoinedGroupListResp
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range joinedGroupList {
|
|
|
|
for _, v := range joinedGroupList {
|
|
|
|
var groupNode pbGroup.GroupInfo
|
|
|
|
var groupNode pbGroup.GroupInfo
|
|
|
|
num := imdb.GetGroupMemberNumByGroupId(v.GroupId)
|
|
|
|
num := imdb.GetGroupMemberNumByGroupId(v.GroupID)
|
|
|
|
owner := imdb.GetGroupOwnerByGroupId(v.GroupId)
|
|
|
|
owner := imdb.GetGroupOwnerByGroupId(v.GroupID)
|
|
|
|
group, err := imdb.FindGroupInfoByGroupId(v.GroupId)
|
|
|
|
group, err := imdb.FindGroupInfoByGroupId(v.GroupID)
|
|
|
|
if num > 0 && owner != "" && err == nil {
|
|
|
|
if num > 0 && owner != "" && err == nil {
|
|
|
|
groupNode.GroupId = v.GroupId
|
|
|
|
groupNode.GroupId = v.GroupID
|
|
|
|
groupNode.FaceUrl = group.FaceUrl
|
|
|
|
groupNode.FaceUrl = group.FaceUrl
|
|
|
|
groupNode.CreateTime = uint64(group.CreateTime.Unix())
|
|
|
|
groupNode.CreateTime = uint64(group.CreateTime.Unix())
|
|
|
|
groupNode.GroupName = group.Name
|
|
|
|
groupNode.GroupName = group.GroupName
|
|
|
|
groupNode.Introduction = group.Introduction
|
|
|
|
groupNode.Introduction = group.Introduction
|
|
|
|
groupNode.Notification = group.Notification
|
|
|
|
groupNode.Notification = group.Notification
|
|
|
|
groupNode.OwnerId = owner
|
|
|
|
groupNode.OwnerId = owner
|
|
|
@ -53,28 +186,21 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Info(claims.UID, req.OperationID, "member num: ", num, "owner: ", owner)
|
|
|
|
log.Info(claims.UID, req.OperationID, "member num: ", num, "owner: ", owner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.ErrorCode = 0
|
|
|
|
resp.ErrCode = 0
|
|
|
|
return &resp, nil
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.InviteUserToGroupReq) (*pbGroup.InviteUserToGroupResp, error) {
|
|
|
|
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.InviteUserToGroupReq) (*pbGroup.InviteUserToGroupResp, error) {
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
log.NewInfo(req.OperationID, "InviteUserToGroup args: ", req.String())
|
|
|
|
if err != nil {
|
|
|
|
if !imdb.IsExistGroupMember(req.GroupID, req.OpUserID) && !utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
|
|
|
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
|
|
|
log.NewError(req.OperationID, "no permission InviteUserToGroup ", req.GroupID)
|
|
|
|
return &pbGroup.InviteUserToGroupResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
|
|
|
|
|
|
|
// if !imdb.IsExistGroupMember(req.GroupID, claims.UID) && claims.UID != config.Config.AppManagerUid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !imdb.IsExistGroupMember(req.GroupID, claims.UID) && !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
|
|
|
|
|
|
|
log.Error(req.Token, req.OperationID, "err= invite user not in group")
|
|
|
|
|
|
|
|
return &pbGroup.InviteUserToGroupResp{ErrorCode: constant.ErrAccess.ErrCode, ErrorMsg: constant.ErrAccess.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
groupInfoFromMysql, err := imdb.FindGroupInfoByGroupId(req.GroupID)
|
|
|
|
groupInfoFromMysql, err := imdb.FindGroupInfoByGroupId(req.GroupID)
|
|
|
|
if err != nil || groupInfoFromMysql == nil {
|
|
|
|
if err != nil || groupInfoFromMysql == nil {
|
|
|
|
log.NewError(req.OperationID, "get group info error", req.GroupID, req.UidList)
|
|
|
|
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed", req.GroupID)
|
|
|
|
return &pbGroup.InviteUserToGroupResp{ErrorCode: constant.ErrAccess.ErrCode, ErrorMsg: constant.ErrAccess.ErrMsg}, nil
|
|
|
|
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -82,12 +208,10 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
|
|
|
//to user: invite: invited
|
|
|
|
//to user: invite: invited
|
|
|
|
//to application
|
|
|
|
//to application
|
|
|
|
var resp pbGroup.InviteUserToGroupResp
|
|
|
|
var resp pbGroup.InviteUserToGroupResp
|
|
|
|
/*
|
|
|
|
opUser, err := imdb.FindUserByUID(req.OpUserID)
|
|
|
|
fromUserInfo, err := imdb.FindUserByUID(claims.UID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.OpUserID)
|
|
|
|
log.Error(claims.UID, req.OperationID, "FindUserByUID failed, err: ", err.Error())
|
|
|
|
}
|
|
|
|
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrParam.ErrCode, ErrorMsg: config.ErrParam.ErrMsg}, nil
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
var nicknameList string
|
|
|
|
var nicknameList string
|
|
|
|
for _, v := range req.UidList {
|
|
|
|
for _, v := range req.UidList {
|
|
|
|
var resultNode pbGroup.Id2Result
|
|
|
|
var resultNode pbGroup.Id2Result
|
|
|
@ -95,58 +219,42 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
|
|
|
resultNode.Result = 0
|
|
|
|
resultNode.Result = 0
|
|
|
|
toUserInfo, err := imdb.FindUserByUID(v)
|
|
|
|
toUserInfo, err := imdb.FindUserByUID(v)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error(v, req.OperationID, "FindUserByUID failed, err: ", err.Error())
|
|
|
|
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error())
|
|
|
|
resultNode.Result = -1
|
|
|
|
resultNode.Result = -1
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if imdb.IsExistGroupMember(req.GroupID, v) {
|
|
|
|
if imdb.IsExistGroupMember(req.GroupID, v) {
|
|
|
|
log.Error(v, req.OperationID, "user has already in group")
|
|
|
|
log.NewError(req.OperationID, "ExistGroupMember failed ", req.GroupID, v)
|
|
|
|
resultNode.Result = -1
|
|
|
|
resultNode.Result = -1
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = imdb.InsertGroupMember(req.GroupID, toUserInfo.UID, toUserInfo.Name, toUserInfo.Icon, 0)
|
|
|
|
err = imdb.InsertGroupMember(req.GroupID, toUserInfo.UserID, toUserInfo.Nickname, toUserInfo.FaceUrl, 0)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error(v, req.OperationID, "InsertGroupMember failed, ", err.Error(), "params: ",
|
|
|
|
log.NewError(req.OperationID, "InsertGroupMember failed ", req.GroupID, toUserInfo.UserID, toUserInfo.Nickname, toUserInfo.FaceUrl)
|
|
|
|
req.GroupID, toUserInfo.UID, toUserInfo.Name, toUserInfo.Icon)
|
|
|
|
|
|
|
|
resultNode.Result = -1
|
|
|
|
resultNode.Result = -1
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = db.DB.AddGroupMember(req.GroupID, toUserInfo.UID)
|
|
|
|
member, err := imdb.GetMemberInfoById(req.GroupID, v)
|
|
|
|
|
|
|
|
if groupInfoFromMysql != nil && opUser != nil && member != nil {
|
|
|
|
|
|
|
|
chat.MemberInvitedNotification(req.OperationID, *groupInfoFromMysql, *opUser, *member)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "args failed, nil ", groupInfoFromMysql, opUser, member)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = db.DB.AddGroupMember(req.GroupID, toUserInfo.UserID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
|
|
|
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nicknameList = nicknameList + toUserInfo.Name + " "
|
|
|
|
nicknameList = nicknameList + toUserInfo.Nickname + " "
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.ErrorCode = 0
|
|
|
|
|
|
|
|
resp.ErrorMsg = "ok"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if claims.UID == config.Config.AppManagerUid
|
|
|
|
|
|
|
|
if utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
|
|
|
|
|
|
|
m, _ := imdb.FindUserByUID(claims.UID)
|
|
|
|
|
|
|
|
var iu inviteUserToGroupReq
|
|
|
|
|
|
|
|
iu.GroupID = req.GroupID
|
|
|
|
|
|
|
|
iu.OperationID = req.OperationID
|
|
|
|
|
|
|
|
iu.Reason = req.Reason
|
|
|
|
|
|
|
|
iu.UidList = req.UidList
|
|
|
|
|
|
|
|
n := content_struct.NotificationContent{1, nicknameList + " invited into the group chat by " + m.Name, iu.ContentToString()}
|
|
|
|
|
|
|
|
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
|
|
|
|
|
|
|
SendID: claims.UID,
|
|
|
|
|
|
|
|
RecvID: req.GroupID,
|
|
|
|
|
|
|
|
Content: n.ContentToString(),
|
|
|
|
|
|
|
|
SendTime: utils.GetCurrentTimestampByNano(),
|
|
|
|
|
|
|
|
MsgFrom: constant.UserMsgType,
|
|
|
|
|
|
|
|
ContentType: constant.InviteUserToGroupTip,
|
|
|
|
|
|
|
|
SessionType: constant.GroupChatType,
|
|
|
|
|
|
|
|
OperationID: req.OperationID,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp.ErrCode = 0
|
|
|
|
return &resp, nil
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -164,20 +272,12 @@ func (c *inviteUserToGroupReq) ContentToString() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) {
|
|
|
|
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) {
|
|
|
|
//claims, err := utils.ParseToken(req.Token)
|
|
|
|
|
|
|
|
//if err != nil {
|
|
|
|
|
|
|
|
// log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
|
|
|
|
|
|
|
// if req.Token != config.Config.Secret {
|
|
|
|
|
|
|
|
// return &pbGroup.GetGroupAllMemberResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var resp pbGroup.GetGroupAllMemberResp
|
|
|
|
var resp pbGroup.GetGroupAllMemberResp
|
|
|
|
resp.ErrorCode = 0
|
|
|
|
resp.ErrCode = 0
|
|
|
|
memberList, err := imdb.FindGroupMemberListByGroupId(req.GroupID)
|
|
|
|
memberList, err := imdb.FindGroupMemberListByGroupId(req.GroupID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
resp.ErrorCode = constant.ErrDb.ErrCode
|
|
|
|
resp.ErrCode = constant.ErrDb.ErrCode
|
|
|
|
resp.ErrorMsg = err.Error()
|
|
|
|
resp.ErrMsg = err.Error()
|
|
|
|
log.NewError(req.OperationID, "FindGroupMemberListByGroupId failed,", err.Error(), req.GroupID)
|
|
|
|
log.NewError(req.OperationID, "FindGroupMemberListByGroupId failed,", err.Error(), req.GroupID)
|
|
|
|
return &resp, nil
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -186,13 +286,13 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
|
|
|
|
var node pbGroup.GroupMemberFullInfo
|
|
|
|
var node pbGroup.GroupMemberFullInfo
|
|
|
|
node.Role = v.AdministratorLevel
|
|
|
|
node.Role = v.AdministratorLevel
|
|
|
|
node.NickName = v.NickName
|
|
|
|
node.NickName = v.NickName
|
|
|
|
node.UserId = v.Uid
|
|
|
|
node.UserId = v.UserID
|
|
|
|
node.FaceUrl = v.UserGroupFaceUrl
|
|
|
|
node.FaceUrl = v.FaceUrl
|
|
|
|
node.JoinTime = uint64(v.JoinTime.Unix())
|
|
|
|
node.JoinTime = uint64(v.JoinTime.Unix())
|
|
|
|
resp.MemberList = append(resp.MemberList, &node)
|
|
|
|
resp.MemberList = append(resp.MemberList, &node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resp.ErrorCode = 0
|
|
|
|
resp.ErrCode = 0
|
|
|
|
return &resp, nil
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -200,16 +300,16 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
|
|
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
|
|
|
return &pbGroup.GetGroupMemberListResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
return &pbGroup.GetGroupMemberListResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
|
|
|
// log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
|
|
|
fmt.Println("req: ", req.GroupID)
|
|
|
|
fmt.Println("req: ", req.GroupID)
|
|
|
|
var resp pbGroup.GetGroupMemberListResp
|
|
|
|
var resp pbGroup.GetGroupMemberListResp
|
|
|
|
resp.ErrorCode = 0
|
|
|
|
resp.ErrCode = 0
|
|
|
|
memberList, err := imdb.GetGroupMemberByGroupId(req.GroupID, req.Filter, req.NextSeq, 30)
|
|
|
|
memberList, err := imdb.GetGroupMemberByGroupId(req.GroupID, req.Filter, req.NextSeq, 30)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
resp.ErrorCode = constant.ErrDb.ErrCode
|
|
|
|
resp.ErrCode = constant.ErrDb.ErrCode
|
|
|
|
resp.ErrorMsg = err.Error()
|
|
|
|
resp.ErrMsg = err.Error()
|
|
|
|
log.Error(claims.UID, req.OperationID, "GetGroupMemberByGroupId failed, ", err.Error(), "params: ", req.GroupID, req.Filter, req.NextSeq)
|
|
|
|
log.Error(claims.UID, req.OperationID, "GetGroupMemberByGroupId failed, ", err.Error(), "params: ", req.GroupID, req.Filter, req.NextSeq)
|
|
|
|
return &resp, nil
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -218,7 +318,7 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
|
|
|
|
var node pbGroup.GroupMemberFullInfo
|
|
|
|
var node pbGroup.GroupMemberFullInfo
|
|
|
|
node.Role = v.AdministratorLevel
|
|
|
|
node.Role = v.AdministratorLevel
|
|
|
|
node.NickName = v.NickName
|
|
|
|
node.NickName = v.NickName
|
|
|
|
node.UserId = v.Uid
|
|
|
|
node.UserId = v.UserID
|
|
|
|
// node.FaceUrl =
|
|
|
|
// node.FaceUrl =
|
|
|
|
node.JoinTime = uint64(v.JoinTime.Unix())
|
|
|
|
node.JoinTime = uint64(v.JoinTime.Unix())
|
|
|
|
resp.MemberList = append(resp.MemberList, &node)
|
|
|
|
resp.MemberList = append(resp.MemberList, &node)
|
|
|
@ -230,7 +330,7 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
|
|
|
|
resp.NextSeq = req.NextSeq + int32(len(memberList))
|
|
|
|
resp.NextSeq = req.NextSeq + int32(len(memberList))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resp.ErrorCode = 0
|
|
|
|
resp.ErrCode = 0
|
|
|
|
return &resp, nil
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -257,54 +357,51 @@ func (c *kickGroupMemberApiReq) ContentToString() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGroupMemberReq) (*pbGroup.KickGroupMemberResp, error) {
|
|
|
|
func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGroupMemberReq) (*pbGroup.KickGroupMemberResp, error) {
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
log.NewInfo(req.OperationID, "KickGroupMember failed ", req.String())
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
|
|
|
|
|
|
|
return &pbGroup.KickGroupMemberResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ownerList, err := imdb.GetOwnerManagerByGroupId(req.GroupID)
|
|
|
|
ownerList, err := imdb.GetOwnerManagerByGroupId(req.GroupID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error(claims.UID, req.OperationID, req.GroupID, "GetOwnerManagerByGroupId, ", err.Error())
|
|
|
|
log.NewError(req.OperationID, "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
|
|
|
return &pbGroup.KickGroupMemberResp{ErrorCode: constant.ErrParam.ErrCode, ErrorMsg: constant.ErrParam.ErrMsg}, nil
|
|
|
|
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrParam.ErrCode, ErrMsg: constant.ErrParam.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//op is group owner?
|
|
|
|
//op is group owner?
|
|
|
|
var flag = 0
|
|
|
|
var flag = 0
|
|
|
|
for _, v := range ownerList {
|
|
|
|
for _, v := range ownerList {
|
|
|
|
if v.Uid == claims.UID {
|
|
|
|
if v.UserID == req.OpUserID {
|
|
|
|
flag = 1
|
|
|
|
flag = 1
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "is group owner ", req.OpUserID, req.GroupID)
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if flag != 1 {
|
|
|
|
if flag != 1 {
|
|
|
|
// if claims.UID == config.Config.AppManagerUid {
|
|
|
|
if utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
|
|
|
|
if utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
|
|
|
|
|
|
|
flag = 1
|
|
|
|
flag = 1
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "is app manager ", req.OpUserID, req.GroupID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if flag != 1 {
|
|
|
|
if flag != 1 {
|
|
|
|
log.Error(claims.UID, req.OperationID, "no access kick")
|
|
|
|
log.NewError(req.OperationID, "failed, no access kick")
|
|
|
|
return &pbGroup.KickGroupMemberResp{ErrorCode: constant.ErrAccess.ErrCode, ErrorMsg: constant.ErrAccess.ErrMsg}, nil
|
|
|
|
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if len(req.UidListInfo) == 0 {
|
|
|
|
if len(req.UidListInfo) == 0 {
|
|
|
|
log.Error(claims.UID, req.OperationID, "kick list 0")
|
|
|
|
log.NewError(req.OperationID, "failed, kick list 0")
|
|
|
|
return &pbGroup.KickGroupMemberResp{ErrorCode: constant.ErrParam.ErrCode, ErrorMsg: constant.ErrParam.ErrMsg}, nil
|
|
|
|
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrParam.ErrCode, ErrMsg: constant.ErrParam.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//remove
|
|
|
|
//remove
|
|
|
|
var resp pbGroup.KickGroupMemberResp
|
|
|
|
var resp pbGroup.KickGroupMemberResp
|
|
|
|
for _, v := range req.UidListInfo {
|
|
|
|
for _, v := range req.UidListInfo {
|
|
|
|
//owner cant kicked
|
|
|
|
//owner cant kicked
|
|
|
|
if v.UserId == claims.UID {
|
|
|
|
if v.UserId == req.OpUserID {
|
|
|
|
log.Error(claims.UID, req.OperationID, v.UserId, "cant kick owner")
|
|
|
|
log.NewError(req.OperationID, v.UserId, "failed, can't kick owner ", req.OpUserID)
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: -1})
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: -1})
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err := imdb.RemoveGroupMember(req.GroupID, v.UserId)
|
|
|
|
err := imdb.RemoveGroupMember(req.GroupID, v.UserId)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error(claims.UID, req.OperationID, v.UserId, req.GroupID, "RemoveGroupMember failed ", err.Error())
|
|
|
|
log.NewError(req.OperationID, "RemoveGroupMember failed ", err.Error(), req.GroupID, v.UserId)
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: -1})
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: -1})
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: 0})
|
|
|
|
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: 0})
|
|
|
@ -312,53 +409,15 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
|
|
|
|
|
|
|
|
|
|
|
err = db.DB.DelGroupMember(req.GroupID, v.UserId)
|
|
|
|
err = db.DB.DelGroupMember(req.GroupID, v.UserId)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error("", "", "delete mongo group member failed, db.DB.DelGroupMember fail [err: %s]", err.Error())
|
|
|
|
log.NewError(req.OperationID, "DelGroupMember failed ", err.Error(), req.GroupID, v.UserId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var kq kickGroupMemberApiReq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kq.GroupID = req.GroupID
|
|
|
|
|
|
|
|
kq.OperationID = req.OperationID
|
|
|
|
|
|
|
|
kq.Reason = req.Reason
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var gf groupMemberFullInfo
|
|
|
|
|
|
|
|
for _, v := range req.UidListInfo {
|
|
|
|
for _, v := range req.UidListInfo {
|
|
|
|
gf.UserId = v.UserId
|
|
|
|
chat.MemberKickedNotificationID(req.OperationID, req.GroupID, req.OpUserID, v.UserId, req.Reason)
|
|
|
|
gf.GroupId = req.GroupID
|
|
|
|
|
|
|
|
kq.UidListInfo = append(kq.UidListInfo, gf)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
n := content_struct.NotificationContent{1, req.GroupID, kq.ContentToString()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
|
|
|
|
|
|
|
log.Info("", req.OperationID, claims.UID, req.GroupID)
|
|
|
|
|
|
|
|
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
|
|
|
|
|
|
|
SendID: claims.UID,
|
|
|
|
|
|
|
|
RecvID: req.GroupID,
|
|
|
|
|
|
|
|
Content: n.ContentToString(),
|
|
|
|
|
|
|
|
SendTime: utils.GetCurrentTimestampByNano(),
|
|
|
|
|
|
|
|
MsgFrom: constant.UserMsgType,
|
|
|
|
|
|
|
|
ContentType: constant.KickGroupMemberTip,
|
|
|
|
|
|
|
|
SessionType: constant.GroupChatType,
|
|
|
|
|
|
|
|
OperationID: req.OperationID,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range req.UidListInfo {
|
|
|
|
|
|
|
|
log.Info("", req.OperationID, claims.UID, v.UserId)
|
|
|
|
|
|
|
|
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
|
|
|
|
|
|
|
SendID: claims.UID,
|
|
|
|
|
|
|
|
RecvID: v.UserId,
|
|
|
|
|
|
|
|
Content: n.ContentToString(),
|
|
|
|
|
|
|
|
SendTime: utils.GetCurrentTimestampBySecond(),
|
|
|
|
|
|
|
|
MsgFrom: constant.UserMsgType,
|
|
|
|
|
|
|
|
ContentType: constant.KickGroupMemberTip,
|
|
|
|
|
|
|
|
SessionType: constant.SingleChatType,
|
|
|
|
|
|
|
|
OperationID: req.OperationID,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.ErrorCode = 0
|
|
|
|
|
|
|
|
|
|
|
|
resp.ErrCode = 0
|
|
|
|
return &resp, nil
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -366,7 +425,7 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
|
|
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
|
|
|
return &pbGroup.GetGroupMembersInfoResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
return &pbGroup.GetGroupMembersInfoResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.InfoByKv(claims.UID, req.OperationID, "param: ", req.MemberList)
|
|
|
|
log.InfoByKv(claims.UID, req.OperationID, "param: ", req.MemberList)
|
|
|
|
var resp pbGroup.GetGroupMembersInfoResp
|
|
|
|
var resp pbGroup.GetGroupMembersInfoResp
|
|
|
@ -392,6 +451,234 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.MemberList = append(resp.MemberList, &memberNode)
|
|
|
|
resp.MemberList = append(resp.MemberList, &memberNode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.ErrorCode = 0
|
|
|
|
resp.ErrCode = 0
|
|
|
|
return &resp, nil
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GetGroupApplicationList(_ context.Context, pb *pbGroup.GetGroupApplicationListReq) (*pbGroup.GetGroupApplicationListResp, error) {
|
|
|
|
|
|
|
|
log.Info("", "", "rpc GetGroupApplicationList call start..., [pb: %s]", pb.String())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply, err := im_mysql_model.GetGroupApplicationList(pb.OpUserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return &pbGroup.GetGroupApplicationListResp{ErrCode: 701, ErrMsg: "GetGroupApplicationList failed"}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsInfoReq) (*pbGroup.GetGroupsInfoResp, error) {
|
|
|
|
|
|
|
|
log.Info(req.Token, req.OperationID, "rpc get group info is server,args=%s", req.String())
|
|
|
|
|
|
|
|
//Parse token, to find current user information
|
|
|
|
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
|
|
|
|
|
|
|
return &pbGroup.GetGroupsInfoResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("", req.OperationID, "args:", req.GroupIDList, claims.UID)
|
|
|
|
|
|
|
|
groupsInfoList := make([]*pbGroup.GroupInfo, 0)
|
|
|
|
|
|
|
|
for _, groupID := range req.GroupIDList {
|
|
|
|
|
|
|
|
groupInfoFromMysql, err := im_mysql_model.FindGroupInfoByGroupId(groupID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error(req.Token, req.OperationID, "find group info failed,err=%s", err.Error())
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var groupInfo pbGroup.GroupInfo
|
|
|
|
|
|
|
|
groupInfo.GroupId = groupID
|
|
|
|
|
|
|
|
groupInfo.GroupName = groupInfoFromMysql.GroupName
|
|
|
|
|
|
|
|
groupInfo.Introduction = groupInfoFromMysql.Introduction
|
|
|
|
|
|
|
|
groupInfo.Notification = groupInfoFromMysql.Notification
|
|
|
|
|
|
|
|
groupInfo.FaceUrl = groupInfoFromMysql.FaceUrl
|
|
|
|
|
|
|
|
groupInfo.OwnerId = im_mysql_model.GetGroupOwnerByGroupId(groupID)
|
|
|
|
|
|
|
|
groupInfo.MemberCount = uint32(im_mysql_model.GetGroupMemberNumByGroupId(groupID))
|
|
|
|
|
|
|
|
groupInfo.CreateTime = uint64(groupInfoFromMysql.CreateTime.Unix())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
groupsInfoList = append(groupsInfoList, &groupInfo)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(req.Token, req.OperationID, "rpc get groupsInfo success return")
|
|
|
|
|
|
|
|
return &pbGroup.GetGroupsInfoResp{Data: groupsInfoList}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GroupApplicationResponse(_ context.Context, pb *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
|
|
|
|
|
|
|
|
log.NewInfo(pb.OperationID, "GroupApplicationResponse args: ", pb.String())
|
|
|
|
|
|
|
|
reply, err := imdb.GroupApplicationResponse(pb)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(pb.OperationID, "GroupApplicationResponse failed ", err.Error(), pb.String())
|
|
|
|
|
|
|
|
return &pbGroup.GroupApplicationResponseResp{ErrCode: 702, ErrMsg: err.Error()}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pb.HandleResult == 1 {
|
|
|
|
|
|
|
|
if pb.ToUserID == "0" {
|
|
|
|
|
|
|
|
err = db.DB.AddGroupMember(pb.GroupID, pb.FromUserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error("", "", "rpc GroupApplicationResponse call..., db.DB.AddGroupMember fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
err = db.DB.AddGroupMember(pb.GroupID, pb.ToUserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error("", "", "rpc GroupApplicationResponse call..., db.DB.AddGroupMember fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if pb.ToUserID == "0" {
|
|
|
|
|
|
|
|
group, err := imdb.FindGroupInfoByGroupId(pb.GroupID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(pb.OperationID, "FindGroupInfoByGroupId failed ", pb.GroupID)
|
|
|
|
|
|
|
|
return reply, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
member, err := imdb.FindGroupMemberInfoByGroupIdAndUserId(pb.GroupID, pb.OpUserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(pb.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed ", pb.GroupID, pb.OpUserID)
|
|
|
|
|
|
|
|
return reply, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
chat.ApplicationProcessedNotification(pb.OperationID, pb.FromUserID, *group, *member, pb.HandleResult, pb.HandledMsg)
|
|
|
|
|
|
|
|
if pb.HandleResult == 1 {
|
|
|
|
|
|
|
|
entrantUser, err := imdb.FindGroupMemberInfoByGroupIdAndUserId(pb.GroupID, pb.FromUserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(pb.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed ", err.Error(), pb.GroupID, pb.FromUserID)
|
|
|
|
|
|
|
|
return reply, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
chat.MemberEnterNotification(pb.OperationID, group, entrantUser)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.NewError(pb.OperationID, "args failed ", pb.String())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.NewInfo(pb.OperationID, "rpc GroupApplicationResponse ok ", reply)
|
|
|
|
|
|
|
|
return reply, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.CommonResp, error) {
|
|
|
|
|
|
|
|
log.NewInfo(req.Token, req.OperationID, "JoinGroup args ", req.String())
|
|
|
|
|
|
|
|
//Parse token, to find current user information
|
|
|
|
|
|
|
|
claims, err := token_verify.ParseToken(req.Token)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "ParseToken failed", err.Error(), req.String())
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
applicationUserInfo, err := im_mysql_model.FindUserByUID(claims.UID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "FindUserByUID failed", err.Error(), claims.UID)
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, err = im_mysql_model.FindGroupRequestUserInfoByGroupIDAndUid(req.GroupID, claims.UID)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
err = im_mysql_model.DelGroupRequest(req.GroupID, claims.UID, "0")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = im_mysql_model.InsertIntoGroupRequest(req.GroupID, claims.UID, "0", req.Message, applicationUserInfo.Nickname, applicationUserInfo.FaceUrl); err != nil {
|
|
|
|
|
|
|
|
log.Error(req.Token, req.OperationID, "Insert into group request failed,er=%s", err.Error())
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: constant.ErrJoinGroupApplication.ErrCode, ErrMsg: constant.ErrJoinGroupApplication.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
memberList, err := im_mysql_model.FindGroupMemberListByGroupIdAndFilterInfo(req.GroupID, constant.GroupOwner)
|
|
|
|
|
|
|
|
if len(memberList) == 0 {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "FindGroupMemberListByGroupIdAndFilterInfo failed ", req.GroupID, constant.GroupOwner, err)
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
group, err := im_mysql_model.FindGroupInfoByGroupId(req.GroupID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed ", req.GroupID)
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
chat.ReceiveJoinApplicationNotification(req.OperationID, memberList[0].UserID, applicationUserInfo, group)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "ReceiveJoinApplicationNotification rpc JoinGroup success return")
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) (*pbGroup.CommonResp, error) {
|
|
|
|
|
|
|
|
log.NewError("QuitGroup args ", req.String())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, err := im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(req.GroupID, req.OpUserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed", err.Error(), req.GroupID, req.OpUserID)
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: constant.ErrQuitGroup.ErrCode, ErrMsg: constant.ErrQuitGroup.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = im_mysql_model.DeleteGroupMemberByGroupIdAndUserId(req.GroupID, req.OpUserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "DeleteGroupMemberByGroupIdAndUserId failed ", err.Error(), req.GroupID, req.OpUserID)
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: constant.ErrQuitGroup.ErrCode, ErrMsg: constant.ErrQuitGroup.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = db.DB.DelGroupMember(req.GroupID, req.OpUserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "DelGroupMember failed ", req.GroupID, req.OpUserID)
|
|
|
|
|
|
|
|
// return &pbGroup.CommonResp{ErrorCode: constant.ErrQuitGroup.ErrCode, ErrorMsg: constant.ErrQuitGroup.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chat.MemberLeaveNotification(req.OperationID, req.GroupID, req.OpUserID)
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "rpc quit group is success return")
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func hasAccess(req *pbGroup.SetGroupInfoReq) bool {
|
|
|
|
|
|
|
|
if utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
groupUserInfo, err := im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(req.GroupID, req.OpUserID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed, ", err.Error(), req.GroupID, req.OpUserID)
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if groupUserInfo.AdministratorLevel == constant.OrdinaryMember {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.CommonResp, error) {
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "SetGroupInfo args ", req.String())
|
|
|
|
|
|
|
|
if !hasAccess(req) {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "no access ")
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: constant.ErrSetGroupInfo.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group, err := im_mysql_model.FindGroupInfoByGroupId(req.GroupID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed, ", err.Error(), req.GroupID)
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: constant.ErrSetGroupInfo.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////bitwise operators: 1:groupName; 10:Notification 100:Introduction; 1000:FaceUrl
|
|
|
|
|
|
|
|
var changedType int32
|
|
|
|
|
|
|
|
if group.GroupName != req.GroupName && req.GroupName != "" {
|
|
|
|
|
|
|
|
changedType = 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if group.Notification != req.Notification && req.Notification != "" {
|
|
|
|
|
|
|
|
changedType = changedType | (1 << 1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if group.Introduction != req.Introduction && req.Introduction != "" {
|
|
|
|
|
|
|
|
changedType = changedType | (1 << 2)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if group.FaceUrl != req.FaceUrl && req.FaceUrl != "" {
|
|
|
|
|
|
|
|
changedType = changedType | (1 << 3)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//only administrators can set group information
|
|
|
|
|
|
|
|
if err = im_mysql_model.SetGroupInfo(req.GroupID, req.GroupName, req.Introduction, req.Notification, req.FaceUrl, ""); err != nil {
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{ErrCode: constant.ErrSetGroupInfo.ErrCode, ErrMsg: constant.ErrSetGroupInfo.ErrMsg}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if changedType != 0 {
|
|
|
|
|
|
|
|
chat.GroupInfoChangedNotification(req.OperationID, changedType, req.GroupID, req.OpUserID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return &pbGroup.CommonResp{}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) TransferGroupOwner(_ context.Context, pb *pbGroup.TransferGroupOwnerReq) (*pbGroup.TransferGroupOwnerResp, error) {
|
|
|
|
|
|
|
|
log.Info("", "", "rpc TransferGroupOwner call start..., [pb: %s]", pb.String())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply, err := im_mysql_model.TransferGroupOwner(pb)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error("", "", "rpc TransferGroupOwner call..., im_mysql_model.TransferGroupOwner fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("", "", "rpc TransferGroupOwner call..., im_mysql_model.TransferGroupOwner")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply, nil
|
|
|
|
|
|
|
|
}
|
|
|
|