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
ccf501a4
Unverified
Commit
ccf501a4
authored
3 years ago
by
Nyaaori
Browse files
Options
Downloads
Patches
Plain Diff
Initial implementation of /report, fixing #13
parent
6f70beb7
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
src/client_server/mod.rs
+2
-0
2 additions, 0 deletions
src/client_server/mod.rs
src/client_server/report.rs
+75
-0
75 additions, 0 deletions
src/client_server/report.rs
src/main.rs
+1
-0
1 addition, 0 deletions
src/main.rs
with
78 additions
and
0 deletions
src/client_server/mod.rs
+
2
−
0
View file @
ccf501a4
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
mod
push
;
mod
push
;
mod
read_marker
;
mod
read_marker
;
mod
redact
;
mod
redact
;
mod
report
;
mod
room
;
mod
room
;
mod
search
;
mod
search
;
mod
session
;
mod
session
;
...
@@ -47,6 +48,7 @@
...
@@ -47,6 +48,7 @@
pub
use
push
::
*
;
pub
use
push
::
*
;
pub
use
read_marker
::
*
;
pub
use
read_marker
::
*
;
pub
use
redact
::
*
;
pub
use
redact
::
*
;
pub
use
report
::
*
;
pub
use
room
::
*
;
pub
use
room
::
*
;
pub
use
search
::
*
;
pub
use
search
::
*
;
pub
use
session
::
*
;
pub
use
session
::
*
;
...
...
This diff is collapsed.
Click to expand it.
src/client_server/report.rs
0 → 100644
+
75
−
0
View file @
ccf501a4
use
std
::
sync
::
Arc
;
use
crate
::{
database
::
admin
::
AdminCommand
,
database
::
DatabaseGuard
,
ConduitResult
,
Error
,
Ruma
};
use
ruma
::{
api
::
client
::{
error
::
ErrorKind
,
r0
::
room
::
report_content
},
events
::
room
::
message
,
Int
,
};
#[cfg(feature
=
"conduit_bin"
)]
use
rocket
::
post
;
/// # `POST /_matrix/client/r0/rooms/{roomId}/report/{eventId}`
///
/// Reports an inappropriate event to homeserver admins
///
#[cfg_attr(
feature
=
"conduit_bin"
,
post(
"/_matrix/client/r0/rooms/<_>/report/<_>"
,
data
=
"<body>"
)
)]
#[tracing::instrument(skip(db,
body))]
pub
async
fn
report_event_route
(
db
:
DatabaseGuard
,
body
:
Ruma
<
report_content
::
Request
<
'_
>>
,
)
->
ConduitResult
<
report_content
::
Response
>
{
let
sender_user
=
body
.sender_user
.as_ref
()
.expect
(
"user is authenticated"
);
let
pdu
=
match
db
.rooms
.get_pdu
(
&
body
.event_id
)
{
Ok
(
pdu
)
if
!
pdu
.is_none
()
=>
pdu
,
_
=>
{
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
InvalidParam
,
"Invalid Event ID"
,
))
}
}
.unwrap
();
if
body
.score
>=
Int
::
from
(
0
)
&&
body
.score
<=
Int
::
from
(
-
100
)
{
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
InvalidParam
,
"Invalid score, must be within 0 to -100"
,
));
};
if
body
.reason
.chars
()
.count
()
>
160
{
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
InvalidParam
,
"Reason too long, should be 160 characters or fewer"
,
));
};
let
mutex_state
=
Arc
::
clone
(
db
.globals
.roomid_mutex_state
.write
()
.unwrap
()
.entry
(
body
.room_id
.clone
())
.or_default
(),
);
let
state_lock
=
mutex_state
.lock
()
.await
;
db
.admin
.send
(
AdminCommand
::
SendMessage
(
message
::
RoomMessageEventContent
::
text_plain
(
format!
(
"Report received from: {}
\r\n\r\n
Event ID: {}
\r\n
Room ID: {}
\r\n
Sent By: {}
\r\n\r\n
Report Score: {}
\r\n
Report Reason: {}"
,
sender_user
,
pdu
.event_id
,
pdu
.room_id
,
pdu
.sender
,
body
.score
,
body
.reason
,
)),
));
drop
(
state_lock
);
db
.flush
()
?
;
Ok
(
report_content
::
Response
{}
.into
())
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
1
−
0
View file @
ccf501a4
...
@@ -101,6 +101,7 @@ fn setup_rocket(config: Figment, data: Arc<RwLock<Database>>) -> rocket::Rocket<
...
@@ -101,6 +101,7 @@ fn setup_rocket(config: Figment, data: Arc<RwLock<Database>>) -> rocket::Rocket<
client_server
::
create_typing_event_route
,
client_server
::
create_typing_event_route
,
client_server
::
create_room_route
,
client_server
::
create_room_route
,
client_server
::
redact_event_route
,
client_server
::
redact_event_route
,
client_server
::
report_event_route
,
client_server
::
create_alias_route
,
client_server
::
create_alias_route
,
client_server
::
delete_alias_route
,
client_server
::
delete_alias_route
,
client_server
::
get_alias_route
,
client_server
::
get_alias_route
,
...
...
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