Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
🥺
conduwuit
Commits
8087a26a
Unverified
Commit
8087a26a
authored
3 years ago
by
Nyaaori
Browse files
Options
Downloads
Patches
Plain Diff
Make createRoom follow spec for m.room.create, allowing creation of spaces
parent
bbe16f84
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/client_server/room.rs
+53
-12
53 additions, 12 deletions
src/client_server/room.rs
with
53 additions
and
12 deletions
src/client_server/room.rs
+
53
−
12
View file @
8087a26a
...
@@ -22,11 +22,16 @@
...
@@ -22,11 +22,16 @@
},
},
EventType
,
EventType
,
},
},
serde
::{
JsonObject
},
serde
::{
Canonical
JsonObject
,
JsonObject
,
Raw
},
RoomAliasId
,
RoomId
,
RoomVersionId
,
RoomAliasId
,
RoomId
,
RoomVersionId
,
};
};
use
serde_json
::{
value
::
to_raw_value
};
use
serde_json
::{
json
,
value
::
to_raw_value
};
use
std
::{
cmp
::
max
,
collections
::
BTreeMap
,
convert
::
TryFrom
,
sync
::
Arc
};
use
std
::{
cmp
::
max
,
collections
::
BTreeMap
,
convert
::{
TryFrom
,
TryInto
},
sync
::
Arc
,
};
use
tracing
::{
info
,
warn
};
use
tracing
::{
info
,
warn
};
#[cfg(feature
=
"conduit_bin"
)]
#[cfg(feature
=
"conduit_bin"
)]
...
@@ -102,15 +107,7 @@ pub async fn create_room_route(
...
@@ -102,15 +107,7 @@ pub async fn create_room_route(
}
}
})
?
;
})
?
;
let
creation_content
=
match
body
.creation_content
.clone
()
{
let
room_version
=
match
body
.room_version
.clone
()
{
Some
(
content
)
=>
content
.deserialize
()
.expect
(
"Invalid creation content"
),
None
=>
create_room
::
CreationContent
::
new
(),
};
let
mut
content
=
RoomCreateEventContent
::
new
(
sender_user
.clone
());
content
.federate
=
creation_content
.federate
;
content
.predecessor
=
creation_content
.predecessor
.clone
();
content
.room_version
=
match
body
.room_version
.clone
()
{
Some
(
room_version
)
=>
{
Some
(
room_version
)
=>
{
if
room_version
==
RoomVersionId
::
Version5
||
room_version
==
RoomVersionId
::
Version6
{
if
room_version
==
RoomVersionId
::
Version5
||
room_version
==
RoomVersionId
::
Version6
{
room_version
room_version
...
@@ -124,6 +121,50 @@ pub async fn create_room_route(
...
@@ -124,6 +121,50 @@ pub async fn create_room_route(
None
=>
RoomVersionId
::
Version6
,
None
=>
RoomVersionId
::
Version6
,
};
};
let
content
=
match
&
body
.creation_content
{
Some
(
content
)
=>
{
let
mut
content
=
content
.deserialize_as
::
<
CanonicalJsonObject
>
()
.expect
(
"Invalid creation content"
);
content
.insert
(
"creator"
.into
(),
json!
(
sender_user
.clone
())
.try_into
()
.unwrap
(),
);
content
.insert
(
"room_version"
.into
(),
json!
(
room_version
.as_str
())
.try_into
()
.unwrap
(),
);
content
}
None
=>
{
let
mut
content
=
Raw
::
<
CanonicalJsonObject
>
::
from_json
(
to_raw_value
(
&
RoomCreateEventContent
::
new
(
sender_user
.clone
()))
.unwrap
(),
)
.deserialize_as
::
<
CanonicalJsonObject
>
()
.unwrap
();
content
.insert
(
"room_version"
.into
(),
json!
(
room_version
.as_str
())
.try_into
()
.unwrap
(),
);
content
}
};
// Validate creation content
match
Raw
::
<
CanonicalJsonObject
>
::
from_json
(
to_raw_value
(
&
content
)
.expect
(
"Invalid creation content"
),
)
.deserialize_as
::
<
RoomCreateEventContent
>
()
{
Ok
(
_t
)
=>
{}
Err
(
_e
)
=>
{
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
BadJson
,
"Invalid creation content"
,
))
}
};
// 1. The room create event
// 1. The room create event
db
.rooms
.build_and_append_pdu
(
db
.rooms
.build_and_append_pdu
(
PduBuilder
{
PduBuilder
{
...
...
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