MCPcopy
hub / github.com/Alishahryar1/free-claude-code / _delete_message_ids

Function _delete_message_ids

messaging/commands.py:93–125  ·  view source on GitHub ↗

Best-effort delete messages by ID. Sorts numeric IDs descending.

(
    handler: MessagingCommandContext, chat_id: str, msg_ids: set[str]
)

Source from the content-addressed store, hash-verified

91
92
93async def _delete_message_ids(
94 handler: MessagingCommandContext, chat_id: str, msg_ids: set[str]
95) -> None:
96 """Best-effort delete messages by ID. Sorts numeric IDs descending."""
97 if not msg_ids:
98 return
99
100 def _as_int(s: str) -> int | None:
101 try:
102 return int(str(s))
103 except Exception:
104 return None
105
106 numeric: list[tuple[int, str]] = []
107 non_numeric: list[str] = []
108 for mid in msg_ids:
109 n = _as_int(mid)
110 if n is None:
111 non_numeric.append(mid)
112 else:
113 numeric.append((n, mid))
114 numeric.sort(reverse=True)
115 ordered = [mid for _, mid in numeric] + non_numeric
116
117 try:
118 CHUNK = 100
119 for i in range(0, len(ordered), CHUNK):
120 chunk = ordered[i : i + CHUNK]
121 await handler.outbound.queue_delete_messages(
122 chat_id, chunk, fire_and_forget=False
123 )
124 except Exception as e:
125 logger.debug(f"Batch delete failed: {type(e).__name__}: {e}")
126
127
128async def _handle_clear_branch(

Callers 2

_handle_clear_branchFunction · 0.85
handle_clear_commandFunction · 0.85

Calls 3

_as_intFunction · 0.85
appendMethod · 0.45
queue_delete_messagesMethod · 0.45

Tested by

no test coverage detected