fix-condition
This commit is contained in:
parent
d475688197
commit
2b8d4469ab
24
src/data.rs
24
src/data.rs
|
@ -108,30 +108,30 @@ pub async fn is_fitting(
|
|||
kind: String,
|
||||
payload: HashMap<String, String>,
|
||||
) -> Result<bool, &'static str> {
|
||||
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:<author_id>
|
||||
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<reaction_kind>
|
||||
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::<Vec<String>>(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");
|
||||
|
|
|
@ -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| {
|
||||
|
|
Loading…
Reference in New Issue
Block a user