Channels: Include last message id on text channels.
API: Return members when fetching messages. Misc: Remove defunct DISABLE_REGISTRATION variable.
This commit is contained in:
@@ -63,6 +63,8 @@ pub enum Channel {
|
|||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
icon: Option<File>,
|
icon: Option<File>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
last_message: Option<String>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ impl Message {
|
|||||||
"last_message": {
|
"last_message": {
|
||||||
"_id": self.id.clone(),
|
"_id": self.id.clone(),
|
||||||
"author": self.author.clone(),
|
"author": self.author.clone(),
|
||||||
"short": text.chars().take(24).collect::<String>()
|
"short": text.chars().take(128).collect::<String>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -133,6 +133,25 @@ impl Message {
|
|||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Channel::TextChannel { id, .. } => {
|
||||||
|
if let Content::Text(_) = &self.content {
|
||||||
|
channels
|
||||||
|
.update_one(
|
||||||
|
doc! { "_id": id },
|
||||||
|
doc! {
|
||||||
|
"$set": {
|
||||||
|
"last_message": &self.id
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|_| Error::DatabaseError {
|
||||||
|
operation: "update_one",
|
||||||
|
with: "channel",
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::notifications::events::ClientboundNotification;
|
|||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
|
use mongodb::bson::from_document;
|
||||||
use mongodb::bson::to_document;
|
use mongodb::bson::to_document;
|
||||||
use mongodb::bson::Document;
|
use mongodb::bson::Document;
|
||||||
use mongodb::options::FindOptions;
|
use mongodb::options::FindOptions;
|
||||||
@@ -148,7 +149,7 @@ impl Server {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Delete all channels, members, bans and invites.
|
// Delete all channels, members, bans and invites.
|
||||||
for with in ["channels", "invites"] {
|
for with in &["channels", "invites"] {
|
||||||
get_collection(with)
|
get_collection(with)
|
||||||
.delete_many(
|
.delete_many(
|
||||||
doc! {
|
doc! {
|
||||||
@@ -163,7 +164,7 @@ impl Server {
|
|||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for with in ["server_members", "server_bans"] {
|
for with in &["server_members", "server_bans"] {
|
||||||
get_collection(with)
|
get_collection(with)
|
||||||
.delete_many(
|
.delete_many(
|
||||||
doc! {
|
doc! {
|
||||||
@@ -207,6 +208,27 @@ impl Server {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn fetch_members(id: &str) -> Result<Vec<Member>> {
|
||||||
|
Ok(get_collection("server_members")
|
||||||
|
.find(
|
||||||
|
doc! {
|
||||||
|
"_id.server": id
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|_| Error::DatabaseError {
|
||||||
|
operation: "find",
|
||||||
|
with: "server_members",
|
||||||
|
})?
|
||||||
|
.filter_map(async move |s| s.ok())
|
||||||
|
.collect::<Vec<Document>>()
|
||||||
|
.await
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|x| from_document(x).ok())
|
||||||
|
.collect::<Vec<Member>>())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn fetch_member_ids(id: &str) -> Result<Vec<String>> {
|
pub async fn fetch_member_ids(id: &str) -> Result<Vec<String>> {
|
||||||
Ok(get_collection("server_members")
|
Ok(get_collection("server_members")
|
||||||
.find(
|
.find(
|
||||||
|
|||||||
@@ -98,11 +98,20 @@ pub async fn req(user: User, target: Ref, options: Form<Options>) -> Result<Json
|
|||||||
|
|
||||||
ids.remove(&user.id);
|
ids.remove(&user.id);
|
||||||
let user_ids = ids.into_iter().collect();
|
let user_ids = ids.into_iter().collect();
|
||||||
|
let users = user.fetch_multiple_users(user_ids).await?;
|
||||||
|
|
||||||
Ok(json!({
|
if let Channel::TextChannel { server, .. } = target {
|
||||||
"messages": messages,
|
Ok(json!({
|
||||||
"users": user.fetch_multiple_users(user_ids).await?
|
"messages": messages,
|
||||||
}))
|
"users": users,
|
||||||
|
"members": Server::fetch_members(&server).await?
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
Ok(json!({
|
||||||
|
"messages": messages,
|
||||||
|
"users": users,
|
||||||
|
}))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(json!(messages))
|
Ok(json!(messages))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::util::variables::{
|
use crate::util::variables::{
|
||||||
APP_URL, AUTUMN_URL, DISABLE_REGISTRATION, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, INVITE_ONLY,
|
APP_URL, AUTUMN_URL, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, INVITE_ONLY,
|
||||||
JANUARY_URL, USE_AUTUMN, USE_EMAIL, USE_HCAPTCHA, USE_JANUARY, USE_VOSO, VAPID_PUBLIC_KEY,
|
JANUARY_URL, USE_AUTUMN, USE_EMAIL, USE_HCAPTCHA, USE_JANUARY, USE_VOSO, VAPID_PUBLIC_KEY,
|
||||||
VOSO_URL, VOSO_WS_HOST,
|
VOSO_URL, VOSO_WS_HOST,
|
||||||
};
|
};
|
||||||
@@ -12,7 +12,6 @@ pub async fn root() -> JsonValue {
|
|||||||
json!({
|
json!({
|
||||||
"revolt": crate::version::VERSION,
|
"revolt": crate::version::VERSION,
|
||||||
"features": {
|
"features": {
|
||||||
"registration": !*DISABLE_REGISTRATION,
|
|
||||||
"captcha": {
|
"captcha": {
|
||||||
"enabled": *USE_HCAPTCHA,
|
"enabled": *USE_HCAPTCHA,
|
||||||
"key": HCAPTCHA_SITEKEY.to_string()
|
"key": HCAPTCHA_SITEKEY.to_string()
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ pub async fn req(user: User, target: Ref, info: Json<Data>) -> Result<JsonValue>
|
|||||||
name: info.name,
|
name: info.name,
|
||||||
description: info.description,
|
description: info.description,
|
||||||
icon: None,
|
icon: None,
|
||||||
|
last_message: None
|
||||||
};
|
};
|
||||||
|
|
||||||
channel.clone().publish().await?;
|
channel.clone().publish().await?;
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
|
|||||||
name: "general".to_string(),
|
name: "general".to_string(),
|
||||||
description: None,
|
description: None,
|
||||||
icon: None,
|
icon: None,
|
||||||
|
last_message: None
|
||||||
}
|
}
|
||||||
.publish()
|
.publish()
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ lazy_static! {
|
|||||||
env::var("REVOLT_VAPID_PUBLIC_KEY").expect("Missing REVOLT_VAPID_PUBLIC_KEY environment variable.");
|
env::var("REVOLT_VAPID_PUBLIC_KEY").expect("Missing REVOLT_VAPID_PUBLIC_KEY environment variable.");
|
||||||
|
|
||||||
// Application Flags
|
// Application Flags
|
||||||
pub static ref DISABLE_REGISTRATION: bool = env::var("REVOLT_DISABLE_REGISTRATION").map_or(false, |v| v == "1");
|
|
||||||
pub static ref INVITE_ONLY: bool = env::var("REVOLT_INVITE_ONLY").map_or(false, |v| v == "1");
|
pub static ref INVITE_ONLY: bool = env::var("REVOLT_INVITE_ONLY").map_or(false, |v| v == "1");
|
||||||
pub static ref USE_EMAIL: bool = env::var("REVOLT_USE_EMAIL_VERIFICATION").map_or(
|
pub static ref USE_EMAIL: bool = env::var("REVOLT_USE_EMAIL_VERIFICATION").map_or(
|
||||||
env::var("REVOLT_SMTP_HOST").is_ok()
|
env::var("REVOLT_SMTP_HOST").is_ok()
|
||||||
|
|||||||
Reference in New Issue
Block a user