2023-04-23 19:50:42 +08:00
|
|
|
package notification2
|
2022-02-15 14:11:20 +08:00
|
|
|
|
|
|
|
|
import (
|
2023-02-02 19:47:21 +08:00
|
|
|
"context"
|
2023-04-23 21:14:40 +08:00
|
|
|
"encoding/json"
|
2023-04-23 19:50:42 +08:00
|
|
|
|
2023-03-16 10:46:06 +08:00
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
2023-04-23 19:50:42 +08:00
|
|
|
"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"
|
2022-02-15 14:11:20 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
|
)
|
|
|
|
|
|
2023-04-23 19:50:42 +08:00
|
|
|
type ConversationNotificationSender struct {
|
|
|
|
|
*rpcclient.MsgClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewConversationNotificationSender(client discoveryregistry.SvcDiscoveryRegistry) *ConversationNotificationSender {
|
|
|
|
|
return &ConversationNotificationSender{rpcclient.NewMsgClient(client)}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-23 21:14:40 +08:00
|
|
|
func (c *ConversationNotificationSender) SetConversationNotification(ctx context.Context, sendID, recvID string, contentType int, m proto.Message) {
|
2022-02-15 14:11:20 +08:00
|
|
|
var err error
|
2023-04-23 19:50:42 +08:00
|
|
|
var n rpcclient.NotificationMsg
|
2022-03-31 14:50:02 +08:00
|
|
|
n.SendID = sendID
|
|
|
|
|
n.RecvID = recvID
|
|
|
|
|
n.ContentType = int32(contentType)
|
2022-02-15 14:11:20 +08:00
|
|
|
n.SessionType = constant.SingleChatType
|
|
|
|
|
n.MsgFrom = constant.SysMsgType
|
2023-04-23 21:14:40 +08:00
|
|
|
n.Content, err = json.Marshal(m)
|
2022-02-15 14:11:20 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-02-14 10:34:34 +08:00
|
|
|
c.Notification(ctx, &n)
|
2022-02-15 14:11:20 +08:00
|
|
|
}
|
|
|
|
|
|
2022-03-31 14:50:02 +08:00
|
|
|
// SetPrivate调用
|
2023-04-23 19:50:42 +08:00
|
|
|
func (c *ConversationNotificationSender) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
|
2023-04-23 21:14:40 +08:00
|
|
|
tips := &sdkws.ConversationSetPrivateTips{
|
2022-03-31 14:50:02 +08:00
|
|
|
RecvID: recvID,
|
|
|
|
|
SendID: sendID,
|
|
|
|
|
IsPrivate: isPrivateChat,
|
|
|
|
|
}
|
2023-04-23 21:14:40 +08:00
|
|
|
c.SetConversationNotification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, tips)
|
2022-03-31 14:50:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 会话改变
|
2023-04-23 19:50:42 +08:00
|
|
|
func (c *ConversationNotificationSender) ConversationChangeNotification(ctx context.Context, userID string) {
|
2023-04-23 21:14:40 +08:00
|
|
|
tips := &sdkws.ConversationUpdateTips{
|
2022-02-15 14:11:20 +08:00
|
|
|
UserID: userID,
|
|
|
|
|
}
|
2023-04-23 21:14:40 +08:00
|
|
|
c.SetConversationNotification(ctx, userID, userID, constant.ConversationOptChangeNotification, tips)
|
2022-02-15 14:11:20 +08:00
|
|
|
}
|
2022-08-05 12:08:00 +08:00
|
|
|
|
2023-02-13 18:14:26 +08:00
|
|
|
// 会话未读数同步
|
2023-04-23 19:50:42 +08:00
|
|
|
func (c *ConversationNotificationSender) ConversationUnreadChangeNotification(ctx context.Context, userID, conversationID string, updateUnreadCountTime int64) {
|
2023-04-23 21:14:40 +08:00
|
|
|
tips := &sdkws.ConversationUpdateTips{
|
2022-09-05 19:07:16 +08:00
|
|
|
UserID: userID,
|
|
|
|
|
ConversationIDList: []string{conversationID},
|
|
|
|
|
UpdateUnreadCountTime: updateUnreadCountTime,
|
2022-08-05 12:08:00 +08:00
|
|
|
}
|
2023-04-23 21:14:40 +08:00
|
|
|
c.SetConversationNotification(ctx, userID, userID, constant.ConversationUnreadNotification, tips)
|
2022-08-05 12:08:00 +08:00
|
|
|
}
|