diff --git a/internal/push/logic/init.go b/internal/push/logic/init.go index 79eb460dc..d2d127091 100644 --- a/internal/push/logic/init.go +++ b/internal/push/logic/init.go @@ -8,23 +8,25 @@ package logic import ( "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" "Open_IM/pkg/common/kafka" "Open_IM/pkg/statistics" "fmt" ) var ( - rpcServer RPCServer - pushCh PushConsumerHandler - producer *kafka.Producer - count uint64 + rpcServer RPCServer + pushCh PushConsumerHandler + pushTerminal []int32 + producer *kafka.Producer + count uint64 ) func Init(rpcPort int) { rpcServer.Init(rpcPort) pushCh.Init() - + pushTerminal = []int32{constant.IOSPlatformID, constant.AndroidPlatformID} } func init() { producer = kafka.NewKafkaProducer(config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.Ws2mschat.Topic) diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index 5a5317b81..607d36db0 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -59,61 +59,64 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) { if v.ResultCode == 0 { continue } - //Use offline push messaging - var UIDList []string - UIDList = append(UIDList, v.RecvID) - customContent := OpenIMContent{ - SessionType: int(pushMsg.MsgData.SessionType), - From: pushMsg.MsgData.SendID, - To: pushMsg.MsgData.RecvID, - Seq: pushMsg.MsgData.Seq, - } - bCustomContent, _ := json.Marshal(customContent) - jsonCustomContent := string(bCustomContent) - var content string - if pushMsg.MsgData.OfflinePushInfo != nil { - content = pushMsg.MsgData.OfflinePushInfo.Title + if utils.IsContainInt32(v.RecvPlatFormID, pushTerminal) { + //Use offline push messaging + var UIDList []string + UIDList = append(UIDList, v.RecvID) + customContent := OpenIMContent{ + SessionType: int(pushMsg.MsgData.SessionType), + From: pushMsg.MsgData.SendID, + To: pushMsg.MsgData.RecvID, + Seq: pushMsg.MsgData.Seq, + } + bCustomContent, _ := json.Marshal(customContent) + jsonCustomContent := string(bCustomContent) + var content string + if pushMsg.MsgData.OfflinePushInfo != nil { + content = pushMsg.MsgData.OfflinePushInfo.Title - } else { - switch pushMsg.MsgData.ContentType { - case constant.Text: - content = constant.ContentType2PushContent[constant.Text] - case constant.Picture: - content = constant.ContentType2PushContent[constant.Picture] - case constant.Voice: - content = constant.ContentType2PushContent[constant.Voice] - case constant.Video: - content = constant.ContentType2PushContent[constant.Video] - case constant.File: - content = constant.ContentType2PushContent[constant.File] - case constant.AtText: - a := AtContent{} - _ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a) - if utils.IsContain(v.RecvID, a.AtUserList) { - content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common] - } else { - content = constant.ContentType2PushContent[constant.GroupMsg] + } else { + switch pushMsg.MsgData.ContentType { + case constant.Text: + content = constant.ContentType2PushContent[constant.Text] + case constant.Picture: + content = constant.ContentType2PushContent[constant.Picture] + case constant.Voice: + content = constant.ContentType2PushContent[constant.Voice] + case constant.Video: + content = constant.ContentType2PushContent[constant.Video] + case constant.File: + content = constant.ContentType2PushContent[constant.File] + case constant.AtText: + a := AtContent{} + _ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a) + if utils.IsContain(v.RecvID, a.AtUserList) { + content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common] + } else { + content = constant.ContentType2PushContent[constant.GroupMsg] + } + default: + content = constant.ContentType2PushContent[constant.Common] } - default: - content = constant.ContentType2PushContent[constant.Common] } - } - var offlinePusher pusher.OfflinePusher - if config.Config.Push.Getui.Enable { - log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), config.Config.Push.Getui) - offlinePusher = getui.GetuiClient - } - if config.Config.Push.Jpns.Enable { - offlinePusher = jpush.JPushClient - } - if offlinePusher == nil { - offlinePusher = jpush.JPushClient - } - pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, pushMsg.OperationID) - if err != nil { - log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error()) - } else { - log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData) + var offlinePusher pusher.OfflinePusher + if config.Config.Push.Getui.Enable { + log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), config.Config.Push.Getui) + offlinePusher = getui.GetuiClient + } + if config.Config.Push.Jpns.Enable { + offlinePusher = jpush.JPushClient + } + if offlinePusher == nil { + offlinePusher = jpush.JPushClient + } + pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, pushMsg.OperationID) + if err != nil { + log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error()) + } else { + log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData) + } + break } } diff --git a/pkg/utils/strings.go b/pkg/utils/strings.go index 38262a95c..49d883f7c 100644 --- a/pkg/utils/strings.go +++ b/pkg/utils/strings.go @@ -43,6 +43,14 @@ func IsContain(target string, List []string) bool { } return false } +func IsContainInt32(target int32, List []int32) bool { + for _, element := range List { + if target == element { + return true + } + } + return false +} func InterfaceArrayToStringArray(data []interface{}) (i []string) { for _, param := range data {