Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mautrix-telegram
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
mautrix-telegram
Commits
9e5cb841
Commit
9e5cb841
authored
7 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Patches
Plain Diff
Refactor more code
parent
9e5843a0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mautrix_telegram/context.py
+0
-1
0 additions, 1 deletion
mautrix_telegram/context.py
mautrix_telegram/portal.py
+22
-14
22 additions, 14 deletions
mautrix_telegram/portal.py
mautrix_telegram/util/file_transfer.py
+8
-2
8 additions, 2 deletions
mautrix_telegram/util/file_transfer.py
with
30 additions
and
17 deletions
mautrix_telegram/context.py
+
0
−
1
View file @
9e5cb841
...
...
@@ -31,4 +31,3 @@ class Context:
yield
self
.
config
yield
self
.
loop
yield
self
.
bot
# yield self.mx
This diff is collapsed.
Click to expand it.
mautrix_telegram/portal.py
+
22
−
14
View file @
9e5cb841
...
...
@@ -332,16 +332,19 @@ class Portal:
user
.
register_portal
(
self
)
await
self
.
main_intent
.
invite
(
self
.
mxid
,
user
.
mxid
)
async
def
delete_telegram_user
(
self
,
user_id
,
kick_message
=
None
):
async
def
delete_telegram_user
(
self
,
user_id
,
sender
):
puppet
=
p
.
Puppet
.
get
(
user_id
)
user
=
u
.
User
.
get_by_tgid
(
user_id
)
if
kick_message
:
kick_message
=
(
f
"
Kicked by
{
sender
.
displayname
}
"
if
sender
and
sender
.
tgid
!=
user
.
tgid
else
"
Left Telegram chat
"
)
if
sender
and
sender
.
tgid
!=
user
.
tgid
:
await
self
.
main_intent
.
kick
(
self
.
mxid
,
puppet
.
mxid
,
kick_message
)
else
:
await
puppet
.
intent
.
leave_room
(
self
.
mxid
)
if
user
:
user
.
unregister_portal
(
self
)
await
self
.
main_intent
.
kick
(
self
.
mxid
,
user
.
mxid
,
kick_message
or
"
Left Telegram chat
"
)
await
self
.
main_intent
.
kick
(
self
.
mxid
,
user
.
mxid
,
kick_message
)
async
def
update_info
(
self
,
user
,
entity
=
None
):
if
self
.
peer_type
==
"
user
"
:
...
...
@@ -367,7 +370,7 @@ class Portal:
if
changed
:
self
.
save
()
async
def
update_username
(
self
,
username
):
async
def
update_username
(
self
,
username
,
save
=
False
):
if
self
.
username
!=
username
:
if
self
.
username
:
await
self
.
main_intent
.
remove_room_alias
(
self
.
_get_alias_localpart
())
...
...
@@ -377,20 +380,27 @@ class Portal:
await
self
.
main_intent
.
set_join_rule
(
self
.
mxid
,
"
public
"
)
else
:
await
self
.
main_intent
.
set_join_rule
(
self
.
mxid
,
"
invite
"
)
if
save
:
self
.
save
()
return
True
return
False
async
def
update_about
(
self
,
about
):
async
def
update_about
(
self
,
about
,
save
=
False
):
if
self
.
about
!=
about
:
self
.
about
=
about
await
self
.
main_intent
.
set_room_topic
(
self
.
mxid
,
self
.
about
)
if
save
:
self
.
save
()
return
True
return
False
async
def
update_title
(
self
,
title
):
async
def
update_title
(
self
,
title
,
save
=
False
):
if
self
.
title
!=
title
:
self
.
title
=
title
await
self
.
main_intent
.
set_room_name
(
self
.
mxid
,
self
.
title
)
if
save
:
self
.
save
()
return
True
return
False
...
...
@@ -399,7 +409,7 @@ class Portal:
return
max
(
photo
.
sizes
,
key
=
(
lambda
photo2
:
(
len
(
photo2
.
bytes
)
if
isinstance
(
photo2
,
PhotoCachedSize
)
else
photo2
.
size
)))
async
def
update_avatar
(
self
,
user
,
photo
):
async
def
update_avatar
(
self
,
user
,
photo
,
save
=
False
):
photo_id
=
f
"
{
photo
.
volume_id
}
-
{
photo
.
local_id
}
"
if
self
.
photo_id
!=
photo_id
:
file
=
await
util
.
transfer_file_to_matrix
(
self
.
db
,
user
.
client
,
self
.
main_intent
,
...
...
@@ -407,6 +417,8 @@ class Portal:
if
file
:
await
self
.
main_intent
.
set_room_avatar
(
self
.
mxid
,
file
.
mxc
)
self
.
photo_id
=
photo_id
if
save
:
self
.
save
()
return
True
return
False
...
...
@@ -974,21 +986,17 @@ class Portal:
# TODO figure out how to see changes to about text / channel username
if
isinstance
(
action
,
MessageActionChatEditTitle
):
if
await
self
.
update_title
(
action
.
title
):
self
.
save
()
await
self
.
update_title
(
action
.
title
,
save
=
True
)
elif
isinstance
(
action
,
MessageActionChatEditPhoto
):
largest_size
=
self
.
_get_largest_photo_size
(
action
.
photo
)
if
await
self
.
update_avatar
(
source
,
largest_size
.
location
):
self
.
save
()
self
.
update_avatar
(
source
,
largest_size
.
location
,
save
=
True
)
elif
isinstance
(
action
,
MessageActionChatAddUser
):
for
user_id
in
action
.
users
:
await
self
.
add_telegram_user
(
user_id
,
source
)
elif
isinstance
(
action
,
MessageActionChatJoinedByLink
):
await
self
.
add_telegram_user
(
sender
.
id
,
source
)
elif
isinstance
(
action
,
MessageActionChatDeleteUser
):
kick_message
=
(
f
"
Kicked by
{
sender
.
displayname
}
"
if
sender
.
id
!=
action
.
user_id
else
None
)
await
self
.
delete_telegram_user
(
action
.
user_id
,
kick_message
)
await
self
.
delete_telegram_user
(
action
.
user_id
,
sender
)
elif
isinstance
(
action
,
MessageActionChatMigrateTo
):
self
.
peer_type
=
"
channel
"
self
.
migrate_and_save
(
action
.
channel_id
)
...
...
This diff is collapsed.
Click to expand it.
mautrix_telegram/util/file_transfer.py
+
8
−
2
View file @
9e5cb841
...
...
@@ -20,6 +20,7 @@ import logging
import
magic
from
PIL
import
Image
from
sqlalchemy.exc
import
IntegrityError
from
telethon.tl.types
import
(
Document
,
FileLocation
,
InputFileLocation
,
InputDocumentFileLocation
)
...
...
@@ -69,7 +70,12 @@ async def transfer_file_to_matrix(db, client, intent, location):
db_file
=
DBTelegramFile
(
id
=
id
,
mxc
=
uploaded
[
"
content_uri
"
],
mime_type
=
mime_type
,
was_converted
=
image_converted
,
timestamp
=
int
(
time
.
time
()))
db
.
add
(
db_file
)
db
.
commit
()
try
:
db
.
add
(
db_file
)
db
.
commit
()
except
IntegrityError
:
log
.
exception
(
"
Integrity error while saving transferred file data.
"
"
This was probably caused by two simultaneous transfers of the same file,
"
"
and should not cause any problems.
"
)
return
db_file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment