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
af6fea3d
Unverified
Commit
af6fea3d
authored
3 years ago
by
Jonas Platte
Browse files
Options
Downloads
Patches
Plain Diff
Refactor some canonical JSON code
parent
a0457000
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pdu.rs
+4
-1
4 additions, 1 deletion
src/pdu.rs
src/ruma_wrapper.rs
+25
-33
25 additions, 33 deletions
src/ruma_wrapper.rs
with
29 additions
and
34 deletions
src/pdu.rs
+
4
−
1
View file @
af6fea3d
...
@@ -213,7 +213,10 @@ pub fn to_member_event(&self) -> Raw<StateEvent<MemberEventContent>> {
...
@@ -213,7 +213,10 @@ pub fn to_member_event(&self) -> Raw<StateEvent<MemberEventContent>> {
pub
fn
convert_to_outgoing_federation_event
(
pub
fn
convert_to_outgoing_federation_event
(
mut
pdu_json
:
CanonicalJsonObject
,
mut
pdu_json
:
CanonicalJsonObject
,
)
->
Raw
<
ruma
::
events
::
pdu
::
Pdu
>
{
)
->
Raw
<
ruma
::
events
::
pdu
::
Pdu
>
{
if
let
Some
(
CanonicalJsonValue
::
Object
(
unsigned
))
=
pdu_json
.get_mut
(
"unsigned"
)
{
if
let
Some
(
unsigned
)
=
pdu_json
.get_mut
(
"unsigned"
)
.and_then
(|
val
|
val
.as_object_mut
())
{
unsigned
.remove
(
"transaction_id"
);
unsigned
.remove
(
"transaction_id"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/ruma_wrapper.rs
+
25
−
33
View file @
af6fea3d
...
@@ -271,41 +271,33 @@ async fn from_data(request: &'a Request<'_>, data: Data) -> data::Outcome<Self,
...
@@ -271,41 +271,33 @@ async fn from_data(request: &'a Request<'_>, data: Data) -> data::Outcome<Self,
http_request
=
http_request
.header
(
header
.name
.as_str
(),
&*
header
.value
);
http_request
=
http_request
.header
(
header
.name
.as_str
(),
&*
header
.value
);
}
}
match
&
mut
json_body
{
if
let
Some
(
json_body
)
=
json_body
.as_mut
()
.and_then
(|
val
|
val
.as_object_mut
())
{
Some
(
CanonicalJsonValue
::
Object
(
json_body
))
=>
{
let
user_id
=
sender_user
.clone
()
.unwrap_or_else
(||
{
let
user_id
=
sender_user
.clone
()
.unwrap_or_else
(||
{
UserId
::
parse_with_server_name
(
""
,
db
.globals
.server_name
())
UserId
::
parse_with_server_name
(
""
,
db
.globals
.server_name
())
.expect
(
"we know this is valid"
)
.expect
(
"we know this is valid"
)
});
});
if
let
Some
(
CanonicalJsonValue
::
Object
(
initial_request
))
=
json_body
if
let
Some
(
initial_request
)
=
json_body
.get
(
"auth"
)
.get
(
"auth"
)
.and_then
(|
auth
|
auth
.as_object
())
.and_then
(|
auth
|
auth
.as_object
())
.and_then
(|
auth
|
auth
.get
(
"session"
))
.and_then
(|
auth
|
auth
.get
(
"session"
))
.and_then
(|
session
|
session
.as_str
())
.and_then
(|
session
|
session
.as_str
())
.and_then
(|
session
|
{
.and_then
(|
session
|
{
db
.uiaa
db
.uiaa
.get_uiaa_request
(
.get_uiaa_request
(
&
user_id
,
&
user_id
,
&
sender_device
.clone
()
.unwrap_or_else
(||
""
.into
()),
&
sender_device
.clone
()
.unwrap_or_else
(||
""
.into
()),
session
,
session
,
)
)
.ok
()
.ok
()
.flatten
()
.flatten
()
})
})
{
{
for
(
key
,
value
)
in
initial_request
{
match
initial_request
{
json_body
.entry
(
key
)
.or_insert
(
value
);
CanonicalJsonValue
::
Object
(
initial_request
)
=>
{
for
(
key
,
value
)
in
initial_request
.into_iter
()
{
json_body
.entry
(
key
)
.or_insert
(
value
);
}
}
_
=>
{}
}
}
}
body
=
serde_json
::
to_vec
(
json_body
)
.expect
(
"value to bytes can't fail"
);
}
}
_
=>
{}
body
=
serde_json
::
to_vec
(
json_body
)
.expect
(
"value to bytes can't fail"
);
}
}
let
http_request
=
http_request
.body
(
&*
body
)
.unwrap
();
let
http_request
=
http_request
.body
(
&*
body
)
.unwrap
();
...
...
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