base: Store the notification counts.
parent
ab832da03e
commit
e38f0762ee
|
@ -624,6 +624,9 @@ impl BaseClient {
|
||||||
summary.mark_members_missing();
|
summary.mark_members_missing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let notification_count = room_info.unread_notifications.into();
|
||||||
|
summary.update_notification_count(notification_count);
|
||||||
|
|
||||||
// TODO should we store this?
|
// TODO should we store this?
|
||||||
let ephemeral = Ephemeral {
|
let ephemeral = Ephemeral {
|
||||||
events: room_info
|
events: room_info
|
||||||
|
@ -636,7 +639,13 @@ impl BaseClient {
|
||||||
|
|
||||||
rooms.join.insert(
|
rooms.join.insert(
|
||||||
room_id,
|
room_id,
|
||||||
JoinedRoom::new(timeline, state, account_data, ephemeral),
|
JoinedRoom::new(
|
||||||
|
timeline,
|
||||||
|
state,
|
||||||
|
account_data,
|
||||||
|
ephemeral,
|
||||||
|
notification_count,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
changes.add_room(summary);
|
changes.add_room(summary);
|
||||||
|
|
|
@ -2,7 +2,9 @@ use serde::{Deserialize, Serialize};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
api::r0::sync::sync_events::DeviceLists,
|
api::r0::sync::sync_events::{
|
||||||
|
DeviceLists, UnreadNotificationsCount as RumaUnreadNotificationsCount,
|
||||||
|
},
|
||||||
events::{
|
events::{
|
||||||
presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent,
|
presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent,
|
||||||
AnySyncStateEvent, AnyToDeviceEvent,
|
AnySyncStateEvent, AnyToDeviceEvent,
|
||||||
|
@ -74,8 +76,8 @@ pub struct Rooms {
|
||||||
/// Updates to joined rooms.
|
/// Updates to joined rooms.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct JoinedRoom {
|
pub struct JoinedRoom {
|
||||||
// /// Counts of unread notifications for this room.
|
/// Counts of unread notifications for this room.
|
||||||
// pub unread_notifications: UnreadNotificationsCount,
|
pub unread_notifications: UnreadNotificationsCount,
|
||||||
/// The timeline of messages and state changes in the room.
|
/// The timeline of messages and state changes in the room.
|
||||||
pub timeline: Timeline,
|
pub timeline: Timeline,
|
||||||
/// Updates to the state, between the time indicated by the `since` parameter, and the start
|
/// Updates to the state, between the time indicated by the `since` parameter, and the start
|
||||||
|
@ -95,12 +97,35 @@ impl JoinedRoom {
|
||||||
state: State,
|
state: State,
|
||||||
account_data: AccountData,
|
account_data: AccountData,
|
||||||
ephemeral: Ephemeral,
|
ephemeral: Ephemeral,
|
||||||
|
unread_notifications: UnreadNotificationsCount,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
timeline,
|
timeline,
|
||||||
state,
|
state,
|
||||||
account_data,
|
account_data,
|
||||||
ephemeral,
|
ephemeral,
|
||||||
|
unread_notifications,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Counts of unread notifications for a room.
|
||||||
|
#[derive(Copy, Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
pub struct UnreadNotificationsCount {
|
||||||
|
/// The number of unread notifications for this room with the highlight flag set.
|
||||||
|
highlight_count: u64,
|
||||||
|
/// The total number of unread notifications for this room.
|
||||||
|
notification_count: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RumaUnreadNotificationsCount> for UnreadNotificationsCount {
|
||||||
|
fn from(notifications: RumaUnreadNotificationsCount) -> Self {
|
||||||
|
Self {
|
||||||
|
highlight_count: notifications.highlight_count.map(|c| c.into()).unwrap_or(0),
|
||||||
|
notification_count: notifications
|
||||||
|
.notification_count
|
||||||
|
.map(|c| c.into())
|
||||||
|
.unwrap_or(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub struct Store {
|
||||||
presence: Tree,
|
presence: Tree,
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::Session;
|
use crate::{responses::UnreadNotificationsCount, Session};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct StateChanges {
|
pub struct StateChanges {
|
||||||
|
@ -171,6 +171,7 @@ impl Room {
|
||||||
canonical_alias: None,
|
canonical_alias: None,
|
||||||
avatar_url: None,
|
avatar_url: None,
|
||||||
topic: None,
|
topic: None,
|
||||||
|
notification_counts: Default::default(),
|
||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,6 +403,7 @@ pub struct InnerSummary {
|
||||||
avatar_url: Option<String>,
|
avatar_url: Option<String>,
|
||||||
topic: Option<String>,
|
topic: Option<String>,
|
||||||
|
|
||||||
|
notification_counts: UnreadNotificationsCount,
|
||||||
summary: SomeSummary,
|
summary: SomeSummary,
|
||||||
members_synced: bool,
|
members_synced: bool,
|
||||||
|
|
||||||
|
@ -462,6 +464,10 @@ impl InnerSummary {
|
||||||
self.encryption.is_some()
|
self.encryption.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_notification_count(&mut self, notification_counts: UnreadNotificationsCount) {
|
||||||
|
self.notification_counts = notification_counts;
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn update(&mut self, summary: &RumaSummary) -> bool {
|
pub(crate) fn update(&mut self, summary: &RumaSummary) -> bool {
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue