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

test-errcode
Gordon 2 years ago
commit 5c610fd24d

@ -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

@ -58,16 +58,16 @@ func StartTransfer(prometheusPort int) error {
extendMsgDatabase := controller.NewExtendMsgDatabase(extendMsgModel, extendMsgCache, tx.NewMongo(mongo.GetClient())) extendMsgDatabase := controller.NewExtendMsgDatabase(extendMsgModel, extendMsgCache, tx.NewMongo(mongo.GetClient()))
msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, msgModel) msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, msgModel)
conversationRpcClient := rpcclient.NewConversationClient(client) conversationRpcClient := rpcclient.NewConversationClient(client)
groupRpcClient := rpcclient.NewGroupClient(client)
msgTransfer := NewMsgTransfer(chatLogDatabase, extendMsgDatabase, msgDatabase, conversationRpcClient) msgTransfer := NewMsgTransfer(chatLogDatabase, extendMsgDatabase, msgDatabase, conversationRpcClient, groupRpcClient)
msgTransfer.initPrometheus() msgTransfer.initPrometheus()
return msgTransfer.Start(prometheusPort) return msgTransfer.Start(prometheusPort)
} }
func NewMsgTransfer(chatLogDatabase controller.ChatLogDatabase, func NewMsgTransfer(chatLogDatabase controller.ChatLogDatabase,
extendMsgDatabase controller.ExtendMsgDatabase, msgDatabase controller.CommonMsgDatabase, extendMsgDatabase controller.ExtendMsgDatabase, msgDatabase controller.CommonMsgDatabase,
conversationRpcClient *rpcclient.ConversationClient) *MsgTransfer { conversationRpcClient *rpcclient.ConversationClient, groupRpcClient *rpcclient.GroupClient) *MsgTransfer {
return &MsgTransfer{persistentCH: NewPersistentConsumerHandler(chatLogDatabase), historyCH: NewOnlineHistoryRedisConsumerHandler(msgDatabase, conversationRpcClient), return &MsgTransfer{persistentCH: NewPersistentConsumerHandler(chatLogDatabase), historyCH: NewOnlineHistoryRedisConsumerHandler(msgDatabase, conversationRpcClient, groupRpcClient),
historyMongoCH: NewOnlineHistoryMongoConsumerHandler(msgDatabase), modifyCH: NewModifyMsgConsumerHandler(extendMsgDatabase)} historyMongoCH: NewOnlineHistoryMongoConsumerHandler(msgDatabase), modifyCH: NewModifyMsgConsumerHandler(extendMsgDatabase)}
} }

@ -63,7 +63,7 @@ type OnlineHistoryRedisConsumerHandler struct {
groupRpcClient *rpcclient.GroupClient groupRpcClient *rpcclient.GroupClient
} }
func NewOnlineHistoryRedisConsumerHandler(database controller.CommonMsgDatabase, conversationRpcClient *rpcclient.ConversationClient) *OnlineHistoryRedisConsumerHandler { func NewOnlineHistoryRedisConsumerHandler(database controller.CommonMsgDatabase, conversationRpcClient *rpcclient.ConversationClient, groupRpcClient *rpcclient.GroupClient) *OnlineHistoryRedisConsumerHandler {
var och OnlineHistoryRedisConsumerHandler var och OnlineHistoryRedisConsumerHandler
och.msgDatabase = database och.msgDatabase = database
och.msgDistributionCh = make(chan Cmd2Value) //no buffer channel och.msgDistributionCh = make(chan Cmd2Value) //no buffer channel
@ -73,6 +73,7 @@ func NewOnlineHistoryRedisConsumerHandler(database controller.CommonMsgDatabase,
go och.Run(i) go och.Run(i)
} }
och.conversationRpcClient = conversationRpcClient och.conversationRpcClient = conversationRpcClient
och.groupRpcClient = groupRpcClient
och.historyConsumerGroup = kafka.NewMConsumerGroup(&kafka.MConsumerGroupConfig{KafkaVersion: sarama.V2_0_0_0, och.historyConsumerGroup = kafka.NewMConsumerGroup(&kafka.MConsumerGroupConfig{KafkaVersion: sarama.V2_0_0_0,
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false}, []string{config.Config.Kafka.Ws2mschat.Topic}, OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false}, []string{config.Config.Kafka.Ws2mschat.Topic},
config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.ConsumerGroupID.MsgToRedis) config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.ConsumerGroupID.MsgToRedis)
@ -90,11 +91,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, utils.GetChatConversationIDByMsg(ctxMsgList[0].message), storageMsgList, notStorageMsgList)
och.handleNotification(ctx, msgChannelValue.conversationID, storageNotificationList, notStorageNotificationList) och.handleNotification(ctx, utils.GetNotificationConversationID(ctxMsgList[0].message), 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 +105,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() {
@ -119,19 +120,27 @@ func (och *OnlineHistoryRedisConsumerHandler) getPushStorageMsgList(conversation
for _, v := range totalMsgs { for _, v := range totalMsgs {
options := utils.Options(v.message.Options) options := utils.Options(v.message.Options)
if !options.IsNotNotification() { if !options.IsNotNotification() {
// 原通知 // clone msg from notificationMsg
notificationMsg := proto.Clone(v.message).(*sdkws.MsgData)
if options.IsSendMsg() { if options.IsSendMsg() {
msg := proto.Clone(v.message).(*sdkws.MsgData)
// 消息 // 消息
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)) msg.Options = utils.NewMsgOptions()
} }
storageMsgList = append(storageMsgList, v.message) if options.IsOfflinePush() {
v.message.Options = utils.WithOptions(utils.Options(v.message.Options), utils.WithOfflinePush(false))
msg.Options = utils.WithOptions(utils.Options(msg.Options), utils.WithOfflinePush(true))
}
if options.IsUnreadCount() {
v.message.Options = utils.WithOptions(utils.Options(v.message.Options), utils.WithUnreadCount(false))
msg.Options = utils.WithOptions(utils.Options(msg.Options), utils.WithUnreadCount(true))
} }
if isStorage(notificationMsg) { storageMsgList = append(storageMsgList, msg)
storageNotificatoinList = append(storageNotificatoinList, notificationMsg) }
if isStorage(v.message) {
storageNotificatoinList = append(storageNotificatoinList, v.message)
} else { } else {
notStorageNotificationList = append(notStorageNotificationList, notificationMsg) notStorageNotificationList = append(notStorageNotificationList, v.message)
} }
} else { } else {
if isStorage(v.message) { if isStorage(v.message) {
@ -155,7 +164,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)
} }

@ -195,9 +195,6 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
if req.Conversation.DraftTextTime != nil { if req.Conversation.DraftTextTime != nil {
m["draft_text_time"] = req.Conversation.DraftTextTime.Value m["draft_text_time"] = req.Conversation.DraftTextTime.Value
} }
if req.Conversation.UnreadCount != nil {
m["unread_count"] = req.Conversation.UnreadCount.Value
}
if req.Conversation.AttachedInfo != nil { if req.Conversation.AttachedInfo != nil {
m["attached_info"] = req.Conversation.AttachedInfo.Value m["attached_info"] = req.Conversation.AttachedInfo.Value
} }
@ -283,7 +280,8 @@ func (c *conversationServer) CreateGroupChatConversations(ctx context.Context, r
func (c *conversationServer) DelGroupChatConversations(ctx context.Context, req *pbConversation.DelGroupChatConversationsReq) (*pbConversation.DelGroupChatConversationsResp, error) { func (c *conversationServer) DelGroupChatConversations(ctx context.Context, req *pbConversation.DelGroupChatConversationsReq) (*pbConversation.DelGroupChatConversationsResp, error) {
if err := c.conversationDatabase.UpdateUsersConversationFiled(ctx, req.OwnerUserID, if err := c.conversationDatabase.UpdateUsersConversationFiled(ctx, req.OwnerUserID,
utils.GetConversationIDBySessionType(constant.SuperGroupChatType, req.GroupID), map[string]interface{}{"max_seq": req.MaxSeq}); err != nil { utils.GetConversationIDBySessionType(constant.SuperGroupChatType, req.GroupID),
map[string]interface{}{"max_seq": req.MaxSeq}); err != nil {
return nil, err return nil, err
} }
return &pbConversation.DelGroupChatConversationsResp{}, nil return &pbConversation.DelGroupChatConversationsResp{}, nil
@ -315,3 +313,11 @@ func (c *conversationServer) GetConversationsHasReadAndMaxSeq(ctx context.Contex
} }
return resp, nil return resp, nil
} }
func (c *conversationServer) GetUserConversationIDsHash(ctx context.Context, req *pbConversation.GetUserConversationIDsHashReq) (*pbConversation.GetUserConversationIDsHashResp, error) {
hash, err := c.conversationDatabase.GetUserConversationIDsHash(ctx, req.OwnerUserID)
if err != nil {
return nil, err
}
return &pbConversation.GetUserConversationIDsHashResp{Hash: hash}, nil
}

@ -117,7 +117,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbfriend.Res
return nil, err return nil, err
} }
friendRequest := tablerelation.FriendRequestModel{FromUserID: req.ToUserID, ToUserID: req.FromUserID, HandleMsg: req.HandleMsg, HandleResult: req.HandleResult} friendRequest := tablerelation.FriendRequestModel{FromUserID: req.FromUserID, ToUserID: req.ToUserID, HandleMsg: req.HandleMsg, HandleResult: req.HandleResult}
if req.HandleResult == constant.FriendResponseAgree { if req.HandleResult == constant.FriendResponseAgree {
err := s.friendDatabase.AgreeFriendRequest(ctx, &friendRequest) err := s.friendDatabase.AgreeFriendRequest(ctx, &friendRequest)
if err != nil { if err != nil {
@ -222,8 +222,6 @@ func (s *friendServer) GetPaginationFriendsApplyFrom(ctx context.Context, req *p
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.ZInfo(ctx, "test log out")
log.ZInfo(ctx, "GetPaginationFriendsApplyFrom.xxx", "total", total, "friendRequests", len(friendRequests), "userRpcClient", s.userRpcClient == nil)
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRpcClient.GetUsersInfoMap) resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRpcClient.GetUsersInfoMap)
if err != nil { if err != nil {
return nil, err return nil, err

@ -62,6 +62,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
return utils.Slice(users, func(e *sdkws.UserInfo) rpcclient.CommonUser { return e }), nil return utils.Slice(users, func(e *sdkws.UserInfo) rpcclient.CommonUser { return e }), nil
}), }),
conversationRpcClient: rpcclient.NewConversationClient(client), conversationRpcClient: rpcclient.NewConversationClient(client),
msgRpcClient: rpcclient.NewMsgClient(client),
}) })
return nil return nil
} }
@ -751,11 +752,12 @@ func (s *groupServer) deleteMemberAndSetConversationSeq(ctx context.Context, gro
if err != nil { if err != nil {
return err return err
} }
maxSeq, ok := resp.MaxSeqs[conevrsationID] //log.ZInfo(ctx, "deleteMemberAndSetConversationSeq.GetMaxSeq", "maxSeqs", resp.MaxSeqs, "conevrsationID", conevrsationID)
if !ok { //maxSeq, ok := resp.MaxSeqs[conevrsationID]
return errs.ErrInternalServer.Wrap("get max seq error") //if !ok {
} // return errs.ErrInternalServer.Wrap("get max seq error")
return s.conversationRpcClient.DelGroupChatConversations(ctx, userIDs, groupID, maxSeq) //}
return s.conversationRpcClient.DelGroupChatConversations(ctx, userIDs, groupID, resp.MaxSeqs[conevrsationID])
} }
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) { func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) {

@ -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.IsNotification(conversationID) {
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 {

@ -32,6 +32,7 @@ type msgServer struct {
friend *rpcclient.FriendClient friend *rpcclient.FriendClient
black *rpcclient.BlackClient black *rpcclient.BlackClient
GroupLocalCache *localcache.GroupLocalCache GroupLocalCache *localcache.GroupLocalCache
ConversationLocalCache *localcache.ConversationLocalCache
MessageLocker MessageLocker MessageLocker MessageLocker
Handlers MessageInterceptorChain Handlers MessageInterceptorChain
} }
@ -39,6 +40,7 @@ type msgServer struct {
func (m *msgServer) addInterceptorHandler(interceptorFunc ...MessageInterceptorFunc) { func (m *msgServer) addInterceptorHandler(interceptorFunc ...MessageInterceptorFunc) {
m.Handlers = append(m.Handlers, interceptorFunc...) m.Handlers = append(m.Handlers, interceptorFunc...)
} }
func (m *msgServer) execInterceptorHandler(ctx context.Context, req *msg.SendMsgReq) error { func (m *msgServer) execInterceptorHandler(ctx context.Context, req *msg.SendMsgReq) error {
for _, handler := range m.Handlers { for _, handler := range m.Handlers {
msgData, err := handler(ctx, req) msgData, err := handler(ctx, req)
@ -49,6 +51,7 @@ func (m *msgServer) execInterceptorHandler(ctx context.Context, req *msg.SendMsg
} }
return nil return nil
} }
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error { func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
rdb, err := cache.NewRedis() rdb, err := cache.NewRedis()
if err != nil { if err != nil {
@ -73,6 +76,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
ExtendMsgDatabase: extendMsgDatabase, ExtendMsgDatabase: extendMsgDatabase,
RegisterCenter: client, RegisterCenter: client,
GroupLocalCache: localcache.NewGroupLocalCache(client), GroupLocalCache: localcache.NewGroupLocalCache(client),
ConversationLocalCache: localcache.NewConversationLocalCache(client),
black: rpcclient.NewBlackClient(client), black: rpcclient.NewBlackClient(client),
friend: rpcclient.NewFriendClient(client), friend: rpcclient.NewFriendClient(client),
MessageLocker: NewLockerMessage(cacheModel), MessageLocker: NewLockerMessage(cacheModel),
@ -127,7 +131,7 @@ func (m *msgServer) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqReq) (*sd
if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil { if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
return nil, err return nil, err
} }
conversationIDs, err := m.Conversation.GetConversationIDs(ctx, req.UserID) conversationIDs, err := m.ConversationLocalCache.GetConversationIDs(ctx, req.UserID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -168,7 +172,6 @@ func (m *msgServer) PullMessageBySeqs(ctx context.Context, req *sdkws.PullMessag
continue continue
} }
resp.Msgs[seq.ConversationID] = &sdkws.PullMsgs{Msgs: notificationMsgs} resp.Msgs[seq.ConversationID] = &sdkws.PullMsgs{Msgs: notificationMsgs}
} }
} }
return resp, nil return resp, nil

@ -341,7 +341,7 @@ type Notification struct {
////////////////////////user/////////////////////// ////////////////////////user///////////////////////
UserInfoUpdated NotificationConf `yaml:"userInfoUpdated"` UserInfoUpdated NotificationConf `yaml:"userInfoUpdated"`
//////////////////////friend/////////////////////// //////////////////////friend///////////////////////
FriendApplication NotificationConf `yaml:"friendApplicationAdded"` FriendApplicationAdded NotificationConf `yaml:"friendApplicationAdded"`
FriendApplicationApproved NotificationConf `yaml:"friendApplicationApproved"` FriendApplicationApproved NotificationConf `yaml:"friendApplicationApproved"`
FriendApplicationRejected NotificationConf `yaml:"friendApplicationRejected"` FriendApplicationRejected NotificationConf `yaml:"friendApplicationRejected"`
FriendAdded NotificationConf `yaml:"friendAdded"` FriendAdded NotificationConf `yaml:"friendAdded"`
@ -358,10 +358,10 @@ type Notification struct {
func GetOptionsByNotification(cfg NotificationConf) utils.Options { func GetOptionsByNotification(cfg NotificationConf) utils.Options {
opts := utils.NewOptions() opts := utils.NewOptions()
if cfg.UnreadCount { if cfg.UnreadCount {
opts = utils.WithOptions(opts, utils.WithUnreadCount()) opts = utils.WithOptions(opts, utils.WithUnreadCount(true))
} }
if cfg.OfflinePush.Enable { if cfg.OfflinePush.Enable {
opts = utils.WithOptions(opts, utils.WithOfflinePush()) opts = utils.WithOptions(opts, utils.WithOfflinePush(true))
} }
switch cfg.ReliabilityLevel { switch cfg.ReliabilityLevel {
case constant.UnreliableNotification: case constant.UnreliableNotification:

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

@ -17,6 +17,7 @@ import (
const ( const (
conversationKey = "CONVERSATION:" conversationKey = "CONVERSATION:"
conversationIDsKey = "CONVERSATION_IDS:" conversationIDsKey = "CONVERSATION_IDS:"
conversationIDsHashKey = "CONVERSATION_IDS_HASH:"
recvMsgOptKey = "RECV_MSG_OPT:" recvMsgOptKey = "RECV_MSG_OPT:"
superGroupRecvMsgNotNotifyUserIDsKey = "SUPER_GROUP_RECV_MSG_NOT_NOTIFY_USER_IDS:" superGroupRecvMsgNotNotifyUserIDsKey = "SUPER_GROUP_RECV_MSG_NOT_NOTIFY_USER_IDS:"
superGroupRecvMsgNotNotifyUserIDsHashKey = "SUPER_GROUP_RECV_MSG_NOT_NOTIFY_USER_IDS_HASH:" superGroupRecvMsgNotNotifyUserIDsHashKey = "SUPER_GROUP_RECV_MSG_NOT_NOTIFY_USER_IDS_HASH:"
@ -31,6 +32,10 @@ type ConversationCache interface {
// get user's conversationIDs from msgCache // get user's conversationIDs from msgCache
GetUserConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) GetUserConversationIDs(ctx context.Context, ownerUserID string) ([]string, error)
DelConversationIDs(userIDs ...string) ConversationCache DelConversationIDs(userIDs ...string) ConversationCache
GetUserConversationIDsHash(ctx context.Context, ownerUserID string) (hash uint64, err error)
DelUserConversationIDsHash(ownerUserIDs ...string) ConversationCache
// get one conversation from msgCache // get one conversation from msgCache
GetConversation(ctx context.Context, ownerUserID, conversationID string) (*relationTb.ConversationModel, error) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*relationTb.ConversationModel, error)
DelConvsersations(ownerUserID string, conversationIDs ...string) ConversationCache DelConvsersations(ownerUserID string, conversationIDs ...string) ConversationCache
@ -107,6 +112,33 @@ func (c *ConversationRedisCache) DelConversationIDs(userIDs ...string) Conversat
return cache return cache
} }
func (c *ConversationRedisCache) getUserConversationIDsHashKey(ownerUserID string) string {
return conversationIDsHashKey + ownerUserID
}
func (c *ConversationRedisCache) GetUserConversationIDsHash(ctx context.Context, ownerUserID string) (hash uint64, err error) {
return getCache(ctx, c.rcClient, c.getUserConversationIDsHashKey(ownerUserID), c.expireTime, func(ctx context.Context) (uint64, error) {
conversationIDs, err := c.GetUserConversationIDs(ctx, ownerUserID)
if err != nil {
return 0, err
}
utils.Sort(conversationIDs, true)
bi := big.NewInt(0)
bi.SetString(utils.Md5(strings.Join(conversationIDs, ";"))[0:8], 16)
return bi.Uint64(), nil
})
}
func (c *ConversationRedisCache) DelUserConversationIDsHash(ownerUserIDs ...string) ConversationCache {
var keys []string
for _, ownerUserID := range ownerUserIDs {
keys = append(keys, c.getUserConversationIDsHashKey(ownerUserID))
}
cache := c.NewCache()
cache.AddKeys(keys...)
return cache
}
func (c *ConversationRedisCache) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*relationTb.ConversationModel, error) { func (c *ConversationRedisCache) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*relationTb.ConversationModel, error) {
return getCache(ctx, c.rcClient, c.getConversationKey(ownerUserID, conversationID), c.expireTime, func(ctx context.Context) (*relationTb.ConversationModel, error) { return getCache(ctx, c.rcClient, c.getConversationKey(ownerUserID, conversationID), c.expireTime, func(ctx context.Context) (*relationTb.ConversationModel, error) {
return c.conversationDB.Take(ctx, ownerUserID, conversationID) return c.conversationDB.Take(ctx, ownerUserID, conversationID)

@ -16,7 +16,7 @@ import (
const ( const (
scanCount = 3000 scanCount = 3000
maxRetryTimes = 5 maxRetryTimes = 5
retryInterval = time.Second * 1 retryInterval = time.Millisecond * 100
) )
var errIndex = errors.New("err index") var errIndex = errors.New("err index")
@ -49,7 +49,7 @@ func (m *metaCacheRedis) ExecDel(ctx context.Context) error {
if err := m.rcClient.TagAsDeletedBatch2(ctx, m.keys); err != nil { if err := m.rcClient.TagAsDeletedBatch2(ctx, m.keys); err != nil {
if retryTimes >= m.maxRetryTimes { if retryTimes >= m.maxRetryTimes {
err = errs.ErrInternalServer.Wrap(fmt.Sprintf("delete cache error: %v, keys: %v, retry times %d, please check redis server", err, m.keys, retryTimes)) err = errs.ErrInternalServer.Wrap(fmt.Sprintf("delete cache error: %v, keys: %v, retry times %d, please check redis server", err, m.keys, retryTimes))
log.ZWarn(ctx, "delete cache failed", err, "keys", m.keys) log.ZWarn(ctx, "delete cache failed, please handle keys", err, "keys", m.keys)
return err return err
} }
retryTimes++ retryTimes++
@ -106,11 +106,11 @@ func getCache[T any](ctx context.Context, rcClient *rockscache.Client, key strin
return t, nil return t, nil
} }
if v == "" { if v == "" {
return t, errs.ErrRecordNotFound.Wrap("msgCache is not found") return t, errs.ErrRecordNotFound.Wrap("cache is not found")
} }
err = json.Unmarshal([]byte(v), &t) err = json.Unmarshal([]byte(v), &t)
if err != nil { if err != nil {
log.ZError(ctx, "msgCache json.Unmarshal failed", err, "key", key, "value", v, "expire", expire) log.ZError(ctx, "cache json.Unmarshal failed", err, "key", key, "value", v, "expire", expire)
return t, utils.Wrap(err, "") return t, utils.Wrap(err, "")
} }
return t, nil return t, nil

@ -30,6 +30,7 @@ type ConversationDatabase interface {
SetUsersConversationFiledTx(ctx context.Context, userIDs []string, conversation *relationTb.ConversationModel, filedMap map[string]interface{}) error SetUsersConversationFiledTx(ctx context.Context, userIDs []string, conversation *relationTb.ConversationModel, filedMap map[string]interface{}) error
CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string) error CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string) error
GetConversationIDs(ctx context.Context, userID string) ([]string, error) GetConversationIDs(ctx context.Context, userID string) ([]string, error)
GetUserConversationIDsHash(ctx context.Context, ownerUserID string) (hash uint64, err error)
} }
func NewConversationDatabase(conversation relationTb.ConversationModelInterface, cache cache.ConversationCache, tx tx.Tx) ConversationDatabase { func NewConversationDatabase(conversation relationTb.ConversationModelInterface, cache cache.ConversationCache, tx tx.Tx) ConversationDatabase {
@ -78,7 +79,7 @@ func (c *ConversationDataBase) SetUsersConversationFiledTx(ctx context.Context,
if err != nil { if err != nil {
return err return err
} }
cache = cache.DelConversationIDs(NotUserIDs...) cache = cache.DelConversationIDs(NotUserIDs...).DelUserConversationIDsHash(NotUserIDs...)
} }
return nil return nil
}); err != nil { }); err != nil {
@ -103,7 +104,7 @@ func (c *ConversationDataBase) CreateConversation(ctx context.Context, conversat
for _, conversation := range conversations { for _, conversation := range conversations {
userIDs = append(userIDs, conversation.OwnerUserID) userIDs = append(userIDs, conversation.OwnerUserID)
} }
return c.cache.DelConversationIDs(userIDs...).ExecDel(ctx) return c.cache.DelConversationIDs(userIDs...).DelUserConversationIDsHash(userIDs...).ExecDel(ctx)
} }
func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Context, conversations []*relationTb.ConversationModel) error { func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Context, conversations []*relationTb.ConversationModel) error {
@ -131,7 +132,7 @@ func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Con
if err := conversationTx.Create(ctx, []*relationTb.ConversationModel{&newConversation}); err != nil { if err := conversationTx.Create(ctx, []*relationTb.ConversationModel{&newConversation}); err != nil {
return err return err
} }
cache = cache.DelConversationIDs([]string{v[0]}...) cache = cache.DelConversationIDs(v[0]).DelUserConversationIDsHash(v[0])
} }
} }
} }
@ -190,7 +191,7 @@ func (c *ConversationDataBase) SetUserConversations(ctx context.Context, ownerUs
if err != nil { if err != nil {
return err return err
} }
cache = cache.DelConversationIDs([]string{ownerUserID}...) cache = cache.DelConversationIDs(ownerUserID).DelUserConversationIDsHash(ownerUserID)
} }
cache = cache.DelConvsersations(ownerUserID, existConversationIDs...) cache = cache.DelConvsersations(ownerUserID, existConversationIDs...)
return nil return nil
@ -218,7 +219,7 @@ func (c *ConversationDataBase) CreateGroupChatConversation(ctx context.Context,
conversation := relationTb.ConversationModel{ConversationType: constant.SuperGroupChatType, GroupID: groupID, OwnerUserID: v, ConversationID: conversationID} conversation := relationTb.ConversationModel{ConversationType: constant.SuperGroupChatType, GroupID: groupID, OwnerUserID: v, ConversationID: conversationID}
conversations = append(conversations, &conversation) conversations = append(conversations, &conversation)
} }
cache = cache.DelConversationIDs(notExistUserIDs...) cache = cache.DelConversationIDs(notExistUserIDs...).DelUserConversationIDsHash(notExistUserIDs...)
err = c.conversationDB.Create(ctx, conversations) err = c.conversationDB.Create(ctx, conversations)
if err != nil { if err != nil {
return err return err
@ -240,3 +241,7 @@ func (c *ConversationDataBase) CreateGroupChatConversation(ctx context.Context,
func (c *ConversationDataBase) GetConversationIDs(ctx context.Context, userID string) ([]string, error) { func (c *ConversationDataBase) GetConversationIDs(ctx context.Context, userID string) ([]string, error) {
return c.cache.GetUserConversationIDs(ctx, userID) return c.cache.GetUserConversationIDs(ctx, userID)
} }
func (c *ConversationDataBase) GetUserConversationIDsHash(ctx context.Context, ownerUserID string) (hash uint64, err error) {
return c.cache.GetUserConversationIDsHash(ctx, ownerUserID)
}

@ -313,15 +313,22 @@ func (db *commonMsgDatabase) unmarshalMsg(msgInfo *unRelationTb.MsgInfoModel) (m
return msgPb, nil return msgPb, nil
} }
func (db *commonMsgDatabase) getMsgBySeqs(ctx context.Context, conversationID string, seqs []int64) (seqMsgs []*sdkws.MsgData, err error) { func (db *commonMsgDatabase) getMsgBySeqs(ctx context.Context, conversationID string, seqs []int64) (totalMsgs []*sdkws.MsgData, err error) {
seqMsgs, unexistSeqs, err := db.findMsgBySeq(ctx, conversationID, seqs) m := db.msg.GetDocIDSeqsMap(conversationID, seqs)
var totalUnExistSeqs []int64
for docID, seqs := range m {
log.ZDebug(ctx, "getMsgBySeqs", "docID", docID, "seqs", seqs)
seqMsgs, unexistSeqs, err := db.findMsgBySeq(ctx, docID, seqs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, unexistSeq := range unexistSeqs { totalMsgs = append(totalMsgs, seqMsgs...)
seqMsgs = append(seqMsgs, db.msg.GenExceptionMessageBySeqs([]int64{unexistSeq})...) totalUnExistSeqs = append(totalUnExistSeqs, unexistSeqs...)
} }
return seqMsgs, nil for _, unexistSeq := range totalUnExistSeqs {
totalMsgs = append(totalMsgs, db.msg.GenExceptionMessageBySeqs([]int64{unexistSeq})...)
}
return totalMsgs, nil
} }
func (db *commonMsgDatabase) refetchDelSeqsMsgs(ctx context.Context, conversationID string, delNums, rangeBegin, begin int64) (seqMsgs []*sdkws.MsgData, err error) { func (db *commonMsgDatabase) refetchDelSeqsMsgs(ctx context.Context, conversationID string, delNums, rangeBegin, begin int64) (seqMsgs []*sdkws.MsgData, err error) {
@ -340,8 +347,8 @@ func (db *commonMsgDatabase) refetchDelSeqsMsgs(ctx context.Context, conversatio
} }
if len(reFetchSeqs) > 0 { if len(reFetchSeqs) > 0 {
m := db.msg.GetDocIDSeqsMap(conversationID, reFetchSeqs) m := db.msg.GetDocIDSeqsMap(conversationID, reFetchSeqs)
for docID, seq := range m { for docID, seqs := range m {
msgs, _, err := db.findMsgBySeq(ctx, docID, seq) msgs, _, err := db.findMsgBySeq(ctx, docID, seqs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -451,7 +458,7 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, conversation
var seqs []int64 var seqs []int64
for i := end; i > end-num; i-- { for i := end; i > end-num; i-- {
if i >= begin { if i >= begin {
seqs = append(seqs, i) seqs = append([]int64{i}, seqs...)
} else { } else {
break break
} }

@ -9,22 +9,22 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
) )
type ConversationLocalCacheInterface interface {
GetRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error)
GetConversationIDs(ctx context.Context, userID string) ([]string, error)
}
type ConversationLocalCache struct { type ConversationLocalCache struct {
lock sync.Mutex lock sync.Mutex
SuperGroupRecvMsgNotNotifyUserIDs map[string][]string SuperGroupRecvMsgNotNotifyUserIDs map[string]Hash
ConversationIDs map[string][]string ConversationIDs map[string]Hash
client discoveryregistry.SvcDiscoveryRegistry client discoveryregistry.SvcDiscoveryRegistry
} }
type Hash struct {
hash uint64
ids []string
}
func NewConversationLocalCache(client discoveryregistry.SvcDiscoveryRegistry) *ConversationLocalCache { func NewConversationLocalCache(client discoveryregistry.SvcDiscoveryRegistry) *ConversationLocalCache {
return &ConversationLocalCache{ return &ConversationLocalCache{
SuperGroupRecvMsgNotNotifyUserIDs: make(map[string][]string, 0), SuperGroupRecvMsgNotNotifyUserIDs: make(map[string]Hash),
ConversationIDs: make(map[string][]string, 0), ConversationIDs: make(map[string]Hash),
client: client, client: client,
} }
} }
@ -50,11 +50,28 @@ func (g *ConversationLocalCache) GetConversationIDs(ctx context.Context, userID
return nil, err return nil, err
} }
client := conversation.NewConversationClient(conn) client := conversation.NewConversationClient(conn)
resp, err := client.GetConversationIDs(ctx, &conversation.GetConversationIDsReq{ resp, err := client.GetUserConversationIDsHash(ctx, &conversation.GetUserConversationIDsHashReq{
OwnerUserID: userID,
})
if err != nil {
return nil, err
}
g.lock.Lock()
defer g.lock.Unlock()
hash, ok := g.ConversationIDs[userID]
if !ok || hash.hash != resp.Hash {
conversationIDsResp, err := client.GetConversationIDs(ctx, &conversation.GetConversationIDsReq{
UserID: userID, UserID: userID,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }
return resp.ConversationIDs, nil g.ConversationIDs[userID] = Hash{
hash: resp.Hash,
ids: conversationIDsResp.ConversationIDs,
}
return conversationIDsResp.ConversationIDs, nil
}
return hash.ids, nil
} }

@ -10,10 +10,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
) )
type GroupLocalCacheInterface interface {
GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error)
}
type GroupLocalCache struct { type GroupLocalCache struct {
lock sync.Mutex lock sync.Mutex
cache map[string]GroupMemberIDsHash cache map[string]GroupMemberIDsHash

@ -197,7 +197,7 @@ func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID strin
break break
} }
} }
log.ZDebug(ctx, "msgInfos", "num", len(doc.Msg)) log.ZDebug(ctx, "msgInfos", "num", len(doc.Msg), "docID", docID)
for _, v := range doc.Msg { for _, v := range doc.Msg {
var msg sdkws.MsgData var msg sdkws.MsgData
if err := proto.Unmarshal(v.Msg, &msg); err != nil { if err := proto.Unmarshal(v.Msg, &msg); err != nil {

File diff suppressed because it is too large Load Diff

@ -165,6 +165,14 @@ message SetConversationsReq {
message SetConversationsResp { message SetConversationsResp {
} }
message GetUserConversationIDsHashReq {
string ownerUserID = 1;
}
message GetUserConversationIDsHashResp {
uint64 hash = 1;
}
service conversation { service conversation {
rpc ModifyConversationField(ModifyConversationFieldReq)returns(ModifyConversationFieldResp); rpc ModifyConversationField(ModifyConversationFieldReq)returns(ModifyConversationFieldResp);
rpc GetConversation(GetConversationReq)returns(GetConversationResp); rpc GetConversation(GetConversationReq)returns(GetConversationResp);
@ -180,4 +188,5 @@ service conversation {
rpc GetConversationIDs(GetConversationIDsReq) returns(GetConversationIDsResp); rpc GetConversationIDs(GetConversationIDsReq) returns(GetConversationIDsResp);
rpc GetConversationsHasReadAndMaxSeq(GetConversationsHasReadAndMaxSeqReq) returns(GetConversationsHasReadAndMaxSeqResp); rpc GetConversationsHasReadAndMaxSeq(GetConversationsHasReadAndMaxSeqReq) returns(GetConversationsHasReadAndMaxSeqResp);
rpc SetConversations(SetConversationsReq) returns(SetConversationsResp); rpc SetConversations(SetConversationsReq) returns(SetConversationsResp);
rpc GetUserConversationIDsHash(GetUserConversationIDsHashReq) returns(GetUserConversationIDsHashResp);
} }

@ -114,7 +114,10 @@ func (g *GroupClient) GetOwnerAndAdminInfos(ctx context.Context, groupID string)
GroupID: groupID, GroupID: groupID,
RoleLevels: []int32{constant.GroupOwner, constant.GroupAdmin}, RoleLevels: []int32{constant.GroupOwner, constant.GroupAdmin},
}) })
return resp.Members, err if err != nil {
return nil, err
}
return resp.Members, nil
} }
func (g *GroupClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) { func (g *GroupClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) {
@ -137,5 +140,8 @@ func (g *GroupClient) GetGroupMemberIDs(ctx context.Context, groupID string) ([]
resp, err := group.NewGroupClient(cc).GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{ resp, err := group.NewGroupClient(cc).GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{
GroupID: groupID, GroupID: groupID,
}) })
return resp.UserIDs, err if err != nil {
return nil, err
}
return resp.UserIDs, nil
} }

@ -41,7 +41,7 @@ func newContentTypeConf() map[int32]config.NotificationConf {
// user // user
constant.UserInfoUpdatedNotification: config.Config.Notification.UserInfoUpdated, constant.UserInfoUpdatedNotification: config.Config.Notification.UserInfoUpdated,
// friend // friend
constant.FriendApplicationNotification: config.Config.Notification.FriendApplication, constant.FriendApplicationNotification: config.Config.Notification.FriendApplicationAdded,
constant.FriendApplicationApprovedNotification: config.Config.Notification.FriendApplicationApproved, constant.FriendApplicationApprovedNotification: config.Config.Notification.FriendApplicationApproved,
constant.FriendApplicationRejectedNotification: config.Config.Notification.FriendApplicationRejected, constant.FriendApplicationRejectedNotification: config.Config.Notification.FriendApplicationRejected,
constant.FriendAddedNotification: config.Config.Notification.FriendAdded, constant.FriendAddedNotification: config.Config.Notification.FriendAdded,

@ -285,7 +285,7 @@ func (g *GroupNotificationSender) mergeGroupFull(ctx context.Context, groupID st
} }
func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, group *relation.GroupModel, members []*relation.GroupMemberModel, userMap map[string]*sdkws.UserInfo) (err error) { func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, group *relation.GroupModel, members []*relation.GroupMemberModel, userMap map[string]*sdkws.UserInfo) (err error) {
defer log.ZDebug(ctx, "return") defer log.ZDebug(ctx, "GroupCreatedNotification.return")
defer func() { defer func() {
if err != nil { if err != nil {
log.ZError(ctx, utils.GetFuncName(1)+" failed", err) log.ZError(ctx, utils.GetFuncName(1)+" failed", err)

@ -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
@ -25,6 +25,12 @@ func NewOptions(opts ...OptionsOpt) Options {
return options return options
} }
func NewMsgOptions() Options {
options := make(map[string]bool, 11)
options[constant.IsOfflinePush] = false
return make(map[string]bool)
}
func WithOptions(options Options, opts ...OptionsOpt) Options { func WithOptions(options Options, opts ...OptionsOpt) Options {
for _, opt := range opts { for _, opt := range opts {
opt(options) opt(options)
@ -32,9 +38,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
} }
} }
@ -56,15 +62,15 @@ func WithPersistent() OptionsOpt {
} }
} }
func WithOfflinePush() OptionsOpt { func WithOfflinePush(b bool) OptionsOpt {
return func(options Options) { return func(options Options) {
options[constant.IsOfflinePush] = true options[constant.IsOfflinePush] = b
} }
} }
func WithUnreadCount() OptionsOpt { func WithUnreadCount(b bool) OptionsOpt {
return func(options Options) { return func(options Options) {
options[constant.IsUnreadCount] = true options[constant.IsUnreadCount] = b
} }
} }
@ -113,7 +119,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 {

@ -170,6 +170,43 @@ 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 GetNotificationConversationID(msg *sdkws.MsgData) string {
switch msg.SessionType {
case constant.SingleChatType:
l := []string{msg.SendID, msg.RecvID}
sort.Strings(l)
return "n_" + strings.Join(l, "_")
case constant.GroupChatType:
return "n_" + msg.GroupID
case constant.SuperGroupChatType:
return "n_" + msg.GroupID
case constant.NotificationChatType:
return "n_" + msg.SendID + "_" + msg.RecvID
}
return ""
}
func GetChatConversationIDByMsg(msg *sdkws.MsgData) string {
switch msg.SessionType {
case constant.SingleChatType:
l := []string{msg.SendID, msg.RecvID}
sort.Strings(l)
return "si_" + strings.Join(l, "_")
case constant.GroupChatType:
return "g_" + msg.GroupID
case constant.SuperGroupChatType:
return "sg_" + msg.GroupID
case constant.NotificationChatType:
return "sn_" + msg.SendID + "_" + msg.RecvID
}
return ""
}
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 {
@ -256,7 +293,7 @@ func GetSeqsBeginEnd(seqs []int64) (int64, int64) {
if len(seqs) == 0 { if len(seqs) == 0 {
return 0, 0 return 0, 0
} }
return seqs[len(seqs)-1], seqs[0] return seqs[0], seqs[len(seqs)-1]
} }
type MsgBySeq []*sdkws.MsgData type MsgBySeq []*sdkws.MsgData

Loading…
Cancel
Save