feat: handle txn ids
This commit is contained in:
parent
6343eea417
commit
4954df3cc3
8 changed files with 111 additions and 9 deletions
|
@ -621,7 +621,8 @@ impl Rooms {
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
self.edus.private_read_set(&room_id, &sender, index, &globals)?;
|
||||
self.edus
|
||||
.private_read_set(&room_id, &sender, index, &globals)?;
|
||||
|
||||
Ok(pdu.event_id)
|
||||
}
|
||||
|
|
|
@ -92,7 +92,13 @@ impl RoomEdus {
|
|||
}
|
||||
|
||||
/// Sets a private read marker at `count`.
|
||||
pub fn private_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64, globals: &super::super::globals::Globals) -> Result<()> {
|
||||
pub fn private_read_set(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
user_id: &UserId,
|
||||
count: u64,
|
||||
globals: &super::super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
let mut key = room_id.to_string().as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&user_id.to_string().as_bytes());
|
||||
|
|
43
src/database/transaction_ids.rs
Normal file
43
src/database/transaction_ids.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use crate::Result;
|
||||
use ruma::{DeviceId, UserId};
|
||||
use sled::IVec;
|
||||
|
||||
pub struct TransactionIds {
|
||||
pub(super) userdevicetxnid_response: sled::Tree, // Response can be empty (/sendToDevice) or the event id (/send)
|
||||
}
|
||||
|
||||
impl TransactionIds {
|
||||
pub fn add_txnid(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
txn_id: &str,
|
||||
data: &[u8],
|
||||
) -> Result<()> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(device_id.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(txn_id.as_bytes());
|
||||
|
||||
self.userdevicetxnid_response.insert(key, data)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn existing_txnid(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
txn_id: &str,
|
||||
) -> Result<Option<IVec>> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(device_id.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(txn_id.as_bytes());
|
||||
|
||||
// If there's no entry, this is a new transaction
|
||||
Ok(self.userdevicetxnid_response.get(key)?)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue