fix: stop /messages at to

Fixes #150
This commit is contained in:
timokoesters 2020-07-26 17:34:12 +02:00
parent 20ab19d828
commit b7df8fe83c
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
2 changed files with 46 additions and 38 deletions

View file

@ -654,14 +654,14 @@ impl Rooms {
}))
}
/// Returns an iterator over all events in a room that happened before the event with id
/// `until` in reverse-chronological order.
/// Returns an iterator over all events and their tokens in a room that happened before the
/// event with id `until` in reverse-chronological order.
pub fn pdus_until(
&self,
user_id: &UserId,
room_id: &RoomId,
until: u64,
) -> impl Iterator<Item = Result<PduEvent>> {
) -> impl Iterator<Item = Result<(IVec, PduEvent)>> {
// Create the first part of the full pdu id
let mut prefix = room_id.to_string().as_bytes().to_vec();
prefix.push(0xff);
@ -677,24 +677,24 @@ impl Rooms {
.rev()
.filter_map(|r| r.ok())
.take_while(move |(k, _)| k.starts_with(&prefix))
.map(move |(_, v)| {
.map(move |(k, v)| {
let mut pdu = serde_json::from_slice::<PduEvent>(&v)
.map_err(|_| Error::bad_database("PDU in db is invalid."))?;
if pdu.sender != user_id {
pdu.unsigned.remove("transaction_id");
}
Ok(pdu)
Ok((k, pdu))
})
}
/// Returns an iterator over all events in a room that happened after the event with id
/// `from` in chronological order.
/// Returns an iterator over all events and their token in a room that happened after the event
/// with id `from` in chronological order.
pub fn pdus_after(
&self,
user_id: &UserId,
room_id: &RoomId,
from: u64,
) -> impl Iterator<Item = Result<PduEvent>> {
) -> impl Iterator<Item = Result<(IVec, PduEvent)>> {
// Create the first part of the full pdu id
let mut prefix = room_id.to_string().as_bytes().to_vec();
prefix.push(0xff);
@ -709,13 +709,13 @@ impl Rooms {
.range(current..)
.filter_map(|r| r.ok())
.take_while(move |(k, _)| k.starts_with(&prefix))
.map(move |(_, v)| {
.map(move |(k, v)| {
let mut pdu = serde_json::from_slice::<PduEvent>(&v)
.map_err(|_| Error::bad_database("PDU in db is invalid."))?;
if pdu.sender != user_id {
pdu.unsigned.remove("transaction_id");
}
Ok(pdu)
Ok((k, pdu))
})
}