Breaking change to FriendStatus, user cache sync.
This commit is contained in:
@@ -145,25 +145,17 @@ pub fn process_event(event: &Notification) {
|
|||||||
match event {
|
match event {
|
||||||
Notification::group_user_join(ev) => {
|
Notification::group_user_join(ev) => {
|
||||||
let mut cache = CACHE.lock().unwrap();
|
let mut cache = CACHE.lock().unwrap();
|
||||||
let entry = cache.pop(&ev.id);
|
if let Some(channel) = cache.peek_mut(&ev.id) {
|
||||||
|
|
||||||
if entry.is_some() {
|
|
||||||
let mut channel = entry.unwrap();
|
|
||||||
channel.recipients.as_mut().unwrap().push(ev.user.clone());
|
channel.recipients.as_mut().unwrap().push(ev.user.clone());
|
||||||
cache.put(ev.id.clone(), channel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Notification::group_user_leave(ev) => {
|
Notification::group_user_leave(ev) => {
|
||||||
let mut cache = CACHE.lock().unwrap();
|
let mut cache = CACHE.lock().unwrap();
|
||||||
let entry = cache.pop(&ev.id);
|
if let Some(channel) = cache.peek_mut(&ev.id) {
|
||||||
|
|
||||||
if entry.is_some() {
|
|
||||||
let mut channel = entry.unwrap();
|
|
||||||
let recipients = channel.recipients.as_mut().unwrap();
|
let recipients = channel.recipients.as_mut().unwrap();
|
||||||
if let Some(pos) = recipients.iter().position(|x| *x == ev.user) {
|
if let Some(pos) = recipients.iter().position(|x| *x == ev.user) {
|
||||||
recipients.remove(pos);
|
recipients.remove(pos);
|
||||||
}
|
}
|
||||||
cache.put(ev.id.clone(), channel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Notification::guild_channel_create(ev) => {
|
Notification::guild_channel_create(ev) => {
|
||||||
|
|||||||
@@ -206,8 +206,8 @@ 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_delete(ev) => {} // ? for later use
|
Notification::guild_channel_delete(_ev) => {} // ? for later use
|
||||||
Notification::guild_delete(ev) => {
|
Notification::guild_delete(ev) => {
|
||||||
let mut cache = CACHE.lock().unwrap();
|
let mut cache = CACHE.lock().unwrap();
|
||||||
cache.pop(&ev.id);
|
cache.pop(&ev.id);
|
||||||
|
|||||||
@@ -130,3 +130,34 @@ impl<'r> FromParam<'r> for User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use crate::notifications::events::Notification;
|
||||||
|
|
||||||
|
pub fn process_event(event: &Notification) {
|
||||||
|
match event {
|
||||||
|
Notification::user_friend_status(ev) => {
|
||||||
|
let mut cache = CACHE.lock().unwrap();
|
||||||
|
if let Some(user) = cache.peek_mut(&ev.id) {
|
||||||
|
if let Some(relations) = user.relations.as_mut() {
|
||||||
|
if ev.status == 0 {
|
||||||
|
if let Some(pos) = relations.iter().position(|x| x.id == ev.user) {
|
||||||
|
relations.remove(pos);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let Some(entry) = relations.iter_mut().find(|x| x.id == ev.user) {
|
||||||
|
entry.status = ev.status as u8;
|
||||||
|
} else {
|
||||||
|
relations.push(
|
||||||
|
UserRelationship {
|
||||||
|
id: ev.id.clone(),
|
||||||
|
status: ev.status as u8
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,5 +41,7 @@ impl Notification {
|
|||||||
|
|
||||||
pub fn push_to_cache(&self) {
|
pub fn push_to_cache(&self) {
|
||||||
crate::database::channel::process_event(&self);
|
crate::database::channel::process_event(&self);
|
||||||
|
crate::database::guild::process_event(&self);
|
||||||
|
crate::database::user::process_event(&self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct FriendStatus {
|
pub struct FriendStatus {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
pub user: String,
|
||||||
pub status: i32,
|
pub status: i32,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,7 +268,8 @@ pub fn add_friend(user: User, target: User) -> Response {
|
|||||||
vec![target.id.clone()],
|
vec![target.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: user.id.clone(),
|
id: target.id.clone(),
|
||||||
|
user: user.id.clone(),
|
||||||
status: Relationship::Friend as i32,
|
status: Relationship::Friend as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -277,7 +278,8 @@ pub fn add_friend(user: User, target: User) -> Response {
|
|||||||
vec![user.id.clone()],
|
vec![user.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: target.id.clone(),
|
id: user.id.clone(),
|
||||||
|
user: target.id.clone(),
|
||||||
status: Relationship::Friend as i32,
|
status: Relationship::Friend as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -339,7 +341,8 @@ pub fn add_friend(user: User, target: User) -> Response {
|
|||||||
vec![user.id.clone()],
|
vec![user.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: target.id.clone(),
|
id: user.id.clone(),
|
||||||
|
user: target.id.clone(),
|
||||||
status: Relationship::Outgoing as i32,
|
status: Relationship::Outgoing as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -348,7 +351,8 @@ pub fn add_friend(user: User, target: User) -> Response {
|
|||||||
vec![target.id.clone()],
|
vec![target.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: user.id.clone(),
|
id: target.id.clone(),
|
||||||
|
user: user.id.clone(),
|
||||||
status: Relationship::Incoming as i32,
|
status: Relationship::Incoming as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -414,7 +418,8 @@ pub fn remove_friend(user: User, target: User) -> Response {
|
|||||||
vec![user.id.clone()],
|
vec![user.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: target.id.clone(),
|
id: user.id.clone(),
|
||||||
|
user: target.id.clone(),
|
||||||
status: Relationship::NONE as i32,
|
status: Relationship::NONE as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -423,7 +428,8 @@ pub fn remove_friend(user: User, target: User) -> Response {
|
|||||||
vec![target.id.clone()],
|
vec![target.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: user.id.clone(),
|
id: target.id.clone(),
|
||||||
|
user: user.id.clone(),
|
||||||
status: Relationship::NONE as i32,
|
status: Relationship::NONE as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -488,7 +494,8 @@ pub fn block_user(user: User, target: User) -> Response {
|
|||||||
vec![user.id.clone()],
|
vec![user.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: target.id.clone(),
|
id: user.id.clone(),
|
||||||
|
user: target.id.clone(),
|
||||||
status: Relationship::Blocked as i32,
|
status: Relationship::Blocked as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -497,7 +504,8 @@ pub fn block_user(user: User, target: User) -> Response {
|
|||||||
vec![target.id.clone()],
|
vec![target.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: user.id.clone(),
|
id: target.id.clone(),
|
||||||
|
user: user.id.clone(),
|
||||||
status: Relationship::BlockedOther as i32,
|
status: Relationship::BlockedOther as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -554,7 +562,8 @@ pub fn block_user(user: User, target: User) -> Response {
|
|||||||
vec![user.id.clone()],
|
vec![user.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: target.id.clone(),
|
id: user.id.clone(),
|
||||||
|
user: target.id.clone(),
|
||||||
status: Relationship::Blocked as i32,
|
status: Relationship::Blocked as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -563,7 +572,8 @@ pub fn block_user(user: User, target: User) -> Response {
|
|||||||
vec![target.id.clone()],
|
vec![target.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: user.id.clone(),
|
id: target.id.clone(),
|
||||||
|
user: user.id.clone(),
|
||||||
status: Relationship::BlockedOther as i32,
|
status: Relationship::BlockedOther as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -603,7 +613,8 @@ pub fn block_user(user: User, target: User) -> Response {
|
|||||||
vec![user.id.clone()],
|
vec![user.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: target.id.clone(),
|
id: user.id.clone(),
|
||||||
|
user: target.id.clone(),
|
||||||
status: Relationship::Blocked as i32,
|
status: Relationship::Blocked as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -646,7 +657,8 @@ pub fn unblock_user(user: User, target: User) -> Response {
|
|||||||
vec![user.id.clone()],
|
vec![user.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: target.id.clone(),
|
id: user.id.clone(),
|
||||||
|
user: target.id.clone(),
|
||||||
status: Relationship::BlockedOther as i32,
|
status: Relationship::BlockedOther as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -695,7 +707,8 @@ pub fn unblock_user(user: User, target: User) -> Response {
|
|||||||
vec![user.id.clone()],
|
vec![user.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: target.id.clone(),
|
id: user.id.clone(),
|
||||||
|
user: target.id.clone(),
|
||||||
status: Relationship::NONE as i32,
|
status: Relationship::NONE as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -704,7 +717,8 @@ pub fn unblock_user(user: User, target: User) -> Response {
|
|||||||
vec![target.id.clone()],
|
vec![target.id.clone()],
|
||||||
None,
|
None,
|
||||||
Notification::user_friend_status(FriendStatus {
|
Notification::user_friend_status(FriendStatus {
|
||||||
id: user.id.clone(),
|
id: target.id.clone(),
|
||||||
|
user: user.id.clone(),
|
||||||
status: Relationship::NONE as i32,
|
status: Relationship::NONE as i32,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user