Check if portal is channel before trusting member list
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
"""Add megagroup field to portals
|
||||||
|
|
||||||
|
Revision ID: 30eca60587f1
|
||||||
|
Revises: cfc972368e50
|
||||||
|
Create Date: 2018-04-29 15:51:04.656605
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '30eca60587f1'
|
||||||
|
down_revision = 'cfc972368e50'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column('portal', sa.Column('megagroup', sa.Boolean()))
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_column('portal', 'megagroup')
|
||||||
@@ -29,6 +29,7 @@ class Portal(Base):
|
|||||||
tgid = Column(Integer, primary_key=True)
|
tgid = Column(Integer, primary_key=True)
|
||||||
tg_receiver = Column(Integer, primary_key=True)
|
tg_receiver = Column(Integer, primary_key=True)
|
||||||
peer_type = Column(String)
|
peer_type = Column(String)
|
||||||
|
megagroup = Column(Boolean)
|
||||||
|
|
||||||
# Matrix portal information
|
# Matrix portal information
|
||||||
mxid = Column(String, unique=True, nullable=True)
|
mxid = Column(String, unique=True, nullable=True)
|
||||||
|
|||||||
@@ -55,13 +55,14 @@ class Portal:
|
|||||||
by_mxid = {}
|
by_mxid = {}
|
||||||
by_tgid = {}
|
by_tgid = {}
|
||||||
|
|
||||||
def __init__(self, tgid, peer_type, tg_receiver=None, mxid=None, username=None, title=None,
|
def __init__(self, tgid, peer_type, tg_receiver=None, mxid=None, username=None, megagroup=False, title=None,
|
||||||
about=None, photo_id=None, db_instance=None):
|
about=None, photo_id=None, db_instance=None):
|
||||||
self.mxid = mxid
|
self.mxid = mxid
|
||||||
self.tgid = tgid
|
self.tgid = tgid
|
||||||
self.tg_receiver = tg_receiver or tgid
|
self.tg_receiver = tg_receiver or tgid
|
||||||
self.peer_type = peer_type
|
self.peer_type = peer_type
|
||||||
self.username = username
|
self.username = username
|
||||||
|
self.megagroup = megagroup
|
||||||
self.title = title
|
self.title = title
|
||||||
self.about = about
|
self.about = about
|
||||||
self.photo_id = photo_id
|
self.photo_id = photo_id
|
||||||
@@ -245,6 +246,9 @@ class Portal:
|
|||||||
puppet = p.Puppet.get(self.tgid) if direct else None
|
puppet = p.Puppet.get(self.tgid) if direct else None
|
||||||
self._main_intent = puppet.intent if direct else self.az.intent
|
self._main_intent = puppet.intent if direct else self.az.intent
|
||||||
|
|
||||||
|
if self.peer_type == "channel":
|
||||||
|
self.megagroup = entity.megagroup
|
||||||
|
|
||||||
if self.peer_type == "channel" and entity.username:
|
if self.peer_type == "channel" and entity.username:
|
||||||
public = config["bridge.public_portals"]
|
public = config["bridge.public_portals"]
|
||||||
alias = self._get_alias_localpart(entity.username)
|
alias = self._get_alias_localpart(entity.username)
|
||||||
@@ -335,7 +339,10 @@ class Portal:
|
|||||||
# * There are close to 10 000 users, because Telegram might not be sending all members.
|
# * There are close to 10 000 users, because Telegram might not be sending all members.
|
||||||
# * The member sync count is limited, because then we might ignore some members.
|
# * The member sync count is limited, because then we might ignore some members.
|
||||||
# * It's a channel, because non-admins don't have access to the member list.
|
# * It's a channel, because non-admins don't have access to the member list.
|
||||||
if len(allowed_tgids) < 9900 and config["bridge.max_initial_member_sync"] == -1:
|
trust_member_list = (len(allowed_tgids) < 9900
|
||||||
|
and config["bridge.max_initial_member_sync"] == -1
|
||||||
|
and (self.megagroup or self.peer_type != "channel"))
|
||||||
|
if trust_member_list:
|
||||||
joined_mxids = await self.main_intent.get_room_members(self.mxid)
|
joined_mxids = await self.main_intent.get_room_members(self.mxid)
|
||||||
for user in joined_mxids:
|
for user in joined_mxids:
|
||||||
if user == self.az.bot_mxid:
|
if user == self.az.bot_mxid:
|
||||||
@@ -1426,8 +1433,8 @@ class Portal:
|
|||||||
return self._db_instance
|
return self._db_instance
|
||||||
|
|
||||||
def new_db_instance(self):
|
def new_db_instance(self):
|
||||||
return DBPortal(tgid=self.tgid, tg_receiver=self.tg_receiver, peer_type=self.peer_type,
|
return DBPortal(tgid=self.tgid, tg_receiver=self.tg_receiver, peer_type=self.peer_type, mxid=self.mxid,
|
||||||
mxid=self.mxid, username=self.username, title=self.title, about=self.about,
|
username=self.username, megagroup=self.megagroup, title=self.title, about=self.about,
|
||||||
photo_id=self.photo_id)
|
photo_id=self.photo_id)
|
||||||
|
|
||||||
def migrate_and_save(self, new_id):
|
def migrate_and_save(self, new_id):
|
||||||
@@ -1466,10 +1473,9 @@ class Portal:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_db(cls, db_portal):
|
def from_db(cls, db_portal):
|
||||||
return Portal(tgid=db_portal.tgid, tg_receiver=db_portal.tg_receiver,
|
return Portal(tgid=db_portal.tgid, tg_receiver=db_portal.tg_receiver, peer_type=db_portal.peer_type,
|
||||||
peer_type=db_portal.peer_type, mxid=db_portal.mxid,
|
mxid=db_portal.mxid, username=db_portal.username, megagroup=db_portal.megagroup,
|
||||||
username=db_portal.username, title=db_portal.title,
|
title=db_portal.title, about=db_portal.about, photo_id=db_portal.photo_id,
|
||||||
about=db_portal.about, photo_id=db_portal.photo_id,
|
|
||||||
db_instance=db_portal)
|
db_instance=db_portal)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user