diff --git a/src/common/constant/constant.go b/src/common/constant/constant.go index 6f176cd51..8a1aa4029 100644 --- a/src/common/constant/constant.go +++ b/src/common/constant/constant.go @@ -35,6 +35,8 @@ const ( Custom = 110 HasReadReceipt = 112 Typing = 113 + Common = 200 + GroupMsg = 201 //SysRelated AcceptFriendApplicationTip = 201 @@ -67,10 +69,14 @@ const ( ) var ContentType2PushContent = map[int64]string{ - Picture: "[picture]", - Voice: "[voice]", - Video: "[video]", - File: "[file]", + Picture: "[图片]", + Voice: "[语音]", + Video: "[视频]", + File: "[文件]", + Text: "你收到了一条文本消息", + AtText: "[有人@你]", + GroupMsg: "你收到一条群聊消息", + Common: "你收到一条新消息", } const FriendAcceptTip = "You have successfully become friends, so start chatting" diff --git a/src/common/db/mongoModel.go b/src/common/db/mongoModel.go index 4bc810e16..d7bcd45e6 100644 --- a/src/common/db/mongoModel.go +++ b/src/common/db/mongoModel.go @@ -5,6 +5,7 @@ import ( "Open_IM/src/common/constant" "Open_IM/src/common/log" pbMsg "Open_IM/src/proto/chat" + "Open_IM/src/utils" "errors" "github.com/golang/protobuf/proto" "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) return nil, nil, MaxSeq, MinSeq, err } - if isContainInt64(pChat.RecvSeq, value) { + if utils.IsContainInt64(pChat.RecvSeq, value) { temp.SendID = pChat.SendID temp.RecvID = pChat.RecvID temp.MsgFrom = pChat.MsgFrom @@ -310,17 +311,7 @@ func (d *DataBases) DelGroupMember(groupID, uid string) error { return nil } -func isContainInt64(target int64, List []int64) bool { - for _, element := range List { - - if target == element { - return true - } - } - return false - -} func getCurrentTimestampByMill() int64 { return time.Now().UnixNano() / 1e6 } diff --git a/src/msg_gateway/gate/rpc_server.go b/src/msg_gateway/gate/rpc_server.go index dd4e8fa01..89f60507e 100644 --- a/src/msg_gateway/gate/rpc_server.go +++ b/src/msg_gateway/gate/rpc_server.go @@ -115,7 +115,7 @@ func (r *RPCServer) MsgToUser(_ context.Context, in *pbRelay.MsgToUserReq) (*pbR } } 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{ Resp: resp, diff --git a/src/push/jpush/push.go b/src/push/jpush/push.go index 3a214c16d..84140da89 100644 --- a/src/push/jpush/push.go +++ b/src/push/jpush/push.go @@ -13,16 +13,16 @@ import ( 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 _ = pf.SetPlatform(platform) var au requestBody.Audience au.SetAlias(accounts) var no requestBody.Notification - no.SetAlert(jsonCustomContent) + no.SetAlert(content) var me requestBody.Message - me.SetMsgContent(jsonCustomContent) + me.SetMsgContent(detailContent) var po requestBody.PushObj po.SetPlatform(&pf) po.SetAudience(&au) diff --git a/src/push/logic/push_to_client.go b/src/push/logic/push_to_client.go index dc28b2b21..5da019c8d 100644 --- a/src/push/logic/push_to_client.go +++ b/src/push/logic/push_to_client.go @@ -23,11 +23,16 @@ import ( ) type OpenIMContent struct { - SessionType int `json:"chatType"` + SessionType int `json:"sessionType"` From string `json:"from"` To string `json:"to"` 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) { var wsResult []*pbRelay.SingleMsgToUser @@ -60,7 +65,7 @@ func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) { if v.RecvPlatFormID == t { //Use offline push messaging var UIDList []string - UIDList = append(UIDList, sendPbData.RecvID) + UIDList = append(UIDList, v.RecvID) customContent := OpenIMContent{ SessionType: int(sendPbData.SessionType), From: sendPbData.SendID, @@ -69,7 +74,29 @@ func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) { } bCustomContent, _ := json.Marshal(customContent) 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 { log.NewError(sendPbData.OperationID, "offline push error", sendPbData.String(), err.Error(), t) } else { diff --git a/src/utils/strings.go b/src/utils/strings.go index c6d676dff..69141a6df 100644 --- a/src/utils/strings.go +++ b/src/utils/strings.go @@ -36,6 +36,17 @@ func IsContain(target string, List []string) bool { } 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) { for _, param := range data {