add cmd/rpc
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
rpcChat "Open_IM/internal/rpc/chat"
|
||||
"Open_IM/internal/rpc/user/internal_service"
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/log"
|
||||
@@ -15,8 +17,6 @@ import (
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
pbRelay "Open_IM/src/proto/relay"
|
||||
pbGetInfo "Open_IM/src/proto/user"
|
||||
rpcChat "Open_IM/src/rpc/chat/chat"
|
||||
"Open_IM/src/rpc/user/internal_service"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
log2 "Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbAuth "Open_IM/src/proto/auth"
|
||||
"Open_IM/src/utils"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type rpcAuth struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewRpcAuthServer(port int) *rpcAuth {
|
||||
return &rpcAuth{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.RpcGetTokenName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) Run() {
|
||||
log2.Info("", "", "rpc get_token init...")
|
||||
|
||||
address := utils.ServerIP + ":" + strconv.Itoa(rpc.rpcPort)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
log2.Error("", "", "listen network failed, err = %s, address = %s", err.Error(), address)
|
||||
return
|
||||
}
|
||||
log2.Info("", "", "listen network success, address = %s", address)
|
||||
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
|
||||
//service registers with etcd
|
||||
|
||||
pbAuth.RegisterAuthServer(srv, rpc)
|
||||
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log2.Error("", "", "register rpc get_token to etcd failed, err = %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log2.Info("", "", "rpc get_token fail, err = %s", err.Error())
|
||||
return
|
||||
}
|
||||
log2.Info("", "", "rpc get_token init success")
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbAuth "Open_IM/src/proto/auth"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (rpc *rpcAuth) UserRegister(_ context.Context, pb *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) {
|
||||
log.Info("", "", "rpc user_register start, [data: %s]", pb.String())
|
||||
|
||||
if err := im_mysql_model.UserRegister(pb); err != nil {
|
||||
log.Error("", "", "rpc user_register error, [data: %s] [err: %s]", pb.String(), err.Error())
|
||||
return &pbAuth.UserRegisterResp{Success: false}, err
|
||||
}
|
||||
log.Info("", "", "rpc user_register success return")
|
||||
|
||||
return &pbAuth.UserRegisterResp{Success: true}, nil
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbAuth "Open_IM/src/proto/auth"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (rpc *rpcAuth) UserToken(_ context.Context, pb *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||
log.Info("", "", "rpc user_token call start..., [pbTokenReq: %s]", pb.String())
|
||||
|
||||
_, err := im_mysql_model.FindUserByUID(pb.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc user_token call..., im_mysql_model.AppServerFindFromUserByUserID fail [uid: %s] [err: %s]", pb.UID, err.Error())
|
||||
return &pbAuth.UserTokenResp{ErrCode: 500, ErrMsg: err.Error()}, err
|
||||
}
|
||||
log.Info("", "", "rpc user_token call..., im_mysql_model.AppServerFindFromUserByUserID")
|
||||
|
||||
tokens, expTime, err := utils.CreateToken(pb.UID, "", pb.Platform)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc user_token call..., utils.CreateToken fail [uid: %s] [err: %s]", pb.UID, err.Error())
|
||||
return &pbAuth.UserTokenResp{ErrCode: 500, ErrMsg: err.Error()}, err
|
||||
}
|
||||
log.Info("", "", "rpc user_token success return, [uid: %s] [tokens: %s]", pb.UID, tokens)
|
||||
|
||||
return &pbAuth.UserTokenResp{Token: tokens, ExpiredTime: expTime}, nil
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
|
||||
commonDB "Open_IM/src/common/db"
|
||||
"Open_IM/src/common/log"
|
||||
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
pbMsg "Open_IM/src/proto/chat"
|
||||
)
|
||||
|
||||
func (rpc *rpcChat) GetNewSeq(_ context.Context, in *pbMsg.GetNewSeqReq) (*pbMsg.GetNewSeqResp, error) {
|
||||
log.InfoByKv("rpc getNewSeq is arriving", in.OperationID, in.String())
|
||||
//seq, err := model.GetBiggestSeqFromReceive(in.UserID)
|
||||
seq, err := commonDB.DB.GetUserSeq(in.UserID)
|
||||
resp := new(pbMsg.GetNewSeqResp)
|
||||
if err == nil {
|
||||
resp.Seq = seq
|
||||
resp.ErrCode = 0
|
||||
resp.ErrMsg = ""
|
||||
return resp, err
|
||||
} else {
|
||||
if err == redis.ErrNil {
|
||||
resp.Seq = 0
|
||||
} else {
|
||||
log.ErrorByKv("getSeq from redis error", in.OperationID, "args", in.String(), "err", err.Error())
|
||||
resp.Seq = -1
|
||||
}
|
||||
resp.ErrCode = 0
|
||||
resp.ErrMsg = ""
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
}
|
||||
func (rpc *rpcChat) PullMessage(_ context.Context, in *pbMsg.PullMessageReq) (*pbMsg.PullMessageResp, error) {
|
||||
log.InfoByKv("rpc pullMessage is arriving", in.OperationID, "args", in.String())
|
||||
resp := new(pbMsg.PullMessageResp)
|
||||
var respSingleMsgFormat []*pbMsg.GatherFormat
|
||||
var respGroupMsgFormat []*pbMsg.GatherFormat
|
||||
SingleMsgFormat, GroupMsgFormat, MaxSeq, MinSeq, err := commonDB.DB.GetUserChat(in.UserID, in.SeqBegin, in.SeqEnd)
|
||||
if err != nil {
|
||||
log.ErrorByKv("pullMsg data error", in.OperationID, in.String())
|
||||
resp.ErrCode = 1
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
respSingleMsgFormat = singleMsgHandleByUser(SingleMsgFormat, in.UserID)
|
||||
respGroupMsgFormat = groupMsgHandleByUser(GroupMsgFormat)
|
||||
return &pbMsg.PullMessageResp{
|
||||
ErrCode: 0,
|
||||
ErrMsg: "",
|
||||
MaxSeq: MaxSeq,
|
||||
MinSeq: MinSeq,
|
||||
SingleUserMsg: respSingleMsgFormat,
|
||||
GroupUserMsg: respGroupMsgFormat,
|
||||
}, nil
|
||||
}
|
||||
func singleMsgHandleByUser(allMsg []*pbMsg.MsgFormat, ownerId string) []*pbMsg.GatherFormat {
|
||||
var userid string
|
||||
var respMsgFormat []*pbMsg.GatherFormat
|
||||
m := make(map[string]MsgFormats)
|
||||
//Gather messages in the dimension of users
|
||||
for _, v := range allMsg {
|
||||
if v.RecvID != ownerId {
|
||||
userid = v.RecvID
|
||||
} else {
|
||||
userid = v.SendID
|
||||
}
|
||||
if value, ok := m[userid]; !ok {
|
||||
var t MsgFormats
|
||||
m[userid] = append(t, v)
|
||||
} else {
|
||||
m[userid] = append(value, v)
|
||||
}
|
||||
}
|
||||
//Return in pb format
|
||||
for user, msg := range m {
|
||||
tempUserMsg := new(pbMsg.GatherFormat)
|
||||
tempUserMsg.ID = user
|
||||
tempUserMsg.List = msg
|
||||
sort.Sort(msg)
|
||||
respMsgFormat = append(respMsgFormat, tempUserMsg)
|
||||
}
|
||||
return respMsgFormat
|
||||
}
|
||||
func groupMsgHandleByUser(allMsg []*pbMsg.MsgFormat) []*pbMsg.GatherFormat {
|
||||
var respMsgFormat []*pbMsg.GatherFormat
|
||||
m := make(map[string]MsgFormats)
|
||||
//Gather messages in the dimension of users
|
||||
for _, v := range allMsg {
|
||||
//Get group ID
|
||||
groupID := strings.Split(v.RecvID, " ")[1]
|
||||
if value, ok := m[groupID]; !ok {
|
||||
var t MsgFormats
|
||||
m[groupID] = append(t, v)
|
||||
} else {
|
||||
m[groupID] = append(value, v)
|
||||
}
|
||||
|
||||
}
|
||||
//Return in pb format
|
||||
for groupID, msg := range m {
|
||||
tempUserMsg := new(pbMsg.GatherFormat)
|
||||
tempUserMsg.ID = groupID
|
||||
tempUserMsg.List = msg
|
||||
sort.Sort(msg)
|
||||
respMsgFormat = append(respMsgFormat, tempUserMsg)
|
||||
}
|
||||
return respMsgFormat
|
||||
}
|
||||
|
||||
type MsgFormats []*pbMsg.MsgFormat
|
||||
|
||||
// Implement the sort.Interface interface to get the number of elements method
|
||||
func (s MsgFormats) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
//Implement the sort.Interface interface comparison element method
|
||||
func (s MsgFormats) Less(i, j int) bool {
|
||||
return s[i].SendTime < s[j].SendTime
|
||||
}
|
||||
|
||||
//Implement the sort.Interface interface exchange element method
|
||||
func (s MsgFormats) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/kafka"
|
||||
log2 "Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
"Open_IM/src/utils"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type rpcChat struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
producer *kafka.Producer
|
||||
}
|
||||
|
||||
func NewRpcChatServer(port int) *rpcChat {
|
||||
rc := rpcChat{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfflineMessageName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
rc.producer = kafka.NewKafkaProducer(config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.Ws2mschat.Topic)
|
||||
return &rc
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) Run() {
|
||||
log2.Info("", "", "rpc get_token init...")
|
||||
|
||||
address := utils.ServerIP + ":" + strconv.Itoa(rpc.rpcPort)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
log2.Error("", "", "listen network failed, err = %s, address = %s", err.Error(), address)
|
||||
return
|
||||
}
|
||||
log2.Info("", "", "listen network success, address = %s", address)
|
||||
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
|
||||
//service registers with etcd
|
||||
|
||||
pbChat.RegisterChatServer(srv, rpc)
|
||||
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log2.Error("", "", "register rpc get_token to etcd failed, err = %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log2.Info("", "", "rpc get_token fail, err = %s", err.Error())
|
||||
return
|
||||
}
|
||||
log2.Info("", "", "rpc get_token init success")
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"Open_IM/internal/api/group"
|
||||
"Open_IM/internal/push/content_struct"
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
http2 "Open_IM/src/common/http"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MsgCallBackReq struct {
|
||||
SendID string `json:"sendID"`
|
||||
RecvID string `json:"recvID"`
|
||||
Content string `json:"content"`
|
||||
SendTime int64 `json:"sendTime"`
|
||||
MsgFrom int32 `json:"msgFrom"`
|
||||
ContentType int32 `json:"contentType"`
|
||||
SessionType int32 `json:"sessionType"`
|
||||
PlatformID int32 `json:"senderPlatformID"`
|
||||
}
|
||||
type MsgCallBackResp struct {
|
||||
ErrCode int32 `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
ResponseErrCode int32 `json:"responseErrCode"`
|
||||
ResponseResult struct {
|
||||
ModifiedMsg string `json:"modifiedMsg"`
|
||||
Ext string `json:"ext"`
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*pbChat.UserSendMsgResp, error) {
|
||||
replay := pbChat.UserSendMsgResp{}
|
||||
log.InfoByKv("sendMsg", pb.OperationID, "args", pb.String())
|
||||
if !utils.VerifyToken(pb.Token, pb.SendID) {
|
||||
return returnMsg(&replay, pb, http.StatusUnauthorized, "token validate err,not authorized", "", 0)
|
||||
}
|
||||
serverMsgID := GetMsgID(pb.SendID)
|
||||
pbData := pbChat.WSToMsgSvrChatMsg{}
|
||||
pbData.MsgFrom = pb.MsgFrom
|
||||
pbData.SessionType = pb.SessionType
|
||||
pbData.ContentType = pb.ContentType
|
||||
pbData.Content = pb.Content
|
||||
pbData.RecvID = pb.RecvID
|
||||
pbData.ForceList = pb.ForceList
|
||||
pbData.OfflineInfo = pb.OffLineInfo
|
||||
pbData.Options = pb.Options
|
||||
pbData.PlatformID = pb.PlatformID
|
||||
pbData.ClientMsgID = pb.ClientMsgID
|
||||
pbData.SendID = pb.SendID
|
||||
pbData.SenderNickName = pb.SenderNickName
|
||||
pbData.SenderFaceURL = pb.SenderFaceURL
|
||||
pbData.MsgID = serverMsgID
|
||||
pbData.OperationID = pb.OperationID
|
||||
pbData.Token = pb.Token
|
||||
pbData.SendTime = utils.GetCurrentTimestampByNano()
|
||||
m := MsgCallBackResp{}
|
||||
if config.Config.MessageCallBack.CallbackSwitch {
|
||||
bMsg, err := http2.Post(config.Config.MessageCallBack.CallbackUrl, MsgCallBackReq{
|
||||
SendID: pb.SendID,
|
||||
RecvID: pb.RecvID,
|
||||
Content: pb.Content,
|
||||
SendTime: pbData.SendTime,
|
||||
MsgFrom: pbData.MsgFrom,
|
||||
ContentType: pb.ContentType,
|
||||
SessionType: pb.SessionType,
|
||||
PlatformID: pb.PlatformID,
|
||||
}, "application/json; charset=utf-8")
|
||||
if err != nil {
|
||||
log.ErrorByKv("callback to Business server err", pb.OperationID, "args", pb.String(), "err", err.Error())
|
||||
return returnMsg(&replay, pb, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError), "", 0)
|
||||
} else if err = json.Unmarshal(bMsg, &m); err != nil {
|
||||
log.ErrorByKv("ws json Unmarshal err", pb.OperationID, "args", pb.String(), "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
} else {
|
||||
if m.ErrCode != 0 {
|
||||
return returnMsg(&replay, pb, m.ResponseErrCode, m.ErrMsg, "", 0)
|
||||
} else {
|
||||
pbData.Content = m.ResponseResult.ModifiedMsg
|
||||
err1 := rpc.sendMsgToKafka(&pbData, pbData.RecvID)
|
||||
err2 := rpc.sendMsgToKafka(&pbData, pbData.SendID)
|
||||
if err1 != nil || err2 != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch pbData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
err1 := rpc.sendMsgToKafka(&pbData, pbData.RecvID)
|
||||
err2 := rpc.sendMsgToKafka(&pbData, pbData.SendID)
|
||||
if err1 != nil || err2 != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
case constant.GroupChatType:
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
req := &pbGroup.GetGroupAllMemberReq{
|
||||
GroupID: pbData.RecvID,
|
||||
Token: pbData.Token,
|
||||
OperationID: pbData.OperationID,
|
||||
}
|
||||
reply, err := client.GetGroupAllMember(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(pbData.Token, pbData.OperationID, "rpc send_msg getGroupInfo failed, err = %s", err.Error())
|
||||
return returnMsg(&replay, pb, 201, err.Error(), "", 0)
|
||||
}
|
||||
if reply.ErrorCode != 0 {
|
||||
log.Error(pbData.Token, pbData.OperationID, "rpc send_msg getGroupInfo failed, err = %s", reply.ErrorMsg)
|
||||
return returnMsg(&replay, pb, reply.ErrorCode, reply.ErrorMsg, "", 0)
|
||||
}
|
||||
var addUidList []string
|
||||
switch pbData.ContentType {
|
||||
case constant.KickGroupMemberTip:
|
||||
var notification content_struct.NotificationContent
|
||||
var kickContent group.KickGroupMemberReq
|
||||
err := utils.JsonStringToStruct(pbData.Content, ¬ification)
|
||||
if err != nil {
|
||||
log.ErrorByKv("json unmarshall err", pbData.OperationID, "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
} else {
|
||||
err := utils.JsonStringToStruct(notification.Detail, &kickContent)
|
||||
if err != nil {
|
||||
log.ErrorByKv("json unmarshall err", pbData.OperationID, "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
}
|
||||
for _, v := range kickContent.UidListInfo {
|
||||
addUidList = append(addUidList, v.UserId)
|
||||
}
|
||||
}
|
||||
case constant.QuitGroupTip:
|
||||
addUidList = append(addUidList, pbData.SendID)
|
||||
default:
|
||||
}
|
||||
groupID := pbData.RecvID
|
||||
for i, v := range reply.MemberList {
|
||||
pbData.RecvID = v.UserId + " " + groupID
|
||||
err := rpc.sendMsgToKafka(&pbData, utils.IntToString(i))
|
||||
if err != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
for i, v := range addUidList {
|
||||
pbData.RecvID = v + " " + groupID
|
||||
err := rpc.sendMsgToKafka(&pbData, utils.IntToString(i+1))
|
||||
if err != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
||||
|
||||
}
|
||||
func (rpc *rpcChat) sendMsgToKafka(m *pbChat.WSToMsgSvrChatMsg, key string) error {
|
||||
pid, offset, err := rpc.producer.SendMessage(m, key)
|
||||
if err != nil {
|
||||
log.ErrorByKv("kafka send failed", m.OperationID, "send data", m.String(), "pid", pid, "offset", offset, "err", err.Error(), "key", key)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func GetMsgID(sendID string) string {
|
||||
t := time.Now().Format("2006-01-02 15:04:05")
|
||||
return t + "-" + sendID + "-" + strconv.Itoa(rand.Int())
|
||||
}
|
||||
func returnMsg(replay *pbChat.UserSendMsgResp, pb *pbChat.UserSendMsgReq, errCode int32, errMsg, serverMsgID string, sendTime int64) (*pbChat.UserSendMsgResp, error) {
|
||||
replay.ErrCode = errCode
|
||||
replay.ErrMsg = errMsg
|
||||
replay.ReqIdentifier = pb.ReqIdentifier
|
||||
replay.ClientMsgID = pb.ClientMsgID
|
||||
replay.ServerMsgID = serverMsgID
|
||||
replay.SendTime = sendTime
|
||||
return replay, nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
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: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc add blacklist success return,uid=%s", req.Uid)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
err = im_mysql_model.InsertInToUserBlackList(req.OwnerUid, req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,Failed to add blacklist", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc add blacklist success return,uid=%s", req.Uid)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/content_struct"
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
//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: config.ErrAddFriend.ErrCode, ErrorMsg: config.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: config.ErrAddFriend.ErrCode, ErrorMsg: config.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
|
||||
//Parse token, to find current user information
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, FailedUidList: req.UidList}, nil
|
||||
}
|
||||
|
||||
if !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.Error(req.Token, req.OperationID, "not magager uid", claims.UID)
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: "not authorized"}, FailedUidList: req.UidList}, nil
|
||||
}
|
||||
if _, err = im_mysql_model.FindUserByUID(req.OwnerUid); err != nil {
|
||||
log.Error(req.Token, req.OperationID, "this user not exists,cant not add friend", req.OwnerUid)
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: "this user not exists,cant not add friend"}, FailedUidList: req.UidList}, nil
|
||||
}
|
||||
for _, v := range req.UidList {
|
||||
if _, err = im_mysql_model.FindUserByUID(v); err != nil {
|
||||
resp.CommonResp.ErrorMsg = "some uid establish failed"
|
||||
resp.CommonResp.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.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
||||
}
|
||||
err2 := im_mysql_model.InsertToFriend(v, req.OwnerUid, 1)
|
||||
if err2 != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
||||
}
|
||||
if err1 == nil && err2 == nil {
|
||||
var name, faceUrl string
|
||||
n := content_struct.NotificationContent{1, constant.FriendAcceptTip, ""}
|
||||
r, err := im_mysql_model.FindUserByUID(v)
|
||||
if err != nil {
|
||||
log.ErrorByKv("get info failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
}
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return &resp, nil
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/push/content_struct"
|
||||
"Open_IM/src/push/logic"
|
||||
"Open_IM/src/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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
//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: config.ErrAgreeToAddFriend.ErrCode, ErrorMsg: config.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: config.ErrMysql.ErrCode, ErrorMsg: config.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
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/utils"
|
||||
"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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
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: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc delete friend success return")
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/utils"
|
||||
"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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.GetBlacklistResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.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: config.ErrGetBlackList.ErrCode, ErrorMsg: config.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
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/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 {
|
||||
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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.GetFriendInfoResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.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: config.ErrSearchUserInfo.ErrCode, ErrorMsg: config.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
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/utils"
|
||||
"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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.GetFriendApplyResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.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: config.ErrMysql.ErrCode, ErrorMsg: config.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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.GetFriendApplyResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.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: config.ErrMysql.ErrCode, ErrorMsg: config.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
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/utils"
|
||||
"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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.GetFriendListResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.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: config.ErrSearchUserInfo.ErrCode, ErrorMsg: config.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
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/utils"
|
||||
"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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.IsFriendResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.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
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/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
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/utils"
|
||||
"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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
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: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc remove blacklist success return,userid=%s", req.Uid)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/utils"
|
||||
"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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
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: config.ErrSetFriendComment.ErrCode, ErrorMsg: config.ErrSetFriendComment.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc set friend comment is success return")
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/content_struct"
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type groupServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewGroupServer(port int) *groupServer {
|
||||
return &groupServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
func (s *groupServer) Run() {
|
||||
log.Info("", "", "rpc group init....")
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.InfoByArgs("listen network failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbGroup.RegisterGroupServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("get etcd failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("listen rpc_group error,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "rpc create group init success")
|
||||
}
|
||||
|
||||
func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (*pbGroup.CreateGroupResp, error) {
|
||||
log.InfoByArgs("rpc create group is server,args=%s", req.String())
|
||||
var (
|
||||
groupId string
|
||||
)
|
||||
//Parse token, to find current user information
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.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.Ex)
|
||||
if err != nil {
|
||||
log.ErrorByKv("create group chat failed", req.OperationID, "err=%s", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
isMagagerFlag := 0
|
||||
tokenUid := claims.UID
|
||||
|
||||
if utils.IsContain(tokenUid, config.Config.Manager.AppManagerUid) {
|
||||
isMagagerFlag = 1
|
||||
}
|
||||
|
||||
if isMagagerFlag == 0 {
|
||||
//Add the group owner to the group first, otherwise the group creation will fail
|
||||
us, err := im_mysql_model.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "find userInfo failed", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, claims.UID, us.Name, us.Icon, constant.GroupOwner)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "create group chat failed,err=%s", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err = db.DB.AddGroupMember(groupId, claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "create mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
}
|
||||
|
||||
//Binding group id and member id
|
||||
for _, user := range req.MemberList {
|
||||
us, err := im_mysql_model.FindUserByUID(user.Uid)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "find userInfo failed,uid=%s", user.Uid, err.Error())
|
||||
continue
|
||||
}
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, user.Uid, us.Name, us.Icon, user.SetRole)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("pull %s to group %s failed,err=%s", user.Uid, groupId, err.Error())
|
||||
}
|
||||
err = db.DB.AddGroupMember(groupId, user.Uid)
|
||||
if err != nil {
|
||||
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if isMagagerFlag == 1 {
|
||||
|
||||
//type NotificationContent struct {
|
||||
// IsDisplay int32 `json:"isDisplay"`
|
||||
// DefaultTips string `json:"defaultTips"`
|
||||
// Detail string `json:"detail"`
|
||||
//} n := NotificationContent{
|
||||
// IsDisplay: 1,
|
||||
// DefaultTips: "You have joined the group chat:" + createGroupResp.Data.GroupName,
|
||||
// Detail: createGroupResp.Data.GroupId,
|
||||
// }
|
||||
|
||||
////Push message when create group chat
|
||||
n := content_struct.NotificationContent{1, req.GroupName, groupId}
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: claims.UID,
|
||||
RecvID: groupId,
|
||||
Content: n.ContentToString(),
|
||||
SendTime: utils.GetCurrentTimestampByNano(),
|
||||
MsgFrom: constant.SysMsgType, //Notification message identification
|
||||
ContentType: constant.CreateGroupTip, //Add friend flag
|
||||
SessionType: constant.GroupChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
}
|
||||
|
||||
log.Info(req.Token, req.OperationID, "rpc create group success return")
|
||||
return &pbGroup.CreateGroupResp{GroupID: groupId}, nil
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/proto/group"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) GetGroupApplicationList(_ context.Context, pb *group.GetGroupApplicationListReq) (*group.GetGroupApplicationListResp, error) {
|
||||
log.Info("", "", "rpc GetGroupApplicationList call start..., [pb: %s]", pb.String())
|
||||
|
||||
reply, err := im_mysql_model.GetGroupApplicationList(pb.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList fail [uid: %s] [err: %s]", pb.UID, err.Error())
|
||||
return &group.GetGroupApplicationListResp{ErrCode: 701, ErrMsg: "GetGroupApplicationList failed"}, nil
|
||||
}
|
||||
log.Info("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList")
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
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 := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.GetGroupsInfoResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.Info("", req.OperationID, "args:", req.GroupIDList, claims.UID)
|
||||
groupsInfoList := make([]*pbGroup.GroupInfo, 0)
|
||||
for _, groupID := range req.GroupIDList {
|
||||
groupInfoFromMysql, err := im_mysql_model.FindGroupInfoByGroupId(groupID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "find group info failed,err=%s", err.Error())
|
||||
continue
|
||||
}
|
||||
var groupInfo pbGroup.GroupInfo
|
||||
groupInfo.GroupId = groupID
|
||||
groupInfo.GroupName = groupInfoFromMysql.Name
|
||||
groupInfo.Introduction = groupInfoFromMysql.Introduction
|
||||
groupInfo.Notification = groupInfoFromMysql.Notification
|
||||
groupInfo.FaceUrl = groupInfoFromMysql.FaceUrl
|
||||
groupInfo.OwnerId = im_mysql_model.GetGroupOwnerByGroupId(groupID)
|
||||
groupInfo.MemberCount = uint32(im_mysql_model.GetGroupMemberNumByGroupId(groupID))
|
||||
groupInfo.CreateTime = uint64(groupInfoFromMysql.CreateTime.Unix())
|
||||
|
||||
groupsInfoList = append(groupsInfoList, &groupInfo)
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc get groupsInfo success return")
|
||||
return &pbGroup.GetGroupsInfoResp{Data: groupsInfoList}, nil
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/content_struct"
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
"encoding/json"
|
||||
|
||||
imdb "Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJoinedGroupListReq) (*pbGroup.GetJoinedGroupListResp, error) {
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
||||
|
||||
joinedGroupList, err := imdb.GetJoinedGroupIdListByMemberId(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(claims.UID, req.OperationID, "GetJoinedGroupIdListByMemberId failed, err: ", err.Error())
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrorCode: config.ErrParam.ErrCode, ErrorMsg: config.ErrParam.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var resp pbGroup.GetJoinedGroupListResp
|
||||
|
||||
for _, v := range joinedGroupList {
|
||||
var groupNode pbGroup.GroupInfo
|
||||
num := imdb.GetGroupMemberNumByGroupId(v.GroupId)
|
||||
owner := imdb.GetGroupOwnerByGroupId(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.Name
|
||||
groupNode.Introduction = group.Introduction
|
||||
groupNode.Notification = group.Notification
|
||||
groupNode.OwnerId = owner
|
||||
groupNode.MemberCount = uint32(int32(num))
|
||||
resp.GroupList = append(resp.GroupList, &groupNode)
|
||||
}
|
||||
log.Info(claims.UID, req.OperationID, "member num: ", num, "owner: ", owner)
|
||||
}
|
||||
resp.ErrorCode = 0
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.InviteUserToGroupReq) (*pbGroup.InviteUserToGroupResp, error) {
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
||||
// if !imdb.IsExistGroupMember(req.GroupID, claims.UID) && claims.UID != config.Config.AppManagerUid
|
||||
|
||||
if !imdb.IsExistGroupMember(req.GroupID, claims.UID) && !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.Error(req.Token, req.OperationID, "err= invite user not in group")
|
||||
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrAccess.ErrCode, ErrorMsg: config.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//
|
||||
//from User: invite: applicant
|
||||
//to user: invite: invited
|
||||
//to application
|
||||
var resp pbGroup.InviteUserToGroupResp
|
||||
/*
|
||||
fromUserInfo, err := imdb.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(claims.UID, req.OperationID, "FindUserByUID failed, err: ", err.Error())
|
||||
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrParam.ErrCode, ErrorMsg: config.ErrParam.ErrMsg}, nil
|
||||
}*/
|
||||
|
||||
for _, v := range req.UidList {
|
||||
var resultNode pbGroup.Id2Result
|
||||
resultNode.UId = v
|
||||
resultNode.Result = 0
|
||||
toUserInfo, err := imdb.FindUserByUID(v)
|
||||
if err != nil {
|
||||
log.Error(v, req.OperationID, "FindUserByUID failed, err: ", err.Error())
|
||||
resultNode.Result = -1
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
continue
|
||||
}
|
||||
|
||||
if imdb.IsExistGroupMember(req.GroupID, v) {
|
||||
log.Error(v, req.OperationID, "user has already in group")
|
||||
resultNode.Result = -1
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
continue
|
||||
}
|
||||
|
||||
err = imdb.InsertGroupMember(req.GroupID, toUserInfo.UID, toUserInfo.Name, toUserInfo.Icon, 0)
|
||||
if err != nil {
|
||||
log.Error(v, req.OperationID, "InsertGroupMember failed, ", err.Error(), "params: ",
|
||||
req.GroupID, toUserInfo.UID, toUserInfo.Name, toUserInfo.Icon)
|
||||
resultNode.Result = -1
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
continue
|
||||
}
|
||||
err = db.DB.AddGroupMember(req.GroupID, toUserInfo.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
}
|
||||
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
}
|
||||
resp.ErrorCode = 0
|
||||
resp.ErrorMsg = "ok"
|
||||
|
||||
//if claims.UID == config.Config.AppManagerUid
|
||||
if utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
var iu inviteUserToGroupReq
|
||||
iu.GroupID = req.GroupID
|
||||
iu.OperationID = req.OperationID
|
||||
iu.Reason = req.Reason
|
||||
iu.UidList = req.UidList
|
||||
n := content_struct.NotificationContent{1, req.GroupID, iu.ContentToString()}
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: claims.UID,
|
||||
RecvID: req.GroupID,
|
||||
Content: n.ContentToString(),
|
||||
SendTime: utils.GetCurrentTimestampByNano(),
|
||||
MsgFrom: constant.UserMsgType,
|
||||
ContentType: constant.InviteUserToGroupTip,
|
||||
SessionType: constant.GroupChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
}
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
type inviteUserToGroupReq struct {
|
||||
GroupID string `json:"groupID"`
|
||||
UidList []string `json:"uidList"`
|
||||
Reason string `json:"reason"`
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
func (c *inviteUserToGroupReq) ContentToString() string {
|
||||
data, _ := json.Marshal(c)
|
||||
dataString := string(data)
|
||||
return dataString
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) {
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
if req.Token != config.Config.Secret {
|
||||
return &pbGroup.GetGroupAllMemberResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
}
|
||||
|
||||
var resp pbGroup.GetGroupAllMemberResp
|
||||
resp.ErrorCode = 0
|
||||
memberList, err := imdb.FindGroupMemberListByGroupId(req.GroupID)
|
||||
if err != nil {
|
||||
resp.ErrorCode = config.ErrDb.ErrCode
|
||||
resp.ErrorMsg = err.Error()
|
||||
log.Error(claims.UID, req.OperationID, "FindGroupMemberListByGroupId failed, ", err.Error(), "params: ", req.GroupID)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
for _, v := range memberList {
|
||||
var node pbGroup.GroupMemberFullInfo
|
||||
node.Role = v.AdministratorLevel
|
||||
node.NickName = v.NickName
|
||||
node.UserId = v.Uid
|
||||
node.FaceUrl = v.UserGroupFaceUrl
|
||||
node.JoinTime = uint64(v.JoinTime.Unix())
|
||||
resp.MemberList = append(resp.MemberList, &node)
|
||||
}
|
||||
|
||||
resp.ErrorCode = 0
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGroupMemberListReq) (*pbGroup.GetGroupMemberListResp, error) {
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.GetGroupMemberListResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
// log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
||||
fmt.Println("req: ", req.GroupID)
|
||||
var resp pbGroup.GetGroupMemberListResp
|
||||
resp.ErrorCode = 0
|
||||
memberList, err := imdb.GetGroupMemberByGroupId(req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
if err != nil {
|
||||
resp.ErrorCode = config.ErrDb.ErrCode
|
||||
resp.ErrorMsg = err.Error()
|
||||
log.Error(claims.UID, req.OperationID, "GetGroupMemberByGroupId failed, ", err.Error(), "params: ", req.GroupID, req.Filter, req.NextSeq)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
for _, v := range memberList {
|
||||
var node pbGroup.GroupMemberFullInfo
|
||||
node.Role = v.AdministratorLevel
|
||||
node.NickName = v.NickName
|
||||
node.UserId = v.Uid
|
||||
// node.FaceUrl =
|
||||
node.JoinTime = uint64(v.JoinTime.Unix())
|
||||
resp.MemberList = append(resp.MemberList, &node)
|
||||
}
|
||||
//db operate get db sorted by join time
|
||||
if int32(len(memberList)) < 30 {
|
||||
resp.NextSeq = 0
|
||||
} else {
|
||||
resp.NextSeq = req.NextSeq + int32(len(memberList))
|
||||
}
|
||||
|
||||
resp.ErrorCode = 0
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
type groupMemberFullInfo struct {
|
||||
GroupId string `json:"groupID"`
|
||||
UserId string `json:"userId"`
|
||||
Role int `json:"role"`
|
||||
JoinTime uint64 `json:"joinTime"`
|
||||
NickName string `json:"nickName"`
|
||||
FaceUrl string `json:"faceUrl"`
|
||||
}
|
||||
|
||||
type kickGroupMemberApiReq struct {
|
||||
GroupID string `json:"groupID"`
|
||||
UidListInfo []groupMemberFullInfo `json:"uidListInfo"`
|
||||
Reason string `json:"reason"`
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
func (c *kickGroupMemberApiReq) ContentToString() string {
|
||||
data, _ := json.Marshal(c)
|
||||
dataString := string(data)
|
||||
return dataString
|
||||
}
|
||||
|
||||
func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGroupMemberReq) (*pbGroup.KickGroupMemberResp, error) {
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.KickGroupMemberResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
||||
|
||||
ownerList, err := imdb.GetOwnerManagerByGroupId(req.GroupID)
|
||||
if err != nil {
|
||||
log.Error(claims.UID, req.OperationID, req.GroupID, "GetOwnerManagerByGroupId, ", err.Error())
|
||||
return &pbGroup.KickGroupMemberResp{ErrorCode: config.ErrParam.ErrCode, ErrorMsg: config.ErrParam.ErrMsg}, nil
|
||||
}
|
||||
//op is group owner?
|
||||
var flag = 0
|
||||
for _, v := range ownerList {
|
||||
if v.Uid == claims.UID {
|
||||
flag = 1
|
||||
break
|
||||
}
|
||||
}
|
||||
if flag != 1 {
|
||||
// if claims.UID == config.Config.AppManagerUid {
|
||||
if utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
flag = 1
|
||||
}
|
||||
}
|
||||
|
||||
if flag != 1 {
|
||||
log.Error(claims.UID, req.OperationID, "no access kick")
|
||||
return &pbGroup.KickGroupMemberResp{ErrorCode: config.ErrAccess.ErrCode, ErrorMsg: config.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
if len(req.UidListInfo) == 0 {
|
||||
log.Error(claims.UID, req.OperationID, "kick list 0")
|
||||
return &pbGroup.KickGroupMemberResp{ErrorCode: config.ErrParam.ErrCode, ErrorMsg: config.ErrParam.ErrMsg}, nil
|
||||
}
|
||||
//remove
|
||||
var resp pbGroup.KickGroupMemberResp
|
||||
for _, v := range req.UidListInfo {
|
||||
//owner cant kicked
|
||||
if v.UserId == claims.UID {
|
||||
log.Error(claims.UID, req.OperationID, v.UserId, "cant kick owner")
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: -1})
|
||||
continue
|
||||
}
|
||||
err := imdb.RemoveGroupMember(req.GroupID, v.UserId)
|
||||
if err != nil {
|
||||
log.Error(claims.UID, req.OperationID, v.UserId, req.GroupID, "RemoveGroupMember failed ", err.Error())
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: -1})
|
||||
} else {
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: 0})
|
||||
}
|
||||
|
||||
err = db.DB.DelGroupMember(req.GroupID, v.UserId)
|
||||
if err != nil {
|
||||
log.Error("", "", "delete mongo group member failed, db.DB.DelGroupMember fail [err: %s]", err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
var kq kickGroupMemberApiReq
|
||||
|
||||
kq.GroupID = req.GroupID
|
||||
kq.OperationID = req.OperationID
|
||||
kq.Reason = req.Reason
|
||||
|
||||
var gf groupMemberFullInfo
|
||||
for _, v := range req.UidListInfo {
|
||||
gf.UserId = v.UserId
|
||||
gf.GroupId = req.GroupID
|
||||
kq.UidListInfo = append(kq.UidListInfo, gf)
|
||||
}
|
||||
|
||||
n := content_struct.NotificationContent{1, req.GroupID, kq.ContentToString()}
|
||||
|
||||
if utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.Info("", req.OperationID, claims.UID, req.GroupID)
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: claims.UID,
|
||||
RecvID: req.GroupID,
|
||||
Content: n.ContentToString(),
|
||||
SendTime: utils.GetCurrentTimestampByNano(),
|
||||
MsgFrom: constant.UserMsgType,
|
||||
ContentType: constant.KickGroupMemberTip,
|
||||
SessionType: constant.GroupChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
|
||||
for _, v := range req.UidListInfo {
|
||||
log.Info("", req.OperationID, claims.UID, v.UserId)
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: claims.UID,
|
||||
RecvID: v.UserId,
|
||||
Content: n.ContentToString(),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.UserMsgType,
|
||||
ContentType: constant.KickGroupMemberTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
}
|
||||
}
|
||||
resp.ErrorCode = 0
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetGroupMembersInfoReq) (*pbGroup.GetGroupMembersInfoResp, error) {
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.GetGroupMembersInfoResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.InfoByKv(claims.UID, req.OperationID, "param: ", req.MemberList)
|
||||
var resp pbGroup.GetGroupMembersInfoResp
|
||||
|
||||
for _, v := range req.MemberList {
|
||||
var memberNode pbGroup.GroupMemberFullInfo
|
||||
memberInfo, err := imdb.GetMemberInfoById(req.GroupID, v)
|
||||
memberNode.UserId = v
|
||||
fmt.Println("id : ", memberNode.UserId)
|
||||
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)
|
||||
continue
|
||||
}
|
||||
user, err := imdb.FindUserByUID(v)
|
||||
if err == nil && user != nil {
|
||||
memberNode.FaceUrl = user.Icon
|
||||
memberNode.JoinTime = uint64(memberInfo.JoinTime.Unix())
|
||||
memberNode.UserId = user.UID
|
||||
memberNode.NickName = memberInfo.NickName
|
||||
memberNode.Role = memberInfo.AdministratorLevel
|
||||
}
|
||||
resp.MemberList = append(resp.MemberList, &memberNode)
|
||||
}
|
||||
resp.ErrorCode = 0
|
||||
return &resp, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/db"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/proto/group"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) GroupApplicationResponse(_ context.Context, pb *group.GroupApplicationResponseReq) (*group.GroupApplicationResponseResp, error) {
|
||||
log.Info("", "", "rpc GroupApplicationResponse call start..., [pb: %s]", pb.String())
|
||||
|
||||
reply, err := im_mysql_model.GroupApplicationResponse(pb)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., im_mysql_model.GroupApplicationResponse fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return &group.GroupApplicationResponseResp{ErrCode: 702, ErrMsg: "rpc GroupApplicationResponse failed"}, nil
|
||||
}
|
||||
|
||||
if pb.HandleResult == 1 {
|
||||
if pb.ToUserID == "0" {
|
||||
err = db.DB.AddGroupMember(pb.GroupID, pb.FromUserID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., db.DB.AddGroupMember fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
err = db.DB.AddGroupMember(pb.GroupID, pb.ToUserID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., db.DB.AddGroupMember fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("", "", "rpc GroupApplicationResponse call..., im_mysql_model.GroupApplicationResponse")
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc join group is server,args=%s", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
applicationUserInfo, err := im_mysql_model.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "No this user,err=%s", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrSearchUserInfo.ErrCode, ErrorMsg: config.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
|
||||
_, err = im_mysql_model.FindGroupRequestUserInfoByGroupIDAndUid(req.GroupID, claims.UID)
|
||||
if err == nil {
|
||||
err = im_mysql_model.DelGroupRequest(req.GroupID, claims.UID, "0")
|
||||
}
|
||||
|
||||
log.Info(req.Token, req.OperationID, "args: ", req.GroupID, claims.UID, "0", req.Message, applicationUserInfo.Name, applicationUserInfo.Icon)
|
||||
|
||||
if err = im_mysql_model.InsertIntoGroupRequest(req.GroupID, claims.UID, "0", req.Message, applicationUserInfo.Name, applicationUserInfo.Icon); err != nil {
|
||||
log.Error(req.Token, req.OperationID, "Insert into group request failed,er=%s", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrJoinGroupApplication.ErrCode, ErrorMsg: config.ErrJoinGroupApplication.ErrMsg}, nil
|
||||
}
|
||||
////Find the the group owner
|
||||
//groupCreatorInfo, err := im_mysql_model.FindGroupMemberListByGroupIdAndFilterInfo(req.GroupID, constant.GroupCreator)
|
||||
//if err != nil {
|
||||
// log.Error(req.Token, req.OperationID, "find group creator failed", err.Error())
|
||||
//} else {
|
||||
// //Push message when join group chat
|
||||
// logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
// SendID: claims.UID,
|
||||
// RecvID: groupCreatorInfo[0].Uid,
|
||||
// Content: content_struct.NewContentStructString(0, "", req.String()),
|
||||
// SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
// MsgFrom: constant.SysMsgType,
|
||||
// ContentType: constant.JoinGroupTip,
|
||||
// SessionType: constant.SingleChatType,
|
||||
// OperationID: req.OperationID,
|
||||
// })
|
||||
//}
|
||||
|
||||
log.Info(req.Token, req.OperationID, "rpc join group success return")
|
||||
return &pbGroup.CommonResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) (*pbGroup.CommonResp, error) {
|
||||
log.InfoByArgs("rpc quit group is server,args:", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.InfoByKv("args:", req.OperationID, req.GetGroupID(), claims.UID)
|
||||
//Check to see whether there is a user in the group.
|
||||
_, err = im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "no such group or you are not in the group,err=%s", err.Error(), req.OperationID, req.GroupID, claims.UID)
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrQuitGroup.ErrCode, ErrorMsg: config.ErrQuitGroup.ErrMsg}, nil
|
||||
}
|
||||
//After the user's verification is successful, user will quit the group chat.
|
||||
err = im_mysql_model.DeleteGroupMemberByGroupIdAndUserId(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("this user exit the group failed,err=%s", err.Error(), req.OperationID, req.GroupID, claims.UID)
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrQuitGroup.ErrCode, ErrorMsg: config.ErrQuitGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err = db.DB.DelGroupMember(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "delete mongo group member failed, db.DB.DelGroupMember fail [err: %s]", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrQuitGroup.ErrCode, ErrorMsg: config.ErrQuitGroup.ErrMsg}, nil
|
||||
}
|
||||
////Push message when quit group chat
|
||||
//jsonInfo, _ := json.Marshal(req)
|
||||
//logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
// SendID: claims.UID,
|
||||
// RecvID: req.GroupID,
|
||||
// Content: string(jsonInfo),
|
||||
// SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
// MsgFrom: constant.SysMsgType,
|
||||
// ContentType: constant.QuitGroupTip,
|
||||
// SessionType: constant.GroupChatType,
|
||||
// OperationID: req.OperationID,
|
||||
//})
|
||||
log.Info(req.Token, req.OperationID, "rpc quit group is success return")
|
||||
|
||||
return &pbGroup.CommonResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc set group info is server,args=%s", req.String())
|
||||
|
||||
//Parse token, to find current user information
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
groupUserInfo, err := im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "your are not in the group,can not change this group info,err=%s", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrSetGroupInfo.ErrCode, ErrorMsg: config.ErrSetGroupInfo.ErrMsg}, nil
|
||||
}
|
||||
if groupUserInfo.AdministratorLevel == constant.OrdinaryMember {
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrSetGroupInfo.ErrCode, ErrorMsg: config.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
//only administrators can set group information
|
||||
if err = im_mysql_model.SetGroupInfo(req.GroupID, req.GroupName, req.Introduction, req.Notification, req.FaceUrl, ""); err != nil {
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrSetGroupInfo.ErrCode, ErrorMsg: config.ErrSetGroupInfo.ErrMsg}, nil
|
||||
}
|
||||
////Push message when set group info
|
||||
//jsonInfo, _ := json.Marshal(req)
|
||||
//logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
// SendID: claims.UID,
|
||||
// RecvID: req.GroupID,
|
||||
// Content: string(jsonInfo),
|
||||
// SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
// MsgFrom: constant.SysMsgType,
|
||||
// ContentType: constant.SetGroupInfoTip,
|
||||
// SessionType: constant.GroupChatType,
|
||||
// OperationID: req.OperationID,
|
||||
//})
|
||||
return &pbGroup.CommonResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/proto/group"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) TransferGroupOwner(_ context.Context, pb *group.TransferGroupOwnerReq) (*group.TransferGroupOwnerResp, error) {
|
||||
log.Info("", "", "rpc TransferGroupOwner call start..., [pb: %s]", pb.String())
|
||||
|
||||
reply, err := im_mysql_model.TransferGroupOwner(pb)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc TransferGroupOwner call..., im_mysql_model.TransferGroupOwner fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
log.Info("", "", "rpc TransferGroupOwner call..., im_mysql_model.TransferGroupOwner")
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbUser "Open_IM/src/proto/user"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type userServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewUserServer(port int) *userServer {
|
||||
return &userServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *userServer) Run() {
|
||||
log.Info("", "", "rpc user init....")
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.InfoByArgs("listen network failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbUser.RegisterUserServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("register rpc token to etcd failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("listen token failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "rpc token init success")
|
||||
}
|
||||
|
||||
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
log.InfoByKv("rpc get_user_info is server", req.OperationID)
|
||||
|
||||
var userInfoList []*pbUser.UserInfo
|
||||
//Obtain user information according to userID
|
||||
if len(req.UserIDList) > 0 {
|
||||
for _, userID := range req.UserIDList {
|
||||
var userInfo pbUser.UserInfo
|
||||
user, err := im_mysql_model.FindUserByUID(userID)
|
||||
if err != nil {
|
||||
log.ErrorByKv("search userinfo failed", req.OperationID, "userID", userID, "err=%s", err.Error())
|
||||
continue
|
||||
}
|
||||
userInfo.Uid = user.UID
|
||||
userInfo.Icon = user.Icon
|
||||
userInfo.Name = user.Name
|
||||
userInfo.Gender = user.Gender
|
||||
userInfo.Mobile = user.Mobile
|
||||
userInfo.Birth = user.Birth
|
||||
userInfo.Email = user.Email
|
||||
userInfo.Ex = user.Ex
|
||||
userInfoList = append(userInfoList, &userInfo)
|
||||
}
|
||||
} else {
|
||||
return &pbUser.GetUserInfoResp{ErrorCode: 999, ErrorMsg: "uidList is nil"}, nil
|
||||
}
|
||||
log.InfoByKv("rpc get userInfo return success", req.OperationID, "token", req.Token)
|
||||
return &pbUser.GetUserInfoResp{
|
||||
ErrorCode: 0,
|
||||
ErrorMsg: "",
|
||||
Data: userInfoList,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package internal_service
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbUser "Open_IM/src/proto/user"
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetUserInfoClient(req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
RpcResp, err := client.GetUserInfo(context.Background(), req)
|
||||
return RpcResp, err
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
** description("").
|
||||
** copyright('open-im,www.open-im.io').
|
||||
** author("fg,Gordon@tuoyun.net").
|
||||
** time(2021/9/15 10:28).
|
||||
*/
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbUser "Open_IM/src/proto/user"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
|
||||
log.InfoByKv("rpc DeleteUsers arrived server", req.OperationID, "args", req.String())
|
||||
var resp pbUser.DeleteUsersResp
|
||||
c, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.ErrorByKv("parse token failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: err.Error()}, FailedUidList: req.DeleteUidList}, nil
|
||||
}
|
||||
if !utils.IsContain(c.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.ErrorByKv(" Authentication failed", req.OperationID, "args", c)
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrorCode: 401, ErrorMsg: "not authorized"}, FailedUidList: req.DeleteUidList}, nil
|
||||
}
|
||||
for _, uid := range req.DeleteUidList {
|
||||
err = im_mysql_model.UserDelete(uid)
|
||||
if err != nil {
|
||||
resp.CommonResp.ErrorCode = 201
|
||||
resp.CommonResp.ErrorMsg = "some uid deleted failed"
|
||||
resp.FailedUidList = append(resp.FailedUidList, uid)
|
||||
}
|
||||
}
|
||||
return &resp, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllUsersUid(_ context.Context, req *pbUser.GetAllUsersUidReq) (*pbUser.GetAllUsersUidResp, error) {
|
||||
log.InfoByKv("rpc GetAllUsersUid arrived server", req.OperationID, "args", req.String())
|
||||
c, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.InfoByKv("parse token failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
}
|
||||
if !utils.IsContain(c.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.ErrorByKv(" Authentication failed", req.OperationID, "args", c)
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: 401, ErrorMsg: "not authorized"}}, nil
|
||||
}
|
||||
uidList, err := im_mysql_model.SelectAllUID()
|
||||
if err != nil {
|
||||
log.ErrorByKv("db get failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
} else {
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: 0, ErrorMsg: ""}, UidList: uidList}, nil
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
pbUser "Open_IM/src/proto/user"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserInfoReq) (*pbUser.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc modify user is server,args=%s", req.String())
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbUser.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: err.Error()}, nil
|
||||
}
|
||||
|
||||
ownerUid := ""
|
||||
//if claims.UID == config.Config.AppManagerUid {
|
||||
if utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
ownerUid = req.Uid
|
||||
} else {
|
||||
ownerUid = claims.UID
|
||||
}
|
||||
|
||||
err = im_mysql_model.UpDateUserInfo(ownerUid, req.Name, req.Icon, req.Mobile, req.Birth, req.Email, req.Ex, req.Gender)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "update user some attribute failed,err=%s", err.Error())
|
||||
return &pbUser.CommonResp{ErrorCode: config.ErrModifyUserInfo.ErrCode, ErrorMsg: config.ErrModifyUserInfo.ErrMsg}, nil
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
newReq := &pbFriend.GetFriendListReq{
|
||||
OperationID: req.OperationID,
|
||||
Token: req.Token,
|
||||
}
|
||||
|
||||
RpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get friend list rpc server failed", err)
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
}
|
||||
if RpcResp.ErrorCode != 0 {
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
|
||||
}
|
||||
self, err := im_mysql_model.FindUserByUID(ownerUid)
|
||||
if err != nil {
|
||||
log.ErrorByKv("get self info failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
}
|
||||
var name, faceUrl string
|
||||
if self != nil {
|
||||
name, faceUrl = self.Name, self.Icon
|
||||
}
|
||||
for _, v := range RpcResp.Data {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: ownerUid,
|
||||
RecvID: v.Uid,
|
||||
SenderNickName: name,
|
||||
SenderFaceURL: faceUrl,
|
||||
Content: ownerUid + "'s info has changed",
|
||||
SendTime: utils.GetCurrentTimestampByNano(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.SetSelfInfoTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
Token: req.Token,
|
||||
})
|
||||
|
||||
}
|
||||
return &pbUser.CommonResp{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user