Replace numbers in meta messages with vcard name. This enriches calls, security code changes, user mutations in groups, etc.

This commit is contained in:
lifnej
2025-10-02 15:38:05 +02:00
parent a4318aca89
commit 695e45f573

View File

@@ -23,10 +23,18 @@ class ContactsFromVCards:
if len(number) <= 5:
continue
for chat in filter_chats_by_prefix(chats, number).values():
if not hasattr(chat, 'name') or (hasattr(chat, 'name') and (chat.name is None or chat.name == '')):
for k, chat in chats.items():
# enrich filename with name
if k.startswith(number) and (
not hasattr(chat, 'name') or (hasattr(chat, 'name') and (chat.name is None or chat.name == ''))):
setattr(chat, 'name', name)
for message in chat.values(): # or {}:
# replace numbers in meta messages (call, user added, security code..) with a name
if not message.media and message.meta and message.data and number in message.data:
# number has a leading or trailing space in data, might be safer to enforce this
message.data = message.data.replace(number + " ", name + " ").replace(" " + number, " " + name)
# skip short numbers like above
contact_map = {number: name for number, name in self.contact_mapping if len(number) > 5}