notification

This commit is contained in:
wangchuxiao 2023-05-16 18:37:14 +08:00
parent 5377f1501d
commit 4f6fb10006
7 changed files with 54 additions and 17 deletions

View File

@ -13,6 +13,7 @@ groupCreated:
groupInfoSet: groupInfoSet:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -23,6 +24,7 @@ groupInfoSet:
joinGroupApplication: joinGroupApplication:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -32,6 +34,7 @@ joinGroupApplication:
memberQuit: memberQuit:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -41,6 +44,7 @@ memberQuit:
groupApplicationAccepted: groupApplicationAccepted:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -50,6 +54,7 @@ groupApplicationAccepted:
groupApplicationRejected: groupApplicationRejected:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -60,6 +65,7 @@ groupApplicationRejected:
groupOwnerTransferred: groupOwnerTransferred:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -69,6 +75,7 @@ groupOwnerTransferred:
memberKicked: memberKicked:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -78,6 +85,7 @@ memberKicked:
memberInvited: memberInvited:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -87,6 +95,7 @@ memberInvited:
memberEnter: memberEnter:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -96,6 +105,7 @@ memberEnter:
groupDismissed: groupDismissed:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -105,6 +115,7 @@ groupDismissed:
groupMuted: groupMuted:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -114,6 +125,7 @@ groupMuted:
groupCancelMuted: groupCancelMuted:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -126,6 +138,7 @@ groupCancelMuted:
groupMemberMuted: groupMemberMuted:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -135,6 +148,7 @@ groupMemberMuted:
groupMemberCancelMuted: groupMemberCancelMuted:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -144,6 +158,7 @@ groupMemberCancelMuted:
groupMemberInfoSet: groupMemberInfoSet:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -154,6 +169,7 @@ groupMemberInfoSet:
#############################friend################################# #############################friend#################################
friendApplicationAdded: friendApplicationAdded:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: false enable: false
@ -163,6 +179,7 @@ friendApplicationAdded:
friendApplicationApproved: friendApplicationApproved:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true
@ -172,6 +189,7 @@ friendApplicationApproved:
friendApplicationRejected: friendApplicationRejected:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true
@ -181,6 +199,7 @@ friendApplicationRejected:
friendAdded: friendAdded:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true
@ -190,6 +209,7 @@ friendAdded:
friendDeleted: friendDeleted:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true
@ -199,6 +219,7 @@ friendDeleted:
friendRemarkSet: friendRemarkSet:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true
@ -208,6 +229,7 @@ friendRemarkSet:
blackAdded: blackAdded:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true
@ -217,6 +239,7 @@ blackAdded:
blackDeleted: blackDeleted:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true
@ -226,6 +249,7 @@ blackDeleted:
friendInfoUpdated: friendInfoUpdated:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true
@ -236,6 +260,7 @@ friendInfoUpdated:
#####################user######################### #####################user#########################
userInfoUpdated: userInfoUpdated:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true
@ -246,6 +271,7 @@ userInfoUpdated:
#####################conversation######################### #####################conversation#########################
conversationChanged: conversationChanged:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true
@ -255,6 +281,7 @@ conversationChanged:
conversationSetPrivate: conversationSetPrivate:
isSendMsg: true isSendMsg: true
reliabilityLevel: 1
unreadCount: false unreadCount: false
offlinePush: offlinePush:
enable: true enable: true

View File

@ -90,11 +90,11 @@ func (och *OnlineHistoryRedisConsumerHandler) Run(channelID int) {
ctxMsgList := msgChannelValue.ctxMsgList ctxMsgList := msgChannelValue.ctxMsgList
ctx := msgChannelValue.ctx ctx := msgChannelValue.ctx
log.ZDebug(ctx, "msg arrived channel", "channel id", channelID, "msgList length", len(ctxMsgList), "conversationID", msgChannelValue.conversationID) log.ZDebug(ctx, "msg arrived channel", "channel id", channelID, "msgList length", len(ctxMsgList), "conversationID", msgChannelValue.conversationID)
storageMsgList, notStorageMsgList, storageNotificationList, notStorageNotificationList, modifyMsgList := och.getPushStorageMsgList(msgChannelValue.conversationID, ctxMsgList) storageMsgList, notStorageMsgList, storageNotificationList, notStorageNotificationList, modifyMsgList := och.getPushStorageMsgList(ctxMsgList)
log.ZDebug(ctx, "msg lens", "storageMsgList", len(storageMsgList), "notStorageMsgList", len(notStorageMsgList), log.ZDebug(ctx, "msg lens", "storageMsgList", len(storageMsgList), "notStorageMsgList", len(notStorageMsgList),
"storageNotificationList", len(storageNotificationList), "notStorageNotificationList", len(notStorageNotificationList), "modifyMsgList", len(modifyMsgList)) "storageNotificationList", len(storageNotificationList), "notStorageNotificationList", len(notStorageNotificationList), "modifyMsgList", len(modifyMsgList))
och.handleMsg(ctx, msgChannelValue.conversationID, storageMsgList, notStorageMsgList) och.handleMsg(ctx, storageMsgList, notStorageMsgList)
och.handleNotification(ctx, msgChannelValue.conversationID, storageNotificationList, notStorageNotificationList) och.handleNotification(ctx, storageNotificationList, notStorageNotificationList)
if err := och.msgDatabase.MsgToModifyMQ(ctx, msgChannelValue.conversationID, modifyMsgList); err != nil { if err := och.msgDatabase.MsgToModifyMQ(ctx, msgChannelValue.conversationID, modifyMsgList); err != nil {
log.ZError(ctx, "msg to modify mq error", err, "conversationID", msgChannelValue.conversationID, "modifyMsgList", modifyMsgList) log.ZError(ctx, "msg to modify mq error", err, "conversationID", msgChannelValue.conversationID, "modifyMsgList", modifyMsgList)
} }
@ -104,7 +104,7 @@ func (och *OnlineHistoryRedisConsumerHandler) Run(channelID int) {
} }
// 获取消息/通知 存储的消息列表, 不存储并且推送的消息列表, // 获取消息/通知 存储的消息列表, 不存储并且推送的消息列表,
func (och *OnlineHistoryRedisConsumerHandler) getPushStorageMsgList(conversationID string, totalMsgs []*ContextMsg) (storageMsgList, notStorageMsgList, storageNotificatoinList, notStorageNotificationList, modifyMsgList []*sdkws.MsgData) { func (och *OnlineHistoryRedisConsumerHandler) getPushStorageMsgList(totalMsgs []*ContextMsg) (storageMsgList, notStorageMsgList, storageNotificatoinList, notStorageNotificationList, modifyMsgList []*sdkws.MsgData) {
isStorage := func(msg *sdkws.MsgData) bool { isStorage := func(msg *sdkws.MsgData) bool {
options2 := utils.Options(msg.Options) options2 := utils.Options(msg.Options)
if options2.IsHistory() { if options2.IsHistory() {
@ -124,7 +124,7 @@ func (och *OnlineHistoryRedisConsumerHandler) getPushStorageMsgList(conversation
if options.IsSendMsg() { if options.IsSendMsg() {
// 消息 // 消息
if v.message.Options != nil { if v.message.Options != nil {
v.message.Options = utils.WithOptions(utils.Options(v.message.Options), utils.WithNotification(false), utils.WithSendMsg(false)) v.message.Options = utils.WithOptions(utils.Options(v.message.Options), utils.WithNotNotification(true), utils.WithSendMsg(false))
} }
storageMsgList = append(storageMsgList, v.message) storageMsgList = append(storageMsgList, v.message)
} }
@ -147,7 +147,8 @@ func (och *OnlineHistoryRedisConsumerHandler) getPushStorageMsgList(conversation
return return
} }
func (och *OnlineHistoryRedisConsumerHandler) handleNotification(ctx context.Context, conversationID string, storageList, notStorageList []*sdkws.MsgData) { func (och *OnlineHistoryRedisConsumerHandler) handleNotification(ctx context.Context, storageList, notStorageList []*sdkws.MsgData) {
conversationID := utils.GetConversationIDByMsg(storageList[0])
och.toPushTopic(ctx, conversationID, notStorageList) och.toPushTopic(ctx, conversationID, notStorageList)
if len(storageList) > 0 { if len(storageList) > 0 {
lastSeq, _, err := och.msgDatabase.BatchInsertChat2Cache(ctx, conversationID, storageList) lastSeq, _, err := och.msgDatabase.BatchInsertChat2Cache(ctx, conversationID, storageList)
@ -155,7 +156,7 @@ func (och *OnlineHistoryRedisConsumerHandler) handleNotification(ctx context.Con
log.ZError(ctx, "notification batch insert to redis error", err, "conversationID", conversationID, "storageList", storageList) log.ZError(ctx, "notification batch insert to redis error", err, "conversationID", conversationID, "storageList", storageList)
return return
} }
log.ZDebug(ctx, "success to next topic") log.ZDebug(ctx, "success to next topic", "conversationID", conversationID)
och.msgDatabase.MsgToMongoMQ(ctx, conversationID, storageList, lastSeq) och.msgDatabase.MsgToMongoMQ(ctx, conversationID, storageList, lastSeq)
och.toPushTopic(ctx, conversationID, storageList) och.toPushTopic(ctx, conversationID, storageList)
} }
@ -167,7 +168,8 @@ func (och *OnlineHistoryRedisConsumerHandler) toPushTopic(ctx context.Context, c
} }
} }
func (och *OnlineHistoryRedisConsumerHandler) handleMsg(ctx context.Context, conversationID string, storageList, notStorageList []*sdkws.MsgData) { func (och *OnlineHistoryRedisConsumerHandler) handleMsg(ctx context.Context, storageList, notStorageList []*sdkws.MsgData) {
conversationID := utils.GetConversationIDByMsg(storageList[0])
och.toPushTopic(ctx, conversationID, notStorageList) och.toPushTopic(ctx, conversationID, notStorageList)
if len(storageList) > 0 { if len(storageList) > 0 {
lastSeq, isNewConversation, err := och.msgDatabase.BatchInsertChat2Cache(ctx, conversationID, storageList) lastSeq, isNewConversation, err := och.msgDatabase.BatchInsertChat2Cache(ctx, conversationID, storageList)

View File

@ -62,11 +62,15 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *msg.SendMsgReq)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var isSend bool = true
conversationID := utils.GetConversationIDByMsg(req.MsgData) conversationID := utils.GetConversationIDByMsg(req.MsgData)
isSend, err := m.modifyMessageByUserMessageReceiveOpt(ctx, req.MsgData.RecvID, conversationID, constant.SingleChatType, req) if utils.MsgIsNotification(req.MsgData) {
isSend, err = m.modifyMessageByUserMessageReceiveOpt(ctx, req.MsgData.RecvID, conversationID, constant.SingleChatType, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
if isSend { if isSend {
err = m.MsgDatabase.MsgToMQ(ctx, conversationID, req.MsgData) err = m.MsgDatabase.MsgToMQ(ctx, conversationID, req.MsgData)
if err != nil { if err != nil {

View File

@ -357,7 +357,6 @@ type Notification struct {
func GetOptionsByNotification(cfg NotificationConf) utils.Options { func GetOptionsByNotification(cfg NotificationConf) utils.Options {
opts := utils.NewOptions() opts := utils.NewOptions()
opts = utils.WithOptions(opts, utils.WithNotification(true))
if cfg.UnreadCount { if cfg.UnreadCount {
opts = utils.WithOptions(opts, utils.WithUnreadCount()) opts = utils.WithOptions(opts, utils.WithUnreadCount())
} }

View File

@ -142,7 +142,7 @@ const (
IsSenderConversationUpdate = "senderConversationUpdate" IsSenderConversationUpdate = "senderConversationUpdate"
IsSenderNotificationPush = "senderNotificationPush" IsSenderNotificationPush = "senderNotificationPush"
IsReactionFromCache = "reactionFromCache" IsReactionFromCache = "reactionFromCache"
IsNotification = "isNotification" IsNotNotification = "isNotification"
IsSendMsg = "isSendMsg" IsSendMsg = "isSendMsg"
//GroupStatus //GroupStatus

View File

@ -7,7 +7,7 @@ type OptionsOpt func(Options)
func NewOptions(opts ...OptionsOpt) Options { func NewOptions(opts ...OptionsOpt) Options {
options := make(map[string]bool, 11) options := make(map[string]bool, 11)
options[constant.IsNotification] = false options[constant.IsNotNotification] = false
options[constant.IsSendMsg] = false options[constant.IsSendMsg] = false
options[constant.IsHistory] = false options[constant.IsHistory] = false
options[constant.IsPersistent] = false options[constant.IsPersistent] = false
@ -32,9 +32,9 @@ func WithOptions(options Options, opts ...OptionsOpt) Options {
return options return options
} }
func WithNotification(b bool) OptionsOpt { func WithNotNotification(b bool) OptionsOpt {
return func(options Options) { return func(options Options) {
options[constant.IsNotification] = b options[constant.IsNotNotification] = b
} }
} }
@ -113,7 +113,7 @@ func (o Options) Is(notification string) bool {
} }
func (o Options) IsNotNotification() bool { func (o Options) IsNotNotification() bool {
return o.Is(constant.IsNotification) return o.Is(constant.IsNotNotification)
} }
func (o Options) IsSendMsg() bool { func (o Options) IsSendMsg() bool {

View File

@ -170,6 +170,11 @@ func GetHashCode(s string) uint32 {
return crc32.ChecksumIEEE([]byte(s)) return crc32.ChecksumIEEE([]byte(s))
} }
func MsgIsNotification(msg *sdkws.MsgData) bool {
options := Options(msg.Options)
return !options.IsNotNotification()
}
func GetConversationIDByMsg(msg *sdkws.MsgData) string { func GetConversationIDByMsg(msg *sdkws.MsgData) string {
options := Options(msg.Options) options := Options(msg.Options)
switch msg.SessionType { switch msg.SessionType {