mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-04 09:34:04 +00:00 
			
		
		
		
	Can refresh active conversations
This commit is contained in:
		@@ -177,10 +177,37 @@ pub fn refresh_list(r: &mut HttpRequestHandler) -> RequestResult {
 | 
			
		||||
 | 
			
		||||
            conversations_helper::mark_user_seen(conv_id as u64, r.user_id()?)?;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // TODO : Check for refresh of already initialized conversations
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Check for refresh of already initialized conversations
 | 
			
		||||
    if r.has_post_parameter("toRefresh") {
 | 
			
		||||
        let v: HashMap<String, HashMap<String, serde_json::Value>> =
 | 
			
		||||
            serde_json::from_str(r.post_string("toRefresh")?.as_str())?;
 | 
			
		||||
 | 
			
		||||
        for (k, v) in v {
 | 
			
		||||
            // Get conversation ID
 | 
			
		||||
            if !k.starts_with("conversation-") {
 | 
			
		||||
                return r.bad_request("Entries of 'toRefresh' must start with 'conversation-'!".to_string());
 | 
			
		||||
            }
 | 
			
		||||
            let conv_id = k.replace("conversation-", "").parse::<u64>()?;
 | 
			
		||||
 | 
			
		||||
            // Extract last message id
 | 
			
		||||
            if !v.contains_key("last_message_id") {
 | 
			
		||||
                return r.bad_request(format!("Missing 'last_message_id' in conversation {}!", conv_id));
 | 
			
		||||
            }
 | 
			
		||||
            let last_message_id = v["last_message_id"].as_u64().unwrap_or(0);
 | 
			
		||||
 | 
			
		||||
            // Check user rights
 | 
			
		||||
            if !conversations_helper::does_user_belongs_to(r.user_id()?, conv_id)? {
 | 
			
		||||
                return r.forbidden(format!("You do not belong to conversation {}!", conv_id));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            let list_conv = conversations_helper::get_new_messages(conv_id, last_message_id)?;
 | 
			
		||||
            list.insert(conv_id, list_conv);
 | 
			
		||||
 | 
			
		||||
            conversations_helper::mark_user_seen(conv_id as u64, r.user_id()?)?;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    r.set_response(ConversationRefreshResultAPI::new(list))
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user