mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 13:36:59 +00:00
Fix block user route, send correct user struct.
Add route for fetching members. Cargo fmt on accident.
This commit is contained in:
@@ -44,7 +44,7 @@ pub enum Channel {
|
||||
owner: String,
|
||||
description: String,
|
||||
recipients: Vec<String>,
|
||||
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
icon: Option<File>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@@ -93,8 +93,7 @@ impl Channel {
|
||||
})?;
|
||||
|
||||
let channel_id = self.id().to_string();
|
||||
ClientboundNotification::ChannelCreate(self)
|
||||
.publish(channel_id);
|
||||
ClientboundNotification::ChannelCreate(self).publish(channel_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -104,7 +103,7 @@ impl Channel {
|
||||
ClientboundNotification::ChannelUpdate {
|
||||
id: id.clone(),
|
||||
data,
|
||||
clear: None
|
||||
clear: None,
|
||||
}
|
||||
.publish(id);
|
||||
|
||||
@@ -188,9 +187,8 @@ impl Channel {
|
||||
with: "channel",
|
||||
})?;
|
||||
|
||||
ClientboundNotification::ChannelDelete { id: id.to_string() }
|
||||
.publish(id.to_string());
|
||||
|
||||
ClientboundNotification::ChannelDelete { id: id.to_string() }.publish(id.to_string());
|
||||
|
||||
if let Channel::Group { icon, .. } = self {
|
||||
if let Some(attachment) = icon {
|
||||
attachment.delete().await?;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
use crate::util::{
|
||||
result::{Error, Result},
|
||||
variables::JANUARY_URL,
|
||||
};
|
||||
use linkify::{LinkFinder, LinkKind};
|
||||
use crate::util::{result::{Error, Result}, variables::JANUARY_URL};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum ImageSize {
|
||||
@@ -33,7 +36,7 @@ pub enum TwitchType {
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum BandcampType {
|
||||
Album,
|
||||
Track
|
||||
Track,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -54,8 +57,8 @@ pub enum Special {
|
||||
Soundcloud,
|
||||
Bandcamp {
|
||||
content_type: BandcampType,
|
||||
id: String
|
||||
}
|
||||
id: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -98,7 +101,7 @@ impl Embed {
|
||||
// Ignore quoted lines.
|
||||
if let Some(c) = v.chars().next() {
|
||||
if c == '>' {
|
||||
return ""
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,12 +134,10 @@ impl Embed {
|
||||
Err(_) => return Err(Error::LabelMe),
|
||||
Ok(result) => match result.status() {
|
||||
reqwest::StatusCode::OK => {
|
||||
let res: Embed = result.json()
|
||||
.await
|
||||
.map_err(|_| Error::InvalidOperation)?;
|
||||
let res: Embed = result.json().await.map_err(|_| Error::InvalidOperation)?;
|
||||
|
||||
Ok(vec![ res ])
|
||||
},
|
||||
Ok(vec![res])
|
||||
}
|
||||
_ => return Err(Error::LabelMe),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -135,9 +135,7 @@ impl Message {
|
||||
self.process_embed();
|
||||
|
||||
let enc = serde_json::to_string(&self).unwrap();
|
||||
ClientboundNotification::Message(self)
|
||||
.publish(channel.id().to_string());
|
||||
|
||||
ClientboundNotification::Message(self).publish(channel.id().to_string());
|
||||
|
||||
/*
|
||||
Web Push Test Code
|
||||
@@ -202,9 +200,11 @@ impl Message {
|
||||
|
||||
for subscription in subscriptions {
|
||||
let mut builder = WebPushMessageBuilder::new(&subscription).unwrap();
|
||||
let sig_builder =
|
||||
VapidSignatureBuilder::from_pem(std::io::Cursor::new(&key), &subscription)
|
||||
.unwrap();
|
||||
let sig_builder = VapidSignatureBuilder::from_pem(
|
||||
std::io::Cursor::new(&key),
|
||||
&subscription,
|
||||
)
|
||||
.unwrap();
|
||||
let signature = sig_builder.build().unwrap();
|
||||
builder.set_vapid_signature(signature);
|
||||
builder.set_payload(ContentEncoding::AesGcm, enc.as_bytes());
|
||||
@@ -250,12 +250,11 @@ impl Message {
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await {
|
||||
.await
|
||||
{
|
||||
ClientboundNotification::MessageUpdate {
|
||||
id,
|
||||
data: json!({
|
||||
"embeds": embeds
|
||||
}),
|
||||
data: json!({ "embeds": embeds }),
|
||||
}
|
||||
.publish(channel);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
mod server;
|
||||
mod autumn;
|
||||
mod january;
|
||||
mod channel;
|
||||
mod january;
|
||||
mod message;
|
||||
mod server;
|
||||
mod user;
|
||||
|
||||
pub use january::*;
|
||||
pub use autumn::*;
|
||||
pub use channel::*;
|
||||
pub use server::*;
|
||||
pub use january::*;
|
||||
pub use message::*;
|
||||
pub use server::*;
|
||||
pub use user::*;
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
use mongodb::bson::doc;
|
||||
use futures::StreamExt;
|
||||
use mongodb::options::{Collation, FindOneOptions};
|
||||
use mongodb::{
|
||||
bson::{doc, from_document},
|
||||
options::FindOptions,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
use crate::database::permissions::user::UserPermissions;
|
||||
use crate::database::*;
|
||||
use crate::notifications::websocket::is_online;
|
||||
use crate::util::result::{Error, Result};
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
pub enum RelationshipStatus {
|
||||
@@ -160,4 +164,46 @@ impl User {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
/// Utility function for fetching multiple users from the perspective of one.
|
||||
pub async fn fetch_multiple_users(&self, user_ids: Vec<String>) -> Result<Vec<User>> {
|
||||
let mut users = vec![];
|
||||
let mut cursor = get_collection("users")
|
||||
.find(
|
||||
doc! {
|
||||
"_id": {
|
||||
"$in": user_ids
|
||||
}
|
||||
},
|
||||
FindOptions::builder()
|
||||
.projection(
|
||||
doc! { "_id": 1, "username": 1, "avatar": 1, "badges": 1, "status": 1 },
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find",
|
||||
with: "users",
|
||||
})?;
|
||||
|
||||
while let Some(result) = cursor.next().await {
|
||||
if let Ok(doc) = result {
|
||||
let other: User = from_document(doc).map_err(|_| Error::DatabaseError {
|
||||
operation: "from_document",
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
let permissions = PermissionCalculator::new(&self)
|
||||
.with_mutual_connection()
|
||||
.with_user(&other)
|
||||
.for_user_given()
|
||||
.await?;
|
||||
|
||||
users.push(other.from(&self).with(permissions));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(users)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user