refactor(sdk): Move timeline::add_event_id to TimelineInner
This commit is contained in:
committed by
Jonas Platte
parent
63bc004e26
commit
c1949e3fc6
@@ -9,7 +9,7 @@ use matrix_sdk_base::{
|
||||
use ruma::{
|
||||
events::{fully_read::FullyReadEvent, AnyMessageLikeEventContent, AnySyncTimelineEvent},
|
||||
serde::Raw,
|
||||
OwnedEventId, OwnedTransactionId, RoomId, UserId,
|
||||
OwnedEventId, OwnedTransactionId, RoomId, TransactionId, UserId,
|
||||
};
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
@@ -18,7 +18,7 @@ use super::{
|
||||
update_read_marker, Flow, TimelineEventHandler, TimelineEventKind, TimelineEventMetadata,
|
||||
TimelineItemPosition,
|
||||
},
|
||||
TimelineInnerMetadata, TimelineItem, TimelineKey,
|
||||
find_event, TimelineInnerMetadata, TimelineItem, TimelineKey,
|
||||
};
|
||||
use crate::events::SyncTimelineEventWithoutContent;
|
||||
|
||||
@@ -105,6 +105,27 @@ impl TimelineInner {
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn add_event_id(&self, txn_id: &TransactionId, event_id: OwnedEventId) {
|
||||
let mut lock = self.items.lock_mut();
|
||||
if let Some((idx, item)) = find_event(&lock, txn_id) {
|
||||
match &item.key {
|
||||
TimelineKey::TransactionId(_) => {
|
||||
lock.set_cloned(
|
||||
idx,
|
||||
Arc::new(TimelineItem::Event(item.with_event_id(Some(event_id)))),
|
||||
);
|
||||
}
|
||||
TimelineKey::EventId(ev_id) => {
|
||||
if *ev_id != event_id {
|
||||
error!("remote echo and send-event response disagree on the event ID");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warn!(%txn_id, "Timeline item not found, can't add event ID");
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn handle_fully_read(&self, raw: Raw<FullyReadEvent>) {
|
||||
let fully_read_event = match raw.deserialize() {
|
||||
Ok(ev) => ev.content.event_id,
|
||||
|
||||
@@ -29,7 +29,7 @@ use ruma::{
|
||||
events::{fully_read::FullyReadEventContent, relation::Annotation, AnyMessageLikeEventContent},
|
||||
OwnedEventId, OwnedUserId, TransactionId, UInt,
|
||||
};
|
||||
use tracing::{error, instrument, warn};
|
||||
use tracing::{error, instrument};
|
||||
|
||||
use super::{Joined, Room};
|
||||
use crate::{
|
||||
@@ -324,7 +324,7 @@ impl Timeline {
|
||||
let room = Joined { inner: self.room.clone() };
|
||||
|
||||
let response = room.send(content, Some(&txn_id)).await?;
|
||||
add_event_id(&self.inner, &txn_id, response.event_id);
|
||||
self.inner.add_event_id(&txn_id, response.event_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -380,24 +380,3 @@ fn find_read_marker(lock: &[Arc<TimelineItem>]) -> Option<usize> {
|
||||
})
|
||||
.map(|(idx, _)| idx)
|
||||
}
|
||||
|
||||
fn add_event_id(items: &TimelineInner, txn_id: &TransactionId, event_id: OwnedEventId) {
|
||||
let mut lock = items.items.lock_mut();
|
||||
if let Some((idx, item)) = find_event(&lock, txn_id) {
|
||||
match &item.key {
|
||||
TimelineKey::TransactionId(_) => {
|
||||
lock.set_cloned(
|
||||
idx,
|
||||
Arc::new(TimelineItem::Event(item.with_event_id(Some(event_id)))),
|
||||
);
|
||||
}
|
||||
TimelineKey::EventId(ev_id) => {
|
||||
if *ev_id != event_id {
|
||||
error!("remote echo and send-event response disagree on the event ID");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warn!(%txn_id, "Timeline item not found, can't add event ID");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user