From c6ade8d9bcaed4e1f86f13ffaeac9fcebedfa590 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Wed, 8 Dec 2021 18:15:14 +0800 Subject: [PATCH] rpc protocol update --- internal/api/chat/send_msg.go | 4 ++-- internal/api/manage/management_chat.go | 2 +- internal/push/logic/push_to_client.go | 6 ++---- internal/rpc/chat/send_msg.go | 8 ++------ pkg/utils/map.go | 6 +++--- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/internal/api/chat/send_msg.go b/internal/api/chat/send_msg.go index 4d53bf769..2c4eee371 100644 --- a/internal/api/chat/send_msg.go +++ b/internal/api/chat/send_msg.go @@ -27,7 +27,7 @@ type paramsUserSendMsg struct { RecvID string `json:"recvID" binding:"required"` ForceList []string `json:"forceList"` Content string `json:"content" binding:"required"` - Options map[string]interface{} `json:"options" ` + Options map[string]int32 `json:"options" ` ClientMsgID string `json:"clientMsgID" binding:"required"` OffLineInfo map[string]interface{} `json:"offlineInfo" ` Ex map[string]interface{} `json:"ext"` @@ -49,7 +49,7 @@ func newUserSendMsgReq(token string, params *paramsUserSendMsg) *pbChat.UserSend RecvID: params.Data.RecvID, ForceList: params.Data.ForceList, Content: params.Data.Content, - Options: utils.MapToJsonString(params.Data.Options), + Options: params.Data.Options, ClientMsgID: params.Data.ClientMsgID, OffLineInfo: utils.MapToJsonString(params.Data.OffLineInfo), Ex: utils.MapToJsonString(params.Data.Ex), diff --git a/internal/api/manage/management_chat.go b/internal/api/manage/management_chat.go index ba056eba1..4cb8f6364 100644 --- a/internal/api/manage/management_chat.go +++ b/internal/api/manage/management_chat.go @@ -72,7 +72,7 @@ func newUserSendMsgReq(params *paramsManagementSendMsg) *pbChat.UserSendMsgReq { ForceList: params.ForceList, Content: newContent, ClientMsgID: utils.GetMsgID(params.SendID), - Options: utils.MapIntToJsonString(options), + Options: options, } return &pbData } diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index 390ba42c5..7051360f3 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -34,11 +34,9 @@ type AtContent struct { IsAtSelf bool `json:"isAtSelf"` } -func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) { +func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo string, Options map[string]int32) { var wsResult []*pbRelay.SingleMsgToUser - MOptions := utils.JsonStringToMap(Options) //Control whether to push message to sender's other terminal - //isSenderSync := utils.GetSwitchFromOptions(MOptions, "senderSync") - isOfflinePush := utils.GetSwitchFromOptions(MOptions, "offlinePush") + isOfflinePush := utils.GetSwitchFromOptions(Options, "offlinePush") log.InfoByKv("Get chat from msg_transfer And push chat", sendPbData.OperationID, "PushData", sendPbData) grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName) //Online push message diff --git a/internal/rpc/chat/send_msg.go b/internal/rpc/chat/send_msg.go index 42d83e1a7..d81e9d580 100644 --- a/internal/rpc/chat/send_msg.go +++ b/internal/rpc/chat/send_msg.go @@ -71,8 +71,7 @@ func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (* } else { pbData.SendTime = pb.SendTime } - Options := utils.JsonStringToMap(pbData.Options) - isHistory := utils.GetSwitchFromOptions(Options, "history") + isHistory := utils.GetSwitchFromOptions(pbData.Options, "history") mReq := MsgCallBackReq{ SendID: pb.SendID, RecvID: pb.RecvID, @@ -224,10 +223,7 @@ func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType i case constant.NotReceiveMessage: return false case constant.ReceiveNotNotifyMessage: - m := utils.JsonStringToMap(msg.Options) - utils.SetSwitchFromOptions(m, "offlinePush", 0) - s := utils.MapToJsonString(m) - msg.OfflineInfo = s + utils.SetSwitchFromOptions(msg.Options, "offlinePush", 0) return true } diff --git a/pkg/utils/map.go b/pkg/utils/map.go index f2c2d07b5..fec4da23e 100644 --- a/pkg/utils/map.go +++ b/pkg/utils/map.go @@ -115,12 +115,12 @@ func JsonStringToMap(str string) (tempMap map[string]interface{}) { _ = json.Unmarshal([]byte(str), &tempMap) return tempMap } -func GetSwitchFromOptions(Options map[string]interface{}, key string) (result bool) { - if flag, ok := Options[key]; !ok || flag.(float64) == 1 { +func GetSwitchFromOptions(Options map[string]int32, key string) (result bool) { + if flag, ok := Options[key]; !ok || flag == 1 { return true } return false } -func SetSwitchFromOptions(Options map[string]interface{}, key string, value interface{}) { +func SetSwitchFromOptions(Options map[string]int32, key string, value int32) { Options[key] = value }