ソースを参照

Add hacky option to detect potential contact name mixup

Tulir Asokan 2 年 前
コミット
12d1b652df
3 ファイル変更17 行追加1 行削除
  1. 1 0
      mautrix_signal/config.py
  2. 1 0
      mautrix_signal/example-config.yaml
  3. 15 1
      mautrix_signal/user.py

+ 1 - 0
mautrix_signal/config.py

@@ -65,6 +65,7 @@ class Config(BaseBridgeConfig):
         copy("bridge.double_puppet_server_map")
         copy("bridge.double_puppet_allow_discovery")
         copy("bridge.create_group_on_invite")
+        copy("bridge.hacky_contact_name_mixup_detection")
         if self["bridge.login_shared_secret"]:
             base["bridge.login_shared_secret_map"] = {
                 base["homeserver.domain"]: self["bridge.login_shared_secret"]

+ 1 - 0
mautrix_signal/example-config.yaml

@@ -237,6 +237,7 @@ bridge:
     # Should the bridge auto-create a group chat on Signal when a ghost is invited to a room?
     # Requires the user to have sufficient power level and double puppeting enabled.
     create_group_on_invite: true
+    hacky_contact_name_mixup_detection: false
 
     # Provisioning API part of the web server for automated portal creation and fetching information.
     # Used by things like mautrix-manager (https://github.com/tulir/mautrix-manager).

+ 15 - 1
mautrix_signal/user.py

@@ -372,9 +372,23 @@ class User(DBUser, BaseUser):
         elif portal.mxid:
             await portal.update_matrix_room(self, group)
 
+    async def _hacky_duplicate_contact_check(self, contacts: list[Profile]) -> None:
+        name_map: dict[str, list[Profile]] = {}
+        for contact in contacts:
+            if contact.contact_name:
+                name_map.setdefault(contact.contact_name, []).append(contact)
+        duplicates = {name: profiles for name, profiles in name_map.items() if len(profiles) > 1}
+        if duplicates:
+            self.log.warning(f"Found duplicate contact names, potential name mixup: {duplicates}")
+        else:
+            self.log.debug("No duplicate contact names found")
+
     async def _sync_contacts(self) -> None:
         create_contact_portal = self.config["bridge.autocreate_contact_portal"]
-        for contact in await self.bridge.signal.list_contacts(self.username):
+        contacts = await self.bridge.signal.list_contacts(self.username)
+        if self.config["bridge.hacky_contact_name_mixup_detection"]:
+            await self._hacky_duplicate_contact_check(contacts)
+        for contact in contacts:
             try:
                 await self.sync_contact(contact, create_contact_portal)
             except Exception: