@@ -78,6 +78,8 @@ type ConversationDatabase interface {
7878 GetPinnedConversationIDs (ctx context.Context , userID string ) ([]string , error )
7979 // FindRandConversation finds random conversations based on the specified timestamp and limit.
8080 FindRandConversation (ctx context.Context , ts int64 , limit int ) ([]* relationtb.Conversation , error )
81+
82+ DeleteUsersConversations (ctx context.Context , userID string , conversationIDs []string ) (err error )
8183}
8284
8385func NewConversationDatabase (conversation database.Conversation , cache cache.ConversationCache , tx tx.Tx ) ConversationDatabase {
@@ -120,7 +122,7 @@ func (c *conversationDatabase) SetUsersConversationFieldTx(ctx context.Context,
120122 cache = cache .DelConversationNotNotifyMessageUserIDs (userIDs ... )
121123 }
122124 if _ , ok := fieldMap ["is_pinned" ]; ok {
123- cache = cache .DelConversationPinnedMessageUserIDs (userIDs ... )
125+ cache = cache .DelUserPinnedConversations (userIDs ... )
124126 }
125127 cache = cache .DelConversationVersionUserIDs (haveUserIDs ... )
126128 }
@@ -172,7 +174,7 @@ func (c *conversationDatabase) UpdateUsersConversationField(ctx context.Context,
172174 cache = cache .DelConversationNotNotifyMessageUserIDs (userIDs ... )
173175 }
174176 if _ , ok := args ["is_pinned" ]; ok {
175- cache = cache .DelConversationPinnedMessageUserIDs (userIDs ... )
177+ cache = cache .DelUserPinnedConversations (userIDs ... )
176178 }
177179 return cache .ChainExecDel (ctx )
178180}
@@ -203,7 +205,7 @@ func (c *conversationDatabase) CreateConversation(ctx context.Context, conversat
203205 DelUserConversationIDsHash (userIDs ... ).
204206 DelConversationVersionUserIDs (userIDs ... ).
205207 DelConversationNotNotifyMessageUserIDs (notNotifyUserIDs ... ).
206- DelConversationPinnedMessageUserIDs (pinnedUserIDs ... ).
208+ DelUserPinnedConversations (pinnedUserIDs ... ).
207209 ChainExecDel (ctx )
208210}
209211
@@ -259,7 +261,7 @@ func (c *conversationDatabase) SetUserConversations(ctx context.Context, ownerUs
259261 cache := c .cache .CloneConversationCache ()
260262 cache = cache .DelConversationVersionUserIDs (ownerUserID ).
261263 DelConversationNotNotifyMessageUserIDs (ownerUserID ).
262- DelConversationPinnedMessageUserIDs (ownerUserID )
264+ DelUserPinnedConversations (ownerUserID )
263265
264266 groupIDs := datautil .Distinct (datautil .Filter (conversations , func (e * relationtb.Conversation ) (string , bool ) {
265267 return e .GroupID , e .GroupID != ""
@@ -429,3 +431,21 @@ func (c *conversationDatabase) GetPinnedConversationIDs(ctx context.Context, use
429431func (c * conversationDatabase ) FindRandConversation (ctx context.Context , ts int64 , limit int ) ([]* relationtb.Conversation , error ) {
430432 return c .conversationDB .FindRandConversation (ctx , ts , limit )
431433}
434+
435+ func (c * conversationDatabase ) DeleteUsersConversations (ctx context.Context , userID string , conversationIDs []string ) (err error ) {
436+ return c .tx .Transaction (ctx , func (ctx context.Context ) error {
437+ err = c .conversationDB .DeleteUsersConversations (ctx , userID , conversationIDs )
438+ if err != nil {
439+ return err
440+ }
441+ cache := c .cache .CloneConversationCache ()
442+ cache = cache .DelConversations (userID , conversationIDs ... ).
443+ DelConversationVersionUserIDs (userID ).
444+ DelConversationIDs (userID ).
445+ DelUserConversationIDsHash (userID ).
446+ DelConversationNotNotifyMessageUserIDs (userID ).
447+ DelUserPinnedConversations (userID )
448+
449+ return cache .ChainExecDel (ctx )
450+ })
451+ }
0 commit comments