notification
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlacklistReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc add blacklist 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 &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
isMagagerFlag := 0
|
||||
tokenUid := claims.UID
|
||||
|
||||
if utils.IsContain(tokenUid, config.Config.Manager.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: constant.ErrMysql.ErrCode, ErrorMsg: constant.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: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc add blacklist success return,uid=%s", req.Uid)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/content_struct"
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc add friend is server,userid=%s", req.Uid)
|
||||
//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 &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
//Cannot add non-existent users
|
||||
if _, err = im_mysql_model.FindUserByUID(req.Uid); err != nil {
|
||||
log.Error(req.Token, req.OperationID, "this user not exists,cant not add friend")
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrAddFriend.ErrCode, ErrorMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//Establish a latest relationship in the friend request table
|
||||
err = im_mysql_model.ReplaceIntoFriendReq(claims.UID, req.Uid, constant.ApplicationFriendFlag, req.ReqMessage)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,create friend request record failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrAddFriend.ErrCode, ErrorMsg: constant.ErrAddFriend.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc add friend is success return,uid=%s", req.Uid)
|
||||
//Push message when add friend successfully
|
||||
senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
|
||||
receiverInfo, errReceive := im_mysql_model.FindUserByUID(req.Uid)
|
||||
if errSend == nil && errReceive == nil {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: senderInfo.UID,
|
||||
RecvID: receiverInfo.UID,
|
||||
Content: content_struct.NewContentStructString(0, "", senderInfo.Name+" asked to add you as a friend"),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.AddFriendTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
}
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "ImportFriend come here,args=%s", req.String())
|
||||
var resp pbFriend.ImportFriendResp
|
||||
var c pbFriend.CommonResp
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "parse token failed", err.Error())
|
||||
c.ErrorCode = constant.ErrAddFriend.ErrCode
|
||||
c.ErrorMsg = constant.ErrParseToken.ErrMsg
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedUidList: req.UidList}, nil
|
||||
}
|
||||
|
||||
if !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.NewError(req.OperationID, "not manager uid", claims.UID)
|
||||
c.ErrorCode = constant.ErrAddFriend.ErrCode
|
||||
c.ErrorMsg = "not authorized"
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedUidList: req.UidList}, nil
|
||||
}
|
||||
if _, err = im_mysql_model.FindUserByUID(req.OwnerUid); err != nil {
|
||||
log.NewError(req.OperationID, "this user not exists,cant not add friend", req.OwnerUid)
|
||||
c.ErrorCode = constant.ErrAddFriend.ErrCode
|
||||
c.ErrorMsg = "this user not exists,cant not add friend"
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedUidList: req.UidList}, nil
|
||||
}
|
||||
for _, v := range req.UidList {
|
||||
if _, fErr := im_mysql_model.FindUserByUID(v); fErr != nil {
|
||||
c.ErrorMsg = "some uid establish failed"
|
||||
c.ErrorCode = 408
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
} else {
|
||||
if _, err = im_mysql_model.FindFriendRelationshipFromFriend(req.OwnerUid, v); err != nil {
|
||||
//Establish two single friendship
|
||||
err1 := im_mysql_model.InsertToFriend(req.OwnerUid, v, 1)
|
||||
if err1 != nil {
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
log.NewError(req.OperationID, "err1,create friendship failed", req.OwnerUid, v, err1.Error())
|
||||
}
|
||||
err2 := im_mysql_model.InsertToFriend(v, req.OwnerUid, 1)
|
||||
if err2 != nil {
|
||||
log.NewError(req.OperationID, "err2,create friendship failed", v, req.OwnerUid, err2.Error())
|
||||
}
|
||||
if err1 == nil && err2 == nil {
|
||||
var name, faceUrl string
|
||||
n := content_struct.NotificationContent{IsDisplay: 1, DefaultTips: constant.FriendAcceptTip}
|
||||
r, err := im_mysql_model.FindUserByUID(v)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "get info failed", err.Error(), v)
|
||||
}
|
||||
if r != nil {
|
||||
name, faceUrl = r.Name, r.Icon
|
||||
}
|
||||
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: v,
|
||||
RecvID: req.OwnerUid,
|
||||
SenderFaceURL: faceUrl,
|
||||
SenderNickName: name,
|
||||
Content: n.ContentToString(),
|
||||
SendTime: utils.GetCurrentTimestampByNano(),
|
||||
MsgFrom: constant.UserMsgType, //Notification message identification
|
||||
ContentType: constant.AcceptFriendApplicationTip, //Add friend flag
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
} else {
|
||||
c.ErrorMsg = "some uid establish failed"
|
||||
c.ErrorCode = 408
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
resp.CommonResp = &c
|
||||
log.NewDebug(req.OperationID, "rpc come end", resp.CommonResp.ErrorCode, resp.CommonResp.ErrorMsg, resp.FailedUidList)
|
||||
return &resp, nil
|
||||
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/content_struct"
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddFriendResponseReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc add friend response 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 &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
//Check there application before agreeing or refuse to a friend's application
|
||||
if _, err = im_mysql_model.FindFriendApplyFromFriendReqByUid(req.Uid, claims.UID); err != nil {
|
||||
log.Error(req.Token, req.OperationID, "No such application record")
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrAgreeToAddFriend.ErrCode, ErrorMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
}
|
||||
//Change friend request status flag
|
||||
err = im_mysql_model.UpdateFriendRelationshipToFriendReq(req.Uid, claims.UID, req.Flag)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,update friend request table failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc add friend response success return,userid=%s,flag=%d", req.Uid, req.Flag)
|
||||
//Change the status of the friend request form
|
||||
if req.Flag == constant.FriendFlag {
|
||||
//Establish friendship after find friend relationship not exists
|
||||
_, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.Uid)
|
||||
//fixme If there is an error, it means that there is no friend record or database err, if no friend record should be inserted,Continue down execution
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, err.Error())
|
||||
}
|
||||
//Establish two single friendship
|
||||
err = im_mysql_model.InsertToFriend(claims.UID, req.Uid, req.Flag)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
||||
}
|
||||
err = im_mysql_model.InsertToFriend(req.Uid, claims.UID, req.Flag)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
||||
}
|
||||
//Push message when establish friends successfully
|
||||
//senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
|
||||
//if errSend == nil {
|
||||
// logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
// SendID: claims.UID,
|
||||
// RecvID: req.Uid,
|
||||
// Content: content_struct.NewContentStructString(1, "", senderInfo.Name+" agreed to 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,
|
||||
// })
|
||||
//}
|
||||
}
|
||||
if req.Flag == constant.RefuseFriendFlag {
|
||||
senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
|
||||
if errSend == nil {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: claims.UID,
|
||||
RecvID: req.Uid,
|
||||
Content: content_struct.NewContentStructString(0, "", senderInfo.Name+" refuse to add you as a friend."),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.UserMsgType, //Notification message identification
|
||||
ContentType: constant.RefuseFriendApplicationTip, //Add friend flag
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
}
|
||||
}
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFriendReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc delete friend 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 &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.DeleteSingleFriendInfo(claims.UID, req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,delete friend failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc delete friend success return")
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,487 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/internal/rpc/chat"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type friendServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewFriendServer(port int) *friendServer {
|
||||
log.NewPrivateLog("friend")
|
||||
return &friendServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) Run() {
|
||||
log.Info("", "", fmt.Sprintf("rpc friend init...."))
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.InfoByArgs(fmt.Sprintf("Failed to listen rpc friend network,err=%s", err.Error()))
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//User friend related services register to etcd
|
||||
pbFriend.RegisterFriendServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("register rpc fiend service to etcd failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("listen rpc friend error,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriendsInfo(ctx context.Context, req *pbFriend.GetFriendsInfoReq) (*pbFriend.GetFriendInfoResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendsInfo args ", req.String())
|
||||
var (
|
||||
isInBlackList int32
|
||||
// isFriend int32
|
||||
comment string
|
||||
)
|
||||
|
||||
friendShip, err := imdb.FindFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindFriendRelationshipFromFriend failed ", err.Error())
|
||||
return &pbFriend.GetFriendInfoResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
// isFriend = constant.FriendFlag
|
||||
}
|
||||
comment = friendShip.Remark
|
||||
|
||||
friendUserInfo, err := imdb.FindUserByUID(req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserByUID failed ", err.Error())
|
||||
return &pbFriend.GetFriendInfoResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err = imdb.FindRelationshipFromBlackList(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
isInBlackList = constant.BlackListFlag
|
||||
}
|
||||
|
||||
resp := pbFriend.GetFriendInfoResp{
|
||||
ErrCode: 0,
|
||||
ErrMsg: "",
|
||||
Data: &pbFriend.FriendInfo{
|
||||
IsBlack: isInBlackList,
|
||||
},
|
||||
}
|
||||
utils.CopyStructFields(resp.Data.FriendUser, friendUserInfo)
|
||||
resp.Data.IsBlack = isInBlackList
|
||||
resp.Data.OwnerUserID = req.CommID.FromUserID
|
||||
resp.Data.Remark = comment
|
||||
resp.Data.CreateTime = friendUserInfo.CreateTime
|
||||
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendsInfo ok ", resp)
|
||||
return &resp, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlacklistReq) (*pbFriend.CommonResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "AddBlacklist args ", req.String())
|
||||
ok := token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
if !ok {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess failed ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
}
|
||||
|
||||
err := imdb.InsertInToUserBlackList(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertInToUserBlackList failed ", err.Error())
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "InsertInToUserBlackList ok ", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
chat.BlackAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.CommonResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriend args ", req.String())
|
||||
ok := token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
if !ok {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess failed ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
}
|
||||
//Cannot add non-existent users
|
||||
if _, err := imdb.FindUserByUID(req.CommID.ToUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserByUID failed ", err.Error(), req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAddFriend.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//Establish a latest relationship in the friend request table
|
||||
err := imdb.ReplaceIntoFriendReq(req.CommID.FromUserID, req.CommID.ToUserID, constant.ApplicationFriendFlag, req.ReqMessage)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "ReplaceIntoFriendReq failed ", err.Error())
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAddFriend.ErrCode, ErrMsg: constant.ErrAddFriend.ErrMsg}, nil
|
||||
}
|
||||
|
||||
chat.FriendApplicationAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID, req.ReqMessage)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) {
|
||||
log.NewInfo(req.OperationID, "ImportFriend failed ", req.String())
|
||||
var resp pbFriend.ImportFriendResp
|
||||
var c pbFriend.CommonResp
|
||||
|
||||
if !utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
|
||||
log.NewError(req.OperationID, "not authorized", req.OpUserID)
|
||||
c.ErrCode = constant.ErrAddFriend.ErrCode
|
||||
c.ErrMsg = "not authorized"
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedUidList: req.FriendUserIDList}, nil
|
||||
}
|
||||
|
||||
if _, err := imdb.FindUserByUID(req.FromUserID); err != nil {
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.FromUserID)
|
||||
c.ErrCode = constant.ErrAddFriend.ErrCode
|
||||
c.ErrMsg = "this user not exists,cant not add friend"
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedUidList: req.FriendUserIDList}, nil
|
||||
}
|
||||
|
||||
for _, v := range req.FriendUserIDList {
|
||||
if _, fErr := imdb.FindUserByUID(v); fErr != nil {
|
||||
c.ErrMsg = "some uid establish failed"
|
||||
c.ErrCode = 408
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
} else {
|
||||
if _, err := imdb.FindFriendRelationshipFromFriend(req.FromUserID, v); err != nil {
|
||||
//Establish two single friendship
|
||||
err1 := imdb.InsertToFriend(req.FromUserID, v, 1)
|
||||
if err1 != nil {
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
log.NewError(req.OperationID, "InsertToFriend failed", req.FromUserID, v, err1.Error())
|
||||
c.ErrMsg = "some uid establish failed"
|
||||
c.ErrCode = 408
|
||||
continue
|
||||
}
|
||||
err2 := imdb.InsertToFriend(v, req.FromUserID, 1)
|
||||
if err2 != nil {
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
log.NewError(req.OperationID, "InsertToFriend failed", v, req.FromUserID, err2.Error())
|
||||
c.ErrMsg = "some uid establish failed"
|
||||
c.ErrCode = 408
|
||||
continue
|
||||
}
|
||||
chat.FriendAddedNotification(req.OperationID, req.OpUserID, req.FromUserID, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
resp.CommonResp = &c
|
||||
log.NewInfo(req.OperationID, "ImportFriend rpc ok ", resp)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddFriendResponseReq) (*pbFriend.CommonResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriendResponse args ", req.String())
|
||||
|
||||
if !token_verify.CheckAccess(rreq.CommID.FromUserID, req.CommID.ToUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess failed ", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAgreeToAddFriend.ErrCode, ErrMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//Check there application before agreeing or refuse to a friend's application
|
||||
//req.CommID.FromUserID process req.CommID.ToUserID
|
||||
if _, err := imdb.FindFriendApplyFromFriendReqByUid(req.CommID.ToUserID, req.CommID.FromUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindFriendApplyFromFriendReqByUid failed ", err.Error(), req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAgreeToAddFriend.ErrCode, ErrMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//Change friend request status flag
|
||||
err := imdb.UpdateFriendRelationshipToFriendReq(req.CommID.ToUserID, req.CommID.FromUserID, req.Flag)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "UpdateFriendRelationshipToFriendReq failed ", err.Error(), req.CommID.ToUserID, req.CommID.FromUserID, req.Flag)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc AddFriendResponse ok")
|
||||
//Change the status of the friend request form
|
||||
if req.Flag == constant.FriendFlag {
|
||||
//Establish friendship after find friend relationship not exists
|
||||
_, err := imdb.FindFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
log.NewWarn(req.CommID.OperationID, "FindFriendRelationshipFromFriend exist", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
} else {
|
||||
//Establish two single friendship
|
||||
err = imdb.InsertToFriend(req.CommID.FromUserID, req.CommID.ToUserID, req.Flag)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID, req.Flag)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAgreeToAddFriend.ErrCode, ErrMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
}
|
||||
}
|
||||
|
||||
_, err = imdb.FindFriendRelationshipFromFriend(req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
if err == nil {
|
||||
log.NewWarn(req.CommID.OperationID, "FindFriendRelationshipFromFriend exist", req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
err = imdb.InsertToFriend(req.CommID.ToUserID, req.CommID.FromUserID, req.Flag)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID, req.Flag)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAgreeToAddFriend.ErrCode, ErrMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
}
|
||||
}
|
||||
|
||||
chat.FriendApplicationProcessedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID, req.Flag)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFriendReq) (*pbFriend.CommonResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "DeleteFriend args ", req.String())
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err := imdb.DeleteSingleFriendInfo(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "DeleteSingleFriendInfo failed", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "DeleteFriend rpc ok")
|
||||
chat.FriendDeletedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetBlacklist args ", req.String())
|
||||
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess failed", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
blackListInfo, err := imdb.GetBlackListByUID(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetBlackListByUID failed ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrGetBlackList.ErrCode, ErrMsg: constant.ErrGetBlackList.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var (
|
||||
userInfoList []*sdk_ws.PublicUserInfo
|
||||
)
|
||||
for _, blackUser := range blackListInfo {
|
||||
var blackUserInfo sdk_ws.PublicUserInfo
|
||||
//Find black user information
|
||||
us, err := imdb.FindUserByUID(blackUser.BlockUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserByUID failed ", err.Error(), blackUser.BlockUserID)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(&blackUserInfo, us)
|
||||
userInfoList = append(userInfoList, &blackUserInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetBlacklist ok")
|
||||
return &pbFriend.GetBlacklistResp{Data: userInfoList}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) SetFriendComment(ctx context.Context, req *pbFriend.SetFriendCommentReq) (*pbFriend.CommonResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "SetFriendComment args ", req.String())
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err := imdb.UpdateFriendComment(req.CommID.FromUserID, req.CommID.OpUserID, req.Remark)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", err.Error(), req.CommID.FromUserID, req.CommID.OpUserID, req.Remark)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrSetFriendComment.ErrCode, ErrMsg: constant.ErrSetFriendComment.ErrMsg}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc SetFriendComment ok")
|
||||
chat.FriendInfoChangedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.RemoveBlacklistReq) (*pbFriend.CommonResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "RemoveBlacklist args ", req.String())
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
err := imdb.RemoveBlackList(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "RemoveBlackList failed", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc RemoveBlacklist ok")
|
||||
chat.BlackDeletedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlackListReq) (*pbFriend.IsInBlackListResp, error) {
|
||||
log.NewInfo("IsInBlackList args ", req.String())
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.IsInBlackListResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var isInBlacklist = false
|
||||
err := imdb.FindRelationshipFromBlackList(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
isInBlacklist = true
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "IsInBlackList rpc ok")
|
||||
return &pbFriend.IsInBlackListResp{Response: isInBlacklist}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) {
|
||||
log.NewInfo("IsFriend args ", req.String())
|
||||
var isFriend int32
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.IsFriendResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
_, err := imdb.FindFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
isFriend = constant.FriendFlag
|
||||
} else {
|
||||
isFriend = constant.ApplicationFriendFlag
|
||||
}
|
||||
log.NewInfo("IsFriend rpc ok")
|
||||
return &pbFriend.IsFriendResp{ShipType: isFriend}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFriendListReq) (*pbFriend.GetFriendListResp, error) {
|
||||
log.NewInfo("GetFriendList args ", req.String())
|
||||
var userInfoList []*pbFriend.FriendInfo
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
friends, err := imdb.FindUserInfoFromFriend(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserInfoFromFriend failed", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
for _, friendUser := range friends {
|
||||
var friendUserInfo pbFriend.FriendInfo
|
||||
//find user is in blackList
|
||||
err = imdb.FindRelationshipFromBlackList(req.CommID.FromUserID, friendUser.FriendUserID)
|
||||
if err == nil {
|
||||
friendUserInfo.IsBlack = constant.BlackListFlag
|
||||
} else {
|
||||
friendUserInfo.IsBlack = 0
|
||||
}
|
||||
//Find user information
|
||||
us, err := imdb.FindUserByUID(friendUser.FriendUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserByUID failed", err.Error(), friendUser.FriendUserID)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(friendUserInfo.FriendUser, us)
|
||||
friendUserInfo.Remark = friendUser.Remark
|
||||
friendUserInfo.OwnerUserID = req.CommID.FromUserID
|
||||
friendUserInfo.CreateTime = friendUser.CreateTime
|
||||
userInfoList = append(userInfoList, &friendUserInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetFriendList ok", pbFriend.GetFriendListResp{Data: userInfoList})
|
||||
return &pbFriend.GetFriendListResp{Data: userInfoList}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyReq) (*pbFriend.GetFriendApplyResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList args ", req.String())
|
||||
var appleUserList []*pbFriend.ApplyUserInfo
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendApplyResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
// Find the current user friend applications received
|
||||
ApplyUsersInfo, err := imdb.FindFriendsApplyFromFriendReq(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindFriendsApplyFromFriendReq ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendApplyResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
|
||||
for _, applyUserInfo := range ApplyUsersInfo {
|
||||
var userInfo pbFriend.ApplyUserInfo
|
||||
//Find friend application status
|
||||
userInfo.Flag = applyUserInfo.Flag
|
||||
userInfo.ReqMessage = applyUserInfo.ReqMessage
|
||||
userInfo.ApplyTime = applyUserInfo.CreateTime
|
||||
|
||||
//Find user information
|
||||
us, err := imdb.FindUserByUID(applyUserInfo.ReqID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserByUID failed ", err.Error(), applyUserInfo.ReqID)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(userInfo.UserInfo, us)
|
||||
appleUserList = append(appleUserList, &userInfo)
|
||||
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetFriendApplyList ok", pbFriend.GetFriendApplyResp{Data: appleUserList})
|
||||
return &pbFriend.GetFriendApplyResp{Data: appleUserList}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetFriendApplyReq) (*pbFriend.GetFriendApplyResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList args ", req.String())
|
||||
var selfApplyOtherUserList []*pbFriend.ApplyUserInfo
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendApplyResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
// Find the self add other userinfo
|
||||
usersInfo, err := imdb.FindSelfApplyFromFriendReq(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindSelfApplyFromFriendReq failed ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendApplyResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
for _, selfApplyOtherUserInfo := range usersInfo {
|
||||
var userInfo pbFriend.ApplyUserInfo
|
||||
//Find friend application status
|
||||
userInfo.Flag = selfApplyOtherUserInfo.Flag
|
||||
userInfo.ReqMessage = selfApplyOtherUserInfo.ReqMessage
|
||||
userInfo.ApplyTime = selfApplyOtherUserInfo.CreateTime
|
||||
//Find user information
|
||||
us, err := imdb.FindUserByUID(selfApplyOtherUserInfo.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserByUID failed", err.Error(), selfApplyOtherUserInfo.UserID)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(userInfo.UserInfo, us)
|
||||
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetSelfApplyList ok", pbFriend.GetFriendApplyResp{Data: selfApplyOtherUserList})
|
||||
return &pbFriend.GetFriendApplyResp{Data: selfApplyOtherUserList}, nil
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc get blacklist is server,args=%s", req.String())
|
||||
var (
|
||||
userInfoList []*pbFriend.UserInfo
|
||||
comment 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 &pbFriend.GetBlacklistResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
blackListInfo, err := im_mysql_model.GetBlackListByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s get blacklist failed", err.Error())
|
||||
return &pbFriend.GetBlacklistResp{ErrorCode: constant.ErrGetBlackList.ErrCode, ErrorMsg: constant.ErrGetBlackList.ErrMsg}, nil
|
||||
}
|
||||
for _, blackUser := range blackListInfo {
|
||||
var blackUserInfo pbFriend.UserInfo
|
||||
//Find black user information
|
||||
us, err := im_mysql_model.FindUserByUID(blackUser.BlockId)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s search black list userInfo failed", err.Error())
|
||||
continue
|
||||
}
|
||||
friendShip, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, blackUser.BlockId)
|
||||
if err == nil {
|
||||
comment = friendShip.Comment
|
||||
}
|
||||
blackUserInfo.Uid = us.UID
|
||||
blackUserInfo.Icon = us.Icon
|
||||
blackUserInfo.Name = us.Name
|
||||
blackUserInfo.Gender = us.Gender
|
||||
blackUserInfo.Mobile = us.Mobile
|
||||
blackUserInfo.Birth = us.Birth
|
||||
blackUserInfo.Email = us.Email
|
||||
blackUserInfo.Ex = us.Ex
|
||||
blackUserInfo.Comment = comment
|
||||
|
||||
userInfoList = append(userInfoList, &blackUserInfo)
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc get blacklist success return")
|
||||
return &pbFriend.GetBlacklistResp{Data: userInfoList}, nil
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type friendServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewFriendServer(port int) *friendServer {
|
||||
log.NewPrivateLog("friend")
|
||||
return &friendServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) Run() {
|
||||
log.Info("", "", fmt.Sprintf("rpc friend init...."))
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.InfoByArgs(fmt.Sprintf("Failed to listen rpc friend network,err=%s", err.Error()))
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//User friend related services register to etcd
|
||||
pbFriend.RegisterFriendServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("register rpc fiend service to etcd failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("listen rpc friend error,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriendsInfo(ctx context.Context, req *pbFriend.GetFriendsInfoReq) (*pbFriend.GetFriendInfoResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc search user is server,args=%s", req.String())
|
||||
var (
|
||||
isInBlackList int32
|
||||
isFriend int32
|
||||
comment 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 &pbFriend.GetFriendInfoResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
friendShip, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.Uid)
|
||||
if err == nil {
|
||||
isFriend = constant.FriendFlag
|
||||
comment = friendShip.Comment
|
||||
}
|
||||
friendUserInfo, err := im_mysql_model.FindUserByUID(req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,no this user", err.Error())
|
||||
return &pbFriend.GetFriendInfoResp{ErrorCode: constant.ErrSearchUserInfo.ErrCode, ErrorMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.FindRelationshipFromBlackList(claims.UID, req.Uid)
|
||||
if err == nil {
|
||||
isInBlackList = constant.BlackListFlag
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc search friend success return")
|
||||
return &pbFriend.GetFriendInfoResp{
|
||||
ErrorCode: 0,
|
||||
ErrorMsg: "",
|
||||
Data: &pbFriend.GetFriendData{
|
||||
Uid: friendUserInfo.UID,
|
||||
Icon: friendUserInfo.Icon,
|
||||
Name: friendUserInfo.Name,
|
||||
Gender: friendUserInfo.Gender,
|
||||
Mobile: friendUserInfo.Mobile,
|
||||
Birth: friendUserInfo.Birth,
|
||||
Email: friendUserInfo.Email,
|
||||
Ex: friendUserInfo.Ex,
|
||||
Comment: comment,
|
||||
IsFriend: isFriend,
|
||||
IsInBlackList: isInBlackList,
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyReq) (*pbFriend.GetFriendApplyResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc get friend apply list is server,args=%s", req.String())
|
||||
var appleUserList []*pbFriend.ApplyUserInfo
|
||||
//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 &pbFriend.GetFriendApplyResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
// Find the current user friend applications received
|
||||
ApplyUsersInfo, err := im_mysql_model.FindFriendsApplyFromFriendReq(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,search applyInfo failed", err.Error())
|
||||
return &pbFriend.GetFriendApplyResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
for _, applyUserInfo := range ApplyUsersInfo {
|
||||
var userInfo pbFriend.ApplyUserInfo
|
||||
//Find friend application status
|
||||
userInfo.Flag = applyUserInfo.Flag
|
||||
userInfo.ReqMessage = applyUserInfo.ReqMessage
|
||||
userInfo.ApplyTime = strconv.FormatInt(applyUserInfo.CreateTime.Unix(), 10)
|
||||
//Find user information
|
||||
us, err := im_mysql_model.FindUserByUID(applyUserInfo.ReqId)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,search userInfo failed", err.Error())
|
||||
continue
|
||||
}
|
||||
userInfo.Uid = us.UID
|
||||
userInfo.Icon = us.Icon
|
||||
userInfo.Name = us.Name
|
||||
userInfo.Gender = us.Gender
|
||||
userInfo.Mobile = us.Mobile
|
||||
userInfo.Birth = us.Birth
|
||||
userInfo.Email = us.Email
|
||||
userInfo.Ex = us.Ex
|
||||
appleUserList = append(appleUserList, &userInfo)
|
||||
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc get friendapplylist success return"))
|
||||
return &pbFriend.GetFriendApplyResp{Data: appleUserList}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetFriendApplyReq) (*pbFriend.GetFriendApplyResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc get self apply list is server,args=%s", req.String())
|
||||
var selfApplyOtherUserList []*pbFriend.ApplyUserInfo
|
||||
//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 &pbFriend.GetFriendApplyResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
// Find the self add other userinfo
|
||||
usersInfo, err := im_mysql_model.FindSelfApplyFromFriendReq(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,search self to other user Info failed", err.Error())
|
||||
return &pbFriend.GetFriendApplyResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
for _, selfApplyOtherUserInfo := range usersInfo {
|
||||
var userInfo pbFriend.ApplyUserInfo
|
||||
//Find friend application status
|
||||
userInfo.Flag = selfApplyOtherUserInfo.Flag
|
||||
userInfo.ReqMessage = selfApplyOtherUserInfo.ReqMessage
|
||||
userInfo.ApplyTime = strconv.FormatInt(selfApplyOtherUserInfo.CreateTime.Unix(), 10)
|
||||
//Find user information
|
||||
us, err := im_mysql_model.FindUserByUID(selfApplyOtherUserInfo.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,search userInfo failed", err.Error())
|
||||
continue
|
||||
}
|
||||
userInfo.Uid = us.UID
|
||||
userInfo.Icon = us.Icon
|
||||
userInfo.Name = us.Name
|
||||
userInfo.Gender = us.Gender
|
||||
userInfo.Mobile = us.Mobile
|
||||
userInfo.Birth = us.Birth
|
||||
userInfo.Email = us.Email
|
||||
userInfo.Ex = us.Ex
|
||||
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc get self apply list success return"))
|
||||
return &pbFriend.GetFriendApplyResp{Data: selfApplyOtherUserList}, nil
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFriendListReq) (*pbFriend.GetFriendListResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc get friend list is server,args=%s", req.String())
|
||||
var userInfoList []*pbFriend.UserInfo
|
||||
//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 &pbFriend.GetFriendListResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
friends, err := im_mysql_model.FindUserInfoFromFriend(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s search friendInfo failed", err.Error())
|
||||
return &pbFriend.GetFriendListResp{ErrorCode: constant.ErrSearchUserInfo.ErrCode, ErrorMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
for _, friendUser := range friends {
|
||||
var friendUserInfo pbFriend.UserInfo
|
||||
|
||||
//find user is in blackList
|
||||
err = im_mysql_model.FindRelationshipFromBlackList(claims.UID, friendUser.FriendId)
|
||||
if err == nil {
|
||||
friendUserInfo.IsInBlackList = constant.BlackListFlag
|
||||
} else {
|
||||
friendUserInfo.IsInBlackList = 0
|
||||
}
|
||||
//Find user information
|
||||
us, err := im_mysql_model.FindUserByUID(friendUser.FriendId)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s search userInfo failed", err.Error())
|
||||
continue
|
||||
}
|
||||
friendUserInfo.Uid = friendUser.FriendId
|
||||
friendUserInfo.Comment = friendUser.Comment
|
||||
friendUserInfo.Icon = us.Icon
|
||||
friendUserInfo.Name = us.Name
|
||||
friendUserInfo.Gender = us.Gender
|
||||
friendUserInfo.Mobile = us.Mobile
|
||||
friendUserInfo.Birth = us.Birth
|
||||
friendUserInfo.Email = us.Email
|
||||
friendUserInfo.Ex = us.Ex
|
||||
|
||||
userInfoList = append(userInfoList, &friendUserInfo)
|
||||
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc get friend list success return")
|
||||
return &pbFriend.GetFriendListResp{Data: userInfoList}, nil
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) {
|
||||
log.InfoByArgs("rpc is friend is server,args=%s", req.String())
|
||||
var isFriend int32
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.IsFriendResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
_, err = im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.ReceiveUid)
|
||||
if err == nil {
|
||||
isFriend = constant.FriendFlag
|
||||
} else {
|
||||
isFriend = constant.ApplicationFriendFlag
|
||||
}
|
||||
log.InfoByArgs(fmt.Sprintf("rpc is friend success return"))
|
||||
return &pbFriend.IsFriendResp{ShipType: isFriend}, nil
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlackListReq) (*pbFriend.IsInBlackListResp, error) {
|
||||
log.InfoByArgs("rpc is in blacklist is server,args=%s", req.String())
|
||||
var isInBlacklist = false
|
||||
err := im_mysql_model.FindRelationshipFromBlackList(req.ReceiveUid, req.SendUid)
|
||||
if err == nil {
|
||||
isInBlacklist = true
|
||||
}
|
||||
log.InfoByArgs(fmt.Sprintf("rpc is in blackList success return"))
|
||||
return &pbFriend.IsInBlackListResp{Response: isInBlacklist}, nil
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.RemoveBlacklistReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc remove blacklist is server,userid=%s", req.Uid)
|
||||
//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 &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.RemoveBlackList(claims.UID, req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,remove blacklist failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc remove blacklist success return,userid=%s", req.Uid)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) SetFriendComment(ctx context.Context, req *pbFriend.SetFriendCommentReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc set friend comment is server,params=%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 &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.UpdateFriendComment(claims.UID, req.Uid, req.Comment)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "set friend comment failed,err=%s", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrSetFriendComment.ErrCode, ErrorMsg: constant.ErrSetFriendComment.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc set friend comment is success return")
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
+188
-274
@@ -11,6 +11,7 @@ import (
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
@@ -70,165 +71,142 @@ func (s *groupServer) Run() {
|
||||
}
|
||||
|
||||
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())
|
||||
log.NewInfo(req.OperationID, "CreateGroup, args ", req.String())
|
||||
if !token_verify.CheckAccess(req.OpUserID, req.FromUserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.FromUserID)
|
||||
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)
|
||||
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())
|
||||
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupId, req.GroupName, req.Introduction, req.Notification, req.FaceUrl, req.Ext)
|
||||
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)
|
||||
us, err := im_mysql_model.FindUserByUID(req.FromUserID)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "find userInfo failed", err.Error())
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.FromUserID)
|
||||
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
|
||||
}
|
||||
//Add the group owner to the group first, otherwise the group creation will fail
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, us.UserID, us.Nickname, us.FaceUrl, constant.GroupOwner)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", 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
|
||||
}
|
||||
err = db.DB.AddGroupMember(groupId, req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "AddGroupMember failed ", err.Error(), groupId, req.FromUserID)
|
||||
// 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)
|
||||
for _, user := range req.InitMemberList {
|
||||
us, err := im_mysql_model.FindUserByUID(user.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), user.Uid)
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), user.UserID)
|
||||
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())
|
||||
if user.Role == 1 {
|
||||
log.NewError(req.OperationID, "only one owner, failed ", user)
|
||||
continue
|
||||
}
|
||||
err = db.DB.AddGroupMember(groupId, user.Uid)
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, user.UserID, us.Nickname, us.FaceUrl, user.Role)
|
||||
if err != nil {
|
||||
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", groupId, user.UserID, us.Nickname, us.FaceUrl, user.Role)
|
||||
}
|
||||
err = db.DB.AddGroupMember(groupId, user.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "add mongo group member failed, db.DB.AddGroupMember failed ", err.Error())
|
||||
}
|
||||
}
|
||||
resp := &pbGroup.CreateGroupResp{}
|
||||
|
||||
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
|
||||
resp.ErrCode = constant.ErrCreateGroup.ErrCode
|
||||
resp.ErrMsg = constant.ErrCreateGroup.ErrMsg
|
||||
return resp, 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
|
||||
chat.GroupCreatedNotification(req)
|
||||
utils.CopyStructFields(resp.GroupInfo, group)
|
||||
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJoinedGroupListReq) (*pbGroup.GetJoinedGroupListResp, error) {
|
||||
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.GetJoinedGroupListResp{ErrCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
log.NewInfo(req.OperationID, "GetJoinedGroupList, args ", req.String())
|
||||
if !token_verify.CheckAccess(req.OpUserID, req.FromUserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.FromUserID)
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
||||
|
||||
joinedGroupList, err := imdb.GetJoinedGroupIdListByMemberId(claims.UID)
|
||||
joinedGroupList, err := imdb.GetJoinedGroupIdListByMemberId(req.FromUserID)
|
||||
if err != nil {
|
||||
log.Error(claims.UID, req.OperationID, "GetJoinedGroupIdListByMemberId failed, err: ", err.Error())
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrParam.ErrCode, ErrorMsg: constant.ErrParam.ErrMsg}, nil
|
||||
log.NewError(req.OperationID, "GetJoinedGroupIdListByMemberId failed ", err.Error(), req.FromUserID)
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrParam.ErrCode, ErrMsg: constant.ErrParam.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var resp pbGroup.GetJoinedGroupListResp
|
||||
|
||||
for _, v := range joinedGroupList {
|
||||
var groupNode pbGroup.GroupInfo
|
||||
var groupNode open_im_sdk.GroupInfo
|
||||
num := imdb.GetGroupMemberNumByGroupId(v.GroupID)
|
||||
owner := imdb.GetGroupOwnerByGroupId(v.GroupID)
|
||||
owner, err2 := imdb.GetGroupOwnerInfoByGroupId(v.GroupID)
|
||||
group, err := imdb.FindGroupInfoByGroupId(v.GroupID)
|
||||
if num > 0 && owner != "" && err == nil {
|
||||
groupNode.GroupId = v.GroupID
|
||||
groupNode.FaceUrl = group.FaceUrl
|
||||
groupNode.CreateTime = uint64(group.CreateTime.Unix())
|
||||
groupNode.GroupName = group.GroupName
|
||||
groupNode.Introduction = group.Introduction
|
||||
groupNode.Notification = group.Notification
|
||||
groupNode.OwnerId = owner
|
||||
groupNode.MemberCount = uint32(int32(num))
|
||||
if num > 0 && owner != nil && err2 == nil && group != nil && err == nil {
|
||||
utils.CopyStructFields(&groupNode, group)
|
||||
utils.CopyStructFields(groupNode.Owner, owner)
|
||||
groupNode.MemberCount = uint32(num)
|
||||
resp.GroupList = append(resp.GroupList, &groupNode)
|
||||
} else {
|
||||
log.NewError(req.OperationID, "check nil ", num, owner, err, group)
|
||||
continue
|
||||
}
|
||||
log.Info(claims.UID, req.OperationID, "member num: ", num, "owner: ", owner)
|
||||
log.NewDebug(req.OperationID, "joinedGroup ", groupNode)
|
||||
}
|
||||
resp.ErrCode = 0
|
||||
log.NewInfo(req.OperationID, "GetJoinedGroupList return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.InviteUserToGroupReq) (*pbGroup.InviteUserToGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "InviteUserToGroup args: ", req.String())
|
||||
log.NewInfo(req.OperationID, "InviteUserToGroup args ", req.String())
|
||||
|
||||
if !imdb.IsExistGroupMember(req.GroupID, req.OpUserID) && !utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
|
||||
log.NewError(req.OperationID, "no permission InviteUserToGroup ", req.GroupID)
|
||||
log.NewError(req.OperationID, "no permission InviteUserToGroup ", req.GroupID, req.OpUserID)
|
||||
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
groupInfoFromMysql, err := imdb.FindGroupInfoByGroupId(req.GroupID)
|
||||
if err != nil || groupInfoFromMysql == nil {
|
||||
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed", req.GroupID)
|
||||
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed ", req.GroupID, err)
|
||||
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//
|
||||
//from User: invite: applicant
|
||||
//to user: invite: invited
|
||||
//to application
|
||||
var resp pbGroup.InviteUserToGroupResp
|
||||
opUser, err := imdb.FindUserByUID(req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.OpUserID)
|
||||
}
|
||||
var nicknameList string
|
||||
for _, v := range req.UidList {
|
||||
for _, v := range req.InvitedUserIDList {
|
||||
var resultNode pbGroup.Id2Result
|
||||
resultNode.UId = v
|
||||
resultNode.UserID = v
|
||||
resultNode.Result = 0
|
||||
toUserInfo, err := imdb.FindUserByUID(v)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error())
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), v)
|
||||
resultNode.Result = -1
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
|
||||
continue
|
||||
}
|
||||
|
||||
if imdb.IsExistGroupMember(req.GroupID, v) {
|
||||
log.NewError(req.OperationID, "ExistGroupMember failed ", req.GroupID, v)
|
||||
log.NewError(req.OperationID, "IsExistGroupMember ", req.GroupID, v)
|
||||
resultNode.Result = -1
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -236,91 +214,69 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertGroupMember failed ", req.GroupID, toUserInfo.UserID, toUserInfo.Nickname, toUserInfo.FaceUrl)
|
||||
resultNode.Result = -1
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
|
||||
continue
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, v)
|
||||
err = db.DB.AddGroupMember(req.GroupID, toUserInfo.UserID)
|
||||
if err != nil {
|
||||
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
log.NewError(req.OperationID, "AddGroupMember failed ", err.Error(), req.GroupID, toUserInfo.UserID)
|
||||
}
|
||||
nicknameList = nicknameList + toUserInfo.Nickname + " "
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
|
||||
}
|
||||
|
||||
resp.ErrCode = 0
|
||||
log.NewInfo(req.OperationID, "InviteUserToGroup rpc return ", resp)
|
||||
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) {
|
||||
log.NewInfo(req.OperationID, "GetGroupAllMember, args ", req.String())
|
||||
var resp pbGroup.GetGroupAllMemberResp
|
||||
resp.ErrCode = 0
|
||||
memberList, err := imdb.FindGroupMemberListByGroupId(req.GroupID)
|
||||
if err != nil {
|
||||
resp.ErrCode = constant.ErrDb.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
resp.ErrMsg = constant.ErrDb.ErrMsg
|
||||
log.NewError(req.OperationID, "FindGroupMemberListByGroupId failed,", err.Error(), req.GroupID)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
for _, v := range memberList {
|
||||
var node pbGroup.GroupMemberFullInfo
|
||||
node.Role = v.AdministratorLevel
|
||||
node.NickName = v.NickName
|
||||
node.UserId = v.UserID
|
||||
node.FaceUrl = v.FaceUrl
|
||||
node.JoinTime = uint64(v.JoinTime.Unix())
|
||||
resp.MemberList = append(resp.MemberList, &node)
|
||||
m := token_verify.IsMangerUserID(req.OpUserID)
|
||||
in := false
|
||||
if m {
|
||||
in = true
|
||||
}
|
||||
for _, v := range memberList {
|
||||
var node open_im_sdk.GroupMemberFullInfo
|
||||
utils.CopyStructFields(node, v)
|
||||
resp.MemberList = append(resp.MemberList, &node)
|
||||
if !m && req.OpUserID == v.UserID {
|
||||
in = true
|
||||
}
|
||||
}
|
||||
if !in {
|
||||
|
||||
}
|
||||
resp.ErrCode = 0
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGroupMemberListReq) (*pbGroup.GetGroupMemberListResp, error) {
|
||||
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.GetGroupMemberListResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
// log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
||||
fmt.Println("req: ", req.GroupID)
|
||||
log.NewInfo(req.OperationID, "GetGroupMemberList, args ", req.String())
|
||||
|
||||
var resp pbGroup.GetGroupMemberListResp
|
||||
resp.ErrCode = 0
|
||||
memberList, err := imdb.GetGroupMemberByGroupId(req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
if err != nil {
|
||||
resp.ErrCode = constant.ErrDb.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
log.Error(claims.UID, req.OperationID, "GetGroupMemberByGroupId failed, ", err.Error(), "params: ", req.GroupID, req.Filter, req.NextSeq)
|
||||
log.NewError(req.OperationID, "GetGroupMemberByGroupId failed,", req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
for _, v := range memberList {
|
||||
var node pbGroup.GroupMemberFullInfo
|
||||
node.Role = v.AdministratorLevel
|
||||
node.NickName = v.NickName
|
||||
node.UserId = v.UserID
|
||||
// node.FaceUrl =
|
||||
node.JoinTime = uint64(v.JoinTime.Unix())
|
||||
var node open_im_sdk.GroupMemberFullInfo
|
||||
utils.CopyStructFields(&node, v)
|
||||
resp.MemberList = append(resp.MemberList, &node)
|
||||
}
|
||||
//db operate get db sorted by join time
|
||||
@@ -331,33 +287,12 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
|
||||
}
|
||||
|
||||
resp.ErrCode = 0
|
||||
log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp)
|
||||
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) {
|
||||
log.NewInfo(req.OperationID, "KickGroupMember failed ", req.String())
|
||||
log.NewInfo(req.OperationID, "KickGroupMember args ", req.String())
|
||||
ownerList, err := imdb.GetOwnerManagerByGroupId(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
@@ -368,209 +303,188 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
for _, v := range ownerList {
|
||||
if v.UserID == req.OpUserID {
|
||||
flag = 1
|
||||
log.NewInfo(req.OperationID, "is group owner ", req.OpUserID, req.GroupID)
|
||||
log.NewDebug(req.OperationID, "is group owner ", req.OpUserID, req.GroupID)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if flag != 1 {
|
||||
if utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
|
||||
if token_verify.IsMangerUserID(req.OpUserID) {
|
||||
flag = 1
|
||||
log.NewInfo(req.OperationID, "is app manager ", req.OpUserID, req.GroupID)
|
||||
log.NewDebug(req.OperationID, "is app manager ", req.OpUserID)
|
||||
}
|
||||
}
|
||||
|
||||
if flag != 1 {
|
||||
log.NewError(req.OperationID, "failed, no access kick")
|
||||
log.NewError(req.OperationID, "failed, no access kick ")
|
||||
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
if len(req.UidListInfo) == 0 {
|
||||
if len(req.KickedUserIDList) == 0 {
|
||||
log.NewError(req.OperationID, "failed, kick list 0")
|
||||
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrParam.ErrCode, ErrMsg: constant.ErrParam.ErrMsg}, nil
|
||||
}
|
||||
|
||||
groupOwnerUserID := ""
|
||||
for _, v := range ownerList {
|
||||
if v.AdministratorLevel == 1 {
|
||||
groupOwnerUserID = v.UserID
|
||||
}
|
||||
}
|
||||
|
||||
//remove
|
||||
var resp pbGroup.KickGroupMemberResp
|
||||
for _, v := range req.UidListInfo {
|
||||
for _, v := range req.KickedUserIDList {
|
||||
//owner cant kicked
|
||||
if v.UserId == req.OpUserID {
|
||||
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})
|
||||
if v == groupOwnerUserID {
|
||||
log.NewError(req.OperationID, "failed, can't kick owner ", v)
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
|
||||
continue
|
||||
}
|
||||
err := imdb.RemoveGroupMember(req.GroupID, v.UserId)
|
||||
err := imdb.RemoveGroupMember(req.GroupID, v)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "RemoveGroupMember failed ", err.Error(), req.GroupID, v.UserId)
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: -1})
|
||||
log.NewError(req.OperationID, "RemoveGroupMember failed ", err.Error(), req.GroupID, v)
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
|
||||
} else {
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: 0})
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: 0})
|
||||
}
|
||||
|
||||
err = db.DB.DelGroupMember(req.GroupID, v.UserId)
|
||||
err = db.DB.DelGroupMember(req.GroupID, v)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "DelGroupMember failed ", err.Error(), req.GroupID, v.UserId)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range req.UidListInfo {
|
||||
chat.MemberKickedNotificationID(req.OperationID, req.GroupID, req.OpUserID, v.UserId, req.Reason)
|
||||
for _, v := range req.KickedUserIDList {
|
||||
chat.MemberKickedNotification(req.OperationID, req.GroupID, req.OpUserID, v, req.Reason)
|
||||
}
|
||||
|
||||
resp.ErrCode = 0
|
||||
log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetGroupMembersInfoReq) (*pbGroup.GetGroupMembersInfoResp, error) {
|
||||
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.GetGroupMembersInfoResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.InfoByKv(claims.UID, req.OperationID, "param: ", req.MemberList)
|
||||
log.NewInfo(req.OperationID, "GetGroupMembersInfo args ", req.String())
|
||||
|
||||
var resp pbGroup.GetGroupMembersInfoResp
|
||||
|
||||
for _, v := range req.MemberList {
|
||||
var memberNode pbGroup.GroupMemberFullInfo
|
||||
var memberNode open_im_sdk.GroupMemberFullInfo
|
||||
memberInfo, err := imdb.GetMemberInfoById(req.GroupID, v)
|
||||
memberNode.UserId = v
|
||||
fmt.Println("id : ", memberNode.UserId)
|
||||
memberNode.UserID = v
|
||||
if err != nil {
|
||||
log.Error(claims.UID, req.OperationID, req.GroupID, v, "GetMemberInfoById failed, ", err.Error())
|
||||
//error occurs, only id is valid
|
||||
resp.MemberList = append(resp.MemberList, &memberNode)
|
||||
log.NewError(req.OperationID, "GetMemberInfoById failed ", err.Error(), req.GroupID, v)
|
||||
continue
|
||||
} else {
|
||||
utils.CopyStructFields(&memberNode, memberInfo)
|
||||
resp.MemberList = append(resp.MemberList, &memberNode)
|
||||
}
|
||||
user, err := imdb.FindUserByUID(v)
|
||||
if err == nil && user != nil {
|
||||
memberNode.FaceUrl = user.FaceUrl
|
||||
memberNode.JoinTime = uint64(memberInfo.JoinTime.Unix())
|
||||
memberNode.UserId = user.UserID
|
||||
memberNode.NickName = memberInfo.NickName
|
||||
memberNode.Role = memberInfo.AdministratorLevel
|
||||
}
|
||||
resp.MemberList = append(resp.MemberList, &memberNode)
|
||||
}
|
||||
resp.ErrCode = 0
|
||||
log.NewInfo(req.OperationID, "GetGroupMembersInfo rpc return ", resp)
|
||||
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)
|
||||
func (s *groupServer) GetGroupApplicationList(_ context.Context, req *pbGroup.GetGroupApplicationListReq) (*pbGroup.GetGroupApplicationListResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetGroupMembersInfo args ", req.String())
|
||||
reply, err := im_mysql_model.GetGroupApplicationList(req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupApplicationList failed ", err.Error(), req.OpUserID)
|
||||
return &pbGroup.GetGroupApplicationListResp{ErrCode: 701, ErrMsg: "GetGroupApplicationList failed"}, nil
|
||||
}
|
||||
log.Info("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList")
|
||||
|
||||
log.NewInfo(req.OperationID, "GetGroupMembersInfo rpc return ", reply)
|
||||
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)
|
||||
log.NewInfo(req.OperationID, "GetGroupsInfo args ", req.String())
|
||||
groupsInfoList := make([]*open_im_sdk.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())
|
||||
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed ", err.Error(), groupID)
|
||||
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())
|
||||
|
||||
var groupInfo open_im_sdk.GroupInfo
|
||||
utils.CopyStructFields(&groupInfo, groupInfoFromMysql)
|
||||
groupsInfoList = append(groupsInfoList, &groupInfo)
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc get groupsInfo success return")
|
||||
return &pbGroup.GetGroupsInfoResp{Data: groupsInfoList}, nil
|
||||
|
||||
resp := pbGroup.GetGroupsInfoResp{GroupInfoList: groupsInfoList}
|
||||
log.NewInfo(req.OperationID, "GetGroupsInfo rpc return ", resp)
|
||||
return &resp, 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)
|
||||
func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.CommonResp, error) {
|
||||
log.NewInfo(req.OperationID, "GroupApplicationResponse args ", req.String())
|
||||
reply, err := imdb.GroupApplicationResponse(req)
|
||||
if err != nil {
|
||||
log.NewError(pb.OperationID, "GroupApplicationResponse failed ", err.Error(), pb.String())
|
||||
return &pbGroup.GroupApplicationResponseResp{ErrCode: 702, ErrMsg: err.Error()}, nil
|
||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.String())
|
||||
return &pbGroup.CommonResp{ErrCode: 702, ErrMsg: err.Error()}, nil
|
||||
}
|
||||
|
||||
if pb.HandleResult == 1 {
|
||||
if pb.ToUserID == "0" {
|
||||
err = db.DB.AddGroupMember(pb.GroupID, pb.FromUserID)
|
||||
if req.HandleResult == 1 {
|
||||
if req.ToUserID == "0" {
|
||||
err = db.DB.AddGroupMember(req.GroupID, req.FromUserID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., db.DB.AddGroupMember fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
log.NewError(req.OperationID, "AddGroupMember failed ", err.Error(), req.GroupID, req.FromUserID)
|
||||
}
|
||||
} else {
|
||||
err = db.DB.AddGroupMember(pb.GroupID, pb.ToUserID)
|
||||
err = db.DB.AddGroupMember(req.GroupID, req.ToUserID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., db.DB.AddGroupMember fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
log.NewError(req.OperationID, "AddGroupMember failed ", err.Error(), req.GroupID, req.ToUserID)
|
||||
}
|
||||
}
|
||||
}
|
||||
if pb.ToUserID == "0" {
|
||||
group, err := imdb.FindGroupInfoByGroupId(pb.GroupID)
|
||||
if req.ToUserID == "0" {
|
||||
group, err := imdb.FindGroupInfoByGroupId(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(pb.OperationID, "FindGroupInfoByGroupId failed ", pb.GroupID)
|
||||
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed ", req.GroupID)
|
||||
return reply, nil
|
||||
}
|
||||
member, err := imdb.FindGroupMemberInfoByGroupIdAndUserId(pb.GroupID, pb.OpUserID)
|
||||
member, err := imdb.FindGroupMemberInfoByGroupIdAndUserId(req.GroupID, req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(pb.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed ", pb.GroupID, pb.OpUserID)
|
||||
log.NewError(req.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed ", req.GroupID, req.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)
|
||||
chat.ApplicationProcessedNotification(req.OperationID, req.FromUserID, *group, *member, req.HandleResult, req.HandledMsg)
|
||||
if req.HandleResult == 1 {
|
||||
entrantUser, err := imdb.FindGroupMemberInfoByGroupIdAndUserId(req.GroupID, req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(pb.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed ", err.Error(), pb.GroupID, pb.FromUserID)
|
||||
log.NewError(req.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed ", err.Error(), req.GroupID, req.FromUserID)
|
||||
return reply, nil
|
||||
}
|
||||
chat.MemberEnterNotification(pb.OperationID, group, entrantUser)
|
||||
chat.MemberEnterNotification(req.OperationID, req.GroupID, entrantUser)
|
||||
}
|
||||
} else {
|
||||
log.NewError(pb.OperationID, "args failed ", pb.String())
|
||||
log.NewError(req.OperationID, "args failed ", req.String())
|
||||
}
|
||||
|
||||
log.NewInfo(pb.OperationID, "rpc GroupApplicationResponse ok ", reply)
|
||||
log.NewInfo(req.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())
|
||||
log.NewInfo(req.OperationID, "JoinGroup args ", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
//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(req.FromUserID)
|
||||
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)
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.FromUserID)
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
|
||||
_, err = im_mysql_model.FindGroupRequestUserInfoByGroupIDAndUid(req.GroupID, claims.UID)
|
||||
_, err = im_mysql_model.FindGroupRequestUserInfoByGroupIDAndUid(req.GroupID, req.FromUserID)
|
||||
if err == nil {
|
||||
err = im_mysql_model.DelGroupRequest(req.GroupID, claims.UID, "0")
|
||||
err = im_mysql_model.DelGroupRequest(req.GroupID, req.FromUserID, "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())
|
||||
if err = im_mysql_model.InsertIntoGroupRequest(req.GroupID, req.FromUserID, "0", req.ReqMessage, applicationUserInfo.Nickname, applicationUserInfo.FaceUrl); err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroupRequest ", err.Error(), req.GroupID, req.FromUserID, "0", req.ReqMessage, applicationUserInfo.Nickname, applicationUserInfo.FaceUrl)
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrJoinGroupApplication.ErrCode, ErrMsg: constant.ErrJoinGroupApplication.ErrMsg}, nil
|
||||
}
|
||||
|
||||
@@ -620,9 +534,9 @@ 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)
|
||||
groupUserInfo, err := im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(req.GroupInfo.GroupID, req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed, ", err.Error(), req.GroupID, req.OpUserID)
|
||||
log.NewError(req.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed, ", err.Error(), req.GroupInfo.GroupID, req.OpUserID)
|
||||
return false
|
||||
|
||||
}
|
||||
@@ -638,39 +552,39 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrSetGroupInfo.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
group, err := im_mysql_model.FindGroupInfoByGroupId(req.GroupID)
|
||||
group, err := im_mysql_model.FindGroupInfoByGroupId(req.GroupInfo.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed, ", err.Error(), req.GroupID)
|
||||
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed, ", err.Error(), req.GroupInfo.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 != "" {
|
||||
if group.GroupName != req.GroupInfo.GroupName && req.GroupInfo.GroupName != "" {
|
||||
changedType = 1
|
||||
}
|
||||
if group.Notification != req.Notification && req.Notification != "" {
|
||||
if group.Notification != req.GroupInfo.Notification && req.GroupInfo.Notification != "" {
|
||||
changedType = changedType | (1 << 1)
|
||||
}
|
||||
if group.Introduction != req.Introduction && req.Introduction != "" {
|
||||
if group.Introduction != req.GroupInfo.Introduction && req.GroupInfo.Introduction != "" {
|
||||
changedType = changedType | (1 << 2)
|
||||
}
|
||||
if group.FaceUrl != req.FaceUrl && req.FaceUrl != "" {
|
||||
if group.FaceUrl != req.GroupInfo.FaceUrl && req.GroupInfo.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 {
|
||||
if err = im_mysql_model.SetGroupInfo(req.GroupInfo.GroupID, req.GroupInfo.GroupName, req.GroupInfo.Introduction, req.GroupInfo.Notification, req.GroupInfo.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)
|
||||
chat.GroupInfoChangedNotification(req.OperationID, changedType, req.GroupInfo.GroupID, req.OpUserID)
|
||||
}
|
||||
|
||||
return &pbGroup.CommonResp{}, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) TransferGroupOwner(_ context.Context, pb *pbGroup.TransferGroupOwnerReq) (*pbGroup.TransferGroupOwnerResp, error) {
|
||||
func (s *groupServer) TransferGroupOwner(_ context.Context, pb *pbGroup.TransferGroupOwnerReq) (*pbGroup.CommonResp, error) {
|
||||
log.Info("", "", "rpc TransferGroupOwner call start..., [pb: %s]", pb.String())
|
||||
|
||||
reply, err := im_mysql_model.TransferGroupOwner(pb)
|
||||
|
||||
Reference in New Issue
Block a user