mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-01 07:35:58 +08:00
Merge branch 'superGroup' of github.com:OpenIMSDK/Open-IM-Server into superGroup
This commit is contained in:
@@ -6,18 +6,25 @@ import (
|
||||
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
)
|
||||
|
||||
func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *pbMsg.GetMaxAndMinSeqReq) (*pbMsg.GetMaxAndMinSeqResp, error) {
|
||||
func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *open_im_sdk.GetMaxAndMinSeqReq) (*open_im_sdk.GetMaxAndMinSeqResp, error) {
|
||||
log.NewInfo(in.OperationID, "rpc getMaxAndMinSeq is arriving", in.String())
|
||||
resp := new(open_im_sdk.GetMaxAndMinSeqResp)
|
||||
m := make(map[string]*open_im_sdk.MaxAndMinSeq)
|
||||
//seq, err := model.GetBiggestSeqFromReceive(in.UserID)
|
||||
maxSeq, err1 := commonDB.DB.GetUserMaxSeq(in.UserID)
|
||||
minSeq, err2 := commonDB.DB.GetUserMinSeq(in.UserID)
|
||||
resp := new(pbMsg.GetMaxAndMinSeqResp)
|
||||
if err1 == nil {
|
||||
resp.MaxSeq = uint32(maxSeq)
|
||||
for _, v := range in.GroupIDList {
|
||||
x := new(open_im_sdk.MaxAndMinSeq)
|
||||
maxSeq, _ := commonDB.DB.GetUserMaxSeq(v)
|
||||
x.MaxSeq = uint32(maxSeq)
|
||||
m[v] = x
|
||||
}
|
||||
resp.GroupMaxAndMinSeq = m
|
||||
} else if err1 == redis.ErrNil {
|
||||
resp.MaxSeq = 0
|
||||
} else {
|
||||
@@ -39,6 +46,7 @@ func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *pbMsg.GetMaxAndMinSeq
|
||||
func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *open_im_sdk.PullMessageBySeqListReq) (*open_im_sdk.PullMessageBySeqListResp, error) {
|
||||
log.NewInfo(in.OperationID, "rpc PullMessageBySeqList is arriving", in.String())
|
||||
resp := new(open_im_sdk.PullMessageBySeqListResp)
|
||||
m := make(map[string]*open_im_sdk.MsgDataList)
|
||||
//msgList, err := commonDB.DB.GetMsgBySeqList(in.UserID, in.SeqList, in.OperationID)
|
||||
redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(in.UserID, in.SeqList, in.OperationID)
|
||||
if err != nil {
|
||||
@@ -60,6 +68,32 @@ func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *open_im_sdk.Pull
|
||||
} else {
|
||||
resp.List = redisMsgList
|
||||
}
|
||||
for k, v := range in.GroupSeqList {
|
||||
x := new(open_im_sdk.MsgDataList)
|
||||
redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(k, v.SeqList, in.OperationID)
|
||||
if err != nil {
|
||||
if err != redis.ErrNil {
|
||||
log.Error(in.OperationID, "get message from redis exception", err.Error(), failedSeqList)
|
||||
} else {
|
||||
log.Debug(in.OperationID, "get message from redis is nil", failedSeqList)
|
||||
}
|
||||
msgList, err1 := commonDB.DB.GetMsgBySeqListMongo2(k, failedSeqList, in.OperationID)
|
||||
if err1 != nil {
|
||||
log.Error(in.OperationID, "PullMessageBySeqList data error", in.String(), err.Error())
|
||||
resp.ErrCode = 201
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
} else {
|
||||
redisMsgList = append(redisMsgList, msgList...)
|
||||
x.MsgDataList = redisMsgList
|
||||
m[k] = x
|
||||
}
|
||||
} else {
|
||||
x.MsgDataList = redisMsgList
|
||||
m[k] = x
|
||||
}
|
||||
}
|
||||
resp.GroupMsgDataList = m
|
||||
//respSingleMsgFormat = singleMsgHandleByUser(SingleMsgFormat, in.UserID)
|
||||
//respGroupMsgFormat = groupMsgHandleByUser(GroupMsgFormat)
|
||||
return resp, nil
|
||||
|
||||
@@ -50,46 +50,49 @@ type MsgCallBackResp struct {
|
||||
}
|
||||
|
||||
func userRelationshipVerification(data *pbChat.SendMsgReq) (bool, int32, string) {
|
||||
if data.MsgData.SessionType == constant.GroupChatType {
|
||||
return true, 0, ""
|
||||
}
|
||||
log.NewDebug(data.OperationID, config.Config.MessageVerify.FriendVerify)
|
||||
reqGetBlackIDListFromCache := &cacheRpc.GetBlackIDListFromCacheReq{UserID: data.MsgData.RecvID, OperationID: data.OperationID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
cacheClient := cacheRpc.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.GetBlackIDListFromCache(context.Background(), reqGetBlackIDListFromCache)
|
||||
if err != nil {
|
||||
log.NewError(data.OperationID, "GetBlackIDListFromCache rpc call failed ", err.Error())
|
||||
} else {
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(data.OperationID, "GetBlackIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
} else {
|
||||
if utils.IsContain(data.MsgData.SendID, cacheResp.UserIDList) {
|
||||
return false, 600, "in black list"
|
||||
}
|
||||
}
|
||||
}
|
||||
log.NewDebug(data.OperationID, config.Config.MessageVerify.FriendVerify)
|
||||
if config.Config.MessageVerify.FriendVerify {
|
||||
reqGetFriendIDListFromCache := &cacheRpc.GetFriendIDListFromCacheReq{UserID: data.MsgData.RecvID, OperationID: data.OperationID}
|
||||
if data.MsgData.SessionType == constant.SingleChatType {
|
||||
log.NewDebug(data.OperationID, config.Config.MessageVerify.FriendVerify)
|
||||
reqGetBlackIDListFromCache := &cacheRpc.GetBlackIDListFromCacheReq{UserID: data.MsgData.RecvID, OperationID: data.OperationID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
cacheClient := cacheRpc.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.GetFriendIDListFromCache(context.Background(), reqGetFriendIDListFromCache)
|
||||
cacheResp, err := cacheClient.GetBlackIDListFromCache(context.Background(), reqGetBlackIDListFromCache)
|
||||
if err != nil {
|
||||
log.NewError(data.OperationID, "GetFriendIDListFromCache rpc call failed ", err.Error())
|
||||
log.NewError(data.OperationID, "GetBlackIDListFromCache rpc call failed ", err.Error())
|
||||
} else {
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(data.OperationID, "GetFriendIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
log.NewError(data.OperationID, "GetBlackIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
} else {
|
||||
if !utils.IsContain(data.MsgData.SendID, cacheResp.UserIDList) {
|
||||
return false, 601, "not friend"
|
||||
if utils.IsContain(data.MsgData.SendID, cacheResp.UserIDList) {
|
||||
return false, 600, "in black list"
|
||||
}
|
||||
}
|
||||
}
|
||||
return true, 0, ""
|
||||
log.NewDebug(data.OperationID, config.Config.MessageVerify.FriendVerify)
|
||||
if config.Config.MessageVerify.FriendVerify {
|
||||
reqGetFriendIDListFromCache := &cacheRpc.GetFriendIDListFromCacheReq{UserID: data.MsgData.RecvID, OperationID: data.OperationID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
cacheClient := cacheRpc.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.GetFriendIDListFromCache(context.Background(), reqGetFriendIDListFromCache)
|
||||
if err != nil {
|
||||
log.NewError(data.OperationID, "GetFriendIDListFromCache rpc call failed ", err.Error())
|
||||
} else {
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(data.OperationID, "GetFriendIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
} else {
|
||||
if !utils.IsContain(data.MsgData.SendID, cacheResp.UserIDList) {
|
||||
return false, 601, "not friend"
|
||||
}
|
||||
}
|
||||
}
|
||||
return true, 0, ""
|
||||
} else {
|
||||
return true, 0, ""
|
||||
}
|
||||
|
||||
} else {
|
||||
return true, 0, ""
|
||||
}
|
||||
|
||||
}
|
||||
func (rpc *rpcChat) encapsulateMsgData(msg *sdk_ws.MsgData) {
|
||||
msg.ServerMsgID = GetMsgID(msg.SendID)
|
||||
@@ -368,6 +371,34 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
||||
|
||||
log.Debug(pb.OperationID, "send msg cost time ", db.GetCurrentTimestampByMill()-newTime, pb.MsgData.ClientMsgID)
|
||||
return returnMsg(&replay, pb, 0, "", msgToMQSingle.MsgData.ServerMsgID, msgToMQSingle.MsgData.SendTime)
|
||||
case constant.SuperGroupChatType:
|
||||
// callback
|
||||
callbackResp := callbackBeforeSendSingleMsg(pb)
|
||||
if callbackResp.ErrCode != 0 {
|
||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSuperGroupMsg resp: ", callbackResp)
|
||||
}
|
||||
if callbackResp.ActionCode != constant.ActionAllow {
|
||||
if callbackResp.ErrCode == 0 {
|
||||
callbackResp.ErrCode = 201
|
||||
}
|
||||
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSuperGroupMsg result", "end rpc and return", callbackResp)
|
||||
return returnMsg(&replay, pb, int32(callbackResp.ErrCode), callbackResp.ErrMsg, "", 0)
|
||||
}
|
||||
msgToMQSingle.MsgData = pb.MsgData
|
||||
log.NewInfo(msgToMQSingle.OperationID, msgToMQSingle)
|
||||
err1 := rpc.sendMsgToKafka(&msgToMQSingle, msgToMQSingle.MsgData.GroupID, constant.OnlineStatus)
|
||||
if err1 != nil {
|
||||
log.NewError(msgToMQSingle.OperationID, "kafka send msg err:RecvID", msgToMQSingle.MsgData.RecvID, msgToMQSingle.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
|
||||
// callback
|
||||
callbackResp = callbackAfterSendSingleMsg(pb)
|
||||
if callbackResp.ErrCode != 0 {
|
||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackAfterSendSuperGroupMsg resp: ", callbackResp)
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", msgToMQSingle.MsgData.ServerMsgID, msgToMQSingle.MsgData.SendTime)
|
||||
|
||||
default:
|
||||
return returnMsg(&replay, pb, 203, "unknown sessionType", "", 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user