Skip to content

feat: delete messages on ban#93

Merged
toto04 merged 3 commits intomainfrom
delete-on-ban
Apr 11, 2026
Merged

feat: delete messages on ban#93
toto04 merged 3 commits intomainfrom
delete-on-ban

Conversation

@toto04
Copy link
Copy Markdown
Contributor

@toto04 toto04 commented Apr 11, 2026

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d7103a22-4cfa-4e06-a4d6-66efc7f4b0a8

📥 Commits

Reviewing files that changed from the base of the PR and between d82a59c and d3f1bc6.

📒 Files selected for processing (1)
  • src/modules/moderation/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/modules/moderation/index.ts

Walkthrough

Updated @polinetwork/backend to ^0.15.9. Extended moderation BAN flow to best-effort sync message storage, fetch up to 100 of the target user's recent messages in the chat, delete those messages, and perform the ban with revoke_messages: true, running fetch/delete concurrently with the ban call.

Changes

Cohort / File(s) Summary
Dependency Update
package.json
Bumped @polinetwork/backend from ^0.15.8 to ^0.15.9.
Moderation BAN flow
src/modules/moderation/index.ts
Added private deleteLastMessages(userId, chatId) helper that syncs MessageUserStorage, queries up to 100 last messages via api.tg.messages.getLastByUser (errors -> []), and best-effort deletes them via modules.shared.api.deleteMessages (errors ignored). Updated "BAN" case to run banChatMember(..., { revoke_messages: true, until_date: ... }) concurrently with deleteLastMessages(...) and return the ban result.

Sequence Diagram

sequenceDiagram
    actor Admin
    participant Mod as Moderation Module
    participant MStorage as MessageUserStorage
    participant TG as Telegram API
    participant Shared as Shared API

    Admin->>Mod: request BAN(target, chat, duration)
    Mod->>MStorage: sync() (best-effort)
    alt sync OK / error ignored
        MStorage-->>Mod: sync complete
    end
    Mod->>TG: getLastByUser(target, chat, limit=100) (errors -> [])
    TG-->>Mod: messages[]
    Mod->>Shared: deleteMessages(messages[]) (best-effort)
    Shared-->>Mod: deletion result (or error ignored)
    par
        Mod->>TG: banChatMember(target, { revoke_messages: true, until_date })
        TG-->>Mod: ban result (true/false)
    and
        Mod->>Mod: deleteLastMessages(...) runs concurrently
    end
    Mod-->>Admin: return ban result
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title 'feat: delete messages on ban' directly and clearly summarizes the main change: adding message deletion functionality when banning users.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/modules/moderation/index.ts`:
- Around line 157-184: Move the immediate ban to the front of the "BAN" case by
calling modules.shared.api.banChatMember(p.chat.id, p.target.id, {...}) first
(await its result or handle failure) and then kickoff the
MessageUserStorage.getInstance().sync(),
api.tg.messages.getLastByUser.query(...), and
modules.shared.api.deleteMessages(...) as best-effort asynchronous work (do not
block the ban); replace the empty .catch(() => {}) handlers with logging of
errors (use the existing logger) so failures are recorded rather than silently
swallowed, and ensure deleteMessages uses the messages map as currently
implemented but runs after the ban without delaying it.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9d6f12e1-0d4b-457a-bba0-c8ce930fe37a

📥 Commits

Reviewing files that changed from the base of the PR and between cb4f2dc and d82a59c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json
  • src/modules/moderation/index.ts

Comment thread src/modules/moderation/index.ts
@toto04 toto04 enabled auto-merge (squash) April 11, 2026 19:07
@toto04 toto04 merged commit eb431ea into main Apr 11, 2026
2 checks passed
@toto04 toto04 deleted the delete-on-ban branch April 11, 2026 19:08
@coderabbitai coderabbitai Bot mentioned this pull request Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants