Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
facebook
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
mautrix
facebook
Commits
b4b292b7
Commit
b4b292b7
authored
5 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Patches
Plain Diff
Add Messenger -> Matrix chat metadata change bridging
parent
813549bd
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ROADMAP.md
+3
-3
3 additions, 3 deletions
ROADMAP.md
mautrix_facebook/portal.py
+46
-3
46 additions, 3 deletions
mautrix_facebook/portal.py
mautrix_facebook/user.py
+16
-6
16 additions, 6 deletions
mautrix_facebook/user.py
with
65 additions
and
12 deletions
ROADMAP.md
+
3
−
3
View file @
b4b292b7
...
@@ -50,9 +50,9 @@
...
@@ -50,9 +50,9 @@
*
[ ] Add member
*
[ ] Add member
*
[ ] Remove member
*
[ ] Remove member
*
[ ] Leave
*
[ ] Leave
*
[
] Chat metadata changes
*
[
x
] Chat metadata changes
*
[
] Title
*
[
x
] Title
*
[
] Avatar
*
[
x
] Avatar
*
[x] Initial chat metadata
*
[x] Initial chat metadata
*
[ ] User metadata
*
[ ] User metadata
*
[x] Name
*
[x] Name
...
...
This diff is collapsed.
Click to expand it.
mautrix_facebook/portal.py
+
46
−
3
View file @
b4b292b7
...
@@ -31,7 +31,7 @@ from mautrix.types import (RoomID, EventType, ContentURI, MessageEventContent, E
...
@@ -31,7 +31,7 @@ from mautrix.types import (RoomID, EventType, ContentURI, MessageEventContent, E
ThumbnailInfo
,
FileInfo
,
AudioInfo
,
VideoInfo
,
Format
,
ThumbnailInfo
,
FileInfo
,
AudioInfo
,
VideoInfo
,
Format
,
TextMessageEventContent
,
MediaMessageEventContent
,
Membership
)
TextMessageEventContent
,
MediaMessageEventContent
,
Membership
)
from
mautrix.appservice
import
AppService
,
IntentAPI
from
mautrix.appservice
import
AppService
,
IntentAPI
from
mautrix.errors
import
MForbidden
from
mautrix.errors
import
MForbidden
,
IntentError
from
.config
import
Config
from
.config
import
Config
from
.db
import
Portal
as
DBPortal
,
Message
as
DBMessage
from
.db
import
Portal
as
DBPortal
,
Message
as
DBMessage
...
@@ -451,7 +451,47 @@ class Portal:
...
@@ -451,7 +451,47 @@ class Portal:
await
sender
.
intent_for
(
self
).
mark_read
(
self
.
mxid
,
self
.
_last_bridged_mxid
)
await
sender
.
intent_for
(
self
).
mark_read
(
self
.
mxid
,
self
.
_last_bridged_mxid
)
async
def
handle_facebook_typing
(
self
,
source
:
'
u.User
'
,
sender
:
'
p.Puppet
'
)
->
None
:
async
def
handle_facebook_typing
(
self
,
source
:
'
u.User
'
,
sender
:
'
p.Puppet
'
)
->
None
:
pass
await
sender
.
intent
.
set_typing
(
self
.
mxid
,
is_typing
=
True
)
async
def
handle_facebook_photo
(
self
,
source
:
'
u.User
'
,
sender
:
'
p.Puppet
'
,
new_photo_id
:
str
,
message_id
:
str
)
->
None
:
if
not
self
.
mxid
or
self
.
is_direct
:
return
if
message_id
in
self
.
_dedup
:
return
self
.
_dedup
.
appendleft
(
message_id
)
# When we fetch thread info manually, we only get the URL instead of the ID,
# so we can't use the actual ID here either.
#self.photo_id = new_photo_id
photo_url
=
await
source
.
fetchImageUrl
(
new_photo_id
)
photo_id
=
self
.
_get_photo_id
(
photo_url
)
if
self
.
photo_id
==
photo_id
:
return
self
.
photo_id
=
photo_id
self
.
_avatar_uri
,
_
,
_
=
await
self
.
_reupload_fb_photo
(
photo_url
,
sender
.
intent
)
try
:
event_id
=
await
sender
.
intent
.
set_room_avatar
(
self
.
mxid
,
self
.
_avatar_uri
)
except
IntentError
:
event_id
=
await
self
.
main_intent
.
set_room_avatar
(
self
.
mxid
,
self
.
_avatar_uri
)
DBMessage
(
mxid
=
event_id
,
mx_room
=
self
.
mxid
,
fbid
=
message_id
,
fb_receiver
=
self
.
fb_receiver
,
index
=
0
).
insert
()
async
def
handle_facebook_name
(
self
,
source
:
'
u.User
'
,
sender
:
'
p.Puppet
'
,
new_name
:
str
,
message_id
:
str
)
->
None
:
if
self
.
name
==
new_name
or
message_id
in
self
.
_dedup
:
return
self
.
_dedup
.
appendleft
(
message_id
)
self
.
name
=
new_name
if
not
self
.
mxid
or
self
.
is_direct
:
return
try
:
event_id
=
await
sender
.
intent
.
set_room_name
(
self
.
mxid
,
self
.
name
)
except
IntentError
:
event_id
=
await
self
.
main_intent
.
set_room_name
(
self
.
mxid
,
self
.
name
)
DBMessage
(
mxid
=
event_id
,
mx_room
=
self
.
mxid
,
fbid
=
message_id
,
fb_receiver
=
self
.
fb_receiver
,
index
=
0
).
insert
()
# endregion
# endregion
# region Getters
# region Getters
...
@@ -472,7 +512,10 @@ class Portal:
...
@@ -472,7 +512,10 @@ class Portal:
@classmethod
@classmethod
def
get_by_fbid
(
cls
,
fbid
:
str
,
fb_receiver
:
Optional
[
str
]
=
None
,
def
get_by_fbid
(
cls
,
fbid
:
str
,
fb_receiver
:
Optional
[
str
]
=
None
,
fb_type
:
Optional
[
ThreadType
]
=
None
)
->
Optional
[
'
Portal
'
]:
fb_type
:
Optional
[
ThreadType
]
=
None
)
->
Optional
[
'
Portal
'
]:
fb_receiver
=
fb_receiver
or
fbid
if
fb_type
:
fb_receiver
=
fb_receiver
if
fb_type
==
ThreadType
.
USER
else
fbid
else
:
fb_receiver
=
fb_receiver
or
fbid
fbid_full
=
(
fbid
,
fb_receiver
)
fbid_full
=
(
fbid
,
fb_receiver
)
try
:
try
:
return
cls
.
by_fbid
[
fbid_full
]
return
cls
.
by_fbid
[
fbid_full
]
...
...
This diff is collapsed.
Click to expand it.
mautrix_facebook/user.py
+
16
−
6
View file @
b4b292b7
...
@@ -289,11 +289,14 @@ class User(Client):
...
@@ -289,11 +289,14 @@ class User(Client):
:param msg: A full set of the data recieved
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
:type thread_type: models.ThreadType
"""
"""
self
.
log
.
info
(
fb_receiver
=
self
.
uid
if
thread_type
==
ThreadType
.
USER
else
None
"
Title change from {} in {} ({}): {}
"
.
format
(
portal
=
po
.
Portal
.
get_by_fbid
(
thread_id
,
fb_receiver
)
author_id
,
thread_id
,
thread_type
.
name
,
new_title
if
not
portal
:
)
return
)
sender
=
pu
.
Puppet
.
get_by_fbid
(
author_id
)
if
not
sender
:
return
await
portal
.
handle_facebook_name
(
self
,
sender
,
new_title
,
mid
)
async
def
onImageChange
(
self
,
mid
=
None
,
author_id
=
None
,
new_image
=
None
,
thread_id
=
None
,
async
def
onImageChange
(
self
,
mid
=
None
,
author_id
=
None
,
new_image
=
None
,
thread_id
=
None
,
thread_type
=
ThreadType
.
GROUP
,
ts
=
None
,
msg
=
None
):
thread_type
=
ThreadType
.
GROUP
,
ts
=
None
,
msg
=
None
):
...
@@ -309,7 +312,14 @@ class User(Client):
...
@@ -309,7 +312,14 @@ class User(Client):
:param msg: A full set of the data recieved
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
:type thread_type: models.ThreadType
"""
"""
self
.
log
.
info
(
"
{} changed thread image in {}
"
.
format
(
author_id
,
thread_id
))
fb_receiver
=
self
.
uid
if
thread_type
==
ThreadType
.
USER
else
None
portal
=
po
.
Portal
.
get_by_fbid
(
thread_id
,
fb_receiver
)
if
not
portal
:
return
sender
=
pu
.
Puppet
.
get_by_fbid
(
author_id
)
if
not
sender
:
return
await
portal
.
handle_facebook_photo
(
self
,
sender
,
new_image
,
mid
)
async
def
onNicknameChange
(
self
,
mid
=
None
,
author_id
=
None
,
changed_for
=
None
,
new_nickname
=
None
,
async
def
onNicknameChange
(
self
,
mid
=
None
,
author_id
=
None
,
changed_for
=
None
,
new_nickname
=
None
,
thread_id
=
None
,
thread_type
=
ThreadType
.
USER
,
ts
=
None
,
metadata
=
None
,
thread_id
=
None
,
thread_type
=
ThreadType
.
USER
,
ts
=
None
,
metadata
=
None
,
...
...
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