mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
conversation
This commit is contained in:
parent
0dc16d54a5
commit
16231ee077
@ -244,14 +244,14 @@ userInfoUpdated:
|
|||||||
ext: "Remove a blocked user"
|
ext: "Remove a blocked user"
|
||||||
|
|
||||||
#####################conversation#########################
|
#####################conversation#########################
|
||||||
conversationOptUpdate:
|
conversationChanged:
|
||||||
isSendMsg: true
|
isSendMsg: true
|
||||||
unreadCount: false
|
unreadCount: false
|
||||||
offlinePush:
|
offlinePush:
|
||||||
enable: true
|
enable: true
|
||||||
title: "conversation opt update"
|
title: "conversation changed"
|
||||||
desc: "conversation opt update"
|
desc: "conversation changed"
|
||||||
ext: "conversation opt update"
|
ext: "conversation changed"
|
||||||
|
|
||||||
conversationSetPrivate:
|
conversationSetPrivate:
|
||||||
isSendMsg: true
|
isSendMsg: true
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
type conversationServer struct {
|
type conversationServer struct {
|
||||||
group *rpcclient.GroupClient
|
group *rpcclient.GroupClient
|
||||||
ConversationDatabase controller.ConversationDatabase
|
conversationDatabase controller.ConversationDatabase
|
||||||
conversationNotificationSender *notification.ConversationNotificationSender
|
conversationNotificationSender *notification.ConversationNotificationSender
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,14 +41,14 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
|||||||
pbConversation.RegisterConversationServer(server, &conversationServer{
|
pbConversation.RegisterConversationServer(server, &conversationServer{
|
||||||
conversationNotificationSender: notification.NewConversationNotificationSender(client),
|
conversationNotificationSender: notification.NewConversationNotificationSender(client),
|
||||||
group: rpcclient.NewGroupClient(client),
|
group: rpcclient.NewGroupClient(client),
|
||||||
ConversationDatabase: controller.NewConversationDatabase(conversationDB, cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB), tx.NewGorm(db)),
|
conversationDatabase: controller.NewConversationDatabase(conversationDB, cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB), tx.NewGorm(db)),
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *conversationServer) GetConversation(ctx context.Context, req *pbConversation.GetConversationReq) (*pbConversation.GetConversationResp, error) {
|
func (c *conversationServer) GetConversation(ctx context.Context, req *pbConversation.GetConversationReq) (*pbConversation.GetConversationResp, error) {
|
||||||
resp := &pbConversation.GetConversationResp{Conversation: &pbConversation.Conversation{}}
|
resp := &pbConversation.GetConversationResp{Conversation: &pbConversation.Conversation{}}
|
||||||
conversations, err := c.ConversationDatabase.FindConversations(ctx, req.OwnerUserID, []string{req.ConversationID})
|
conversations, err := c.conversationDatabase.FindConversations(ctx, req.OwnerUserID, []string{req.ConversationID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ func (c *conversationServer) GetConversation(ctx context.Context, req *pbConvers
|
|||||||
|
|
||||||
func (c *conversationServer) GetAllConversations(ctx context.Context, req *pbConversation.GetAllConversationsReq) (*pbConversation.GetAllConversationsResp, error) {
|
func (c *conversationServer) GetAllConversations(ctx context.Context, req *pbConversation.GetAllConversationsReq) (*pbConversation.GetAllConversationsResp, error) {
|
||||||
resp := &pbConversation.GetAllConversationsResp{Conversations: []*pbConversation.Conversation{}}
|
resp := &pbConversation.GetAllConversationsResp{Conversations: []*pbConversation.Conversation{}}
|
||||||
conversations, err := c.ConversationDatabase.GetUserAllConversation(ctx, req.OwnerUserID)
|
conversations, err := c.conversationDatabase.GetUserAllConversation(ctx, req.OwnerUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ func (c *conversationServer) GetAllConversations(ctx context.Context, req *pbCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *conversationServer) GetConversations(ctx context.Context, req *pbConversation.GetConversationsReq) (*pbConversation.GetConversationsResp, error) {
|
func (c *conversationServer) GetConversations(ctx context.Context, req *pbConversation.GetConversationsReq) (*pbConversation.GetConversationsResp, error) {
|
||||||
conversations, err := c.ConversationDatabase.FindConversations(ctx, req.OwnerUserID, req.ConversationIDs)
|
conversations, err := c.conversationDatabase.FindConversations(ctx, req.OwnerUserID, req.ConversationIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ func (c *conversationServer) GetConversations(ctx context.Context, req *pbConver
|
|||||||
|
|
||||||
func (c *conversationServer) BatchSetConversations(ctx context.Context, req *pbConversation.BatchSetConversationsReq) (*pbConversation.BatchSetConversationsResp, error) {
|
func (c *conversationServer) BatchSetConversations(ctx context.Context, req *pbConversation.BatchSetConversationsReq) (*pbConversation.BatchSetConversationsResp, error) {
|
||||||
conversations := convert.ConversationsPb2DB(req.Conversations)
|
conversations := convert.ConversationsPb2DB(req.Conversations)
|
||||||
err := c.ConversationDatabase.SetUserConversations(ctx, req.OwnerUserID, conversations)
|
err := c.conversationDatabase.SetUserConversations(ctx, req.OwnerUserID, conversations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ func (c *conversationServer) SetConversation(ctx context.Context, req *pbConvers
|
|||||||
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
|
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err := c.ConversationDatabase.SetUserConversations(ctx, req.Conversation.OwnerUserID, []*tableRelation.ConversationModel{&conversation})
|
err := c.conversationDatabase.SetUserConversations(ctx, req.Conversation.OwnerUserID, []*tableRelation.ConversationModel{&conversation})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ func (c *conversationServer) SetConversation(ctx context.Context, req *pbConvers
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *conversationServer) SetRecvMsgOpt(ctx context.Context, req *pbConversation.SetRecvMsgOptReq) (*pbConversation.SetRecvMsgOptResp, error) {
|
func (c *conversationServer) SetRecvMsgOpt(ctx context.Context, req *pbConversation.SetRecvMsgOptReq) (*pbConversation.SetRecvMsgOptResp, error) {
|
||||||
if err := c.ConversationDatabase.SetUsersConversationFiledTx(ctx, []string{req.OwnerUserID}, &tableRelation.ConversationModel{OwnerUserID: req.OwnerUserID, ConversationID: req.ConversationID, RecvMsgOpt: req.RecvMsgOpt}, map[string]interface{}{"recv_msg_opt": req.RecvMsgOpt}); err != nil {
|
if err := c.conversationDatabase.SetUsersConversationFiledTx(ctx, []string{req.OwnerUserID}, &tableRelation.ConversationModel{OwnerUserID: req.OwnerUserID, ConversationID: req.ConversationID, RecvMsgOpt: req.RecvMsgOpt}, map[string]interface{}{"recv_msg_opt": req.RecvMsgOpt}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c.conversationNotificationSender.ConversationChangeNotification(ctx, req.OwnerUserID)
|
c.conversationNotificationSender.ConversationChangeNotification(ctx, req.OwnerUserID)
|
||||||
@ -129,7 +129,7 @@ func (c *conversationServer) ModifyConversationField(ctx context.Context, req *p
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if req.FieldType == constant.FieldIsPrivateChat {
|
if req.FieldType == constant.FieldIsPrivateChat {
|
||||||
err := c.ConversationDatabase.SyncPeerUserPrivateConversationTx(ctx, &conversation)
|
err := c.conversationDatabase.SyncPeerUserPrivateConversationTx(ctx, &conversation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ func (c *conversationServer) ModifyConversationField(ctx context.Context, req *p
|
|||||||
case constant.FieldBurnDuration:
|
case constant.FieldBurnDuration:
|
||||||
filedMap["burn_duration"] = req.Conversation.BurnDuration
|
filedMap["burn_duration"] = req.Conversation.BurnDuration
|
||||||
}
|
}
|
||||||
err = c.ConversationDatabase.SetUsersConversationFiledTx(ctx, req.UserIDList, &conversation, filedMap)
|
err = c.conversationDatabase.SetUsersConversationFiledTx(ctx, req.UserIDList, &conversation, filedMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ func (c *conversationServer) ModifyConversationField(ctx context.Context, req *p
|
|||||||
|
|
||||||
// 获取超级大群开启免打扰的用户ID
|
// 获取超级大群开启免打扰的用户ID
|
||||||
func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req *pbConversation.GetRecvMsgNotNotifyUserIDsReq) (*pbConversation.GetRecvMsgNotNotifyUserIDsResp, error) {
|
func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req *pbConversation.GetRecvMsgNotNotifyUserIDsReq) (*pbConversation.GetRecvMsgNotNotifyUserIDsResp, error) {
|
||||||
userIDs, err := c.ConversationDatabase.FindRecvMsgNotNotifyUserIDs(ctx, req.GroupID)
|
userIDs, err := c.conversationDatabase.FindRecvMsgNotNotifyUserIDs(ctx, req.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||||
|
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
|
||||||
@ -348,10 +349,21 @@ type Notification struct {
|
|||||||
BlackDeleted NotificationConf `yaml:"blackDeleted"`
|
BlackDeleted NotificationConf `yaml:"blackDeleted"`
|
||||||
FriendInfoUpdated NotificationConf `yaml:"friendInfoUpdated"`
|
FriendInfoUpdated NotificationConf `yaml:"friendInfoUpdated"`
|
||||||
//////////////////////conversation///////////////////////
|
//////////////////////conversation///////////////////////
|
||||||
ConversationOptUpdate NotificationConf `yaml:"conversationOptUpdate"`
|
ConversationChanged NotificationConf `yaml:"conversationChanged"`
|
||||||
ConversationSetPrivate NotificationConf `yaml:"conversationSetPrivate"`
|
ConversationSetPrivate NotificationConf `yaml:"conversationSetPrivate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetOptionsByNotification(cfg NotificationConf) utils.Options {
|
||||||
|
opts := utils.NewOptions()
|
||||||
|
if cfg.UnreadCount {
|
||||||
|
opts = utils.WithOptions(opts, utils.WithUnreadCount())
|
||||||
|
}
|
||||||
|
if cfg.OfflinePush.Enable {
|
||||||
|
opts = utils.WithOptions(opts, utils.WithOfflinePush())
|
||||||
|
}
|
||||||
|
return opts
|
||||||
|
}
|
||||||
|
|
||||||
func (c *config) unmarshalConfig(config interface{}, configPath string) error {
|
func (c *config) unmarshalConfig(config interface{}, configPath string) error {
|
||||||
bytes, err := ioutil.ReadFile(configPath)
|
bytes, err := ioutil.ReadFile(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -44,7 +44,7 @@ const (
|
|||||||
BlackDeletedNotification = 1208 //remove_black
|
BlackDeletedNotification = 1208 //remove_black
|
||||||
FriendInfoUpdatedNotification = 1209
|
FriendInfoUpdatedNotification = 1209
|
||||||
|
|
||||||
ConversationOptChangeNotification = 1300 // change conversation opt
|
ConversationChangeNotification = 1300 // change conversation opt
|
||||||
|
|
||||||
UserNotificationBegin = 1301
|
UserNotificationBegin = 1301
|
||||||
UserInfoUpdatedNotification = 1303 //SetSelfInfoTip = 204
|
UserInfoUpdatedNotification = 1303 //SetSelfInfoTip = 204
|
||||||
@ -142,6 +142,7 @@ const (
|
|||||||
IsSenderConversationUpdate = "senderConversationUpdate"
|
IsSenderConversationUpdate = "senderConversationUpdate"
|
||||||
IsSenderNotificationPush = "senderNotificationPush"
|
IsSenderNotificationPush = "senderNotificationPush"
|
||||||
IsReactionFromCache = "reactionFromCache"
|
IsReactionFromCache = "reactionFromCache"
|
||||||
|
IsNotification = "isNotification"
|
||||||
|
|
||||||
//GroupStatus
|
//GroupStatus
|
||||||
GroupOk = 0
|
GroupOk = 0
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
package rpcclient
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||||
|
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -9,30 +15,69 @@ type MetaClient struct {
|
|||||||
// contains filtered or unexported fields
|
// contains filtered or unexported fields
|
||||||
client discoveryregistry.SvcDiscoveryRegistry
|
client discoveryregistry.SvcDiscoveryRegistry
|
||||||
rpcRegisterName string
|
rpcRegisterName string
|
||||||
|
getUsersInfo func(ctx context.Context, userIDs []string) ([]CommonUser, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMetaClient(client discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string) *MetaClient {
|
func NewMetaClient(client discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string, opts ...MetaClientOptions) *MetaClient {
|
||||||
return &MetaClient{
|
c := &MetaClient{
|
||||||
client: client,
|
client: client,
|
||||||
rpcRegisterName: rpcRegisterName,
|
rpcRegisterName: rpcRegisterName,
|
||||||
}
|
}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(c)
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
type MetaClientOptions func(*MetaClient)
|
||||||
|
|
||||||
|
func WithDBFunc(fn func(ctx context.Context, userIDs []string) (users []*relationTb.UserModel, err error)) MetaClientOptions {
|
||||||
|
return func(s *MetaClient) {
|
||||||
|
f := func(ctx context.Context, userIDs []string) (result []CommonUser, err error) {
|
||||||
|
users, err := fn(ctx, userIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, user := range users {
|
||||||
|
result = append(result, user)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
s.getUsersInfo = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithRpcFunc(fn func(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error)) MetaClientOptions {
|
||||||
|
return func(s *MetaClient) {
|
||||||
|
f := func(ctx context.Context, userIDs []string) (result []CommonUser, err error) {
|
||||||
|
users, err := fn(ctx, userIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, user := range users {
|
||||||
|
result = append(result, user)
|
||||||
|
}
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
s.getUsersInfo = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MetaClient) getFaceURLAndName(userID string) (faceURL, nickname string, err error) {
|
||||||
|
users, err := m.getUsersInfo(context.Background(), []string{userID})
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
if len(users) == 0 {
|
||||||
|
return "", "", errs.ErrRecordNotFound.Wrap(fmt.Sprintf("notification user %s not found", userID))
|
||||||
|
}
|
||||||
|
return users[0].GetFaceURL(), users[0].GetNickname(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MetaClient) getConn() (*grpc.ClientConn, error) {
|
func (m *MetaClient) getConn() (*grpc.ClientConn, error) {
|
||||||
return m.client.GetConn(m.rpcRegisterName)
|
return m.client.GetConn(m.rpcRegisterName)
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotificationMsg struct {
|
|
||||||
SendID string
|
|
||||||
RecvID string
|
|
||||||
Content []byte
|
|
||||||
MsgFrom int32
|
|
||||||
ContentType int32
|
|
||||||
SessionType int32
|
|
||||||
SenderNickname string
|
|
||||||
SenderFaceURL string
|
|
||||||
}
|
|
||||||
|
|
||||||
type CommonUser interface {
|
type CommonUser interface {
|
||||||
GetNickname() string
|
GetNickname() string
|
||||||
GetFaceURL() string
|
GetFaceURL() string
|
||||||
|
@ -2,6 +2,7 @@ package rpcclient
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
"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/constant"
|
||||||
@ -9,6 +10,7 @@ import (
|
|||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MsgClient struct {
|
type MsgClient struct {
|
||||||
@ -46,26 +48,29 @@ func (m *MsgClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMes
|
|||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MsgClient) Notification(ctx context.Context, notificationMsg *NotificationMsg) error {
|
func (c *MsgClient) Notification(ctx context.Context, sendID, recvID string, contentType, sessionType int32, m proto.Message, cfg config.NotificationConf, opts ...utils.OptionsOpt) error {
|
||||||
var err error
|
content, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
var req msg.SendMsgReq
|
var req msg.SendMsgReq
|
||||||
var msg sdkws.MsgData
|
var msg sdkws.MsgData
|
||||||
var offlineInfo sdkws.OfflinePushInfo
|
var offlineInfo sdkws.OfflinePushInfo
|
||||||
var title, desc, ex string
|
var title, desc, ex string
|
||||||
var pushEnable, unReadCount bool
|
msg.SendID = sendID
|
||||||
msg.SendID = notificationMsg.SendID
|
msg.RecvID = recvID
|
||||||
msg.RecvID = notificationMsg.RecvID
|
msg.Content = content
|
||||||
msg.Content = notificationMsg.Content
|
msg.MsgFrom = constant.SysMsgType
|
||||||
msg.MsgFrom = notificationMsg.MsgFrom
|
msg.ContentType = contentType
|
||||||
msg.ContentType = notificationMsg.ContentType
|
msg.SessionType = sessionType
|
||||||
msg.SessionType = notificationMsg.SessionType
|
|
||||||
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||||
msg.ClientMsgID = utils.GetMsgID(notificationMsg.SendID)
|
msg.ClientMsgID = utils.GetMsgID(sendID)
|
||||||
msg.Options = make(map[string]bool, 7)
|
// msg.Options = make(map[string]bool, 7)
|
||||||
msg.SenderNickname = notificationMsg.SenderNickname
|
// todo notification get sender name and face url
|
||||||
msg.SenderFaceURL = notificationMsg.SenderFaceURL
|
// msg.SenderNickname, msg.SenderFaceURL, err = c.getFaceURLAndName(sendID)
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, unReadCount)
|
options := config.GetOptionsByNotification(cfg)
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, pushEnable)
|
options = utils.WithOptions(options, opts...)
|
||||||
|
msg.Options = options
|
||||||
offlineInfo.Title = title
|
offlineInfo.Title = title
|
||||||
offlineInfo.Desc = desc
|
offlineInfo.Desc = desc
|
||||||
offlineInfo.Ex = ex
|
offlineInfo.Ex = ex
|
||||||
|
@ -2,13 +2,12 @@ package notification
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"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/constant"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
"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"
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConversationNotificationSender struct {
|
type ConversationNotificationSender struct {
|
||||||
@ -19,21 +18,6 @@ func NewConversationNotificationSender(client discoveryregistry.SvcDiscoveryRegi
|
|||||||
return &ConversationNotificationSender{rpcclient.NewMsgClient(client)}
|
return &ConversationNotificationSender{rpcclient.NewMsgClient(client)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConversationNotificationSender) SetConversationNotification(ctx context.Context, sendID, recvID string, contentType int, m proto.Message) {
|
|
||||||
var err error
|
|
||||||
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 = json.Marshal(m)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.Notification(ctx, &n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetPrivate调用
|
// SetPrivate调用
|
||||||
func (c *ConversationNotificationSender) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
|
func (c *ConversationNotificationSender) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
|
||||||
tips := &sdkws.ConversationSetPrivateTips{
|
tips := &sdkws.ConversationSetPrivateTips{
|
||||||
@ -41,7 +25,7 @@ func (c *ConversationNotificationSender) ConversationSetPrivateNotification(ctx
|
|||||||
SendID: sendID,
|
SendID: sendID,
|
||||||
IsPrivate: isPrivateChat,
|
IsPrivate: isPrivateChat,
|
||||||
}
|
}
|
||||||
c.SetConversationNotification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, tips)
|
c.Notification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, constant.SingleChatType, tips, config.Config.Notification.ConversationSetPrivate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 会话改变
|
// 会话改变
|
||||||
@ -49,7 +33,7 @@ func (c *ConversationNotificationSender) ConversationChangeNotification(ctx cont
|
|||||||
tips := &sdkws.ConversationUpdateTips{
|
tips := &sdkws.ConversationUpdateTips{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
}
|
}
|
||||||
c.SetConversationNotification(ctx, userID, userID, constant.ConversationOptChangeNotification, tips)
|
c.Notification(ctx, userID, userID, constant.ConversationChangeNotification, constant.SingleChatType, tips, config.Config.Notification.ConversationChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 会话未读数同步
|
// 会话未读数同步
|
||||||
@ -59,5 +43,5 @@ func (c *ConversationNotificationSender) ConversationUnreadChangeNotification(ct
|
|||||||
ConversationIDList: []string{conversationID},
|
ConversationIDList: []string{conversationID},
|
||||||
UpdateUnreadCountTime: updateUnreadCountTime,
|
UpdateUnreadCountTime: updateUnreadCountTime,
|
||||||
}
|
}
|
||||||
c.SetConversationNotification(ctx, userID, userID, constant.ConversationUnreadNotification, tips)
|
c.Notification(ctx, userID, userID, constant.ConversationUnreadNotification, constant.SingleChatType, tips, config.Config.Notification.ConversationChanged)
|
||||||
}
|
}
|
||||||
|
@ -1 +1,150 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
|
import "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||||
|
|
||||||
|
type Options map[string]bool
|
||||||
|
type OptionsOpt func(Options)
|
||||||
|
|
||||||
|
func NewOptions(opts ...OptionsOpt) Options {
|
||||||
|
options := make(map[string]bool, 11)
|
||||||
|
options[constant.IsNotification] = false
|
||||||
|
options[constant.IsHistory] = false
|
||||||
|
options[constant.IsPersistent] = false
|
||||||
|
options[constant.IsOfflinePush] = false
|
||||||
|
options[constant.IsUnreadCount] = false
|
||||||
|
options[constant.IsConversationUpdate] = false
|
||||||
|
options[constant.IsSenderSync] = false
|
||||||
|
options[constant.IsNotPrivate] = false
|
||||||
|
options[constant.IsSenderConversationUpdate] = false
|
||||||
|
options[constant.IsSenderNotificationPush] = false
|
||||||
|
options[constant.IsReactionFromCache] = false
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(options)
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithOptions(options Options, opts ...OptionsOpt) Options {
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(options)
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithNotification() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsNotification] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithHistory() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsHistory] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithPersistent() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsPersistent] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithOfflinePush() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsOfflinePush] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithUnreadCount() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsUnreadCount] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithConversationUpdate() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsConversationUpdate] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithSenderSync() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsSenderSync] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithNotPrivate() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsNotPrivate] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithSenderConversationUpdate() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsSenderConversationUpdate] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithSenderNotificationPush() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsSenderNotificationPush] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithReactionFromCache() OptionsOpt {
|
||||||
|
return func(options Options) {
|
||||||
|
options[constant.IsReactionFromCache] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) Is(notification string) bool {
|
||||||
|
v, ok := o[notification]
|
||||||
|
if !ok || v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsNotification() bool {
|
||||||
|
return o.Is(constant.IsNotification)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsHistory(options Options) bool {
|
||||||
|
return o.Is(constant.IsHistory)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsPersistent(options Options) bool {
|
||||||
|
return o.Is(constant.IsPersistent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsOfflinePush(options Options) bool {
|
||||||
|
return o.Is(constant.IsOfflinePush)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsUnreadCount(options Options) bool {
|
||||||
|
return o.Is(constant.IsUnreadCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsConversationUpdate(options Options) bool {
|
||||||
|
return o.Is(constant.IsConversationUpdate)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsSenderSync(options Options) bool {
|
||||||
|
return o.Is(constant.IsSenderSync)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsNotPrivate(options Options) bool {
|
||||||
|
return o.Is(constant.IsNotPrivate)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsSenderConversationUpdate(options Options) bool {
|
||||||
|
return o.Is(constant.IsSenderConversationUpdate)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsSenderNotificationPush(options Options) bool {
|
||||||
|
return o.Is(constant.IsSenderNotificationPush)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o Options) IsReactionFromCache(options Options) bool {
|
||||||
|
return o.Is(constant.IsReactionFromCache)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user