Add all possible notifications.

This commit is contained in:
Paul Makles
2020-04-13 17:47:48 +01:00
parent 0f793f84a2
commit 8043690d38
12 changed files with 435 additions and 96 deletions

View File

@@ -0,0 +1,13 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UserJoin {
pub id: String,
pub user: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UserLeave {
pub id: String,
pub user: String,
}

View File

@@ -0,0 +1,33 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UserJoin {
pub id: String,
pub user: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UserLeave {
pub id: String,
pub user: String,
pub banned: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ChannelCreate {
pub id: String,
pub channel: String,
pub name: String,
pub description: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ChannelDelete {
pub id: String,
pub channel: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Delete {
pub id: String,
}

View File

@@ -8,3 +8,14 @@ pub struct Create {
pub author: String,
pub content: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Edit {
pub id: String,
pub content: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Delete {
pub id: String,
}

View File

@@ -1,11 +1,25 @@
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
pub mod groups;
pub mod guilds;
pub mod message;
pub mod users;
#[allow(non_camel_case_types)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum Notification {
MessageCreate(message::Create),
message_create(message::Create),
message_edit(message::Edit),
message_delete(message::Delete),
group_user_join(groups::UserJoin),
group_user_leave(groups::UserLeave),
guild_user_join(guilds::UserJoin),
guild_user_leave(guilds::UserLeave),
guild_channel_create(guilds::ChannelCreate),
guild_channel_delete(guilds::ChannelDelete),
guild_delete(guilds::Delete),
user_friend_status(users::FriendStatus),
}
impl Notification {

View File

@@ -0,0 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct FriendStatus {
pub id: String,
pub status: i32,
}

View File

@@ -1,3 +1,5 @@
use crate::guards::channel::ChannelRef;
use once_cell::sync::OnceCell;
use std::sync::mpsc::{channel, Sender};
use std::thread;
@@ -62,3 +64,11 @@ pub fn send_message_threaded<U: Into<Option<Vec<String>>>, G: Into<Option<String
.is_ok()
}
}
pub fn send_message_given_channel(data: events::Notification, channel: &ChannelRef) {
match channel.channel_type {
0..=1 => send_message_threaded(channel.recipients.clone(), None, data),
2 => send_message_threaded(None, channel.guild.clone(), data),
_ => unreachable!(),
};
}

View File

@@ -18,8 +18,6 @@ pub struct PubSubMessage {
user_recipients: Option<Vec<String>>,
target_guild: Option<String>,
notification_type: String,
data: Notification,
}
@@ -29,10 +27,6 @@ pub fn send_message(users: Option<Vec<String>>, guild: Option<String>, data: Not
source: SOURCEID.get().unwrap().to_string(),
user_recipients: users.into(),
target_guild: guild.into(),
notification_type: match data {
Notification::MessageCreate(_) => "message_create",
}
.to_string(),
data,
};