|
|
@ -71,6 +71,8 @@ type ConversationDatabase interface {
|
|
|
|
GetOwnerConversation(ctx context.Context, ownerUserID string, pagination pagination.Pagination) (int64, []*relationtb.Conversation, error)
|
|
|
|
GetOwnerConversation(ctx context.Context, ownerUserID string, pagination pagination.Pagination) (int64, []*relationtb.Conversation, error)
|
|
|
|
// GetNotNotifyConversationIDs gets not notify conversationIDs by userID
|
|
|
|
// GetNotNotifyConversationIDs gets not notify conversationIDs by userID
|
|
|
|
GetNotNotifyConversationIDs(ctx context.Context, userID string) ([]string, error)
|
|
|
|
GetNotNotifyConversationIDs(ctx context.Context, userID string) ([]string, error)
|
|
|
|
|
|
|
|
// GetPinnedConversationIDs gets pinned conversationIDs by userID
|
|
|
|
|
|
|
|
GetPinnedConversationIDs(ctx context.Context, userID string) ([]string, error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewConversationDatabase(conversation database.Conversation, cache cache.ConversationCache, tx tx.Tx) ConversationDatabase {
|
|
|
|
func NewConversationDatabase(conversation database.Conversation, cache cache.ConversationCache, tx tx.Tx) ConversationDatabase {
|
|
|
@ -112,6 +114,9 @@ func (c *conversationDatabase) SetUsersConversationFieldTx(ctx context.Context,
|
|
|
|
cache = cache.DelConversationNotReceiveMessageUserIDs(conversation.ConversationID)
|
|
|
|
cache = cache.DelConversationNotReceiveMessageUserIDs(conversation.ConversationID)
|
|
|
|
cache = cache.DelConversationNotNotifyMessageUserIDs(userIDs...)
|
|
|
|
cache = cache.DelConversationNotNotifyMessageUserIDs(userIDs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := fieldMap["is_pinned"]; ok {
|
|
|
|
|
|
|
|
cache = cache.DelConversationPinnedMessageUserIDs(userIDs...)
|
|
|
|
|
|
|
|
}
|
|
|
|
cache = cache.DelConversationVersionUserIDs(haveUserIDs...)
|
|
|
|
cache = cache.DelConversationVersionUserIDs(haveUserIDs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NotUserIDs := stringutil.DifferenceString(haveUserIDs, userIDs)
|
|
|
|
NotUserIDs := stringutil.DifferenceString(haveUserIDs, userIDs)
|
|
|
@ -149,6 +154,9 @@ func (c *conversationDatabase) UpdateUsersConversationField(ctx context.Context,
|
|
|
|
cache = cache.DelConversationNotReceiveMessageUserIDs(conversationID)
|
|
|
|
cache = cache.DelConversationNotReceiveMessageUserIDs(conversationID)
|
|
|
|
cache = cache.DelConversationNotNotifyMessageUserIDs(userIDs...)
|
|
|
|
cache = cache.DelConversationNotNotifyMessageUserIDs(userIDs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := args["is_pinned"]; ok {
|
|
|
|
|
|
|
|
cache = cache.DelConversationPinnedMessageUserIDs(userIDs...)
|
|
|
|
|
|
|
|
}
|
|
|
|
return cache.ChainExecDel(ctx)
|
|
|
|
return cache.ChainExecDel(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -159,6 +167,7 @@ func (c *conversationDatabase) CreateConversation(ctx context.Context, conversat
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
userIDs []string
|
|
|
|
userIDs []string
|
|
|
|
notNotifyUserIDs []string
|
|
|
|
notNotifyUserIDs []string
|
|
|
|
|
|
|
|
pinnedUserIDs []string
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
cache := c.cache.CloneConversationCache()
|
|
|
|
cache := c.cache.CloneConversationCache()
|
|
|
@ -169,9 +178,16 @@ func (c *conversationDatabase) CreateConversation(ctx context.Context, conversat
|
|
|
|
if conversation.RecvMsgOpt == constant.ReceiveNotNotifyMessage {
|
|
|
|
if conversation.RecvMsgOpt == constant.ReceiveNotNotifyMessage {
|
|
|
|
notNotifyUserIDs = append(notNotifyUserIDs, conversation.OwnerUserID)
|
|
|
|
notNotifyUserIDs = append(notNotifyUserIDs, conversation.OwnerUserID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if conversation.IsPinned == true {
|
|
|
|
|
|
|
|
pinnedUserIDs = append(pinnedUserIDs, conversation.OwnerUserID)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cache.DelConversationIDs(userIDs...).DelUserConversationIDsHash(userIDs...).DelConversationVersionUserIDs(userIDs...).
|
|
|
|
return cache.DelConversationIDs(userIDs...).
|
|
|
|
DelConversationNotNotifyMessageUserIDs(notNotifyUserIDs...).ChainExecDel(ctx)
|
|
|
|
DelUserConversationIDsHash(userIDs...).
|
|
|
|
|
|
|
|
DelConversationVersionUserIDs(userIDs...).
|
|
|
|
|
|
|
|
DelConversationNotNotifyMessageUserIDs(notNotifyUserIDs...).
|
|
|
|
|
|
|
|
DelConversationPinnedMessageUserIDs(pinnedUserIDs...).
|
|
|
|
|
|
|
|
ChainExecDel(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *conversationDatabase) SyncPeerUserPrivateConversationTx(ctx context.Context, conversations []*relationtb.Conversation) error {
|
|
|
|
func (c *conversationDatabase) SyncPeerUserPrivateConversationTx(ctx context.Context, conversations []*relationtb.Conversation) error {
|
|
|
@ -224,7 +240,9 @@ func (c *conversationDatabase) GetUserAllConversation(ctx context.Context, owner
|
|
|
|
func (c *conversationDatabase) SetUserConversations(ctx context.Context, ownerUserID string, conversations []*relationtb.Conversation) error {
|
|
|
|
func (c *conversationDatabase) SetUserConversations(ctx context.Context, ownerUserID string, conversations []*relationtb.Conversation) error {
|
|
|
|
return c.tx.Transaction(ctx, func(ctx context.Context) error {
|
|
|
|
return c.tx.Transaction(ctx, func(ctx context.Context) error {
|
|
|
|
cache := c.cache.CloneConversationCache()
|
|
|
|
cache := c.cache.CloneConversationCache()
|
|
|
|
cache = cache.DelConversationVersionUserIDs(ownerUserID).DelConversationNotNotifyMessageUserIDs(ownerUserID)
|
|
|
|
cache = cache.DelConversationVersionUserIDs(ownerUserID).
|
|
|
|
|
|
|
|
DelConversationNotNotifyMessageUserIDs(ownerUserID).
|
|
|
|
|
|
|
|
DelConversationPinnedMessageUserIDs(ownerUserID)
|
|
|
|
|
|
|
|
|
|
|
|
groupIDs := datautil.Distinct(datautil.Filter(conversations, func(e *relationtb.Conversation) (string, bool) {
|
|
|
|
groupIDs := datautil.Distinct(datautil.Filter(conversations, func(e *relationtb.Conversation) (string, bool) {
|
|
|
|
return e.GroupID, e.GroupID != ""
|
|
|
|
return e.GroupID, e.GroupID != ""
|
|
|
@ -374,3 +392,11 @@ func (c *conversationDatabase) GetNotNotifyConversationIDs(ctx context.Context,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return conversationIDs, nil
|
|
|
|
return conversationIDs, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *conversationDatabase) GetPinnedConversationIDs(ctx context.Context, userID string) ([]string, error) {
|
|
|
|
|
|
|
|
conversationIDs, err := c.cache.GetPinnedConversationIDs(ctx, userID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return conversationIDs, nil
|
|
|
|
|
|
|
|
}
|
|
|
|