1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-12-27 22:18:51 +00:00

Propagate unread conversations number update

This commit is contained in:
Pierre HUBERT 2021-02-06 16:26:53 +01:00
parent dab76a3677
commit 7cf5977da2
3 changed files with 30 additions and 2 deletions

View File

@ -344,6 +344,20 @@ pub fn delete_message(r: &mut HttpRequestHandler) -> RequestResult {
/// Events handler
pub fn handle_event(e: &events_helper::Event) -> Res {
match e {
Event::UpdatedNumberUnreadConversations(users) => {
for user in users.iter() {
if user_ws_controller::is_user_connected(user) {
user_ws_controller::send_message_to_user(
&UserWsMessage::no_id_message(
"number_unread_conversations",
conversations_helper::count_unread_for_user(user)?,
)?,
user,
)?;
}
}
}
Event::NewConversationMessage(msg) => {
user_ws_controller::send_message_to_specific_connections(
|f| f.conversations.contains(&msg.conv_id),

View File

@ -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(())
}

View File

@ -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),