Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
F
federation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
15
Issues
15
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jaywink
federation
Commits
36443e85
Commit
36443e85
authored
Jan 02, 2021
by
jaywink
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Emulate Cerulean by creating a thread room for each top level post
parent
6b3e1708
Pipeline
#5400
passed with stage
in 1 minute and 46 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
federation/entities/matrix/entities.py
federation/entities/matrix/entities.py
+38
-0
No files found.
federation/entities/matrix/entities.py
View file @
36443e85
...
...
@@ -80,6 +80,38 @@ class MatrixEntityMixin(BaseEntity):
class
MatrixRoomMessage
(
Post
,
MatrixEntityMixin
):
_event_type
=
EventType
.
ROOM_MESSAGE
.
value
_thread_room_event_id
:
str
=
None
_thread_room_id
:
str
=
None
def
create_thread_room
(
self
):
headers
=
appservice_auth_header
()
# Create the thread room
response
=
requests
.
post
(
url
=
f"
{
super
().
get_endpoint
()
}
/createRoom?user_id=
{
self
.
mxid
}
"
,
json
=
{
# TODO auto-invite recipients if private chat
"preset"
:
"public_chat"
if
self
.
public
else
"private_chat"
,
"name"
:
f"Thread by
{
self
.
mxid
}
"
,
"topic"
:
self
.
url
,
},
headers
=
headers
,
)
response
.
raise_for_status
()
self
.
_thread_room_id
=
response
.
json
()[
"room_id"
]
# Send the thread message
response
=
requests
.
put
(
url
=
f"
{
super
().
get_endpoint
()
}
/rooms/
{
self
.
_thread_room_id
}
/send/
{
self
.
event_type
}
/"
f"
{
str
(
uuid4
())
}
?user_id=
{
self
.
mxid
}
"
,
json
=
{
"body"
:
self
.
raw_content
,
"msgtype"
:
"m.text"
,
"format"
:
"org.matrix.custom.html"
,
"formatted_body"
:
self
.
rendered_content
,
},
headers
=
headers
,
)
response
.
raise_for_status
()
self
.
_thread_room_event_id
=
response
.
json
()[
"event_id"
]
def
payloads
(
self
)
->
List
[
Dict
]:
payloads
=
super
().
payloads
()
...
...
@@ -91,6 +123,10 @@ class MatrixRoomMessage(Post, MatrixEntityMixin):
"msgtype"
:
"m.text"
,
"format"
:
"org.matrix.custom.html"
,
"formatted_body"
:
self
.
rendered_content
,
# Fields to emulate Cerulean
"org.matrix.cerulean.event_id"
:
self
.
_thread_room_event_id
,
"org.matrix.cerulean.room_id"
:
self
.
_thread_room_id
,
"org.matrix.cerulean.root"
:
True
,
},
"method"
:
"put"
,
})
...
...
@@ -105,6 +141,8 @@ class MatrixRoomMessage(Post, MatrixEntityMixin):
self
.
get_profile_room_id
()
# Upload embedded images and replace the HTTP urls in the message with MXC urls so clients show the images
self
.
upload_embedded_images
()
# Create thread room
self
.
create_thread_room
()
def
upload_embedded_images
(
self
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment