mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-05 01:25:58 +08:00
callback update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
@@ -17,6 +18,40 @@ func (rpc *rpcChat) SetMessageReactionExtensions(ctx context.Context, req *msg.S
|
||||
var rResp msg.SetMessageReactionExtensionsResp
|
||||
rResp.ClientMsgID = req.ClientMsgID
|
||||
rResp.MsgFirstModifyTime = req.MsgFirstModifyTime
|
||||
callbackResp := callbackSetMessageReactionExtensions(req)
|
||||
if callbackResp.ActionCode != constant.ActionAllow || callbackResp.ErrCode != 0 {
|
||||
rResp.ErrCode = int32(callbackResp.ErrCode)
|
||||
rResp.ErrMsg = callbackResp.ErrMsg
|
||||
for _, value := range req.ReactionExtensionList {
|
||||
temp := new(msg.KeyValueResp)
|
||||
temp.KeyValue = value
|
||||
temp.ErrMsg = callbackResp.ErrMsg
|
||||
temp.ErrCode = 100
|
||||
rResp.Result = append(rResp.Result, temp)
|
||||
}
|
||||
return &rResp, nil
|
||||
}
|
||||
//if ExternalExtension
|
||||
if req.IsExternalExtensions {
|
||||
var isHistory bool
|
||||
if req.IsReact {
|
||||
isHistory = false
|
||||
} else {
|
||||
isHistory = true
|
||||
}
|
||||
rResp.MsgFirstModifyTime = callbackResp.MsgFirstModifyTime
|
||||
rResp.Result = callbackResp.ResultReactionExtensionList
|
||||
ExtendMessageUpdatedNotification(req.OperationID, req.OpUserID, req.SourceID, req.SessionType, req, &rResp, isHistory, false)
|
||||
return &rResp, nil
|
||||
}
|
||||
for _, v := range callbackResp.ResultReactionExtensionList {
|
||||
if v.ErrCode == 0 {
|
||||
req.ReactionExtensionList[v.KeyValue.TypeKey] = v.KeyValue
|
||||
} else {
|
||||
delete(req.ReactionExtensionList, v.KeyValue.TypeKey)
|
||||
rResp.Result = append(rResp.Result, v)
|
||||
}
|
||||
}
|
||||
isExists, err := db.DB.JudgeMessageReactionEXISTS(req.ClientMsgID, req.SessionType)
|
||||
if err != nil {
|
||||
rResp.ErrCode = 100
|
||||
@@ -243,6 +278,38 @@ func (rpc *rpcChat) AddMessageReactionExtensions(ctx context.Context, req *msg.M
|
||||
func (rpc *rpcChat) DeleteMessageReactionExtensions(ctx context.Context, req *msg.DeleteMessageListReactionExtensionsReq) (resp *msg.DeleteMessageListReactionExtensionsResp, err error) {
|
||||
log.Debug(req.OperationID, utils.GetSelfFuncName(), "rpc args is:", req.String())
|
||||
var rResp msg.DeleteMessageListReactionExtensionsResp
|
||||
callbackResp := callbackDeleteMessageReactionExtensions(req)
|
||||
if callbackResp.ActionCode != constant.ActionAllow || callbackResp.ErrCode != 0 {
|
||||
rResp.ErrCode = int32(callbackResp.ErrCode)
|
||||
rResp.ErrMsg = callbackResp.ErrMsg
|
||||
for _, value := range req.ReactionExtensionList {
|
||||
temp := new(msg.KeyValueResp)
|
||||
temp.KeyValue = value
|
||||
temp.ErrMsg = callbackResp.ErrMsg
|
||||
temp.ErrCode = 100
|
||||
rResp.Result = append(rResp.Result, temp)
|
||||
}
|
||||
return &rResp, nil
|
||||
}
|
||||
//if ExternalExtension
|
||||
if req.IsExternalExtensions {
|
||||
rResp.Result = callbackResp.ResultReactionExtensionList
|
||||
ExtendMessageDeleteNotification(req.OperationID, req.OpUserID, req.SourceID, req.SessionType, req, &rResp, false, false)
|
||||
return &rResp, nil
|
||||
|
||||
}
|
||||
for _, v := range callbackResp.ResultReactionExtensionList {
|
||||
if v.ErrCode != 0 {
|
||||
func(req *[]*server_api_params.KeyValue, typeKey string) {
|
||||
for i := 0; i < len(*req); i++ {
|
||||
if (*req)[i].TypeKey == typeKey {
|
||||
*req = append((*req)[:i], (*req)[i+1:]...)
|
||||
}
|
||||
}
|
||||
}(&req.ReactionExtensionList, v.KeyValue.TypeKey)
|
||||
rResp.Result = append(rResp.Result, v)
|
||||
}
|
||||
}
|
||||
isExists, err := db.DB.JudgeMessageReactionEXISTS(req.ClientMsgID, req.SessionType)
|
||||
if err != nil {
|
||||
rResp.ErrCode = 100
|
||||
|
||||
@@ -25,6 +25,10 @@ func ExtendMessageUpdatedNotification(operationID, sendID string, sourceID strin
|
||||
keyMap[valueResp.KeyValue.TypeKey] = valueResp.KeyValue
|
||||
}
|
||||
}
|
||||
if len(keyMap) == 0 {
|
||||
log.NewWarn(operationID, "all key set failed can not send notification", *req)
|
||||
return
|
||||
}
|
||||
m.SuccessReactionExtensionList = keyMap
|
||||
m.ClientMsgID = req.ClientMsgID
|
||||
m.IsReact = resp.IsReact
|
||||
@@ -44,6 +48,10 @@ func ExtendMessageDeleteNotification(operationID, sendID string, sourceID string
|
||||
keyMap[valueResp.KeyValue.TypeKey] = valueResp.KeyValue
|
||||
}
|
||||
}
|
||||
if len(keyMap) == 0 {
|
||||
log.NewWarn(operationID, "all key set failed can not send notification", *req)
|
||||
return
|
||||
}
|
||||
m.SuccessReactionExtensionList = keyMap
|
||||
m.ClientMsgID = req.ClientMsgID
|
||||
m.MsgFirstModifyTime = req.MsgFirstModifyTime
|
||||
|
||||
@@ -2,6 +2,7 @@ package msg
|
||||
|
||||
import (
|
||||
cbApi "Open_IM/pkg/call_back_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
@@ -10,58 +11,50 @@ import (
|
||||
http2 "net/http"
|
||||
)
|
||||
|
||||
func callbackSetMessageReactionExtensions(req *msg.SetMessageReactionExtensionsReq) cbApi.CommonCallbackResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: req.OperationID}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), req.String())
|
||||
|
||||
}
|
||||
|
||||
func callbackDeleteMessageReactionExtensions(req *msg.DeleteMessageListReactionExtensionsReq) {
|
||||
|
||||
}
|
||||
func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: msg.OperationID}
|
||||
if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable {
|
||||
return callbackResp
|
||||
func callbackSetMessageReactionExtensions(setReq *msg.SetMessageReactionExtensionsReq) *cbApi.CallbackBeforeSetMessageReactionExtResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: setReq.OperationID}
|
||||
log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), setReq.String())
|
||||
req := cbApi.CallbackBeforeSetMessageReactionExtReq{
|
||||
OperationID: setReq.OperationID,
|
||||
CallbackCommand: constant.CallbackBeforeSetMessageReactionExtensionCommand,
|
||||
SourceID: setReq.SourceID,
|
||||
OpUserID: setReq.OpUserID,
|
||||
SessionType: setReq.SessionType,
|
||||
ReactionExtensionList: setReq.ReactionExtensionList,
|
||||
ClientMsgID: setReq.ClientMsgID,
|
||||
IsReact: setReq.IsReact,
|
||||
IsExternalExtensions: setReq.IsExternalExtensions,
|
||||
MsgFirstModifyTime: setReq.MsgFirstModifyTime,
|
||||
}
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||
commonCallbackReq.CallbackCommand = constant.CallbackAfterSendGroupMsgCommand
|
||||
req := cbApi.CallbackAfterSendGroupMsgReq{
|
||||
CommonCallbackReq: commonCallbackReq,
|
||||
GroupID: msg.MsgData.GroupID,
|
||||
}
|
||||
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: &callbackResp}
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackAfterSendGroupMsgCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
|
||||
resp := &cbApi.CallbackBeforeSetMessageReactionExtResp{CommonCallbackResp: &callbackResp}
|
||||
defer log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSetMessageReactionExtensionCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
return callbackResp
|
||||
}
|
||||
return callbackResp
|
||||
}
|
||||
func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp {
|
||||
return resp
|
||||
|
||||
commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendSingleMsgCommand
|
||||
req := cbApi.CallbackBeforeSendSingleMsgReq{
|
||||
CommonCallbackReq: commonCallbackReq,
|
||||
RecvID: msg.MsgData.RecvID,
|
||||
}
|
||||
|
||||
func callbackDeleteMessageReactionExtensions(setReq *msg.DeleteMessageListReactionExtensionsReq) *cbApi.CallbackDeleteMessageReactionExtResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: setReq.OperationID}
|
||||
log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), setReq.String())
|
||||
req := cbApi.CallbackDeleteMessageReactionExtReq{
|
||||
OperationID: setReq.OperationID,
|
||||
CallbackCommand: constant.CallbackBeforeDeleteMessageReactionExtensionsCommand,
|
||||
SourceID: setReq.SourceID,
|
||||
OpUserID: setReq.OpUserID,
|
||||
SessionType: setReq.SessionType,
|
||||
ReactionExtensionList: setReq.ReactionExtensionList,
|
||||
ClientMsgID: setReq.ClientMsgID,
|
||||
IsExternalExtensions: setReq.IsExternalExtensions,
|
||||
MsgFirstModifyTime: setReq.MsgFirstModifyTime,
|
||||
}
|
||||
resp := &cbApi.CallbackBeforeSendSingleMsgResp{
|
||||
CommonCallbackResp: &callbackResp,
|
||||
}
|
||||
//utils.CopyStructFields(req, msg.MsgData)
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSendSingleMsgCommand, req, resp, config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackTimeOut); err != nil {
|
||||
resp := &cbApi.CallbackDeleteMessageReactionExtResp{CommonCallbackResp: &callbackResp}
|
||||
defer log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeDeleteMessageReactionExtensionsCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
if !config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackFailedContinue {
|
||||
callbackResp.ActionCode = constant.ActionForbidden
|
||||
return callbackResp
|
||||
} else {
|
||||
callbackResp.ActionCode = constant.ActionAllow
|
||||
return callbackResp
|
||||
}
|
||||
}
|
||||
return callbackResp
|
||||
return resp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user