fix(messages): sync preserve private dialogs after clearing history
This commit is contained in:
parent
3926db7762
commit
e22fac1c3f
19 changed files with 923 additions and 231 deletions
|
|
@ -35,42 +35,6 @@ func (q *Queries) AdvanceDialogReadInboxFloor(ctx context.Context, arg AdvanceDi
|
|||
return err
|
||||
}
|
||||
|
||||
const clearDialogAfterHistoryDelete = `-- name: ClearDialogAfterHistoryDelete :exec
|
||||
UPDATE dialogs d
|
||||
SET
|
||||
top_message_id = 0,
|
||||
top_message_date = 0,
|
||||
read_inbox_max_id = GREATEST(d.read_inbox_max_id, d.top_message_id),
|
||||
read_outbox_max_id = GREATEST(d.read_outbox_max_id, d.top_message_id),
|
||||
unread_count = 0,
|
||||
unread_mark = false,
|
||||
unread_mentions_count = 0,
|
||||
unread_reactions_count = (
|
||||
SELECT COUNT(*)::int
|
||||
FROM message_boxes m2
|
||||
WHERE m2.owner_user_id = d.user_id
|
||||
AND m2.peer_type = d.peer_type
|
||||
AND m2.peer_id = d.peer_id
|
||||
AND NOT m2.deleted
|
||||
AND m2.reaction_unread
|
||||
),
|
||||
updated_at = now()
|
||||
WHERE d.user_id = $1::bigint
|
||||
AND d.peer_type = $2::text
|
||||
AND d.peer_id = $3::bigint
|
||||
`
|
||||
|
||||
type ClearDialogAfterHistoryDeleteParams struct {
|
||||
UserID int64
|
||||
PeerType string
|
||||
PeerID int64
|
||||
}
|
||||
|
||||
func (q *Queries) ClearDialogAfterHistoryDelete(ctx context.Context, arg ClearDialogAfterHistoryDeleteParams) error {
|
||||
_, err := q.db.Exec(ctx, clearDialogAfterHistoryDelete, arg.UserID, arg.PeerType, arg.PeerID)
|
||||
return err
|
||||
}
|
||||
|
||||
const clearDialogDrafts = `-- name: ClearDialogDrafts :many
|
||||
WITH doomed AS (
|
||||
SELECT d.user_id, d.peer_type, d.peer_id, d.top_message_id
|
||||
|
|
|
|||
|
|
@ -886,12 +886,13 @@ WITH target AS (
|
|||
WHERE m.owner_user_id = $1::bigint
|
||||
AND m.peer_type = $2::text
|
||||
AND m.peer_id = $3::bigint
|
||||
AND ($4::int <= 0 OR m.box_id <= $4::int)
|
||||
AND ($5::int <= 0 OR m.message_date >= $5::int)
|
||||
AND ($6::int <= 0 OR m.message_date <= $6::int)
|
||||
AND ($4::int <= 0 OR m.box_id <> $4::int)
|
||||
AND ($5::int <= 0 OR m.box_id <= $5::int)
|
||||
AND ($6::int <= 0 OR m.message_date >= $6::int)
|
||||
AND ($7::int <= 0 OR m.message_date <= $7::int)
|
||||
AND NOT m.deleted
|
||||
ORDER BY m.box_id DESC
|
||||
LIMIT $7::int
|
||||
LIMIT $8::int
|
||||
FOR UPDATE SKIP LOCKED
|
||||
),
|
||||
updated AS (
|
||||
|
|
@ -923,6 +924,7 @@ type DeleteMessageBoxesByPeerBatchParams struct {
|
|||
OwnerUserID int64
|
||||
PeerType string
|
||||
PeerID int64
|
||||
KeepBoxID int32
|
||||
MaxID int32
|
||||
MinDate int32
|
||||
MaxDate int32
|
||||
|
|
@ -943,6 +945,7 @@ func (q *Queries) DeleteMessageBoxesByPeerBatch(ctx context.Context, arg DeleteM
|
|||
arg.OwnerUserID,
|
||||
arg.PeerType,
|
||||
arg.PeerID,
|
||||
arg.KeepBoxID,
|
||||
arg.MaxID,
|
||||
arg.MinDate,
|
||||
arg.MaxDate,
|
||||
|
|
@ -2108,9 +2111,10 @@ SELECT EXISTS (
|
|||
WHERE m.owner_user_id = $1::bigint
|
||||
AND m.peer_type = $2::text
|
||||
AND m.peer_id = $3::bigint
|
||||
AND ($4::int <= 0 OR m.box_id <= $4::int)
|
||||
AND ($5::int <= 0 OR m.message_date >= $5::int)
|
||||
AND ($6::int <= 0 OR m.message_date <= $6::int)
|
||||
AND ($4::int <= 0 OR m.box_id <> $4::int)
|
||||
AND ($5::int <= 0 OR m.box_id <= $5::int)
|
||||
AND ($6::int <= 0 OR m.message_date >= $6::int)
|
||||
AND ($7::int <= 0 OR m.message_date <= $7::int)
|
||||
AND NOT m.deleted
|
||||
LIMIT 1
|
||||
)::boolean AS more
|
||||
|
|
@ -2120,6 +2124,7 @@ type HasDeletableMessageBoxByPeerParams struct {
|
|||
OwnerUserID int64
|
||||
PeerType string
|
||||
PeerID int64
|
||||
KeepBoxID int32
|
||||
MaxID int32
|
||||
MinDate int32
|
||||
MaxDate int32
|
||||
|
|
@ -2130,6 +2135,7 @@ func (q *Queries) HasDeletableMessageBoxByPeer(ctx context.Context, arg HasDelet
|
|||
arg.OwnerUserID,
|
||||
arg.PeerType,
|
||||
arg.PeerID,
|
||||
arg.KeepBoxID,
|
||||
arg.MaxID,
|
||||
arg.MinDate,
|
||||
arg.MaxDate,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue