mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-22 01:15:16 +00:00
Count the number of unread conversations of a user
This commit is contained in:
@ -276,6 +276,15 @@ pub fn send_message(msg: &NewConversationMessage) -> ResultBoxError<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Count the number of unread conversation for a specified user
|
||||
pub fn count_unread_for_user(user_id: UserID) -> ResultBoxError<usize> {
|
||||
database::QueryInfo::new(CONV_USERS_TABLE)
|
||||
.cond_user_id("user_id", user_id)
|
||||
.cond_legacy_bool("saw_last_message", false)
|
||||
.cond_legacy_bool("following", true)
|
||||
.exec_count()
|
||||
}
|
||||
|
||||
/// 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)
|
||||
|
@ -142,6 +142,16 @@ impl QueryInfo {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cond_legacy_bool(mut self, key: &str, val: bool) -> QueryInfo {
|
||||
let val = match val {
|
||||
true => "1".to_string(),
|
||||
false => "2".to_string()
|
||||
};
|
||||
|
||||
self.conditions.insert(key.to_string(), val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set custom where
|
||||
pub fn set_custom_where(mut self, custom_where: &str) -> QueryInfo {
|
||||
self.custom_where = Some(custom_where.to_string());
|
||||
|
Reference in New Issue
Block a user