mirror of https://gitlab.com/famedly/conduit
Merge pull request 'feat: handle txn ids' (#198) from txnids into master
Reviewed-on: https://git.koesters.xyz/timo/conduit/pulls/198merge-requests/22/head
commit
d15b8d7c4e
@ -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…
Reference in New Issue