push content modify

This commit is contained in:
Gordon 2021-11-04 16:52:48 +08:00
parent 817d2b11a5
commit 2440575093
6 changed files with 57 additions and 22 deletions

View File

@ -35,6 +35,8 @@ const (
Custom = 110 Custom = 110
HasReadReceipt = 112 HasReadReceipt = 112
Typing = 113 Typing = 113
Common = 200
GroupMsg = 201
//SysRelated //SysRelated
AcceptFriendApplicationTip = 201 AcceptFriendApplicationTip = 201
@ -67,10 +69,14 @@ const (
) )
var ContentType2PushContent = map[int64]string{ var ContentType2PushContent = map[int64]string{
Picture: "[picture]", Picture: "[图片]",
Voice: "[voice]", Voice: "[语音]",
Video: "[video]", Video: "[视频]",
File: "[file]", File: "[文件]",
Text: "你收到了一条文本消息",
AtText: "[有人@你]",
GroupMsg: "你收到一条群聊消息",
Common: "你收到一条新消息",
} }
const FriendAcceptTip = "You have successfully become friends, so start chatting" const FriendAcceptTip = "You have successfully become friends, so start chatting"

View File

@ -5,6 +5,7 @@ import (
"Open_IM/src/common/constant" "Open_IM/src/common/constant"
"Open_IM/src/common/log" "Open_IM/src/common/log"
pbMsg "Open_IM/src/proto/chat" pbMsg "Open_IM/src/proto/chat"
"Open_IM/src/utils"
"errors" "errors"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"gopkg.in/mgo.v2/bson" "gopkg.in/mgo.v2/bson"
@ -124,7 +125,7 @@ func (d *DataBases) GetMsgBySeqList(uid string, seqList []int64) (SingleMsg []*p
log.NewError("", "not find seqUid", seqUid, value, uid, seqList) log.NewError("", "not find seqUid", seqUid, value, uid, seqList)
return nil, nil, MaxSeq, MinSeq, err return nil, nil, MaxSeq, MinSeq, err
} }
if isContainInt64(pChat.RecvSeq, value) { if utils.IsContainInt64(pChat.RecvSeq, value) {
temp.SendID = pChat.SendID temp.SendID = pChat.SendID
temp.RecvID = pChat.RecvID temp.RecvID = pChat.RecvID
temp.MsgFrom = pChat.MsgFrom temp.MsgFrom = pChat.MsgFrom
@ -310,17 +311,7 @@ func (d *DataBases) DelGroupMember(groupID, uid string) error {
return nil return nil
} }
func isContainInt64(target int64, List []int64) bool {
for _, element := range List {
if target == element {
return true
}
}
return false
}
func getCurrentTimestampByMill() int64 { func getCurrentTimestampByMill() int64 {
return time.Now().UnixNano() / 1e6 return time.Now().UnixNano() / 1e6
} }

View File

@ -115,7 +115,7 @@ func (r *RPCServer) MsgToUser(_ context.Context, in *pbRelay.MsgToUserReq) (*pbR
} }
} }
if !tag { if !tag {
log.NewError(in.OperationID, "push err ,ws conn not in map", in.String()) log.NewError(in.OperationID, "push err ,no matched ws conn not in map", in.String())
} }
return &pbRelay.MsgToUserResp{ return &pbRelay.MsgToUserResp{
Resp: resp, Resp: resp,

View File

@ -13,16 +13,16 @@ import (
type JPushResp struct { type JPushResp struct {
} }
func JGAccountListPush(accounts []string, jsonCustomContent string, platform string) ([]byte, error) { func JGAccountListPush(accounts []string, content, detailContent, platform string) ([]byte, error) {
var pf requestBody.Platform var pf requestBody.Platform
_ = pf.SetPlatform(platform) _ = pf.SetPlatform(platform)
var au requestBody.Audience var au requestBody.Audience
au.SetAlias(accounts) au.SetAlias(accounts)
var no requestBody.Notification var no requestBody.Notification
no.SetAlert(jsonCustomContent) no.SetAlert(content)
var me requestBody.Message var me requestBody.Message
me.SetMsgContent(jsonCustomContent) me.SetMsgContent(detailContent)
var po requestBody.PushObj var po requestBody.PushObj
po.SetPlatform(&pf) po.SetPlatform(&pf)
po.SetAudience(&au) po.SetAudience(&au)

View File

@ -23,11 +23,16 @@ import (
) )
type OpenIMContent struct { type OpenIMContent struct {
SessionType int `json:"chatType"` SessionType int `json:"sessionType"`
From string `json:"from"` From string `json:"from"`
To string `json:"to"` To string `json:"to"`
Seq int64 `json:"seq"` Seq int64 `json:"seq"`
} }
type AtContent struct {
Text string `json:"text"`
AtUserList []string `json:"atUserList"`
IsAtSelf bool `json:"isAtSelf"`
}
func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) { func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) {
var wsResult []*pbRelay.SingleMsgToUser var wsResult []*pbRelay.SingleMsgToUser
@ -60,7 +65,7 @@ func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) {
if v.RecvPlatFormID == t { if v.RecvPlatFormID == t {
//Use offline push messaging //Use offline push messaging
var UIDList []string var UIDList []string
UIDList = append(UIDList, sendPbData.RecvID) UIDList = append(UIDList, v.RecvID)
customContent := OpenIMContent{ customContent := OpenIMContent{
SessionType: int(sendPbData.SessionType), SessionType: int(sendPbData.SessionType),
From: sendPbData.SendID, From: sendPbData.SendID,
@ -69,7 +74,29 @@ func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) {
} }
bCustomContent, _ := json.Marshal(customContent) bCustomContent, _ := json.Marshal(customContent)
jsonCustomContent := string(bCustomContent) jsonCustomContent := string(bCustomContent)
pushResult, err := push.JGAccountListPush(UIDList, jsonCustomContent, utils.PlatformIDToName(t)) var content string
switch sendPbData.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(sendPbData.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:
}
pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, utils.PlatformIDToName(t))
if err != nil { 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(), t)
} else { } else {

View File

@ -36,6 +36,17 @@ func IsContain(target string, List []string) bool {
} }
return false return false
}
func IsContainInt64(target int64, List []int64) bool {
for _, element := range List {
if target == element {
return true
}
}
return false
} }
func InterfaceArrayToStringArray(data []interface{}) (i []string) { func InterfaceArrayToStringArray(data []interface{}) (i []string) {
for _, param := range data { for _, param := range data {