mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 02:26:00 +08:00
add management interface
This commit is contained in:
@@ -17,7 +17,23 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.InsertInToUserBlackList(claims.UID, req.Uid)
|
||||
|
||||
isMagagerFlag := 0
|
||||
tokenUid := claims.UID
|
||||
if tokenUid == config.Config.AppManagerUid {
|
||||
isMagagerFlag = 1
|
||||
}
|
||||
if isMagagerFlag == 0 {
|
||||
err = im_mysql_model.InsertInToUserBlackList(claims.UID, req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,Failed to add blacklist", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc add blacklist success return,uid=%s", req.Uid)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
err = im_mysql_model.InsertInToUserBlackList(req.OwnerUid, req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,Failed to add blacklist", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
|
||||
|
||||
@@ -51,3 +51,66 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
||||
}
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "ImportFriendis server,userid=%s", req.OwnerUid)
|
||||
//Parse token, to find current user information
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
if claims.UID != config.Config.AppManagerUid {
|
||||
log.Error(req.Token, req.OperationID, "not magager uid", claims.UID, config.Config.AppManagerUid)
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
if _, err = im_mysql_model.FindUserByUID(req.Uid); err != nil {
|
||||
log.Error(req.Token, req.OperationID, "this user not exists,cant not add friend", req.Uid)
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
|
||||
if _, err = im_mysql_model.FindUserByUID(req.OwnerUid); err != nil {
|
||||
log.Error(req.Token, req.OperationID, "this user not exists,cant not add friend", req.OwnerUid)
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
|
||||
_, err = im_mysql_model.FindFriendRelationshipFromFriend(req.OwnerUid, req.Uid)
|
||||
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, err.Error())
|
||||
}
|
||||
//Establish two single friendship
|
||||
err = im_mysql_model.InsertToFriend(req.OwnerUid, req.Uid, 1)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
||||
}
|
||||
err = im_mysql_model.InsertToFriend(req.Uid, req.OwnerUid, 1)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
||||
}
|
||||
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: req.OwnerUid,
|
||||
RecvID: req.Uid,
|
||||
Content: content_struct.NewContentStructString(0, "", " add you as a friend."),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.UserMsgType, //Notification message identification
|
||||
ContentType: constant.AcceptFriendApplicationTip, //Add friend flag
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: req.Uid,
|
||||
RecvID: req.OwnerUid,
|
||||
Content: content_struct.NewContentStructString(0, "", " add you as a friend."),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.UserMsgType, //Notification message identification
|
||||
ContentType: constant.AcceptFriendApplicationTip, //Add friend flag
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,10 @@ import (
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/push/content_struct"
|
||||
"Open_IM/src/push/logic"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
@@ -82,22 +85,30 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//Add the group owner to the group first, otherwise the group creation will fail
|
||||
us, err := im_mysql_model.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "find userInfo failed", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, claims.UID, us.Name, us.Icon, constant.GroupOwner)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "create group chat failed,err=%s", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
isMagagerFlag := 0
|
||||
tokenUid := claims.UID
|
||||
if tokenUid == config.Config.AppManagerUid {
|
||||
isMagagerFlag = 1
|
||||
}
|
||||
|
||||
err = db.DB.AddGroupMember(groupId, claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "create mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
if isMagagerFlag == 0 {
|
||||
//Add the group owner to the group first, otherwise the group creation will fail
|
||||
us, err := im_mysql_model.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "find userInfo failed", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, claims.UID, us.Name, us.Icon, constant.GroupOwner)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "create group chat failed,err=%s", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err = db.DB.AddGroupMember(groupId, claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "create mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
}
|
||||
|
||||
//Binding group id and member id
|
||||
@@ -116,17 +127,33 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
}
|
||||
}
|
||||
////Push message when create group chat
|
||||
//logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
// SendID: claims.UID,
|
||||
// RecvID: groupId,
|
||||
// Content: content_struct.NewContentStructString(0, "", req.String()),
|
||||
// SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
// MsgFrom: constant.SysMsgType, //Notification message identification
|
||||
// ContentType: constant.CreateGroupTip, //Add friend flag
|
||||
// SessionType: constant.GroupChatType,
|
||||
// OperationID: req.OperationID,
|
||||
//})
|
||||
|
||||
if isMagagerFlag == 1 {
|
||||
|
||||
//type NotificationContent struct {
|
||||
// IsDisplay int32 `json:"isDisplay"`
|
||||
// DefaultTips string `json:"defaultTips"`
|
||||
// Detail string `json:"detail"`
|
||||
//} n := NotificationContent{
|
||||
// IsDisplay: 1,
|
||||
// DefaultTips: "You have joined the group chat:" + createGroupResp.Data.GroupName,
|
||||
// Detail: createGroupResp.Data.GroupId,
|
||||
// }
|
||||
|
||||
////Push message when create group chat
|
||||
n := content_struct.NotificationContent{1, req.GroupName, groupId}
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: claims.UID,
|
||||
RecvID: groupId,
|
||||
Content: n.ContentToString(),
|
||||
SendTime: utils.GetCurrentTimestampByNano(),
|
||||
MsgFrom: constant.SysMsgType, //Notification message identification
|
||||
ContentType: constant.CreateGroupTip, //Add friend flag
|
||||
SessionType: constant.GroupChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
}
|
||||
|
||||
log.Info(req.Token, req.OperationID, "rpc create group success return")
|
||||
return &pbGroup.CreateGroupResp{GroupID: groupId}, nil
|
||||
}
|
||||
|
||||
+105
-43
@@ -2,7 +2,12 @@ package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
"Open_IM/src/push/content_struct"
|
||||
"Open_IM/src/push/logic"
|
||||
"encoding/json"
|
||||
|
||||
imdb "Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
@@ -59,7 +64,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
}
|
||||
log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
||||
|
||||
if !imdb.IsExistGroupMember(req.GroupID, claims.UID) {
|
||||
if !imdb.IsExistGroupMember(req.GroupID, claims.UID) && claims.UID != config.Config.AppManagerUid {
|
||||
log.Error(req.Token, req.OperationID, "err= invite user not in group")
|
||||
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrAccess.ErrCode, ErrorMsg: config.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
@@ -94,16 +99,6 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
continue
|
||||
}
|
||||
/*
|
||||
err = imdb.InsertGroupRequest(req.GroupID, fromUserInfo.UID, fromUserInfo.Name, fromUserInfo.Icon, toUserInfo.UID, req.Reason, "invited", 1)
|
||||
if err != nil {
|
||||
log.Error(v, req.OperationID, "InsertGroupRequest failed, err: ", err.Error(), "params: ",
|
||||
req.GroupID, fromUserInfo.UID, fromUserInfo.Name, fromUserInfo.Icon, toUserInfo.UID, req.Reason)
|
||||
resultNode.Result = -1
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
continue
|
||||
}
|
||||
*/
|
||||
|
||||
err = imdb.InsertGroupMember(req.GroupID, toUserInfo.UID, toUserInfo.Name, toUserInfo.Icon, 0)
|
||||
if err != nil {
|
||||
@@ -122,22 +117,42 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
}
|
||||
resp.ErrorCode = 0
|
||||
resp.ErrorMsg = "ok"
|
||||
/*
|
||||
var chatMsg pbChat.WSToMsgSvrChatMsg
|
||||
chatMsg.SendID = claims.UID
|
||||
chatMsg.RecvID = req.GroupID
|
||||
content, _ := json.Marshal(req)
|
||||
chatMsg.Content = string(content)
|
||||
chatMsg.SendTime = utils.GetCurrentTimestampBySecond()
|
||||
chatMsg.MsgFrom = constant.UserMsgType
|
||||
chatMsg.ContentType = constant.InviteUserToGroupTip
|
||||
chatMsg.SessionType = constant.GroupChatType
|
||||
logic.SendMsgByWS(&chatMsg)
|
||||
*/
|
||||
|
||||
if claims.UID == config.Config.AppManagerUid {
|
||||
var iu inviteUserToGroupReq
|
||||
iu.GroupID = req.GroupID
|
||||
iu.OperationID = req.OperationID
|
||||
iu.Reason = req.Reason
|
||||
iu.UidList = req.UidList
|
||||
n := content_struct.NotificationContent{1, req.GroupID, 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,
|
||||
})
|
||||
}
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
type inviteUserToGroupReq struct {
|
||||
GroupID string `json:"groupID"`
|
||||
UidList []string `json:"uidList"`
|
||||
Reason string `json:"reason"`
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
func (c *inviteUserToGroupReq) ContentToString() string {
|
||||
data, _ := json.Marshal(c)
|
||||
dataString := string(data)
|
||||
return dataString
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) {
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
@@ -209,6 +224,28 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
type groupMemberFullInfo struct {
|
||||
GroupId string `json:"groupID"`
|
||||
UserId string `json:"userId"`
|
||||
Role int `json:"role"`
|
||||
JoinTime uint64 `json:"joinTime"`
|
||||
NickName string `json:"nickName"`
|
||||
FaceUrl string `json:"faceUrl"`
|
||||
}
|
||||
|
||||
type kickGroupMemberApiReq struct {
|
||||
GroupID string `json:"groupID"`
|
||||
UidListInfo []groupMemberFullInfo `json:"uidListInfo"`
|
||||
Reason string `json:"reason"`
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
func (c *kickGroupMemberApiReq) ContentToString() string {
|
||||
data, _ := json.Marshal(c)
|
||||
dataString := string(data)
|
||||
return dataString
|
||||
}
|
||||
|
||||
func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGroupMemberReq) (*pbGroup.KickGroupMemberResp, error) {
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
@@ -230,6 +267,12 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
break
|
||||
}
|
||||
}
|
||||
if flag != 1 {
|
||||
if claims.UID == config.Config.AppManagerUid {
|
||||
flag = 1
|
||||
}
|
||||
}
|
||||
|
||||
if flag != 1 {
|
||||
log.Error(claims.UID, req.OperationID, "no access kick")
|
||||
return &pbGroup.KickGroupMemberResp{ErrorCode: config.ErrAccess.ErrCode, ErrorMsg: config.ErrAccess.ErrMsg}, nil
|
||||
@@ -262,29 +305,48 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
}
|
||||
|
||||
}
|
||||
var kq kickGroupMemberApiReq
|
||||
|
||||
/*
|
||||
var chatMsg pbChat.WSToMsgSvrChatMsg
|
||||
chatMsg.SendID = claims.UID
|
||||
chatMsg.RecvID = req.GroupID
|
||||
content, _ := json.Marshal(req)
|
||||
chatMsg.Content = string(content)
|
||||
chatMsg.SendTime = utils.GetCurrentTimestampBySecond()
|
||||
chatMsg.MsgFrom = constant.UserMsgType
|
||||
chatMsg.ContentType = constant.KickGroupMemberTip
|
||||
chatMsg.SessionType = constant.GroupChatType
|
||||
logic.SendMsgByWS(&chatMsg)
|
||||
kq.GroupID = req.GroupID
|
||||
kq.OperationID = req.OperationID
|
||||
kq.Reason = req.Reason
|
||||
|
||||
for _, v := range req.UidList {
|
||||
kickChatMsg := chatMsg
|
||||
kickChatMsg.RecvID = v
|
||||
kickChatMsg.SendTime = utils.GetCurrentTimestampBySecond()
|
||||
kickChatMsg.SessionType = constant.SingleChatType
|
||||
logic.SendMsgByWS(&kickChatMsg)
|
||||
var gf groupMemberFullInfo
|
||||
for _, v := range req.UidListInfo {
|
||||
gf.UserId = v.UserId
|
||||
gf.GroupId = req.GroupID
|
||||
kq.UidListInfo = append(kq.UidListInfo, gf)
|
||||
}
|
||||
|
||||
n := content_struct.NotificationContent{1, req.GroupID, kq.ContentToString()}
|
||||
|
||||
if claims.UID == config.Config.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
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
** description("").
|
||||
** copyright('open-im,www.open-im.io').
|
||||
** author("fg,Gordon@tuoyun.net").
|
||||
** time(2021/9/15 10:28).
|
||||
*/
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbUser "Open_IM/src/proto/user"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
|
||||
log.InfoByKv("rpc DeleteUsers arrived server", req.OperationID, "args", req.String())
|
||||
var resp pbUser.DeleteUsersResp
|
||||
c, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.ErrorByKv("parse token failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: err.Error()}, FailedUidList: req.DeleteUidList}, nil
|
||||
}
|
||||
if c.UID != config.Config.AppManagerUid {
|
||||
log.ErrorByKv(" Authentication failed", req.OperationID, "args", c)
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrorCode: 401, ErrorMsg: "not authorized"}, FailedUidList: req.DeleteUidList}, nil
|
||||
}
|
||||
for _, uid := range req.DeleteUidList {
|
||||
err = im_mysql_model.UserDelete(uid)
|
||||
if err != nil {
|
||||
resp.CommonResp.ErrorCode = 201
|
||||
resp.CommonResp.ErrorMsg = "some uid deleted failed"
|
||||
resp.FailedUidList = append(resp.FailedUidList, uid)
|
||||
}
|
||||
}
|
||||
return &resp, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllUsersUid(_ context.Context, req *pbUser.GetAllUsersUidReq) (*pbUser.GetAllUsersUidResp, error) {
|
||||
log.InfoByKv("rpc GetAllUsersUid arrived server", req.OperationID, "args", req.String())
|
||||
c, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.InfoByKv("parse token failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
}
|
||||
if c.UID != config.Config.AppManagerUid {
|
||||
log.ErrorByKv(" Authentication failed", req.OperationID, "args", c)
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: 401, ErrorMsg: "not authorized"}}, nil
|
||||
}
|
||||
uidList, err := im_mysql_model.SelectAllUID()
|
||||
if err != nil {
|
||||
log.ErrorByKv("db get failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
} else {
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: 0, ErrorMsg: ""}, UidList: uidList}, nil
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,15 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbUser.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: err.Error()}, nil
|
||||
}
|
||||
err = im_mysql_model.UpDateUserInfo(claims.UID, req.Name, req.Icon, req.Mobile, req.Birth, req.Email, req.Ex, req.Gender)
|
||||
|
||||
ownerUid := ""
|
||||
if claims.UID == config.Config.AppManagerUid {
|
||||
ownerUid = req.Uid
|
||||
} else {
|
||||
ownerUid = claims.UID
|
||||
}
|
||||
|
||||
err = im_mysql_model.UpDateUserInfo(ownerUid, req.Name, req.Icon, req.Mobile, req.Birth, req.Email, req.Ex, req.Gender)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "update user some attribute failed,err=%s", err.Error())
|
||||
return &pbUser.CommonResp{ErrorCode: config.ErrModifyUserInfo.ErrCode, ErrorMsg: config.ErrModifyUserInfo.ErrMsg}, nil
|
||||
@@ -43,7 +51,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
|
||||
}
|
||||
self, err := im_mysql_model.FindUserByUID(claims.UID)
|
||||
self, err := im_mysql_model.FindUserByUID(ownerUid)
|
||||
if err != nil {
|
||||
log.ErrorByKv("get self info failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
}
|
||||
@@ -53,12 +61,12 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
}
|
||||
for _, v := range RpcResp.Data {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: claims.UID,
|
||||
SendID: ownerUid,
|
||||
RecvID: v.Uid,
|
||||
SenderNickName: name,
|
||||
SenderFaceURL: faceUrl,
|
||||
Content: claims.UID + "'s info has changed",
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
Content: ownerUid + "'s info has changed",
|
||||
SendTime: utils.GetCurrentTimestampByNano(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.SetSelfInfoTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
|
||||
Reference in New Issue
Block a user