Messaging: Upsert mentions into unreads.

Messaging: Allow multiple attachment upload.
This commit is contained in:
Paul
2021-06-22 17:42:18 +01:00
parent b10d4f3559
commit ad06ff16c4
28 changed files with 116 additions and 92 deletions

View File

@@ -128,7 +128,7 @@ impl Channel {
operation: "delete_many",
with: "channel_invites",
})?;
// Delete any unreads.
get_collection("channel_unreads")
.delete_many(

View File

@@ -6,6 +6,7 @@ use crate::{
};
use futures::StreamExt;
use mongodb::options::UpdateOptions;
use mongodb::{
bson::{doc, to_bson, DateTime},
options::FindOptions,
@@ -55,7 +56,7 @@ impl Content {
"00000000000000000000000000".to_string(),
target.id().to_string(),
self,
None
None,
)
.publish(&target)
.await
@@ -79,11 +80,16 @@ pub struct Message {
#[serde(skip_serializing_if = "Option::is_none")]
pub embeds: Option<Vec<Embed>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mentions: Option<Vec<String>>
pub mentions: Option<Vec<String>>,
}
impl Message {
pub fn create(author: String, channel: String, content: Content, mentions: Option<Vec<String>>) -> Message {
pub fn create(
author: String,
channel: String,
content: Content,
mentions: Option<Vec<String>>,
) -> Message {
Message {
id: Ulid::new().to_string(),
nonce: None,
@@ -94,7 +100,7 @@ impl Message {
attachments: None,
edited: None,
embeds: None,
mentions
mentions,
}
}
@@ -208,7 +214,7 @@ impl Message {
"mentions": message
}
},
None
UpdateOptions::builder().upsert(true).build(),
)
.await
/*.map_err(|_| Error::DatabaseError {
@@ -241,7 +247,7 @@ impl Message {
}
_ => {}
}
// Fetch their corresponding sessions.
if let Ok(mut cursor) = get_collection("accounts")
.find(
@@ -309,7 +315,7 @@ impl Message {
ClientboundNotification::MessageUpdate {
id: self.id.clone(),
channel: self.channel.clone(),
data
data,
}
.publish(channel);
self.process_embed();
@@ -348,7 +354,7 @@ impl Message {
ClientboundNotification::MessageUpdate {
id,
channel: channel.clone(),
data: json!({ "embeds": embeds })
data: json!({ "embeds": embeds }),
}
.publish(channel);
}

View File

@@ -3,8 +3,8 @@ use crate::util::{
variables::JANUARY_URL,
};
use linkify::{LinkFinder, LinkKind};
use serde::{Deserialize, Serialize};
use regex::Regex;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ImageSize {

View File

@@ -39,13 +39,13 @@ pub struct SystemMessageChannels {
pub user_joined: Option<String>,
pub user_left: Option<String>,
pub user_kicked: Option<String>,
pub user_banned: Option<String>
pub user_banned: Option<String>,
}
pub enum RemoveMember {
Leave,
Kick,
Ban
Ban,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -361,14 +361,20 @@ impl Server {
}
RemoveMember::Kick => {
if let Some(cid) = &channels.user_kicked {
Some((cid.clone(), SystemMessage::UserKicked { id: id.to_string() }))
Some((
cid.clone(),
SystemMessage::UserKicked { id: id.to_string() },
))
} else {
None
}
}
RemoveMember::Ban => {
if let Some(cid) = &channels.user_banned {
Some((cid.clone(), SystemMessage::UserBanned { id: id.to_string() }))
Some((
cid.clone(),
SystemMessage::UserBanned { id: id.to_string() },
))
} else {
None
}

View File

@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
pub type UserSettings = HashMap<String, (i64, String)>;
@@ -14,6 +14,6 @@ pub struct ChannelUnread {
#[serde(rename = "_id")]
pub id: ChannelCompositeKey,
pub last_id: String,
pub last_id: Option<String>,
pub mentions: Option<Vec<String>>,
}

View File

@@ -261,7 +261,7 @@ impl User {
doc! {
"_id.user": &self.id
},
None
None,
)
.await
.map_err(|_| Error::DatabaseError {

View File

@@ -8,18 +8,18 @@ use std::ops;
#[derive(Debug, PartialEq, Eq, TryFromPrimitive, Copy, Clone)]
#[repr(u32)]
pub enum ServerPermission {
View = 0b00000000000000000000000000000001, // 1
ManageRoles = 0b00000000000000000000000000000010, // 2
ManageChannels = 0b00000000000000000000000000000100, // 4
ManageServer = 0b00000000000000000000000000001000, // 8
KickMembers = 0b00000000000000000000000000010000, // 16
BanMembers = 0b00000000000000000000000000100000, // 32
View = 0b00000000000000000000000000000001, // 1
ManageRoles = 0b00000000000000000000000000000010, // 2
ManageChannels = 0b00000000000000000000000000000100, // 4
ManageServer = 0b00000000000000000000000000001000, // 8
KickMembers = 0b00000000000000000000000000010000, // 16
BanMembers = 0b00000000000000000000000000100000, // 32
// 6 bits of space
ChangeNickname = 0b00000000000000000001000000000000, // 4096
ChangeNickname = 0b00000000000000000001000000000000, // 4096
ManageNicknames = 0b00000000000000000010000000000000, // 8192
ChangeAvatar = 0b00000000000000000100000000000000, // 16392
RemoveAvatars = 0b00000000000000001000000000000000, // 32784
// 16 bits of space
ChangeAvatar = 0b00000000000000000100000000000000, // 16392
RemoveAvatars = 0b00000000000000001000000000000000, // 32784
// 16 bits of space
}
impl_op_ex!(+ |a: &ServerPermission, b: &ServerPermission| -> u32 { *a as u32 | *b as u32 });

View File

@@ -55,8 +55,7 @@ impl<'a> PermissionCalculator<'a> {
.map(|v| v.to_owned())
.unwrap_or_else(|| get_relationship(&self.perspective, &target))
{
RelationshipStatus::Friend |
RelationshipStatus::User => return Ok(u32::MAX),
RelationshipStatus::Friend | RelationshipStatus::User => return Ok(u32::MAX),
RelationshipStatus::Blocked | RelationshipStatus::BlockedOther => {
return Ok(UserPermission::Access as u32)
}