Skip to content

Commit 159c9b4

Browse files
mgoldenbergHywan
authored andcommitted
refactor(indexeddb): add room id to event_cache_store::types::GenericEvent
Signed-off-by: Michael Goldenberg <[email protected]>
1 parent aead1a4 commit 159c9b4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ impl_event_cache_store! {
209209
.put_item(
210210
room_id,
211211
&types::Event::InBand(InBandEvent {
212+
room_id: room_id.to_owned(),
212213
content: item,
213214
position: types::Position {
214215
chunk_identifier,
@@ -229,6 +230,7 @@ impl_event_cache_store! {
229230
.put_event(
230231
room_id,
231232
&types::Event::InBand(InBandEvent {
233+
room_id: room_id.to_owned(),
232234
content: item,
233235
position: at.into(),
234236
}),
@@ -526,7 +528,7 @@ impl_event_cache_store! {
526528
self.transaction(&[keys::EVENTS], IdbTransactionMode::Readwrite)?;
527529
let event = match transaction.get_event_by_id(room_id, &event_id).await? {
528530
Some(mut inner) => inner.with_content(event),
529-
None => types::Event::OutOfBand(OutOfBandEvent { content: event, position: () }),
531+
None => types::Event::OutOfBand(OutOfBandEvent { room_id: room_id.to_owned(), content: event, position: () }),
530532
};
531533
transaction.put_event(room_id, &event).await?;
532534
transaction.commit().await?;

crates/matrix-sdk-indexeddb/src/event_cache_store/types.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ impl From<Event> for TimelineEvent {
7171
}
7272

7373
impl Event {
74+
/// The [`RoomId`] of the room in which the underlying event exists.
75+
pub fn room_id(&self) -> &RoomId {
76+
match self {
77+
Event::InBand(e) => &e.room_id,
78+
Event::OutOfBand(e) => &e.room_id,
79+
}
80+
}
81+
7482
/// The [`OwnedEventId`] of the underlying event.
7583
pub fn event_id(&self) -> Option<OwnedEventId> {
7684
match self {
@@ -116,6 +124,8 @@ impl Event {
116124
/// in-band or out-of-band.
117125
#[derive(Debug, Serialize, Deserialize)]
118126
pub struct GenericEvent<P> {
127+
/// The room in which the event exists.
128+
pub room_id: OwnedRoomId,
119129
/// The full content of the event.
120130
pub content: TimelineEvent,
121131
/// The position of the event, if it is in a chunk.

0 commit comments

Comments
 (0)