You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/rpcclient/notification/conevrsation.go

64 lines
2.1 KiB

2 years ago
package notification
3 years ago
import (
"context"
2 years ago
"encoding/json"
2 years ago
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
2 years ago
"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"
3 years ago
"github.com/golang/protobuf/proto"
)
2 years ago
type ConversationNotificationSender struct {
*rpcclient.MsgClient
}
func NewConversationNotificationSender(client discoveryregistry.SvcDiscoveryRegistry) *ConversationNotificationSender {
return &ConversationNotificationSender{rpcclient.NewMsgClient(client)}
}
2 years ago
func (c *ConversationNotificationSender) SetConversationNotification(ctx context.Context, sendID, recvID string, contentType int, m proto.Message) {
3 years ago
var err error
2 years ago
var n rpcclient.NotificationMsg
n.SendID = sendID
n.RecvID = recvID
n.ContentType = int32(contentType)
3 years ago
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
2 years ago
n.Content, err = json.Marshal(m)
3 years ago
if err != nil {
return
}
c.Notification(ctx, &n)
3 years ago
}
// SetPrivate调用
2 years ago
func (c *ConversationNotificationSender) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
2 years ago
tips := &sdkws.ConversationSetPrivateTips{
RecvID: recvID,
SendID: sendID,
IsPrivate: isPrivateChat,
}
2 years ago
c.SetConversationNotification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, tips)
}
// 会话改变
2 years ago
func (c *ConversationNotificationSender) ConversationChangeNotification(ctx context.Context, userID string) {
2 years ago
tips := &sdkws.ConversationUpdateTips{
3 years ago
UserID: userID,
}
2 years ago
c.SetConversationNotification(ctx, userID, userID, constant.ConversationOptChangeNotification, tips)
3 years ago
}
2 years ago
2 years ago
// 会话未读数同步
2 years ago
func (c *ConversationNotificationSender) ConversationUnreadChangeNotification(ctx context.Context, userID, conversationID string, updateUnreadCountTime int64) {
2 years ago
tips := &sdkws.ConversationUpdateTips{
UserID: userID,
ConversationIDList: []string{conversationID},
UpdateUnreadCountTime: updateUnreadCountTime,
2 years ago
}
2 years ago
c.SetConversationNotification(ctx, userID, userID, constant.ConversationUnreadNotification, tips)
2 years ago
}