forked from jmug/stoatchat
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>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
icon: Option<File>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
last_message: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ impl Message {
|
||||
"last_message": {
|
||||
"_id": self.id.clone(),
|
||||
"author": self.author.clone(),
|
||||
"short": text.chars().take(24).collect::<String>()
|
||||
"short": text.chars().take(128).collect::<String>()
|
||||
}
|
||||
}
|
||||
} 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 futures::StreamExt;
|
||||
use mongodb::bson::doc;
|
||||
use mongodb::bson::from_document;
|
||||
use mongodb::bson::to_document;
|
||||
use mongodb::bson::Document;
|
||||
use mongodb::options::FindOptions;
|
||||
@@ -148,7 +149,7 @@ impl Server {
|
||||
})?;
|
||||
|
||||
// Delete all channels, members, bans and invites.
|
||||
for with in ["channels", "invites"] {
|
||||
for with in &["channels", "invites"] {
|
||||
get_collection(with)
|
||||
.delete_many(
|
||||
doc! {
|
||||
@@ -163,7 +164,7 @@ impl Server {
|
||||
})?;
|
||||
}
|
||||
|
||||
for with in ["server_members", "server_bans"] {
|
||||
for with in &["server_members", "server_bans"] {
|
||||
get_collection(with)
|
||||
.delete_many(
|
||||
doc! {
|
||||
@@ -207,6 +208,27 @@ impl Server {
|
||||
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>> {
|
||||
Ok(get_collection("server_members")
|
||||
.find(
|
||||
|
||||
Reference in New Issue
Block a user