fix-condition

This commit is contained in:
2023-10-16 17:03:57 +03:00
parent d475688197
commit 2b8d4469ab
2 changed files with 13 additions and 13 deletions

View File

@@ -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");