Add proper support for receiving messages sent as a channel. Fixes #740
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# mautrix-telegram - A Matrix-Telegram puppeting bridge
|
||||
# Copyright (C) 2021 Tulir Asokan
|
||||
# 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
|
||||
@@ -45,6 +45,7 @@ class Puppet:
|
||||
username: str | None
|
||||
photo_id: str | None
|
||||
is_bot: bool | None
|
||||
is_channel: bool
|
||||
|
||||
custom_mxid: UserID | None
|
||||
access_token: str | None
|
||||
@@ -61,7 +62,7 @@ class Puppet:
|
||||
|
||||
columns: ClassVar[str] = (
|
||||
"id, is_registered, displayname, displayname_source, displayname_contact, "
|
||||
"displayname_quality, disable_updates, username, photo_id, is_bot, "
|
||||
"displayname_quality, disable_updates, username, photo_id, is_bot, is_channel, "
|
||||
"custom_mxid, access_token, next_batch, base_url"
|
||||
)
|
||||
|
||||
@@ -103,6 +104,7 @@ class Puppet:
|
||||
self.username,
|
||||
self.photo_id,
|
||||
self.is_bot,
|
||||
self.is_channel,
|
||||
self.custom_mxid,
|
||||
self.access_token,
|
||||
self.next_batch,
|
||||
@@ -114,7 +116,7 @@ class Puppet:
|
||||
"UPDATE puppet "
|
||||
"SET is_registered=$2, displayname=$3, displayname_source=$4, displayname_contact=$5,"
|
||||
" displayname_quality=$6, disable_updates=$7, username=$8, photo_id=$9, is_bot=$10,"
|
||||
" custom_mxid=$11, access_token=$12, next_batch=$13, base_url=$14 "
|
||||
" is_channel=$11, custom_mxid=$12, access_token=$13, next_batch=$14, base_url=$15 "
|
||||
"WHERE id=$1"
|
||||
)
|
||||
await self.db.execute(q, *self._values)
|
||||
@@ -123,8 +125,8 @@ class Puppet:
|
||||
q = (
|
||||
"INSERT INTO puppet ("
|
||||
" id, is_registered, displayname, displayname_source, displayname_contact,"
|
||||
" displayname_quality, disable_updates, username, photo_id, is_bot,"
|
||||
" displayname_quality, disable_updates, username, photo_id, is_bot, is_channel,"
|
||||
" custom_mxid, access_token, next_batch, base_url"
|
||||
") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)"
|
||||
") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)"
|
||||
)
|
||||
await self.db.execute(q, *self._values)
|
||||
|
||||
@@ -2,4 +2,10 @@ from mautrix.util.async_db import UpgradeTable
|
||||
|
||||
upgrade_table = UpgradeTable()
|
||||
|
||||
from . import v01_initial_revision, v02_sponsored_events, v03_reactions, v04_disappearing_messages
|
||||
from . import (
|
||||
v01_initial_revision,
|
||||
v02_sponsored_events,
|
||||
v03_reactions,
|
||||
v04_disappearing_messages,
|
||||
v05_channel_ghosts,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# mautrix-telegram - A Matrix-Telegram 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 asyncpg import Connection
|
||||
|
||||
from . import upgrade_table
|
||||
|
||||
|
||||
@upgrade_table.register(description="Add separate ghost users for channel senders")
|
||||
async def upgrade_v5(conn: Connection, scheme: str) -> None:
|
||||
await conn.execute("ALTER TABLE puppet ADD COLUMN is_channel BOOLEAN NOT NULL DEFAULT false")
|
||||
if scheme == "postgres":
|
||||
await conn.execute("ALTER TABLE puppet ALTER COLUMN is_channel DROP DEFAULT")
|
||||
Reference in New Issue
Block a user