diff --git a/src/controllers/conversations_controller.rs b/src/controllers/conversations_controller.rs index 3838872..e5bb8a7 100644 --- a/src/controllers/conversations_controller.rs +++ b/src/controllers/conversations_controller.rs @@ -5,6 +5,7 @@ use std::collections::HashMap; use crate::api_data::conversation_api::ConversationAPI; +use crate::api_data::conversation_message_api::ConversationMessageAPI; use crate::api_data::conversations_refresh_api::ConversationRefreshResultAPI; use crate::api_data::res_create_conversation::ResCreateConversation; use crate::api_data::res_find_private_conversations::ResFindPrivateConversations; @@ -214,5 +215,18 @@ pub fn refresh_list(r: &mut HttpRequestHandler) -> RequestResult { /// Refresh a single conversation pub fn refresh_single(r: &mut HttpRequestHandler) -> RequestResult { - r.success("implement it") + let conv_id = r.post_conv_id("conversationID")?; + let last_message_id = r.post_u64("last_message_id")?; + + let messages = match last_message_id { + // Get latest messages of the conversation + 0 => conversations_helper::get_last_messages(conv_id, 10)?, + + // Get new messages + _ => conversations_helper::get_new_messages(conv_id, last_message_id)?, + }; + + conversations_helper::mark_user_seen(conv_id, r.user_id()?)?; + + r.set_response(ConversationMessageAPI::for_list(&messages)) } \ No newline at end of file