Merge remote-tracking branch 'origin/tuoyun' into tuoyun

This commit is contained in:
wenxu12345
2021-12-10 11:06:32 +08:00
19 changed files with 112 additions and 60 deletions
+2 -1
View File
@@ -42,7 +42,8 @@ func UserGetSeq(c *gin.Context) {
msgClient := pbMsg.NewChatClient(grpcConn)
reply, err := msgClient.GetMaxAndMinSeq(context.Background(), &pbData)
if err != nil {
log.ErrorByKv("rpc call failed to getNewSeq", pbData.OperationID, "err", err, "pbData", pbData.String())
log.NewError(params.OperationID, "UserGetSeq rpc failed, ", params, err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "UserGetSeq rpc failed, " + err.Error()})
return
}
+2 -1
View File
@@ -43,7 +43,8 @@ func UserPullMsg(c *gin.Context) {
msgClient := pbChat.NewChatClient(grpcConn)
reply, err := msgClient.PullMessage(context.Background(), &pbData)
if err != nil {
log.ErrorByKv("PullMessage error", pbData.OperationID, "err", err.Error())
log.NewError(params.OperationID, "UserPullMsg rpc failed, ", params, err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "UserPullMsg rpc failed, " + err.Error()})
return
}
log.InfoByKv("rpc call success to pullMsgRep", pbData.OperationID, "ReplyArgs", reply.String(), "maxSeq", reply.GetMaxSeq(),
+8 -3
View File
@@ -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: utils.MapIntToJsonString(params.Data.Options),
ClientMsgID: params.Data.ClientMsgID,
OffLineInfo: utils.MapToJsonString(params.Data.OffLineInfo),
Ex: utils.MapToJsonString(params.Data.Ex),
@@ -77,7 +77,12 @@ func UserSendMsg(c *gin.Context) {
log.Info("", "", "api UserSendMsg call, api call rpc...")
reply, _ := client.UserSendMsg(context.Background(), pbData)
reply, err := client.UserSendMsg(context.Background(), pbData)
if err != nil {
log.NewError(params.OperationID, "UserSendMsg rpc failed, ", params, err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "UserSendMsg rpc failed, " + err.Error()})
return
}
log.Info("", "", "api UserSendMsg call end..., [data: %s] [reply: %s]", pbData.String(), reply.String())
c.JSON(http.StatusOK, gin.H{
+3 -3
View File
@@ -15,7 +15,7 @@ import (
type paramsSetReceiveMessageOpt struct {
OperationID string `json:"operationID" binding:"required"`
Option int32 `json:"option" binding:"required"`
Option *int32 `json:"option" binding:"required"`
ConversationIdList []string `json:"conversationIdList" binding:"required"`
}
@@ -31,7 +31,7 @@ type SetReceiveMessageOptResp struct {
}
type paramGetReceiveMessageOpt struct {
ConversationIdList []string `json:"ConversationIdList" binding:"required"`
ConversationIdList []string `json:"conversationIdList" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
@@ -159,7 +159,7 @@ func SetReceiveMessageOpt(c *gin.Context) {
req := &user.SetReceiveMessageOptReq{
UId: claims.UID,
Opt: params.Option,
Opt: *params.Option,
ConversationId: params.ConversationIdList,
OperationID: params.OperationID,
}
@@ -54,11 +54,11 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
pbSaveData.OperationID = pbData.OperationID
pbSaveData.RecvID = pbData.RecvID
pbSaveData.PlatformID = pbData.PlatformID
Options := utils.JsonStringToMap(pbData.Options)
options := utils.JsonStringToMap(pbData.Options)
//Control whether to store offline messages (mongo)
isHistory := utils.GetSwitchFromOptions(Options, "history")
isHistory := utils.GetSwitchFromOptions(options, "history")
//Control whether to store history messages (mysql)
isPersist := utils.GetSwitchFromOptions(Options, "persistent")
isPersist := utils.GetSwitchFromOptions(options, "persistent")
switch pbData.SessionType {
case constant.SingleChatType:
log.NewDebug(pbSaveData.OperationID, "msg_transfer chat type = SingleChatType", isHistory, isPersist)
@@ -40,9 +40,9 @@ func (pc *PersistentConsumerHandler) handleChatWs2Mysql(msg []byte, msgKey strin
log.ErrorByKv("msg_transfer Unmarshal chat err", "", "chat", string(msg), "err", err.Error())
return
}
Options := utils.JsonStringToMap(pbData.Options)
options := utils.JsonStringToMap(pbData.Options)
//Control whether to store history messages (mysql)
isPersist := utils.GetSwitchFromOptions(Options, "persistent")
isPersist := utils.GetSwitchFromOptions(options, "persistent")
//Only process receiver data
if isPersist {
if msgKey == pbData.RecvID && pbData.SessionType == constant.SingleChatType {
+4 -2
View File
@@ -20,15 +20,17 @@ func JGAccountListPush(accounts []string, content, detailContent, platform strin
var au requestBody.Audience
au.SetAlias(accounts)
var no requestBody.Notification
no.SetAlert(content)
no.SetAndroidIntent()
no.SetAlert(content, platform)
var me requestBody.Message
me.SetMsgContent(detailContent)
var o requestBody.Options
o.SetApnsProduction(false)
var po requestBody.PushObj
po.SetPlatform(&pf)
po.SetAudience(&au)
po.SetNotification(&no)
po.SetMessage(&me)
po.SetOptions(&o)
con, err := json.Marshal(po)
if err != nil {
@@ -1,6 +1,9 @@
package requestBody
import "Open_IM/pkg/common/config"
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
)
type Notification struct {
Alert string `json:"alert,omitempty"`
@@ -15,11 +18,23 @@ type Android struct {
} `json:"intent,omitempty"`
}
type Ios struct {
Alert string `json:"alert,omitempty"`
Sound string `json:"sound,omitempty"`
Badge string `json:"badge,omitempty"`
}
func (n *Notification) SetAlert(alert string) {
func (n *Notification) SetAlert(alert, platform string) {
n.Alert = alert
n.Android.Alert = alert
switch platform {
case constant.AndroidPlatformStr:
n.Android.Alert = alert
n.SetAndroidIntent()
case constant.IOSPlatformStr:
n.IOS.Alert = alert
n.IOS.Sound = "default"
n.IOS.Badge = "+1"
default:
}
}
func (n *Notification) SetAndroidIntent() {
n.Android.Intent.URL = config.Config.Push.Jpns.PushIntent
@@ -0,0 +1,9 @@
package requestBody
type Options struct {
ApnsProduction bool `json:"apns_production"`
}
func (o *Options) SetApnsProduction(c bool) {
o.ApnsProduction = c
}
@@ -5,6 +5,7 @@ type PushObj struct {
Audience interface{} `json:"audience"`
Notification interface{} `json:"notification,omitempty"`
Message interface{} `json:"message,omitempty"`
Options interface{} `json:"options,omitempty"`
}
func (p *PushObj) SetPlatform(pf *Platform) {
@@ -22,3 +23,6 @@ func (p *PushObj) SetNotification(no *Notification) {
func (p *PushObj) SetMessage(m *Message) {
p.Message = m
}
func (p *PushObj) SetOptions(o *Options) {
p.Options = o
}
+2 -1
View File
@@ -12,6 +12,7 @@ import (
"Open_IM/pkg/common/log"
pbChat "Open_IM/pkg/proto/chat"
pbRelay "Open_IM/pkg/proto/relay"
"Open_IM/pkg/utils"
"github.com/Shopify/sarama"
"github.com/golang/protobuf/proto"
)
@@ -53,7 +54,7 @@ func (ms *PushConsumerHandler) handleMs2PsChat(msg []byte) {
sendPbData.PlatformID = pbData.PlatformID
sendPbData.RecvSeq = pbData.RecvSeq
//Call push module to send message to the user
MsgToUser(&sendPbData, pbData.OfflineInfo, pbData.Options)
MsgToUser(&sendPbData, pbData.OfflineInfo, utils.JsonStringToMap(pbData.Options))
}
func (PushConsumerHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }
func (PushConsumerHandler) Cleanup(_ sarama.ConsumerGroupSession) error { return nil }
+1 -1
View File
@@ -65,7 +65,7 @@ func (r *RPCServer) PushMsg(_ context.Context, pbData *pbPush.PushMsgReq) (*pbPu
sendPbData.PlatformID = pbData.PlatformID
sendPbData.RecvSeq = pbData.RecvSeq
//Call push module to send message to the user
MsgToUser(&sendPbData, pbData.OfflineInfo, pbData.Options)
MsgToUser(&sendPbData, pbData.OfflineInfo, utils.JsonStringToMap(pbData.Options))
return &pbPush.PushMsgResp{
ResultCode: 0,
}, nil
+5 -7
View File
@@ -34,12 +34,10 @@ 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")
log.InfoByKv("Get chat from msg_transfer And push chat", sendPbData.OperationID, "PushData", sendPbData)
isOfflinePush := utils.GetSwitchFromOptions(Options, "offlinePush")
log.InfoByKv("Get chat from msg_transfer And push chat", sendPbData.OperationID, "PushData", sendPbData, Options, isOfflinePush)
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
//Online push message
log.InfoByKv("test", sendPbData.OperationID, "len grpc", len(grpcCons), "data", sendPbData)
@@ -100,9 +98,9 @@ func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) {
}
pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t))
if err != nil {
log.NewError(sendPbData.OperationID, "offline push error", sendPbData.String(), err.Error(), t)
log.NewError(sendPbData.OperationID, "offline push error", sendPbData.String(), err.Error(), constant.PlatformIDToName(t))
} else {
log.NewDebug(sendPbData.OperationID, "offline push return result is ", string(pushResult), sendPbData, t)
log.NewDebug(sendPbData.OperationID, "offline push return result is ", string(pushResult), sendPbData, constant.PlatformIDToName(t))
}
}
+22 -6
View File
@@ -71,8 +71,8 @@ func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*
} else {
pbData.SendTime = pb.SendTime
}
Options := utils.JsonStringToMap(pbData.Options)
isHistory := utils.GetSwitchFromOptions(Options, "history")
options := utils.JsonStringToMap(pbData.Options)
isHistory := utils.GetSwitchFromOptions(options, "history")
mReq := MsgCallBackReq{
SendID: pb.SendID,
RecvID: pb.RecvID,
@@ -190,6 +190,20 @@ func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*
}
}
type WSToMsgSvrChatMsg struct {
SendID string `protobuf:"bytes,1,opt,name=SendID" json:"SendID,omitempty"`
RecvID string `protobuf:"bytes,2,opt,name=RecvID" json:"RecvID,omitempty"`
Content string `protobuf:"bytes,3,opt,name=Content" json:"Content,omitempty"`
MsgFrom int32 `protobuf:"varint,5,opt,name=MsgFrom" json:"MsgFrom,omitempty"`
ContentType int32 `protobuf:"varint,8,opt,name=ContentType" json:"ContentType,omitempty"`
SessionType int32 `protobuf:"varint,9,opt,name=SessionType" json:"SessionType,omitempty"`
OperationID string `protobuf:"bytes,10,opt,name=OperationID" json:"OperationID,omitempty"`
}
func Notification(m *WSToMsgSvrChatMsg, onlineUserOnly bool, offlineInfo interface{}) {
}
func (rpc *rpcChat) sendMsgToKafka(m *pbChat.WSToMsgSvrChatMsg, key string) error {
pid, offset, err := rpc.producer.SendMessage(m, key)
@@ -224,10 +238,12 @@ func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType i
case constant.NotReceiveMessage:
return false
case constant.ReceiveNotNotifyMessage:
m := utils.JsonStringToMap(msg.OfflineInfo)
utils.SetSwitchFromOptions(m, "offlinePush", 0)
s := utils.MapToJsonString(m)
msg.OfflineInfo = s
options := utils.JsonStringToMap(msg.Options)
if options == nil {
options = make(map[string]int32, 2)
}
utils.SetSwitchFromOptions(options, "offlinePush", 0)
msg.Options = utils.MapIntToJsonString(options)
return true
}