mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Propagate unread conversations number update
This commit is contained in:
@ -312,6 +312,15 @@ pub fn send_message(msg: &NewConversationMessage) -> ResultBoxError<()> {
|
||||
.set_u64("last_active", t)
|
||||
.exec()?;
|
||||
|
||||
// Get the list of users to notify after the update
|
||||
let list_to_notify = database::QueryInfo::new(CONV_USERS_TABLE)
|
||||
.cond_u64("conv_id", msg.conv_id)
|
||||
.cond_legacy_bool("saw_last_message", true)
|
||||
.cond_legacy_bool("following", true)
|
||||
.set_custom_where("user_id != ?")
|
||||
.add_custom_where_argument_user_id(&msg.user_id)
|
||||
.exec(|r| r.get_user_id("user_id"))?;
|
||||
|
||||
// Mark all the users of the conversation as unread
|
||||
database::UpdateInfo::new(CONV_USERS_TABLE)
|
||||
.cond_u64("conv_id", msg.conv_id)
|
||||
@ -323,7 +332,8 @@ pub fn send_message(msg: &NewConversationMessage) -> ResultBoxError<()> {
|
||||
.set_legacy_bool("saw_last_message", false)
|
||||
.exec()?;
|
||||
|
||||
// TODO : send an event (updated_number_unread_conversations)
|
||||
// Send an event (updated_number_unread_conversations)
|
||||
events_helper::propagate_event(&Event::UpdatedNumberUnreadConversations(&list_to_notify))?;
|
||||
|
||||
// Send an event (sent_conversation_message)
|
||||
events_helper::propagate_event(&Event::NewConversationMessage(&get_single_message(msg_id)?))?;
|
||||
@ -411,7 +421,8 @@ pub fn mark_user_seen(conv_id: u64, user_id: &UserID) -> ResultBoxError<()> {
|
||||
.set_legacy_bool("saw_last_message", true)
|
||||
.exec()?;
|
||||
|
||||
// TODO : push an event (updated_number_unread_conversations)
|
||||
// Push an event (updated_number_unread_conversations)
|
||||
events_helper::propagate_event(&Event::UpdatedNumberUnreadConversations(&vec![user_id.clone()]))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ pub enum Event<'a> {
|
||||
/// Updated the number of notifications of one of multiple users user
|
||||
UpdatedNotificationsNumber(&'a Vec<UserID>),
|
||||
|
||||
/// Updated the number of unread conversations
|
||||
UpdatedNumberUnreadConversations(&'a Vec<UserID>),
|
||||
|
||||
/// Created a new conversation message
|
||||
NewConversationMessage(&'a ConversationMessage),
|
||||
|
||||
|
Reference in New Issue
Block a user