@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
use revolt_models::v0::{
|
||||
AppendMessage, Channel, Emoji, FieldsChannel, FieldsMember, FieldsRole, FieldsServer,
|
||||
FieldsUser, FieldsWebhook, MemberCompositeKey, Message, PartialChannel, PartialMember,
|
||||
PartialMessage, PartialRole, PartialServer, PartialUser, PartialWebhook, Server, User,
|
||||
PartialMessage, PartialRole, PartialServer, PartialUser, PartialWebhook, Report, Server, User,
|
||||
UserSettings, Webhook,
|
||||
};
|
||||
use revolt_result::Error;
|
||||
@@ -176,8 +176,8 @@ pub enum EventV1 {
|
||||
/// Delete emoji
|
||||
EmojiDelete { id: String },
|
||||
|
||||
/*/// New report
|
||||
ReportCreate(Report), */
|
||||
/// New report
|
||||
ReportCreate(Report),
|
||||
/// New channel
|
||||
ChannelCreate(Channel),
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use iso8601_timestamp::Timestamp;
|
||||
use revolt_models::v0::{ReportStatus, ReportedContent};
|
||||
|
||||
auto_derived!(
|
||||
/// User-generated platform moderation report
|
||||
@@ -19,130 +19,4 @@ auto_derived!(
|
||||
#[serde(default)]
|
||||
pub notes: String,
|
||||
}
|
||||
|
||||
/// Reason for reporting content (message or server)
|
||||
pub enum ContentReportReason {
|
||||
/// No reason has been specified
|
||||
NoneSpecified,
|
||||
|
||||
/// Illegal content catch-all reason
|
||||
Illegal,
|
||||
|
||||
/// Selling or facilitating use of drugs or other illegal goods
|
||||
IllegalGoods,
|
||||
|
||||
/// Extortion or blackmail
|
||||
IllegalExtortion,
|
||||
|
||||
/// Revenge or child pornography
|
||||
IllegalPornography,
|
||||
|
||||
/// Illegal hacking activity
|
||||
IllegalHacking,
|
||||
|
||||
/// Extreme violence, gore, or animal cruelty
|
||||
/// With exception to violence potrayed in media / creative arts
|
||||
ExtremeViolence,
|
||||
|
||||
/// Content that promotes harm to others / self
|
||||
PromotesHarm,
|
||||
|
||||
/// Unsolicited advertisements
|
||||
UnsolicitedSpam,
|
||||
|
||||
/// This is a raid
|
||||
Raid,
|
||||
|
||||
/// Spam or platform abuse
|
||||
SpamAbuse,
|
||||
|
||||
/// Scams or fraud
|
||||
ScamsFraud,
|
||||
|
||||
/// Distribution of malware or malicious links
|
||||
Malware,
|
||||
|
||||
/// Harassment or abuse targeted at another user
|
||||
Harassment,
|
||||
}
|
||||
|
||||
/// Reason for reporting a user
|
||||
pub enum UserReportReason {
|
||||
/// No reason has been specified
|
||||
NoneSpecified,
|
||||
|
||||
/// Unsolicited advertisements
|
||||
UnsolicitedSpam,
|
||||
|
||||
/// User is sending spam or otherwise abusing the platform
|
||||
SpamAbuse,
|
||||
|
||||
/// User's profile contains inappropriate content for a general audience
|
||||
InappropriateProfile,
|
||||
|
||||
/// User is impersonating another user
|
||||
Impersonation,
|
||||
|
||||
/// User is evading a ban
|
||||
BanEvasion,
|
||||
|
||||
/// User is not of minimum age to use the platform
|
||||
Underage,
|
||||
}
|
||||
|
||||
/// The content being reported
|
||||
#[serde(tag = "type")]
|
||||
pub enum ReportedContent {
|
||||
/// Report a message
|
||||
Message {
|
||||
/// ID of the message
|
||||
id: String,
|
||||
/// Reason for reporting message
|
||||
report_reason: ContentReportReason,
|
||||
},
|
||||
/// Report a server
|
||||
Server {
|
||||
/// ID of the server
|
||||
id: String,
|
||||
/// Reason for reporting server
|
||||
report_reason: ContentReportReason,
|
||||
},
|
||||
/// Report a user
|
||||
User {
|
||||
/// ID of the user
|
||||
id: String,
|
||||
/// Reason for reporting a user
|
||||
report_reason: UserReportReason,
|
||||
/// Message context
|
||||
message_id: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Status of the report
|
||||
#[serde(tag = "status")]
|
||||
pub enum ReportStatus {
|
||||
/// Report is waiting for triage / action
|
||||
Created {},
|
||||
|
||||
/// Report was rejected
|
||||
Rejected {
|
||||
rejection_reason: String,
|
||||
closed_at: Option<Timestamp>,
|
||||
},
|
||||
|
||||
/// Report was actioned and resolved
|
||||
Resolved { closed_at: Option<Timestamp> },
|
||||
}
|
||||
|
||||
/// Just the status of the report
|
||||
pub enum ReportStatusString {
|
||||
/// Report is waiting for triage / action
|
||||
Created,
|
||||
|
||||
/// Report was rejected
|
||||
Rejected,
|
||||
|
||||
/// Report was actioned and resolved
|
||||
Resolved,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use revolt_models::v0::{Message, Server, User};
|
||||
use revolt_models::v0::MessageSort;
|
||||
use revolt_result::Result;
|
||||
|
||||
use crate::{Database, Message, MessageFilter, MessageQuery, MessageTimePeriod, Server, User};
|
||||
|
||||
auto_derived!(
|
||||
/// Snapshot of some content
|
||||
@@ -33,3 +36,86 @@ auto_derived!(
|
||||
User(User),
|
||||
}
|
||||
);
|
||||
|
||||
impl SnapshotContent {
|
||||
/// Generate snapshot from a given message
|
||||
pub async fn generate_from_message(
|
||||
db: &Database,
|
||||
message: Message,
|
||||
) -> Result<(SnapshotContent, Vec<String>)> {
|
||||
// Collect message attachments
|
||||
let files = message
|
||||
.attachments
|
||||
.as_ref()
|
||||
.map(|attachments| attachments.iter().map(|x| x.id.to_string()).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
// Collect prior context
|
||||
let prior_context = db
|
||||
.fetch_messages(MessageQuery {
|
||||
filter: MessageFilter {
|
||||
channel: Some(message.channel.to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
limit: Some(15),
|
||||
time_period: MessageTimePeriod::Absolute {
|
||||
before: Some(message.id.to_string()),
|
||||
after: None,
|
||||
sort: Some(MessageSort::Latest),
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
|
||||
// Collect leading context
|
||||
let leading_context = db
|
||||
.fetch_messages(MessageQuery {
|
||||
filter: MessageFilter {
|
||||
channel: Some(message.channel.to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
limit: Some(15),
|
||||
time_period: MessageTimePeriod::Absolute {
|
||||
before: None,
|
||||
after: Some(message.id.to_string()),
|
||||
sort: Some(MessageSort::Oldest),
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok((
|
||||
SnapshotContent::Message {
|
||||
message,
|
||||
prior_context: prior_context.into_iter().map(Into::into).collect(),
|
||||
leading_context: leading_context.into_iter().map(Into::into).collect(),
|
||||
},
|
||||
files,
|
||||
))
|
||||
}
|
||||
|
||||
/// Generate snapshot from a given server
|
||||
pub fn generate_from_server(server: Server) -> Result<(SnapshotContent, Vec<String>)> {
|
||||
// Collect server's icon and banner
|
||||
let files = [&server.icon, &server.banner]
|
||||
.iter()
|
||||
.filter_map(|x| x.as_ref().map(|x| x.id.to_string()))
|
||||
.collect();
|
||||
|
||||
Ok((SnapshotContent::Server(server), files))
|
||||
}
|
||||
|
||||
/// Generate snapshot from a given user
|
||||
pub fn generate_from_user(user: User) -> Result<(SnapshotContent, Vec<String>)> {
|
||||
// Collect user's avatar and profile background
|
||||
let files = [
|
||||
user.avatar.as_ref(),
|
||||
user.profile
|
||||
.as_ref()
|
||||
.and_then(|profile| profile.background.as_ref()),
|
||||
]
|
||||
.iter()
|
||||
.filter_map(|x| x.as_ref().map(|x| x.id.to_string()))
|
||||
.collect();
|
||||
|
||||
Ok((SnapshotContent::User(user), files))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,6 +445,19 @@ impl From<Masquerade> for crate::Masquerade {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::Report> for Report {
|
||||
fn from(value: crate::Report) -> Self {
|
||||
Report {
|
||||
id: value.id,
|
||||
author_id: value.author_id,
|
||||
content: value.content,
|
||||
additional_context: value.additional_context,
|
||||
status: value.status,
|
||||
notes: value.notes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::ServerBan> for ServerBan {
|
||||
fn from(value: crate::ServerBan) -> Self {
|
||||
ServerBan {
|
||||
|
||||
Reference in New Issue
Block a user