1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Get the list of unread conversations

This commit is contained in:
2020-06-22 18:55:24 +02:00
parent 744111f416
commit 93a52d083f
6 changed files with 79 additions and 3 deletions

View File

@ -12,6 +12,7 @@ use crate::data::user::UserID;
use crate::helpers::database;
use crate::helpers::database::InsertQuery;
use crate::utils::date_utils::time;
use crate::data::unread_conversation::UnreadConversation;
/// Create a new conversation. This method returns the ID of the created conversation
pub fn create(conv: &NewConversation) -> ResultBoxError<u64> {
@ -285,6 +286,29 @@ pub fn count_unread_for_user(user_id: UserID) -> ResultBoxError<usize> {
.exec_count()
}
/// Get the list of unread conversations of a user
pub fn get_list_unread(user_id: UserID) -> ResultBoxError<Vec<UnreadConversation>> {
database::QueryInfo::new(CONV_USERS_TABLE)
.alias("users")
.join(CONV_LIST_TABLE, "list", "users.conv_id = list.id")
.join(CONV_MESSAGES_TABLE, "messages", "messages.conv_id = users.conv_id")
.cond_user_id("users.user_id", user_id)
.cond_legacy_bool("users.following", true)
.cond_legacy_bool("users.saw_last_message", false)
.set_custom_where("list.last_active = messages.time_insert")
.set_order("list.last_active DESC")
.exec(|res| Ok(UnreadConversation{
id: res.get_u64("conv_id")?,
name: res.get_optional_str("name")?,
last_active: res.get_u64("last_active")?,
user_id: res.get_user_id("user_id")?,
message: res.get_str("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)