Kaynağa Gözat

db/puppet: add contact_info_set flag

Signed-off-by: Sumner Evans <sumner@beeper.com>
Sumner Evans 2 yıl önce
ebeveyn
işleme
df4d44a57b

+ 11 - 9
mautrix_signal/db/puppet.py

@@ -40,6 +40,7 @@ class Puppet:
     avatar_url: ContentURI | None
     name_set: bool
     avatar_set: bool
+    contact_info_set: bool
     is_registered: bool
 
     custom_mxid: UserID | None
@@ -62,6 +63,7 @@ class Puppet:
             self.avatar_url,
             self.name_set,
             self.avatar_set,
+            self.contact_info_set,
             self.is_registered,
             self.custom_mxid,
             self.access_token,
@@ -79,9 +81,9 @@ class Puppet:
     async def insert(self) -> None:
         q = """
         INSERT INTO puppet (uuid, number, name, name_quality, avatar_hash, avatar_url,
-                            name_set, avatar_set, is_registered,
+                            name_set, avatar_set, contact_info_set, is_registered,
                             custom_mxid, access_token, next_batch, base_url)
-        VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
+        VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
         """
         async with self.db.acquire() as conn, conn.transaction():
             await self._delete_existing_number(conn)
@@ -96,8 +98,8 @@ class Puppet:
         q = """
         UPDATE puppet
         SET number=$2, name=$3, name_quality=$4, avatar_hash=$5, avatar_url=$6,
-            name_set=$7, avatar_set=$8, is_registered=$9,
-            custom_mxid=$10, access_token=$11, next_batch=$12, base_url=$13
+            name_set=$7, avatar_set=$8, contact_info_set=$9, is_registered=$10,
+            custom_mxid=$11, access_token=$12, next_batch=$13, base_url=$14
         WHERE uuid=$1
         """
         await self.db.execute(q, *self._values)
@@ -111,11 +113,11 @@ class Puppet:
         base_url = URL(base_url_str) if base_url_str is not None else None
         return cls(base_url=base_url, **data)
 
-    _select_base = (
-        "SELECT uuid, number, name, name_quality, avatar_hash, avatar_url, name_set, avatar_set, "
-        "       is_registered, custom_mxid, access_token, next_batch, base_url "
-        "FROM puppet"
-    )
+    _select_base = """
+        SELECT uuid, number, name, name_quality, avatar_hash, avatar_url, name_set, avatar_set,
+               contact_info_set, is_registered, custom_mxid, access_token, next_batch, base_url
+        FROM puppet
+    """
 
     @classmethod
     async def get_by_uuid(cls, uuid: UUID) -> Puppet | None:

+ 1 - 0
mautrix_signal/db/upgrade/__init__.py

@@ -14,4 +14,5 @@ from . import (
     v09_group_topic,
     v10_puppet_name_quality,
     v11_drop_number_support,
+    v12_add_contact_info_to_puppet,
 )

+ 10 - 9
mautrix_signal/db/upgrade/v00_latest_revision.py

@@ -18,7 +18,7 @@ from mautrix.util.async_db import Connection
 from . import upgrade_table
 
 
-@upgrade_table.register(description="Initial revision", upgrades_to=11)
+@upgrade_table.register(description="Initial revision", upgrades_to=12)
 async def upgrade_latest(conn: Connection) -> None:
     await conn.execute(
         """CREATE TABLE portal (
@@ -49,14 +49,15 @@ async def upgrade_latest(conn: Connection) -> None:
     )
     await conn.execute(
         """CREATE TABLE puppet (
-            uuid         UUID PRIMARY KEY,
-            number       TEXT UNIQUE,
-            name         TEXT,
-            name_quality INTEGER NOT NULL DEFAULT 0,
-            avatar_hash  TEXT,
-            avatar_url   TEXT,
-            name_set     BOOLEAN NOT NULL DEFAULT false,
-            avatar_set   BOOLEAN NOT NULL DEFAULT false,
+            uuid             UUID PRIMARY KEY,
+            number           TEXT UNIQUE,
+            name             TEXT,
+            name_quality     INTEGER NOT NULL DEFAULT 0,
+            avatar_hash      TEXT,
+            avatar_url       TEXT,
+            name_set         BOOLEAN NOT NULL DEFAULT false,
+            avatar_set       BOOLEAN NOT NULL DEFAULT false,
+            contact_info_set BOOLEAN NOT NULL DEFAULT false,
 
             is_registered BOOLEAN NOT NULL DEFAULT false,
 

+ 25 - 0
mautrix_signal/db/upgrade/v12_add_contact_info_to_puppet.py

@@ -0,0 +1,25 @@
+# mautrix-signal - A Matrix-Signal puppeting bridge
+# Copyright (C) 2022 Tulir Asokan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+from mautrix.util.async_db import Connection
+
+from . import upgrade_table
+
+
+@upgrade_table.register(description="Add contact_info_set flag to puppet")
+async def upgrade_v12(conn: Connection) -> None:
+    await conn.execute(
+        "ALTER TABLE puppet ADD COLUMN contact_info_set BOOLEAN NOT NULL DEFAULT false"
+    )

+ 2 - 0
mautrix_signal/puppet.py

@@ -78,6 +78,7 @@ class Puppet(DBPuppet, BasePuppet):
         avatar_hash: str | None = None,
         name_set: bool = False,
         avatar_set: bool = False,
+        contact_info_set: bool = False,
         is_registered: bool = False,
         custom_mxid: UserID | None = None,
         access_token: str | None = None,
@@ -95,6 +96,7 @@ class Puppet(DBPuppet, BasePuppet):
             avatar_hash=avatar_hash,
             name_set=name_set,
             avatar_set=avatar_set,
+            contact_info_set=contact_info_set,
             is_registered=is_registered,
             custom_mxid=custom_mxid,
             access_token=access_token,