浏览代码

Handle conflicting puppet rows when finding UUID. Fixes #82

Tulir Asokan 4 年之前
父节点
当前提交
c12508ac33
共有 2 个文件被更改,包括 4 次插入4 次删除
  1. 2 3
      mautrix_signal/db/puppet.py
  2. 2 1
      mautrix_signal/puppet.py

+ 2 - 3
mautrix_signal/db/puppet.py

@@ -62,10 +62,9 @@ class Puppet:
                               self.access_token, self.next_batch, self._base_url_str)
 
     async def _set_uuid(self, uuid: UUID) -> None:
-        if self.uuid:
-            raise ValueError("Can't re-set UUID for puppet")
-        self.uuid = uuid
         async with self.db.acquire() as conn, conn.transaction():
+            await conn.execute("DELETE FROM puppet WHERE uuid=$1 AND number<>$2",
+                               uuid, self.number)
             await conn.execute("UPDATE puppet SET uuid=$1 WHERE number=$2", uuid, self.number)
             uuid = str(uuid)
             await conn.execute("UPDATE portal SET chat_id=$1 WHERE chat_id=$2", uuid, self.number)

+ 2 - 1
mautrix_signal/puppet.py

@@ -130,8 +130,9 @@ class Puppet(DBPuppet, BasePuppet):
             user.uuid = self.uuid
             user.by_uuid[user.uuid] = user
             await user.update()
-        await self._set_uuid(uuid)
+        self.uuid = uuid
         self.by_uuid[self.uuid] = self
+        await self._set_uuid(uuid)
         async for portal in p.Portal.find_private_chats_with(Address(number=self.number)):
             self.log.trace(f"Updating chat_id of private chat portal {portal.receiver}")
             portal.handle_uuid_receive(self.uuid)