Skip to content
Snippets Groups Projects
Commit 11ce7c9e authored by insert's avatar insert
Browse files

Handle incoming changes and push to cache.

parent 8956400e
No related merge requests found
...@@ -207,54 +207,28 @@ use crate::notifications::events::Notification; ...@@ -207,54 +207,28 @@ use crate::notifications::events::Notification;
pub fn process_event(event: &Notification) { pub fn process_event(event: &Notification) {
match event { match event {
Notification::guild_channel_create(ev) => {} // ? for later use Notification::guild_channel_create(ev) => {} // ? for later use
Notification::guild_channel_create(ev) => {} // ? for later use Notification::guild_channel_delete(ev) => {} // ? for later use
Notification::guild_delete(ev) => {} Notification::guild_delete(ev) => {
Notification::guild_user_join(ev) => {}
Notification::guild_user_leave(ev) => {}
/*Notification::group_user_join(ev) => {
let mut cache = CACHE.lock().unwrap(); let mut cache = CACHE.lock().unwrap();
let entry = cache.pop(&ev.id); cache.pop(&ev.id);
if entry.is_some() {
let mut channel = entry.unwrap();
channel.recipients.as_mut().unwrap().push(ev.user.clone());
cache.put(ev.id.clone(), channel);
}
} }
Notification::group_user_leave(ev) => { Notification::guild_user_join(ev) => {
let mut cache = CACHE.lock().unwrap(); let mut cache = MEMBER_CACHE.lock().unwrap();
let entry = cache.pop(&ev.id);
if entry.is_some() {
let mut channel = entry.unwrap();
let recipients = channel.recipients.as_mut().unwrap();
if let Some(pos) = recipients.iter().position(|x| *x == ev.user) {
recipients.remove(pos);
}
cache.put(ev.id.clone(), channel);
}
}
Notification::guild_channel_create(ev) => {
let mut cache = CACHE.lock().unwrap();
cache.put( cache.put(
ev.id.clone(), MemberKey ( ev.id.clone(), ev.user.clone() ),
Channel { Member {
id: ev.channel.clone(), id: MemberRef {
channel_type: 2, guild: ev.id.clone(),
active: None, user: ev.user.clone()
last_message: None, },
recipients: None, nickname: None
owner: None,
guild: Some(ev.id.clone()),
name: Some(ev.name.clone()),
description: Some(ev.description.clone())
} }
); );
} }
Notification::guild_channel_delete(ev) => { Notification::guild_user_leave(ev) => {
let mut cache = CACHE.lock().unwrap(); let mut cache = MEMBER_CACHE.lock().unwrap();
cache.pop(&ev.channel); cache.pop(&MemberKey ( ev.id.clone(), ev.user.clone() ));
}*/ }
_ => {} _ => {}
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment