mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Mark the conversation as seen
This commit is contained in:
parent
e7de23e995
commit
bfeea42828
@ -172,10 +172,10 @@ pub fn refresh_list(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.forbidden(format!("Your do not belongs to conversation {} !", conv_id))?;
|
||||
}
|
||||
|
||||
let msgs_conv = conversations_helper::get_last_messages(conv_id as u64, 10)?;
|
||||
list.insert(conv_id as u64, msgs_conv);
|
||||
let list_conv = conversations_helper::get_last_messages(conv_id as u64, 10)?;
|
||||
list.insert(conv_id as u64, list_conv);
|
||||
|
||||
//TODO : mark user seen
|
||||
conversations_helper::mark_user_seen(conv_id as u64, r.user_id()?)?;
|
||||
}
|
||||
|
||||
// TODO : Check for refresh of already initialized conversations
|
||||
|
@ -2,15 +2,15 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use crate::constants::database_tables_names::{CONV_LIST_TABLE, CONV_USERS_TABLE, CONV_MESSAGES_TABLE};
|
||||
use crate::constants::database_tables_names::{CONV_LIST_TABLE, CONV_MESSAGES_TABLE, CONV_USERS_TABLE};
|
||||
use crate::data::conversation::Conversation;
|
||||
use crate::data::conversation_message::ConversationMessage;
|
||||
use crate::data::error::{ExecError, ResultBoxError};
|
||||
use crate::data::new_conversation::NewConversation;
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::database::InsertQuery;
|
||||
use crate::helpers::database;
|
||||
use crate::helpers::database::InsertQuery;
|
||||
use crate::utils::date_utils::time;
|
||||
use crate::data::conversation_message::ConversationMessage;
|
||||
|
||||
/// Create a new conversation. This method returns the ID of the created conversation
|
||||
pub fn create(conv: &NewConversation) -> ResultBoxError<u64> {
|
||||
@ -213,6 +213,16 @@ pub fn get_last_messages(conv_id: u64, number_of_messages: u64) -> ResultBoxErro
|
||||
})
|
||||
}
|
||||
|
||||
/// Indicate that a user has seen the last messages of a conversation
|
||||
pub fn mark_user_seen(conv_id: u64, user_id: UserID) -> ResultBoxError<()> {
|
||||
database::UpdateInfo::new(CONV_USERS_TABLE)
|
||||
.cond_u64("conv_id", conv_id)
|
||||
.cond_user_id("user_id", user_id)
|
||||
.cond_legacy_bool("saw_last_message", false)
|
||||
.set_legacy_bool("saw_last_message", true)
|
||||
.exec()
|
||||
}
|
||||
|
||||
/// Turn a database entry into a ConversationInfo object
|
||||
fn db_to_conversation_info(row: &database::RowResult) -> ResultBoxError<Conversation> {
|
||||
let conv_id = row.get_u64("id")?;
|
||||
@ -238,6 +248,6 @@ fn db_to_conversation_message(row: &database::RowResult) -> ResultBoxError<Conve
|
||||
conv_id: row.get_u64("conv_id")?,
|
||||
user_id: row.get_user_id("user_id")?,
|
||||
message: row.get_optional_str("message")?,
|
||||
image_path: row.get_optional_str("image_path")?
|
||||
image_path: row.get_optional_str("image_path")?,
|
||||
})
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
use std::collections;
|
||||
use std::collections::HashMap;
|
||||
use std::error::Error;
|
||||
use std::ops::Add;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use chrono::{TimeZone, Utc};
|
||||
use mysql::{Binary, Pool, ResultSet, Value};
|
||||
use mysql::prelude::Queryable;
|
||||
|
||||
use crate::data::config::DatabaseConfig;
|
||||
use crate::data::error::{ExecError, ResultBoxError};
|
||||
use std::collections::HashMap;
|
||||
use chrono::{Utc, TimeZone};
|
||||
use crate::data::user::UserID;
|
||||
|
||||
/// Database access helper
|
||||
@ -595,6 +595,17 @@ impl UpdateInfo {
|
||||
self
|
||||
}
|
||||
|
||||
/// Filter with a legacy boolean
|
||||
pub fn cond_legacy_bool(mut self, name: &str, val: bool) -> UpdateInfo {
|
||||
let num = match val {
|
||||
true => 1,
|
||||
false => 0
|
||||
};
|
||||
|
||||
self.cond.insert(name.to_string(), Value::Int(num));
|
||||
self
|
||||
}
|
||||
|
||||
/// Set an new optional string
|
||||
///
|
||||
/// None => Empty string
|
||||
|
Loading…
Reference in New Issue
Block a user