-
Notifications
You must be signed in to change notification settings - Fork 331
feat(threads): automatically subscribe a user to a thread under the semantics of MSC4306 #5462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
67e3bee
6dcc394
71b23c6
20f4c9d
08b99d3
aa23aab
0ac8699
a682a46
ec33f24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,16 +19,16 @@ use std::collections::BTreeSet; | |
use eyeball_im::VectorDiff; | ||
use matrix_sdk_base::{ | ||
event_cache::{Event, Gap}, | ||
linked_chunk::{ChunkContent, Position}, | ||
linked_chunk::{ChunkContent, OwnedLinkedChunkId, Position}, | ||
}; | ||
use ruma::OwnedEventId; | ||
use ruma::{OwnedEventId, OwnedRoomId}; | ||
use tokio::sync::broadcast::{Receiver, Sender}; | ||
use tracing::trace; | ||
|
||
use crate::event_cache::{ | ||
deduplicator::DeduplicationOutcome, | ||
room::{events::EventLinkedChunk, LoadMoreEventsBackwardsOutcome}, | ||
BackPaginationOutcome, EventsOrigin, | ||
BackPaginationOutcome, EventsOrigin, RoomEventCacheLinkedChunkUpdate, | ||
}; | ||
|
||
/// An update coming from a thread event cache. | ||
|
@@ -42,6 +42,9 @@ pub struct ThreadEventCacheUpdate { | |
|
||
/// All the information related to a single thread. | ||
pub(crate) struct ThreadEventCache { | ||
/// The room owning this thread. | ||
room_id: OwnedRoomId, | ||
|
||
/// The ID of the thread root event, which is the first event in the thread | ||
/// (and eventually the first in the linked chunk). | ||
thread_root: OwnedEventId, | ||
|
@@ -51,12 +54,24 @@ pub(crate) struct ThreadEventCache { | |
|
||
/// A sender for live events updates in this thread. | ||
sender: Sender<ThreadEventCacheUpdate>, | ||
|
||
linked_chunk_update_sender: Sender<RoomEventCacheLinkedChunkUpdate>, | ||
bnjbvr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
impl ThreadEventCache { | ||
/// Create a new empty thread event cache. | ||
pub fn new(thread_root: OwnedEventId) -> Self { | ||
Self { chunk: EventLinkedChunk::new(), sender: Sender::new(32), thread_root } | ||
pub fn new( | ||
room_id: OwnedRoomId, | ||
thread_root: OwnedEventId, | ||
linked_chunk_update_sender: Sender<RoomEventCacheLinkedChunkUpdate>, | ||
) -> Self { | ||
Self { | ||
chunk: EventLinkedChunk::new(), | ||
sender: Sender::new(32), | ||
room_id, | ||
thread_root, | ||
linked_chunk_update_sender, | ||
} | ||
} | ||
|
||
/// Subscribe to live events from this thread. | ||
|
@@ -78,6 +93,22 @@ impl ThreadEventCache { | |
} | ||
} | ||
|
||
// TODO(bnjbvr): share more code with `RoomEventCacheState` to avoid the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope it is not. I'd expect all these refactorings to happen around the same time, when we unify backpagination in threads and in the main room -> when persisting threads happens. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem. |
||
// duplication here too. | ||
fn propagate_changes(&mut self) { | ||
// This is a lie, at the moment! We're not persisting threads yet, so we're just | ||
// forwarding all updates to the linked chunk update sender. | ||
let updates = self.chunk.store_updates().take(); | ||
|
||
let _ = self.linked_chunk_update_sender.send(RoomEventCacheLinkedChunkUpdate { | ||
updates, | ||
linked_chunk: OwnedLinkedChunkId::Thread( | ||
self.room_id.clone(), | ||
self.thread_root.clone(), | ||
), | ||
}); | ||
} | ||
|
||
/// Push some live events to this thread, and propagate the updates to | ||
/// the listeners. | ||
pub fn add_live_events(&mut self, events: Vec<Event>) { | ||
|
@@ -104,6 +135,8 @@ impl ThreadEventCache { | |
|
||
self.chunk.push_live_events(None, &events); | ||
|
||
self.propagate_changes(); | ||
|
||
let diffs = self.chunk.updates_as_vector_diffs(); | ||
if !diffs.is_empty() { | ||
let _ = self.sender.send(ThreadEventCacheUpdate { diffs, origin: EventsOrigin::Sync }); | ||
|
@@ -249,6 +282,8 @@ impl ThreadEventCache { | |
// Add the paginated events to the thread chunk. | ||
let reached_start = self.chunk.finish_back_pagination(prev_gap_id, new_gap, &events); | ||
|
||
self.propagate_changes(); | ||
|
||
// Notify observers about the updates. | ||
let updates = self.chunk.updates_as_vector_diffs(); | ||
if !updates.is_empty() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type isn't tested in this commit neither the next commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by a type that's not tested? Do you mean testing the methods on the type? As the method is tested in the integration with the thread subscriber task, and the type itself is mostly POD, I'm not sure to see the value in testing it in isolation…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's tested via an integration test, that's good.