You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.8 KiB
81 lines
2.8 KiB
4 years ago
|
package user
|
||
|
|
||
|
import (
|
||
3 years ago
|
"Open_IM/internal/push/logic"
|
||
4 years ago
|
"Open_IM/src/common/config"
|
||
3 years ago
|
"Open_IM/src/common/constant"
|
||
4 years ago
|
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||
3 years ago
|
"Open_IM/src/common/log"
|
||
3 years ago
|
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||
3 years ago
|
pbChat "Open_IM/src/proto/chat"
|
||
|
pbFriend "Open_IM/src/proto/friend"
|
||
4 years ago
|
pbUser "Open_IM/src/proto/user"
|
||
|
"Open_IM/src/utils"
|
||
|
"context"
|
||
3 years ago
|
"strings"
|
||
4 years ago
|
)
|
||
|
|
||
|
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserInfoReq) (*pbUser.CommonResp, error) {
|
||
3 years ago
|
log.Info(req.Token, req.OperationID, "rpc modify user is server,args=%s", req.String())
|
||
4 years ago
|
claims, err := utils.ParseToken(req.Token)
|
||
|
if err != nil {
|
||
3 years ago
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||
4 years ago
|
return &pbUser.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: err.Error()}, nil
|
||
|
}
|
||
3 years ago
|
|
||
|
ownerUid := ""
|
||
3 years ago
|
//if claims.UID == config.Config.AppManagerUid {
|
||
|
if utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||
3 years ago
|
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)
|
||
4 years ago
|
if err != nil {
|
||
3 years ago
|
log.Error(req.Token, req.OperationID, "update user some attribute failed,err=%s", err.Error())
|
||
4 years ago
|
return &pbUser.CommonResp{ErrorCode: config.ErrModifyUserInfo.ErrCode, ErrorMsg: config.ErrModifyUserInfo.ErrMsg}, nil
|
||
|
}
|
||
3 years ago
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||
|
client := pbFriend.NewFriendClient(etcdConn)
|
||
|
newReq := &pbFriend.GetFriendListReq{
|
||
|
OperationID: req.OperationID,
|
||
|
Token: req.Token,
|
||
|
}
|
||
|
|
||
|
RpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||
|
if err != nil {
|
||
|
log.Error(req.Token, req.OperationID, "err=%s,call get friend list rpc server failed", err)
|
||
|
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||
|
}
|
||
|
if RpcResp.ErrorCode != 0 {
|
||
|
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||
3 years ago
|
|
||
|
}
|
||
3 years ago
|
self, err := im_mysql_model.FindUserByUID(ownerUid)
|
||
3 years ago
|
if err != nil {
|
||
|
log.ErrorByKv("get self info failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||
|
}
|
||
|
var name, faceUrl string
|
||
|
if self != nil {
|
||
|
name, faceUrl = self.Name, self.Icon
|
||
3 years ago
|
}
|
||
|
for _, v := range RpcResp.Data {
|
||
|
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||
3 years ago
|
SendID: ownerUid,
|
||
3 years ago
|
RecvID: v.Uid,
|
||
|
SenderNickName: name,
|
||
|
SenderFaceURL: faceUrl,
|
||
3 years ago
|
Content: ownerUid + "'s info has changed",
|
||
|
SendTime: utils.GetCurrentTimestampByNano(),
|
||
3 years ago
|
MsgFrom: constant.SysMsgType,
|
||
|
ContentType: constant.SetSelfInfoTip,
|
||
|
SessionType: constant.SingleChatType,
|
||
|
OperationID: req.OperationID,
|
||
|
Token: req.Token,
|
||
3 years ago
|
})
|
||
3 years ago
|
|
||
3 years ago
|
}
|
||
4 years ago
|
return &pbUser.CommonResp{}, nil
|
||
|
}
|