conduwuit/src/service/key_value/transaction_ids.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
982 B
Rust
Raw Normal View History

2022-10-05 20:34:31 +02:00
use ruma::{DeviceId, TransactionId, UserId};
use crate::{KeyValueDatabase, Result};
impl crate::transaction_ids::Data for KeyValueDatabase {
fn add_txnid(
&self, user_id: &UserId, device_id: Option<&DeviceId>, txn_id: &TransactionId, data: &[u8],
2020-08-25 13:24:38 +02:00
) -> Result<()> {
let mut key = user_id.as_bytes().to_vec();
key.push(0xFF);
key.extend_from_slice(device_id.map(DeviceId::as_bytes).unwrap_or_default());
2020-08-25 13:24:38 +02:00
key.push(0xFF);
key.extend_from_slice(txn_id.as_bytes());
2021-06-08 18:10:00 +02:00
self.userdevicetxnid_response.insert(&key, data)?;
2020-08-25 13:24:38 +02:00
Ok(())
}
fn existing_txnid(
&self, user_id: &UserId, device_id: Option<&DeviceId>, txn_id: &TransactionId,
2021-06-08 18:10:00 +02:00
) -> Result<Option<Vec<u8>>> {
2020-08-25 13:24:38 +02:00
let mut key = user_id.as_bytes().to_vec();
key.push(0xFF);
key.extend_from_slice(device_id.map(DeviceId::as_bytes).unwrap_or_default());
2020-08-25 13:24:38 +02:00
key.push(0xFF);
key.extend_from_slice(txn_id.as_bytes());
// If there's no entry, this is a new transaction
2021-06-17 20:34:14 +02:00
self.userdevicetxnid_response.get(&key)
2020-08-25 13:24:38 +02:00
}
}