feat(bindings): Expose read receipts to FFI

This commit is contained in:
Doug
2023-01-16 09:58:40 +00:00
committed by GitHub
parent 6c53842599
commit 6540b9bb49
2 changed files with 43 additions and 0 deletions

View File

@@ -255,6 +255,12 @@ interface Room {
// Raises an exception if there are no timeline listeners.
[Throws=ClientError]
void paginate_backwards(PaginationOptions opts);
[Throws=ClientError]
void send_read_receipt(string event_id);
[Throws=ClientError]
void send_read_marker(string fully_read_event_id, string? read_receipt_event_id);
[Throws=ClientError]
void send(RoomMessageEventContent msg, string? txn_id);

View File

@@ -250,6 +250,43 @@ impl Room {
}
}
pub fn send_read_receipt(&self, event_id: String) -> Result<()> {
let room = match &self.room {
SdkRoom::Joined(j) => j.clone(),
_ => bail!("Can't send read receipts to room that isn't in joined state"),
};
let event_id = EventId::parse(event_id)?;
RUNTIME.block_on(async move {
room.read_receipt(&event_id).await?;
Ok(())
})
}
pub fn send_read_marker(
&self,
fully_read_event_id: String,
read_receipt_event_id: Option<String>,
) -> Result<()> {
let room = match &self.room {
SdkRoom::Joined(j) => j.clone(),
_ => bail!("Can't send read markers to room that isn't in joined state"),
};
let fully_read =
EventId::parse(fully_read_event_id).context("parsing fully read event ID")?;
let read_receipt = read_receipt_event_id
.map(EventId::parse)
.transpose()
.context("parsing read receipt event ID")?;
RUNTIME.block_on(async move {
room.read_marker(&fully_read, read_receipt.as_deref()).await?;
Ok(())
})
}
pub fn send(&self, msg: Arc<RoomMessageEventContent>, txn_id: Option<String>) -> Result<()> {
let timeline = match &*self.timeline.read().unwrap() {
Some(t) => Arc::clone(t),