From 2b8d4469ab02a10318aa7c1064aabce5f408e704 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 16 Oct 2023 17:03:57 +0300 Subject: [PATCH] fix-condition --- src/data.rs | 24 ++++++++++++------------ src/main.rs | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/data.rs b/src/data.rs index 7d4f909..194aca5 100644 --- a/src/data.rs +++ b/src/data.rs @@ -108,30 +108,30 @@ pub async fn is_fitting( kind: String, payload: HashMap, ) -> Result { - match kind.as_str() { - "new_follower" => { - // payload is AuthorFollower - Ok(payload.get("author").unwrap().to_string() == listener_id.to_string()) + match &kind[0..9] { + "new_follo" => { + // payload is Author, kind is new_follower: + let author_id = kind.split(":").last().unwrap(); + Ok(author_id.to_string() == listener_id.to_string()) } - "new_reaction" => { - // payload is Reaction + "new_react" => { + // payload is Reaction, kind is new_reaction let shout_id = payload.get("shout").unwrap(); let recipients = get_shout_followers(shout_id).await.unwrap(); Ok(recipients.contains(&listener_id)) } "new_shout" => { - // payload is Shout + // payload is Shout, kind is "new_shout" // TODO: check all community subscribers if no then // check all topics subscribers if no then // check all authors subscribers Ok(true) } - "new_message" => { - // payload is Chat - let members_str = payload.get("members").unwrap(); - let members = serde_json::from_str::>(members_str).unwrap(); - Ok(members.contains(&listener_id.to_string())) + "new_messa" => { + // payload is Message, kind is "new_message" + + Ok(true) } _ => { eprintln!("unknown payload kind"); diff --git a/src/main.rs b/src/main.rs index b8e6d2f..3121810 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,7 +79,7 @@ async fn connect_handler( while let Some(msg) = pubsub.on_message().next().await { let message_str: String = msg.get_payload().unwrap(); let message_data: RedisMessageData = serde_json::from_str(&message_str).unwrap(); - if data::is_fitting(listener_id, message_data.kind.to_string(), message_data.payload).await.is_ok() { + if msg.get_channel_name().starts_with("chat:") || data::is_fitting(listener_id, message_data.kind.to_string(), message_data.payload).await.is_ok() { let send_result = tx.send(message_str); if send_result.is_err() { let _ = con.srem::<&str, &i32, usize>("authors-online", &listener_id).await.map_err(|e| {