Repository navigation
Conversation
In private chats and basic groups messages.deleteMessages takes bare ids and Telethon drops the peer, so a wrong id or a range in a DM deleted messages in other chats, for both sides. Fetch the ids back through the peer first: a typed id that is not a message of the chat is refused and nothing is deleted, ids that only came from a range are skipped and listed in skipped. call log delete checks every chat before deleting anything. Channels and supergroups are unchanged.
…ountry e164() prefixed + to any digits, so an Iranian 9123456789 typed without its trunk 0 became +91 (India) and a US 2125551234 became +212 (Morocco), and the lookup or import reached a stranger. Add a strict parse_e164 for user input (leading +, country code not starting with 0, 7 to 15 digits, separators, direction marks and Persian digits tolerated) and use it in resolve phone, contact add/remove --phone and +phone peer refs. vCard and CSV import and sync skip rows they cannot read and list them in rejected; sync --delete-missing --apply refuses when a row was rejected. e164() stays for phones the server returns.
tl_entities built MessageEntityFormattedDate without its required date, the constructor raised TypeError and the entity was dropped silently, and the read side dropped the date and flags too. MessageEntity gains date, date_unix and the six display flags; tl_entities passes them (a date chip without a date is now a USAGE error, not a silent drop), received entities keep them, and every place that copies an entity uses structs.replace so new fields are not lost when text is split or shifted.
… failed unban A kick is ban then unban, and the unban cleared any ban already in place, so kicking a banned user let them back in. In a channel or supergroup the member is now looked up first: an already banned user stays banned and a non-member is left alone (already: true). Naming this account is refused before anyone is removed. The ban and unban run under asyncio.shield, and a failed unban raises an error under the cause's code saying the user is now banned, with the unban command.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #59
What was wrong
Line numbers at 2f303da.
message deletecould delete messages in other chats.tlgr/ops/message.py:1637calledclient.delete_messages(peer, ids, revoke=revoke). For a private chat or basic group Telethon sendsmessages.deleteMessages(id=[...])with no peer, and those ids are account-wide, so a wrong id deleted a message in whatever chat held it, for both sides (revoke is the default). Ranges (message delete @alice 100-120) made it likely: in a DM most ids in a range belong to other DMs.tlgr/ops/call.py:1591(call log delete) had the same shape.e164()(tlgr/ops/contact.py:133) prefixed+to any digits, so9123456789(an Iranian mobile without its trunk 0) became +91 India and2125551234became +212 Morocco. It was used for user input inresolve phone(tlgr/ops/resolve.py:331),contact add --phone(contact.py:776),contact remove --phone(contact.py:950) and vCard/CSVimport/sync(contact.py:411,:426).+phonepeer refs (tlgr/models/peer.py:341) accepted+0....tl_entities(tlgr/ops/_send.py:189) builtMessageEntityFormattedDate(offset, length)without the requireddate; theTypeErrorwas swallowed at:217.message_entities(tlgr/ops/_serialize.py:342) dropped the date and flags on read, and four places that copy aMessageEntityfield by field would have dropped them again.chat member removecould lift a ban.tlgr/ops/chat_member.py:573banned then unbanned (:605) with no membership check, so kicking an already banned user unbanned them. There was no self guard, a cancel between the two calls could leave the ban in place, and a failed unban surfaced as a bare RPC error.Changes
ops/_common.py:ids_outside_chat()fetches the ids back through the peer (get_messagesreturns None for an id from another chat, 100 per call, paced by thebulkbucket) and returns the ones that are not messages of the chat. Channels and supergroups are skipped.message deleterefuses typed ids that are not in the chat (NOT_FOUND naming them, nothing deleted). Ids that only came from a range are skipped and listed in a newskippedfield, with a warning.call log deletechecks every chat before deleting anything. Scheduled deletes are per peer and unchanged.models/peer.py:parse_e164()for typed numbers. It needs a leading+, a country code that does not start with 0, and 7 to 15 digits. Spaces, dots, brackets, dashes, RTL direction marks and Persian/Arabic-Indic digits are tolerated.0912...,00 98...,8 999...and bare digits are refused, and the message says how to write the number. Used byresolve phone,contact add/remove --phone(remove checks every number before deleting anything) and+phonepeer refs.e164()stays, documented as the formatter for phones the server returns (and for contact cards inside messages).rejectedlist (line, value, name, reason) with a warning; the rest still import. A file with no usable rows is a USAGE error that names the rejected lines. vCard 4tel:values are accepted.contact sync --delete-missing --applyrefuses when any row was rejected, because a skipped0912...row may be exactly the+98912...contact the diff would delete (deleteByPhones is irreversible).MessageEntitygainsdate,date_unixand the six display flags (relative,short_time,long_time,short_date,long_date,day_of_week). These match Telethon 1.44'sMessageEntityFormattedDate(offset, length, date, ...). On send,date_unixordate(anythingparse_dttakes) is passed. Aformatted_datewithout a date is a USAGE error, not a silent drop. On read,core.text.entity_from_tlkeeps them, and_serialize.message_entitiesnow uses it. The copy sites (split_text, spoiler shifting,_recount) usemsgspec.structs.replace, so a future field is not lost either.chat member remove: every named user is checked against this account before anyone is removed (refused with "runtlgr chat leave"). In a channel or supergroup the member is looked up first: someone already banned stays banned and someone not in the chat is left alone (removed: false, already: true).--purge/--messages/--reportstill apply. Ban plus unban run underasyncio.shield. A failed unban raises under the cause's code (for example RATE_LIMITED withwait_seconds), says the user is now BANNED, lists who was removed before, and hints thechat member unbancommand.delete_messagesnow models Telegram's account-wide id space for non-channel peers, and call log entries also live in the DM history.Tests
test_ops_message::test_delete_refuses_an_id_from_another_private_chattest_ops_message::test_delete_in_a_basic_group_checks_ids_tootest_ops_message::test_a_range_skips_ids_that_belong_to_other_chats102-105where 104 is Bob'stest_ops_message::test_a_channel_delete_is_not_checkedtest_ops_call::test_a_row_naming_another_chats_message_is_refusedcall log deletewith a foreign rowtest_models::TestParseE164(17 cases)test_models::test_a_phone_ref_with_a_zero_country_code_is_refused+0912...peer reftest_ops_contacts::test_a_phone_without_a_plus_is_refused_before_any_lookupresolve phone 912 345 6789looked up as +91test_ops_contacts::test_a_phone_without_a_country_code_is_refused_not_guessedcontact add --phone 2125551234imports +212test_ops_contacts::test_a_local_phone_is_refused_before_anything_is_deletedcontact removewith a local numbertest_ops_contacts::test_a_local_number_is_reported_and_the_rest_importedtest_ops_contacts::test_a_vcard_with_only_a_local_number_is_rejected0912..., plus a vCard 4tel:valuetest_ops_contacts::test_a_file_of_only_local_numbers_is_a_usage_errortest_ops_contacts::test_sync_refuses_to_delete_when_a_row_was_rejected--delete-missing --applywith an unreadable rowtest_ops_message::test_a_formatted_date_entity_is_sent_with_its_datebytes(entity)serialisestest_ops_message::test_a_formatted_date_entity_without_a_date_is_a_usage_errortest_ops_message::test_a_received_date_chip_keeps_its_datetest_text::test_a_date_chip_survives_json_and_splitssplit_texttest_ops_chat_admin::test_kicking_an_already_banned_user_does_not_unban_themtest_ops_chat_admin::test_kicking_a_non_member_changes_nothingtest_ops_chat_admin::test_kicking_yourself_is_refused_before_anyone_is_removedmein the list, Bob kicked firsttest_ops_chat_admin::test_kicking_yourself_by_username_is_refused_tootest_ops_chat_admin::test_a_failed_unban_says_the_user_is_now_bannedNot changed, and why
message thread disable(message.py:1396) deletes in the linked discussion group, which is always a supergroup, using an id the server returned. No cross-chat risk, so it is not checked.contact add --from-message) keep the lenient formatter: the number comes from the server, not from the caller.messages.deleteChatUser) are a true removal with no ban step, so they are unchanged.--date-chipconvenience flag from the report.--entitieswith aformatted_datenow works.Not verified
get_messages(peer, ids=...)returning None for an id from another chat. Telethon 1.44's_IDsIterdoes that by comparingpeer_id. A message deleted in the meantime also comes back None and is refused the same way.ENTITY_DATE_FORMAT_INVALIDfor bad ones). The flags are passed through as given.make check: pass (lint, typecheck, 13689 tests passed, docs, parity; coverage 84%)