forget rooms, load history
This commit is contained in:
parent
4cc0a07092
commit
23cb550d00
3 changed files with 92 additions and 8 deletions
39
src/data.rs
39
src/data.rs
|
@ -338,6 +338,13 @@ impl Data {
|
|||
);
|
||||
}
|
||||
|
||||
pub fn room_forget(&self, room_id: &RoomId, user_id: &UserId) {
|
||||
self.db.userid_leftroomids.remove_value(
|
||||
user_id.to_string().as_bytes(),
|
||||
room_id.to_string().as_bytes().into(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn room_invite(&self, sender: &UserId, room_id: &RoomId, user_id: &UserId) {
|
||||
self.pdu_append(
|
||||
room_id.clone(),
|
||||
|
@ -375,6 +382,15 @@ impl Data {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn room_pdu_first(&self, room_id: &RoomId, pdu_index: u64) -> bool {
|
||||
let mut pdu_id = vec![b'd'];
|
||||
pdu_id.extend_from_slice(room_id.to_string().as_bytes());
|
||||
pdu_id.push(0xff);
|
||||
pdu_id.extend_from_slice(&pdu_index.to_be_bytes());
|
||||
|
||||
self.db.pduid_pdu.get_lt(&pdu_id).unwrap().is_none()
|
||||
}
|
||||
|
||||
pub fn pdu_get(&self, event_id: &EventId) -> Option<RoomV3Pdu> {
|
||||
self.db
|
||||
.eventid_pduid
|
||||
|
@ -577,6 +593,29 @@ impl Data {
|
|||
pdus
|
||||
}
|
||||
|
||||
pub fn pdus_until(&self, room_id: &RoomId, until: u64) -> Vec<PduEvent> {
|
||||
let mut pdus = Vec::new();
|
||||
|
||||
// Create the first part of the full pdu id
|
||||
let mut prefix = vec![b'd'];
|
||||
prefix.extend_from_slice(room_id.to_string().as_bytes());
|
||||
prefix.push(0xff); // Add delimiter so we don't find rooms starting with the same id
|
||||
|
||||
let mut current = prefix.clone();
|
||||
current.extend_from_slice(&until.to_be_bytes());
|
||||
|
||||
while let Some((key, value)) = self.db.pduid_pdu.get_lt(¤t).unwrap() {
|
||||
if key.starts_with(&prefix) {
|
||||
current = key.to_vec();
|
||||
pdus.push(serde_json::from_slice(&value).expect("pdu in db is valid"));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pdus
|
||||
}
|
||||
|
||||
pub fn roomlatest_update(&self, user_id: &UserId, room_id: &RoomId, event: EduEvent) {
|
||||
let mut prefix = room_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue