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
91d839a1
Commit
91d839a1
authored
5 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Patches
Plain Diff
Add non-persistent deduplication and other stuff
parent
2847b9c7
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_facebook/portal.py
+36
-7
36 additions, 7 deletions
mautrix_facebook/portal.py
mautrix_facebook/puppet.py
+1
-1
1 addition, 1 deletion
mautrix_facebook/puppet.py
mautrix_facebook/user.py
+9
-3
9 additions, 3 deletions
mautrix_facebook/user.py
with
46 additions
and
11 deletions
mautrix_facebook/portal.py
+
36
−
7
View file @
91d839a1
...
@@ -49,6 +49,9 @@ class Portal:
...
@@ -49,6 +49,9 @@ class Portal:
photo
:
str
photo
:
str
avatar_uri
:
ContentURI
avatar_uri
:
ContentURI
messages_by_fbid
:
Dict
[
str
,
EventID
]
messages_by_mxid
:
Dict
[
EventID
,
str
]
_main_intent
:
Optional
[
IntentAPI
]
_main_intent
:
Optional
[
IntentAPI
]
def
__init__
(
self
,
fbid
:
str
,
fb_type
:
ThreadType
,
mxid
:
Optional
[
RoomID
]
=
None
,
def
__init__
(
self
,
fbid
:
str
,
fb_type
:
ThreadType
,
mxid
:
Optional
[
RoomID
]
=
None
,
...
@@ -63,6 +66,9 @@ class Portal:
...
@@ -63,6 +66,9 @@ class Portal:
self
.
_main_intent
=
None
self
.
_main_intent
=
None
self
.
messages_by_fbid
=
{}
self
.
messages_by_mxid
=
{}
self
.
name
=
name
self
.
name
=
name
self
.
photo
=
photo
self
.
photo
=
photo
self
.
avatar_uri
=
avatar_uri
self
.
avatar_uri
=
avatar_uri
...
@@ -113,7 +119,7 @@ class Portal:
...
@@ -113,7 +119,7 @@ class Portal:
await
self
.
main_intent
.
set_room_name
(
self
.
mxid
,
self
.
name
)
await
self
.
main_intent
.
set_room_name
(
self
.
mxid
,
self
.
name
)
async
def
_update_photo
(
self
,
photo
:
str
)
->
None
:
async
def
_update_photo
(
self
,
photo
:
str
)
->
None
:
if
self
.
photo
!=
photo
:
if
self
.
photo
!=
photo
or
len
(
self
.
avatar_uri
)
==
0
:
self
.
photo
=
photo
self
.
photo
=
photo
if
self
.
mxid
and
not
self
.
is_direct
:
if
self
.
mxid
and
not
self
.
is_direct
:
async
with
aiohttp
.
ClientSession
()
as
session
:
async
with
aiohttp
.
ClientSession
()
as
session
:
...
@@ -123,11 +129,11 @@ class Portal:
...
@@ -123,11 +129,11 @@ class Portal:
await
self
.
main_intent
.
set_room_avatar
(
self
.
mxid
,
self
.
avatar_uri
)
await
self
.
main_intent
.
set_room_avatar
(
self
.
mxid
,
self
.
avatar_uri
)
async
def
_update_participants
(
self
,
source
:
'
u.User
'
,
info
:
ThreadClass
)
->
None
:
async
def
_update_participants
(
self
,
source
:
'
u.User
'
,
info
:
ThreadClass
)
->
None
:
if
not
self
.
mxid
:
if
self
.
is_direct
:
return
elif
self
.
is_direct
:
await
p
.
Puppet
.
get
(
info
.
uid
).
update_info
(
source
=
source
,
info
=
info
)
await
p
.
Puppet
.
get
(
info
.
uid
).
update_info
(
source
=
source
,
info
=
info
)
return
return
elif
not
self
.
mxid
:
return
users
=
await
source
.
fetchAllUsersFromThreads
(
info
)
users
=
await
source
.
fetchAllUsersFromThreads
(
info
)
puppets
=
{
user
:
p
.
Puppet
.
get
(
user
.
uid
)
for
user
in
users
}
puppets
=
{
user
:
p
.
Puppet
.
get
(
user
.
uid
)
for
user
in
users
}
await
asyncio
.
gather
(
*
[
puppet
.
update_info
(
source
=
source
,
info
=
user
)
await
asyncio
.
gather
(
*
[
puppet
.
update_info
(
source
=
source
,
info
=
user
)
...
@@ -154,11 +160,34 @@ class Portal:
...
@@ -154,11 +160,34 @@ class Portal:
if
not
self
.
mxid
:
if
not
self
.
mxid
:
raise
Exception
(
"
Failed to create room
"
)
raise
Exception
(
"
Failed to create room
"
)
self
.
by_mxid
[
self
.
mxid
]
=
self
self
.
by_mxid
[
self
.
mxid
]
=
self
await
self
.
_update_participants
(
source
,
info
)
if
not
self
.
is_direct
:
await
self
.
_update_participants
(
source
,
info
)
async
def
handle_matrix_message
(
self
,
sender
:
'
u.User
'
,
message
:
MessageEventContent
,
async
def
handle_matrix_message
(
self
,
sender
:
'
u.User
'
,
message
:
MessageEventContent
,
event_id
:
EventID
):
event_id
:
EventID
)
->
None
:
await
sender
.
send
(
FBMessage
(
text
=
message
.
body
),
self
.
fbid
,
self
.
fb_type
)
if
event_id
in
self
.
messages_by_mxid
:
print
(
f
"
handle_matrix_message(
{
event_id
}
) --> cancelled
"
)
return
print
(
f
"
handle_matrix_message(
{
event_id
}
) --> sending
"
)
fbid
=
await
sender
.
send
(
FBMessage
(
text
=
message
.
body
),
self
.
fbid
,
self
.
fb_type
)
print
(
f
"
handle_matrix_message(
{
event_id
}
) --> sent
"
)
self
.
messages_by_fbid
[
fbid
]
=
event_id
self
.
messages_by_mxid
[
event_id
]
=
fbid
print
(
f
"
handle_matrix_message(
{
event_id
}
) --> mapped to
{
fbid
}
"
)
async
def
handle_facebook_message
(
self
,
source
:
'
u.User
'
,
sender
:
'
p.Puppet
'
,
message
:
FBMessage
)
->
None
:
if
message
.
uid
in
self
.
messages_by_fbid
:
print
(
f
"
handle_facebook_message(
{
message
.
uid
}
) --> cancelled
"
)
return
print
(
f
"
handle_facebook_message(
{
message
.
uid
}
) --> sending
"
)
if
not
self
.
mxid
:
await
self
.
create_matrix_room
(
source
)
event_id
=
await
sender
.
intent
.
send_text
(
self
.
mxid
,
message
.
text
)
print
(
f
"
handle_facebook_message(
{
message
.
uid
}
) --> sent
"
)
self
.
messages_by_mxid
[
event_id
]
=
message
.
uid
self
.
messages_by_fbid
[
message
.
uid
]
=
event_id
print
(
f
"
handle_facebook_message(
{
message
.
uid
}
) --> mapped to
{
event_id
}
"
)
@classmethod
@classmethod
def
get_by_mxid
(
cls
,
mxid
:
RoomID
)
->
Optional
[
'
Portal
'
]:
def
get_by_mxid
(
cls
,
mxid
:
RoomID
)
->
Optional
[
'
Portal
'
]:
...
...
This diff is collapsed.
Click to expand it.
mautrix_facebook/puppet.py
+
1
−
1
View file @
91d839a1
...
@@ -85,7 +85,7 @@ class Puppet:
...
@@ -85,7 +85,7 @@ class Puppet:
await
self
.
intent
.
set_displayname
(
self
.
name
)
await
self
.
intent
.
set_displayname
(
self
.
name
)
async
def
_update_photo
(
self
,
photo
:
str
)
->
None
:
async
def
_update_photo
(
self
,
photo
:
str
)
->
None
:
if
photo
!=
self
.
photo
:
if
photo
!=
self
.
photo
or
len
(
self
.
avatar_uri
)
==
0
:
self
.
photo
=
photo
self
.
photo
=
photo
async
with
aiohttp
.
ClientSession
()
as
session
:
async
with
aiohttp
.
ClientSession
()
as
session
:
resp
=
await
session
.
get
(
self
.
photo
)
resp
=
await
session
.
get
(
self
.
photo
)
...
...
This diff is collapsed.
Click to expand it.
mautrix_facebook/user.py
+
9
−
3
View file @
91d839a1
...
@@ -172,11 +172,17 @@ class User(Client):
...
@@ -172,11 +172,17 @@ class User(Client):
:type message_object: models.Message
:type message_object: models.Message
:type thread_type: models.ThreadType
:type thread_type: models.ThreadType
"""
"""
if
author_id
==
self
.
uid
:
self
.
log
.
debug
(
f
"
Ignoring message from self (
{
mid
}
,
{
author_id
}
,
{
message
}
,
"
f
"
{
thread_id
}
,
{
thread_type
}
)
"
)
return
self
.
log
.
debug
(
f
"
onMessage(
{
mid
}
,
{
author_id
}
,
{
message
}
,
{
thread_id
}
,
{
thread_type
}
)
"
)
portal
=
po
.
Portal
.
get_by_fbid
(
thread_id
,
thread_type
)
portal
=
po
.
Portal
.
get_by_fbid
(
thread_id
,
thread_type
)
puppet
=
pu
.
Puppet
.
get
(
author_id
)
puppet
=
pu
.
Puppet
.
get
(
author_id
)
if
not
portal
.
mxid
:
if
not
puppet
.
name
:
await
portal
.
create_matrix_room
(
self
)
await
puppet
.
update_info
(
self
)
await
puppet
.
intent
.
send_text
(
portal
.
mxid
,
message
)
message_object
.
uid
=
mid
await
portal
.
handle_facebook_message
(
self
,
puppet
,
message_object
)
async
def
onColorChange
(
self
,
mid
=
None
,
author_id
=
None
,
new_color
=
None
,
thread_id
=
None
,
async
def
onColorChange
(
self
,
mid
=
None
,
author_id
=
None
,
new_color
=
None
,
thread_id
=
None
,
thread_type
=
ThreadType
.
USER
,
ts
=
None
,
metadata
=
None
,
msg
=
None
):
thread_type
=
ThreadType
.
USER
,
ts
=
None
,
metadata
=
None
,
msg
=
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