mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Add new field in conversation members table to ease database access
This commit is contained in:
@ -352,16 +352,18 @@ pub fn send_message(msg: &NewConversationMessage) -> ResultBoxError<()> {
|
||||
.add_custom_where_argument_user_id(msg.user_id.as_ref().unwrap_or(&UserID::invalid()))
|
||||
.exec(|r| r.get_user_id("user_id"))?;
|
||||
|
||||
let new_message = get_single_message(msg_id)?;
|
||||
|
||||
// Mark the user has seen his message
|
||||
if let Some(user_id) = &msg.user_id {
|
||||
mark_user_seen(msg.conv_id, user_id, msg_id)?;
|
||||
mark_user_seen(msg.conv_id, user_id, &new_message)?;
|
||||
}
|
||||
|
||||
// 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)?))?;
|
||||
events_helper::propagate_event(&Event::NewConversationMessage(&new_message))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -429,11 +431,12 @@ pub fn get_list_unread(user_id: &UserID) -> ResultBoxError<Vec<ConvID>> {
|
||||
}
|
||||
|
||||
/// Indicate that a user has seen the last messages of a conversation
|
||||
pub fn mark_user_seen(conv_id: ConvID, user_id: &UserID, last_msg: u64) -> ResultBoxError<()> {
|
||||
pub fn mark_user_seen(conv_id: ConvID, user_id: &UserID, last_msg: &ConversationMessage) -> ResultBoxError<()> {
|
||||
database::UpdateInfo::new(CONV_MEMBERS_TABLE)
|
||||
.cond_conv_id("conv_id", conv_id)
|
||||
.cond_user_id("user_id", user_id)
|
||||
.set_u64("last_message_seen", last_msg)
|
||||
.set_u64("last_message_seen", last_msg.id)
|
||||
.set_u64("last_access", last_msg.time_sent)
|
||||
.exec()?;
|
||||
|
||||
// Push an event (updated_number_unread_conversations)
|
||||
@ -523,6 +526,7 @@ fn db_to_conversation_member(row: &database::RowResult) -> Res<ConversationMembe
|
||||
following: row.get_legacy_bool("following")?,
|
||||
is_admin: row.get_legacy_bool("is_admin")?,
|
||||
last_message_seen: row.get_u64("last_message_seen")?,
|
||||
last_access: row.get_optional_u64("last_access")?.unwrap_or(0),
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user