notification

This commit is contained in:
wangchuxiao
2023-04-23 21:14:40 +08:00
parent f6cebdbdef
commit 0071252777
7 changed files with 94 additions and 466 deletions
+9 -32
View File
@@ -2,13 +2,12 @@ package notification2
import (
"context"
"encoding/json"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
)
@@ -20,25 +19,15 @@ func NewConversationNotificationSender(client discoveryregistry.SvcDiscoveryRegi
return &ConversationNotificationSender{rpcclient.NewMsgClient(client)}
}
func (c *ConversationNotificationSender) SetConversationNotification(ctx context.Context, sendID, recvID string, contentType int, m proto.Message, tips *sdkws.TipsComm) {
func (c *ConversationNotificationSender) SetConversationNotification(ctx context.Context, sendID, recvID string, contentType int, m proto.Message) {
var err error
tips.Detail, err = proto.Marshal(m)
if err != nil {
return
}
marshaler := jsonpb.Marshaler{
OrigName: true,
EnumsAsInts: false,
EmitDefaults: false,
}
tips.JsonDetail, _ = marshaler.MarshalToString(m)
var n rpcclient.NotificationMsg
n.SendID = sendID
n.RecvID = recvID
n.ContentType = int32(contentType)
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.Content, err = proto.Marshal(tips)
n.Content, err = json.Marshal(m)
if err != nil {
return
}
@@ -47,40 +36,28 @@ func (c *ConversationNotificationSender) SetConversationNotification(ctx context
// SetPrivate调用
func (c *ConversationNotificationSender) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
conversationSetPrivateTips := &sdkws.ConversationSetPrivateTips{
tips := &sdkws.ConversationSetPrivateTips{
RecvID: recvID,
SendID: sendID,
IsPrivate: isPrivateChat,
}
var tips sdkws.TipsComm
var tipsMsg string
if isPrivateChat == true {
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.OpenTips
} else {
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.CloseTips
}
tips.DefaultTips = tipsMsg
c.SetConversationNotification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, conversationSetPrivateTips, &tips)
c.SetConversationNotification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, tips)
}
// 会话改变
func (c *ConversationNotificationSender) ConversationChangeNotification(ctx context.Context, userID string) {
ConversationChangedTips := &sdkws.ConversationUpdateTips{
tips := &sdkws.ConversationUpdateTips{
UserID: userID,
}
var tips sdkws.TipsComm
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
c.SetConversationNotification(ctx, userID, userID, constant.ConversationOptChangeNotification, ConversationChangedTips, &tips)
c.SetConversationNotification(ctx, userID, userID, constant.ConversationOptChangeNotification, tips)
}
// 会话未读数同步
func (c *ConversationNotificationSender) ConversationUnreadChangeNotification(ctx context.Context, userID, conversationID string, updateUnreadCountTime int64) {
ConversationChangedTips := &sdkws.ConversationUpdateTips{
tips := &sdkws.ConversationUpdateTips{
UserID: userID,
ConversationIDList: []string{conversationID},
UpdateUnreadCountTime: updateUnreadCountTime,
}
var tips sdkws.TipsComm
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
c.SetConversationNotification(ctx, userID, userID, constant.ConversationUnreadNotification, ConversationChangedTips, &tips)
c.SetConversationNotification(ctx, userID, userID, constant.ConversationUnreadNotification, tips)
}
+4 -49
View File
@@ -2,8 +2,8 @@ package notification2
import (
"context"
"encoding/json"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
@@ -12,7 +12,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/convert"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
)
@@ -96,56 +95,13 @@ func (c *FriendNotificationSender) getFromToUserNickname(ctx context.Context, fr
func (c *FriendNotificationSender) friendNotification(ctx context.Context, fromUserID, toUserID string, contentType int32, m proto.Message) {
var err error
var tips sdkws.TipsComm
tips.Detail, err = proto.Marshal(m)
if err != nil {
return
}
marshaler := jsonpb.Marshaler{
OrigName: true,
EnumsAsInts: false,
EmitDefaults: false,
}
tips.JsonDetail, _ = marshaler.MarshalToString(m)
fromUserNickname, toUserNickname, err := c.getFromToUserNickname(ctx, fromUserID, toUserID)
if err != nil {
return
}
cn := config.Config.Notification
switch contentType {
case constant.FriendApplicationNotification:
tips.DefaultTips = fromUserNickname + cn.FriendApplication.DefaultTips.Tips
case constant.FriendApplicationApprovedNotification:
tips.DefaultTips = fromUserNickname + cn.FriendApplicationApproved.DefaultTips.Tips
case constant.FriendApplicationRejectedNotification:
tips.DefaultTips = fromUserNickname + cn.FriendApplicationRejected.DefaultTips.Tips
case constant.FriendAddedNotification:
tips.DefaultTips = cn.FriendAdded.DefaultTips.Tips
case constant.FriendDeletedNotification:
tips.DefaultTips = cn.FriendDeleted.DefaultTips.Tips + toUserNickname
case constant.FriendRemarkSetNotification:
tips.DefaultTips = fromUserNickname + cn.FriendRemarkSet.DefaultTips.Tips
case constant.BlackAddedNotification:
tips.DefaultTips = cn.BlackAdded.DefaultTips.Tips
case constant.BlackDeletedNotification:
tips.DefaultTips = cn.BlackDeleted.DefaultTips.Tips + toUserNickname
case constant.UserInfoUpdatedNotification:
tips.DefaultTips = cn.UserInfoUpdated.DefaultTips.Tips
case constant.FriendInfoUpdatedNotification:
tips.DefaultTips = cn.FriendInfoUpdated.DefaultTips.Tips + toUserNickname
default:
return
}
var n rpcclient.NotificationMsg
n.SendID = fromUserID
n.RecvID = toUserID
n.ContentType = contentType
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.Content, err = proto.Marshal(&tips)
n.Content, err = json.Marshal(m)
if err != nil {
return
}
@@ -153,8 +109,8 @@ func (c *FriendNotificationSender) friendNotification(ctx context.Context, fromU
}
func (u *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Context, opUserID string, changedUserID string) {
selfInfoUpdatedTips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
u.friendNotification(ctx, opUserID, changedUserID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
tips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
u.friendNotification(ctx, opUserID, changedUserID, constant.UserInfoUpdatedNotification, &tips)
}
func (c *FriendNotificationSender) FriendApplicationAddNotification(ctx context.Context, req *pbFriend.ApplyToAddFriendReq) {
@@ -190,7 +146,6 @@ func (c *FriendNotificationSender) FriendAddedNotification(ctx context.Context,
friendAddedTips.OpUser.Ex = user[0].GetEx()
friendAddedTips.OpUser.Nickname = user[0].GetNickname()
friendAddedTips.OpUser.FaceURL = user[0].GetFaceURL()
friends, err := c.db.FindFriendsWithError(ctx, fromUserID, []string{toUserID})
if err != nil {
return