Skip to content

Commit 7f8e7cf

Browse files
committed
Merge remote-tracking branch 'tulir/master' into hs/portal-limit
2 parents b0256ba + d4d6cfa commit 7f8e7cf

55 files changed

Lines changed: 1770 additions & 1187 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ __pycache__
1414
/registration.yaml
1515
*.log*
1616
*.db
17+
*.pickle
1718
*.bak

.gitlab-ci.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,24 @@ build amd64:
1414
- amd64
1515
script:
1616
- docker pull $CI_REGISTRY_IMAGE:latest || true
17-
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64 .
17+
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --build-arg TARGETARCH=amd64 --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64 .
1818
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64
1919
- docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64
20+
after_script:
21+
- |
22+
if [ "$CI_COMMIT_BRANCH" = "master" ]; then
23+
apk add --update curl
24+
rm -rf /var/cache/apk/*
25+
curl "$NOVA_ADMIN_API_URL" -H "Content-Type: application/json" -d '{"password":"'"$NOVA_ADMIN_NIGHTLY_PASS"'","bridge":"'$NOVA_BRIDGE_TYPE'","image":"'$CI_REGISTRY_IMAGE':'$CI_COMMIT_SHA'-amd64"}'
26+
fi
2027
2128
build arm64:
2229
stage: build
2330
tags:
2431
- arm64
2532
script:
2633
- docker pull $CI_REGISTRY_IMAGE:latest || true
27-
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64 .
34+
- docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --build-arg TARGETARCH=arm64 --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64 .
2835
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64
2936
- docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64
3037

@@ -36,6 +43,6 @@ manifest:
3643
script:
3744
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64
3845
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64
39-
- if [ $CI_COMMIT_BRANCH == "master" ]; then docker manifest create $CI_REGISTRY_IMAGE:latest $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64 $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64 && docker manifest push $CI_REGISTRY_IMAGE:latest; fi
40-
- if [ $CI_COMMIT_BRANCH != "master" ]; then docker manifest create $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64 $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64 && docker manifest push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME; fi
46+
- if [ "$CI_COMMIT_BRANCH" = "master" ]; then docker manifest create $CI_REGISTRY_IMAGE:latest $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64 $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64 && docker manifest push $CI_REGISTRY_IMAGE:latest; fi
47+
- if [ "$CI_COMMIT_BRANCH" != "master" ]; then docker manifest create $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64 $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64 && docker manifest push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME; fi
4148
- docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-amd64 $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-arm64

Dockerfile

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.11
1+
FROM dock.mau.dev/tulir/lottieconverter:alpine-3.12
22

3-
RUN echo "@edge_main http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories
4-
RUN echo "@edge_testing http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
5-
RUN echo "@edge_community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
3+
ARG TARGETARCH=amd64
4+
5+
RUN echo $'\
6+
@edge http://dl-cdn.alpinelinux.org/alpine/edge/main\n\
7+
@edge http://dl-cdn.alpinelinux.org/alpine/edge/testing\n\
8+
@edge http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories
69

710
RUN apk add --no-cache \
11+
python3 py3-pip py3-setuptools py3-wheel \
812
py3-virtualenv \
913
py3-pillow \
1014
py3-aiohttp \
1115
py3-magic \
1216
py3-sqlalchemy \
13-
py3-alembic@edge_testing \
17+
py3-telethon-session-sqlalchemy@edge \
18+
py3-alembic@edge \
1419
py3-psycopg2 \
1520
py3-ruamel.yaml \
16-
py3-commonmark@edge_testing \
21+
py3-commonmark@edge \
1722
# Indirect dependencies
1823
py3-idna \
1924
#moviepy
@@ -22,33 +27,28 @@ RUN apk add --no-cache \
2227
py3-requests \
2328
#imageio
2429
py3-numpy \
25-
#telethon
26-
py3-rsa \
30+
#py3-telethon@edge \ (outdated)
2731
# Optional for socks proxies
2832
py3-pysocks \
2933
# cryptg
3034
py3-cffi \
35+
py3-qrcode@edge \
3136
py3-brotli \
3237
# Other dependencies
3338
ffmpeg \
3439
ca-certificates \
3540
su-exec \
3641
netcat-openbsd \
37-
# olm
38-
olm-dev@edge_community \
39-
# matrix-nio?
40-
py3-future \
41-
py3-atomicwrites \
42-
py3-pycryptodome@edge_main \
43-
py3-peewee@edge_community \
44-
py3-pyrsistent@edge_community \
45-
py3-jsonschema \
46-
py3-aiofiles \
47-
py3-cachetools@edge_community \
48-
py3-prometheus-client@edge_community \
42+
# encryption
43+
olm-dev \
44+
py3-pycryptodome \
4945
py3-unpaddedbase64 \
50-
py3-pyaes@edge_testing \
51-
py3-logbook@edge_testing
46+
py3-future \
47+
bash \
48+
curl \
49+
jq && \
50+
curl -sLo yq https://github.com/mikefarah/yq/releases/download/3.3.2/yq_linux_${TARGETARCH} && \
51+
chmod +x yq && mv yq /usr/bin/yq
5252

5353
COPY requirements.txt /opt/mautrix-telegram/requirements.txt
5454
COPY optional-requirements.txt /opt/mautrix-telegram/optional-requirements.txt
@@ -64,7 +64,7 @@ RUN apk add --virtual .build-deps \
6464
COPY . /opt/mautrix-telegram
6565
RUN apk add git && pip3 install .[speedups,hq_thumbnails,metrics,e2be] && apk del git \
6666
# This doesn't make the image smaller, but it's needed so that the `version` command works properly
67-
&& rm -rf mautrix_telegram
67+
&& cp mautrix_telegram/example-config.yaml . && rm -rf mautrix_telegram
6868

6969
VOLUME /data
7070
ENV UID=1337 GID=1337 \

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@
77

88
A Matrix-Telegram hybrid puppeting/relaybot bridge.
99

10-
### [Wiki](https://github.com/tulir/mautrix-telegram/wiki)
10+
## Sponsors
11+
* [Joel Lehtonen / Zouppen](https://github.com/zouppen)
1112

12-
### [Features & Roadmap](https://github.com/tulir/mautrix-telegram/blob/master/ROADMAP.md)
13+
### Wiki
14+
All setup and usage instructions are located in the GitHub
15+
[wiki](https://github.com/tulir/mautrix-telegram/wiki). Some quick links:
16+
17+
* [Bridge setup](https://github.com/tulir/mautrix-telegram/wiki/Bridge-setup)
18+
(or [with Docker](https://github.com/tulir/mautrix-telegram/wiki/Bridge-setup-with-Docker))
19+
* Basic usage: [Authentication](https://github.com/tulir/mautrix-telegram/wiki/Authentication),
20+
[Creating chats](https://github.com/tulir/mautrix-telegram/wiki/Creating-and-managing-chats),
21+
[Relaybot setup](https://github.com/tulir/mautrix-telegram/wiki/Relay-bot)
22+
23+
### Features & Roadmap
24+
[ROADMAP.md](https://github.com/tulir/mautrix-telegram/blob/master/ROADMAP.md)
25+
contains a general overview of what is supported by the bridge.
1326

1427
## Discussion
1528
Matrix room: [`#telegram:maunium.net`](https://matrix.to/#/#telegram:maunium.net)
1629

1730
Telegram chat: [`mautrix_telegram`](https://t.me/mautrix_telegram) (bridged to Matrix room)
1831

1932
## Preview
20-
![Preview](https://raw.githubusercontent.com/tulir/mautrix-telegram/master/preview.png)
33+
![Preview](preview.png)

ROADMAP.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* [x] Message edits
77
* [ ] ‡ Message history
88
* [x] Presence
9-
* [x] Typing notifications*
10-
* [x] Read receipts*
11-
* [x] Pinning messages*
9+
* [x] Typing notifications
10+
* [x] Read receipts
11+
* [x] Pinning messages
1212
* [x] Power level
1313
* [x] Normal chats
1414
* [ ] Non-hardcoded PL requirements
@@ -28,7 +28,10 @@
2828
* [ ] Buttons
2929
* [x] Message deletions
3030
* [x] Message edits
31-
* [ ] Message history
31+
* [x] Message history
32+
* [x] Manually (`!tg backfill`)
33+
* [x] Automatically when creating portal
34+
* [x] Automatically for missed messages
3235
* [x] Avatars
3336
* [x] Presence
3437
* [x] Typing notifications
@@ -50,12 +53,11 @@
5053
* [x] At startup
5154
* [x] When receiving invite or message
5255
* [x] Private chat creation by inviting Matrix puppet of Telegram user to new room
53-
* [x] Option to use bot to relay messages for unauthenticated Matrix users
54-
* [x] Option to use own Matrix account for messages sent from other Telegram clients
56+
* [x] Option to use bot to relay messages for unauthenticated Matrix users (relaybot)
57+
* [x] Option to use own Matrix account for messages sent from other Telegram clients (double puppeting)
5558
* [ ] ‡ Calls (hard, not yet supported by Telethon)
56-
* [ ] ‡ Secret chats (not yet supported by Telethon)
57-
* [ ] ‡ E2EE in Matrix rooms (not yet supported
59+
* [ ] ‡ Secret chats (i.e. End-to-bridge encryption on Telegram)
60+
* [x] End-to-bridge encryption in Matrix rooms (see [wiki](https://github.com/tulir/mautrix-telegram/wiki/End%E2%80%90to%E2%80%90bridge-encryption))
5861

59-
\* Requires [double puppeting](https://github.com/tulir/mautrix-telegram/wiki/Authentication#replacing-telegram-accounts-matrix-puppet-with-matrix-account) to be enabled
60-
† Information not automatically sent from source, i.e. implementation may not be possible
62+
† Information not automatically sent from source, i.e. implementation may not be possible
6163
‡ Maybe, i.e. this feature may or may not be implemented at some point

alembic/env.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
mxtg_config.load()
2222
config.set_main_option("sqlalchemy.url", mxtg_config["appservice.database"].replace("%", "%%"))
2323

24-
2524
AlchemySessionContainer.create_table_classes(None, "telethon_", Base)
2625

2726
# Interpret the config file for Python logging.
@@ -55,7 +54,8 @@ def run_migrations_offline():
5554
"""
5655
url = config.get_main_option("sqlalchemy.url")
5756
context.configure(
58-
url=url, target_metadata=target_metadata, literal_binds=True)
57+
url=url, target_metadata=target_metadata, literal_binds=True,
58+
render_as_batch=True)
5959

6060
with context.begin_transaction():
6161
context.run_migrations()
@@ -76,7 +76,8 @@ def run_migrations_online():
7676
with connectable.connect() as connection:
7777
context.configure(
7878
connection=connection,
79-
target_metadata=target_metadata
79+
target_metadata=target_metadata,
80+
render_as_batch=True
8081
)
8182

8283
with context.begin_transaction():
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Store Matrix avatar URL in database
2+
3+
Revision ID: 3e3745baa458
4+
Revises: dff56c93da8d
5+
Create Date: 2020-06-15 14:32:10.454033
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '3e3745baa458'
14+
down_revision = 'dff56c93da8d'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
with op.batch_alter_table('portal', schema=None) as batch_op:
22+
batch_op.add_column(sa.Column('avatar_url', sa.String(), nullable=True))
23+
24+
# ### end Alembic commands ###
25+
26+
27+
def downgrade():
28+
# ### commands auto generated by Alembic - please adjust! ###
29+
with op.batch_alter_table('portal', schema=None) as batch_op:
30+
batch_op.drop_column('avatar_url')
31+
32+
# ### end Alembic commands ###
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Add double puppet base URL to puppet table
2+
3+
Revision ID: 888275d58e57
4+
Revises: a328bf4f0932
5+
Create Date: 2020-10-14 18:52:00.730666
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
from sqlalchemy.dialects import postgresql
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '888275d58e57'
14+
down_revision = 'a328bf4f0932'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
with op.batch_alter_table('puppet', schema=None) as batch_op:
22+
batch_op.add_column(sa.Column('base_url', sa.Text(), nullable=True))
23+
# ### end Alembic commands ###
24+
25+
26+
def downgrade():
27+
# ### commands auto generated by Alembic - please adjust! ###
28+
with op.batch_alter_table('puppet', schema=None) as batch_op:
29+
batch_op.drop_column('base_url')
30+
# ### end Alembic commands ###
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Store encryption state event in db
2+
3+
Revision ID: a328bf4f0932
4+
Revises: ccbaff858240
5+
Create Date: 2020-07-11 21:31:27.059813
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
from mautrix.client.state_store.sqlalchemy import SerializableType
12+
from mautrix.types import RoomEncryptionStateEventContent
13+
14+
# revision identifiers, used by Alembic.
15+
revision = 'a328bf4f0932'
16+
down_revision = 'ccbaff858240'
17+
branch_labels = None
18+
depends_on = None
19+
20+
21+
def upgrade():
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
with op.batch_alter_table('mx_room_state', schema=None) as batch_op:
24+
batch_op.add_column(sa.Column('encryption',
25+
SerializableType(RoomEncryptionStateEventContent),
26+
nullable=True))
27+
batch_op.add_column(sa.Column('has_full_member_list', sa.Boolean(), nullable=True))
28+
batch_op.add_column(sa.Column('is_encrypted', sa.Boolean(), nullable=True))
29+
# ### end Alembic commands ###
30+
31+
32+
def downgrade():
33+
# ### commands auto generated by Alembic - please adjust! ###
34+
with op.batch_alter_table('mx_room_state', schema=None) as batch_op:
35+
batch_op.drop_column('is_encrypted')
36+
batch_op.drop_column('has_full_member_list')
37+
batch_op.drop_column('encryption')
38+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)