mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-09-19 03:18:46 +00:00
Can refresh active conversations
This commit is contained in:
@@ -213,6 +213,16 @@ pub fn get_last_messages(conv_id: u64, number_of_messages: u64) -> ResultBoxErro
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the new messages of a conversation
|
||||
pub fn get_new_messages(conv_id: u64, last_message_id: u64) -> ResultBoxError<Vec<ConversationMessage>> {
|
||||
database::QueryInfo::new(CONV_MESSAGES_TABLE)
|
||||
.cond_u64("conv_id", conv_id)
|
||||
.set_custom_where("id > ?")
|
||||
.add_custom_where_argument_u64(last_message_id)
|
||||
.set_order("id")
|
||||
.exec(db_to_conversation_message)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
|
@@ -71,6 +71,9 @@ pub struct QueryInfo {
|
||||
/// Custom WHERE condition
|
||||
pub custom_where: Option<String>,
|
||||
|
||||
/// Custom WHERE values
|
||||
pub custom_where_ars: Vec<mysql::Value>,
|
||||
|
||||
/// Limit of the query (0 = no limit)
|
||||
pub limit: u64,
|
||||
|
||||
@@ -92,6 +95,7 @@ impl QueryInfo {
|
||||
joins: Vec::new(),
|
||||
conditions: collections::HashMap::new(),
|
||||
custom_where: None,
|
||||
custom_where_ars: vec![],
|
||||
limit: 0,
|
||||
order: None,
|
||||
fields: Vec::new(),
|
||||
@@ -144,6 +148,12 @@ impl QueryInfo {
|
||||
self
|
||||
}
|
||||
|
||||
/// Add a custom u64 WHERE value
|
||||
pub fn add_custom_where_argument_u64(mut self, val: u64) -> QueryInfo {
|
||||
self.custom_where_ars.push(mysql::Value::UInt(val));
|
||||
self
|
||||
}
|
||||
|
||||
/// Append a field to the list of selected fields
|
||||
pub fn add_field(mut self, key: &str) -> QueryInfo {
|
||||
self.fields.push(key.to_string());
|
||||
@@ -349,7 +359,7 @@ pub fn query<E, F: Fn(&RowResult) -> ProcessRowResult<E>>(info: QueryInfo, proce
|
||||
|
||||
for (k, v) in info.conditions {
|
||||
where_args.push(format!("{} = ?", k));
|
||||
params.push(v)
|
||||
params.push(mysql::Value::from(v));
|
||||
}
|
||||
|
||||
let where_args = format!(" WHERE {} ", where_args.join(" AND "));
|
||||
@@ -359,6 +369,9 @@ pub fn query<E, F: Fn(&RowResult) -> ProcessRowResult<E>>(info: QueryInfo, proce
|
||||
// Custom WHERE clause
|
||||
if let Some(custom_where) = info.custom_where {
|
||||
query = query.add(format!(" AND ({})", custom_where).as_str());
|
||||
|
||||
let mut custom_args = info.custom_where_ars;
|
||||
params.append(&mut custom_args);
|
||||
}
|
||||
|
||||
// ORDER clause
|
||||
|
Reference in New Issue
Block a user