MCPcopy Index your code
hub / github.com/tinode/chat / delMsg

Function delMsg

tn-cli/commands.py:258–362  ·  view source on GitHub ↗
(id, cmd, ignored)

Source from the content-addressed store, hash-verified

256
257# {del}
258def delMsg(id, cmd, ignored):
259 if not cmd.what:
260 stdoutln("Must specify what to delete")
261 return None
262
263 enum_what = None
264 before = None
265 seq_list = None
266 cred = None
267 if cmd.what == 'msg':
268 enum_what = pb.ClientDel.MSG
269 cmd.topic = cmd.topic if cmd.topic else tn_globals.DefaultTopic
270 if not cmd.topic:
271 stdoutln("Must specify topic to delete messages")
272 return None
273 if cmd.user:
274 stdoutln("Unexpected '--user' parameter")
275 return None
276 if not cmd.seq:
277 stdoutln("Must specify message IDs to delete")
278 return None
279
280 if cmd.seq == 'all':
281 seq_list = [pb.SeqRange(low=1, hi=0x8FFFFFF)]
282 else:
283 # Split a list like '1,2,3,10-22' into ranges.
284 try:
285 seq_list = []
286 for item in cmd.seq.split(','):
287 if '-' in item:
288 low, hi = [int(x.strip()) for x in item.split('-')]
289 if low>=hi or low<=0:
290 stdoutln("Invalid message ID range {0}-{1}".format(low, hi))
291 return None
292 seq_list.append(pb.SeqRange(low=low, hi=hi))
293 else:
294 seq_list.append(pb.SeqRange(low=int(item.strip())))
295 except ValueError as err:
296 stdoutln("Invalid message IDs: {0}".format(err))
297 return None
298
299 elif cmd.what == 'sub':
300 cmd.topic = cmd.topic if cmd.topic else tn_globals.DefaultTopic
301 cmd.user = cmd.user if cmd.user else tn_globals.DefaultUser
302 if not cmd.user or not cmd.topic:
303 stdoutln("Must specify topic and user to delete subscription")
304 return None
305 enum_what = pb.ClientDel.SUB
306
307 elif cmd.what == 'topic':
308 cmd.topic = cmd.topic if cmd.topic else tn_globals.DefaultTopic
309 if cmd.user:
310 stdoutln("Unexpected '--user' parameter")
311 return None
312 if not cmd.topic:
313 stdoutln("Must specify topic to delete")
314 return None
315 enum_what = pb.ClientDel.TOPIC

Callers

nothing calls this directly

Calls 4

stdoutlnFunction · 0.90
parse_credFunction · 0.90
pack_extraFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…