Clean up (mostly automated with cargo clippy --fix)
This commit is contained in:
parent
979ec6b4fa
commit
d68c93b5fa
36 changed files with 364 additions and 393 deletions
|
@ -192,7 +192,7 @@ impl SqliteTable {
|
|||
impl Tree for SqliteTable {
|
||||
#[tracing::instrument(skip(self, key))]
|
||||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
|
||||
self.get_with_guard(&self.engine.read_lock(), key)
|
||||
self.get_with_guard(self.engine.read_lock(), key)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, key, value))]
|
||||
|
@ -275,7 +275,7 @@ impl Tree for SqliteTable {
|
|||
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = TupleOfBytes> + 'a> {
|
||||
let guard = self.engine.read_lock_iterator();
|
||||
|
||||
self.iter_with_guard(&guard)
|
||||
self.iter_with_guard(guard)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, from, backwards))]
|
||||
|
|
|
@ -32,13 +32,13 @@ impl AccountData {
|
|||
.as_bytes()
|
||||
.to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(&user_id.as_bytes());
|
||||
prefix.extend_from_slice(user_id.as_bytes());
|
||||
prefix.push(0xff);
|
||||
|
||||
let mut roomuserdataid = prefix.clone();
|
||||
roomuserdataid.extend_from_slice(&globals.next_count()?.to_be_bytes());
|
||||
roomuserdataid.push(0xff);
|
||||
roomuserdataid.extend_from_slice(&event_type.as_bytes());
|
||||
roomuserdataid.extend_from_slice(event_type.as_bytes());
|
||||
|
||||
let mut key = prefix;
|
||||
key.extend_from_slice(event_type.as_bytes());
|
||||
|
@ -83,7 +83,7 @@ impl AccountData {
|
|||
.as_bytes()
|
||||
.to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&user_id.as_bytes());
|
||||
key.extend_from_slice(user_id.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(kind.as_ref().as_bytes());
|
||||
|
||||
|
@ -118,7 +118,7 @@ impl AccountData {
|
|||
.as_bytes()
|
||||
.to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(&user_id.as_bytes());
|
||||
prefix.extend_from_slice(user_id.as_bytes());
|
||||
prefix.push(0xff);
|
||||
|
||||
// Skip the data that's exactly at since, because we sent that last time
|
||||
|
|
|
@ -113,7 +113,7 @@ impl Globals {
|
|||
.map(|key| (version, key))
|
||||
})
|
||||
.and_then(|(version, key)| {
|
||||
ruma::signatures::Ed25519KeyPair::from_der(&key, version)
|
||||
ruma::signatures::Ed25519KeyPair::from_der(key, version)
|
||||
.map_err(|_| Error::bad_database("Private or public keys are invalid."))
|
||||
});
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ impl KeyBackups {
|
|||
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
|
||||
self.backupid_algorithm.insert(
|
||||
&key,
|
||||
|
@ -41,7 +41,7 @@ impl KeyBackups {
|
|||
pub fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
|
||||
self.backupid_algorithm.remove(&key)?;
|
||||
self.backupid_etag.remove(&key)?;
|
||||
|
@ -64,7 +64,7 @@ impl KeyBackups {
|
|||
) -> Result<String> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
|
||||
if self.backupid_algorithm.get(&key)?.is_none() {
|
||||
return Err(Error::BadRequest(
|
||||
|
@ -75,7 +75,7 @@ impl KeyBackups {
|
|||
|
||||
self.backupid_algorithm.insert(
|
||||
&key,
|
||||
&serde_json::to_string(backup_metadata)
|
||||
serde_json::to_string(backup_metadata)
|
||||
.expect("BackupAlgorithm::to_string always works")
|
||||
.as_bytes(),
|
||||
)?;
|
||||
|
@ -192,7 +192,7 @@ impl KeyBackups {
|
|||
pub fn get_etag(&self, user_id: &UserId, version: &str) -> Result<String> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
|
||||
Ok(utils::u64_from_bytes(
|
||||
&self
|
||||
|
@ -223,7 +223,7 @@ impl KeyBackups {
|
|||
let mut parts = key.rsplit(|&b| b == 0xff);
|
||||
|
||||
let session_id =
|
||||
utils::string_from_bytes(&parts.next().ok_or_else(|| {
|
||||
utils::string_from_bytes(parts.next().ok_or_else(|| {
|
||||
Error::bad_database("backupkeyid_backup key is invalid.")
|
||||
})?)
|
||||
.map_err(|_| {
|
||||
|
@ -231,7 +231,7 @@ impl KeyBackups {
|
|||
})?;
|
||||
|
||||
let room_id = RoomId::try_from(
|
||||
utils::string_from_bytes(&parts.next().ok_or_else(|| {
|
||||
utils::string_from_bytes(parts.next().ok_or_else(|| {
|
||||
Error::bad_database("backupkeyid_backup key is invalid.")
|
||||
})?)
|
||||
.map_err(|_| Error::bad_database("backupkeyid_backup room_id is invalid."))?,
|
||||
|
@ -280,7 +280,7 @@ impl KeyBackups {
|
|||
let mut parts = key.rsplit(|&b| b == 0xff);
|
||||
|
||||
let session_id =
|
||||
utils::string_from_bytes(&parts.next().ok_or_else(|| {
|
||||
utils::string_from_bytes(parts.next().ok_or_else(|| {
|
||||
Error::bad_database("backupkeyid_backup key is invalid.")
|
||||
})?)
|
||||
.map_err(|_| {
|
||||
|
@ -325,7 +325,7 @@ impl KeyBackups {
|
|||
pub fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
key.push(0xff);
|
||||
|
||||
for (outdated_key, _) in self.backupkeyid_backup.scan_prefix(key) {
|
||||
|
@ -343,9 +343,9 @@ impl KeyBackups {
|
|||
) -> Result<()> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&room_id.as_bytes());
|
||||
key.extend_from_slice(room_id.as_bytes());
|
||||
key.push(0xff);
|
||||
|
||||
for (outdated_key, _) in self.backupkeyid_backup.scan_prefix(key) {
|
||||
|
@ -364,11 +364,11 @@ impl KeyBackups {
|
|||
) -> Result<()> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&room_id.as_bytes());
|
||||
key.extend_from_slice(room_id.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&session_id.as_bytes());
|
||||
key.extend_from_slice(session_id.as_bytes());
|
||||
|
||||
for (outdated_key, _) in self.backupkeyid_backup.scan_prefix(key) {
|
||||
self.backupkeyid_backup.remove(&outdated_key)?;
|
||||
|
|
|
@ -4,7 +4,10 @@ use image::{imageops::FilterType, GenericImageView};
|
|||
use super::abstraction::Tree;
|
||||
use crate::{utils, Error, Result};
|
||||
use std::{mem, sync::Arc};
|
||||
use tokio::{fs::File, io::AsyncReadExt, io::AsyncWriteExt};
|
||||
use tokio::{
|
||||
fs::File,
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
};
|
||||
|
||||
pub struct FileMeta {
|
||||
pub content_disposition: Option<String>,
|
||||
|
|
|
@ -236,7 +236,7 @@ pub fn get_actions<'a>(
|
|||
member_count: 10_u32.into(), // TODO: get member count efficiently
|
||||
user_display_name: db
|
||||
.users
|
||||
.displayname(&user)?
|
||||
.displayname(user)?
|
||||
.unwrap_or_else(|| user.localpart().to_owned()),
|
||||
users_power_levels: power_levels.users.clone(),
|
||||
default_power_level: power_levels.users_default,
|
||||
|
@ -302,7 +302,7 @@ async fn send_notice(
|
|||
if event_id_only {
|
||||
send_request(
|
||||
&db.globals,
|
||||
&url,
|
||||
url,
|
||||
send_event_notification::v1::Request::new(notifi),
|
||||
)
|
||||
.await?;
|
||||
|
@ -332,7 +332,7 @@ async fn send_notice(
|
|||
|
||||
send_request(
|
||||
&db.globals,
|
||||
&url,
|
||||
url,
|
||||
send_event_notification::v1::Request::new(notifi),
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -252,7 +252,7 @@ impl Rooms {
|
|||
return Ok(HashMap::new());
|
||||
};
|
||||
|
||||
let auth_events = state_res::auth_types_for_event(kind, sender, state_key, &content);
|
||||
let auth_events = state_res::auth_types_for_event(kind, sender, state_key, content);
|
||||
|
||||
let mut sauthevents = auth_events
|
||||
.into_iter()
|
||||
|
@ -339,7 +339,7 @@ impl Rooms {
|
|||
new_state_ids_compressed: HashSet<CompressedStateEvent>,
|
||||
db: &Database,
|
||||
) -> Result<()> {
|
||||
let previous_shortstatehash = self.current_shortstatehash(&room_id)?;
|
||||
let previous_shortstatehash = self.current_shortstatehash(room_id)?;
|
||||
|
||||
let state_hash = self.calculate_hash(
|
||||
&new_state_ids_compressed
|
||||
|
@ -424,7 +424,7 @@ impl Rooms {
|
|||
}
|
||||
}
|
||||
|
||||
self.update_joined_count(room_id, &db)?;
|
||||
self.update_joined_count(room_id, db)?;
|
||||
|
||||
self.roomid_shortstatehash
|
||||
.insert(room_id.as_bytes(), &new_shortstatehash.to_be_bytes())?;
|
||||
|
@ -704,7 +704,7 @@ impl Rooms {
|
|||
event_id: &EventId,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<u64> {
|
||||
if let Some(short) = self.eventidshort_cache.lock().unwrap().get_mut(&event_id) {
|
||||
if let Some(short) = self.eventidshort_cache.lock().unwrap().get_mut(event_id) {
|
||||
return Ok(*short);
|
||||
}
|
||||
|
||||
|
@ -732,7 +732,7 @@ impl Rooms {
|
|||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_shortroomid(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
self.roomid_shortroomid
|
||||
.get(&room_id.as_bytes())?
|
||||
.get(room_id.as_bytes())?
|
||||
.map(|bytes| {
|
||||
utils::u64_from_bytes(&bytes)
|
||||
.map_err(|_| Error::bad_database("Invalid shortroomid in db."))
|
||||
|
@ -757,7 +757,7 @@ impl Rooms {
|
|||
|
||||
let mut statekey = event_type.as_ref().as_bytes().to_vec();
|
||||
statekey.push(0xff);
|
||||
statekey.extend_from_slice(&state_key.as_bytes());
|
||||
statekey.extend_from_slice(state_key.as_bytes());
|
||||
|
||||
let short = self
|
||||
.statekey_shortstatekey
|
||||
|
@ -784,13 +784,13 @@ impl Rooms {
|
|||
room_id: &RoomId,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<u64> {
|
||||
Ok(match self.roomid_shortroomid.get(&room_id.as_bytes())? {
|
||||
Ok(match self.roomid_shortroomid.get(room_id.as_bytes())? {
|
||||
Some(short) => utils::u64_from_bytes(&short)
|
||||
.map_err(|_| Error::bad_database("Invalid shortroomid in db."))?,
|
||||
None => {
|
||||
let short = globals.next_count()?;
|
||||
self.roomid_shortroomid
|
||||
.insert(&room_id.as_bytes(), &short.to_be_bytes())?;
|
||||
.insert(room_id.as_bytes(), &short.to_be_bytes())?;
|
||||
short
|
||||
}
|
||||
})
|
||||
|
@ -814,7 +814,7 @@ impl Rooms {
|
|||
|
||||
let mut statekey = event_type.as_ref().as_bytes().to_vec();
|
||||
statekey.push(0xff);
|
||||
statekey.extend_from_slice(&state_key.as_bytes());
|
||||
statekey.extend_from_slice(state_key.as_bytes());
|
||||
|
||||
let short = match self.statekey_shortstatekey.get(&statekey)? {
|
||||
Some(shortstatekey) => utils::u64_from_bytes(&shortstatekey)
|
||||
|
@ -891,12 +891,12 @@ impl Rooms {
|
|||
.ok_or_else(|| Error::bad_database("Invalid statekey in shortstatekey_statekey."))?;
|
||||
|
||||
let event_type =
|
||||
EventType::try_from(utils::string_from_bytes(&eventtype_bytes).map_err(|_| {
|
||||
EventType::try_from(utils::string_from_bytes(eventtype_bytes).map_err(|_| {
|
||||
Error::bad_database("Event type in shortstatekey_statekey is invalid unicode.")
|
||||
})?)
|
||||
.map_err(|_| Error::bad_database("Event type in shortstatekey_statekey is invalid."))?;
|
||||
|
||||
let state_key = utils::string_from_bytes(&statekey_bytes).map_err(|_| {
|
||||
let state_key = utils::string_from_bytes(statekey_bytes).map_err(|_| {
|
||||
Error::bad_database("Statekey in shortstatekey_statekey is invalid unicode.")
|
||||
})?;
|
||||
|
||||
|
@ -956,10 +956,8 @@ impl Rooms {
|
|||
/// Returns the `count` of this pdu's id.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn pdu_count(&self, pdu_id: &[u8]) -> Result<u64> {
|
||||
Ok(
|
||||
utils::u64_from_bytes(&pdu_id[pdu_id.len() - size_of::<u64>()..])
|
||||
.map_err(|_| Error::bad_database("PDU has invalid count bytes."))?,
|
||||
)
|
||||
utils::u64_from_bytes(&pdu_id[pdu_id.len() - size_of::<u64>()..])
|
||||
.map_err(|_| Error::bad_database("PDU has invalid count bytes."))
|
||||
}
|
||||
|
||||
/// Returns the `count` of this pdu's id.
|
||||
|
@ -1076,7 +1074,7 @@ impl Rooms {
|
|||
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_pdu(&self, event_id: &EventId) -> Result<Option<Arc<PduEvent>>> {
|
||||
if let Some(p) = self.pdu_cache.lock().unwrap().get_mut(&event_id) {
|
||||
if let Some(p) = self.pdu_cache.lock().unwrap().get_mut(event_id) {
|
||||
return Ok(Some(Arc::clone(p)));
|
||||
}
|
||||
|
||||
|
@ -1138,9 +1136,9 @@ impl Rooms {
|
|||
/// Removes a pdu and creates a new one with the same id.
|
||||
#[tracing::instrument(skip(self))]
|
||||
fn replace_pdu(&self, pdu_id: &[u8], pdu: &PduEvent) -> Result<()> {
|
||||
if self.pduid_pdu.get(&pdu_id)?.is_some() {
|
||||
if self.pduid_pdu.get(pdu_id)?.is_some() {
|
||||
self.pduid_pdu.insert(
|
||||
&pdu_id,
|
||||
pdu_id,
|
||||
&serde_json::to_vec(pdu).expect("PduEvent::to_vec always works"),
|
||||
)?;
|
||||
Ok(())
|
||||
|
@ -1225,20 +1223,20 @@ impl Rooms {
|
|||
#[tracing::instrument(skip(self, pdu))]
|
||||
pub fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()> {
|
||||
self.eventid_outlierpdu.insert(
|
||||
&event_id.as_bytes(),
|
||||
event_id.as_bytes(),
|
||||
&serde_json::to_vec(&pdu).expect("CanonicalJsonObject is valid"),
|
||||
)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn mark_event_soft_failed(&self, event_id: &EventId) -> Result<()> {
|
||||
self.softfailedeventids.insert(&event_id.as_bytes(), &[])
|
||||
self.softfailedeventids.insert(event_id.as_bytes(), &[])
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn is_event_soft_failed(&self, event_id: &EventId) -> Result<bool> {
|
||||
self.softfailedeventids
|
||||
.get(&event_id.as_bytes())
|
||||
.get(event_id.as_bytes())
|
||||
.map(|o| o.is_some())
|
||||
}
|
||||
|
||||
|
@ -1268,7 +1266,7 @@ impl Rooms {
|
|||
{
|
||||
if let Some(shortstatehash) = self.pdu_shortstatehash(&pdu.event_id).unwrap() {
|
||||
if let Some(prev_state) = self
|
||||
.state_get(shortstatehash, &pdu.kind, &state_key)
|
||||
.state_get(shortstatehash, &pdu.kind, state_key)
|
||||
.unwrap()
|
||||
{
|
||||
unsigned.insert(
|
||||
|
@ -1350,15 +1348,15 @@ impl Rooms {
|
|||
|
||||
let rules_for_user = db
|
||||
.account_data
|
||||
.get::<push_rules::PushRulesEvent>(None, &user, EventType::PushRules)?
|
||||
.get::<push_rules::PushRulesEvent>(None, user, EventType::PushRules)?
|
||||
.map(|ev| ev.content.global)
|
||||
.unwrap_or_else(|| push::Ruleset::server_default(&user));
|
||||
.unwrap_or_else(|| push::Ruleset::server_default(user));
|
||||
|
||||
let mut highlight = false;
|
||||
let mut notify = false;
|
||||
|
||||
for action in pusher::get_actions(
|
||||
&user,
|
||||
user,
|
||||
&rules_for_user,
|
||||
&power_levels,
|
||||
&sync_pdu,
|
||||
|
@ -1388,7 +1386,7 @@ impl Rooms {
|
|||
highlights.push(userroom_id);
|
||||
}
|
||||
|
||||
for senderkey in db.pusher.get_pusher_senderkeys(&user) {
|
||||
for senderkey in db.pusher.get_pusher_senderkeys(user) {
|
||||
db.sending.send_push_pdu(&*pdu_id, senderkey)?;
|
||||
}
|
||||
}
|
||||
|
@ -1401,7 +1399,7 @@ impl Rooms {
|
|||
match pdu.kind {
|
||||
EventType::RoomRedaction => {
|
||||
if let Some(redact_id) = &pdu.redacts {
|
||||
self.redact_pdu(&redact_id, &pdu)?;
|
||||
self.redact_pdu(redact_id, pdu)?;
|
||||
}
|
||||
}
|
||||
EventType::RoomMember => {
|
||||
|
@ -1741,9 +1739,9 @@ impl Rooms {
|
|||
state_ids_compressed: HashSet<CompressedStateEvent>,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
let shorteventid = self.get_or_create_shorteventid(&event_id, globals)?;
|
||||
let shorteventid = self.get_or_create_shorteventid(event_id, globals)?;
|
||||
|
||||
let previous_shortstatehash = self.current_shortstatehash(&room_id)?;
|
||||
let previous_shortstatehash = self.current_shortstatehash(room_id)?;
|
||||
|
||||
let state_hash = self.calculate_hash(
|
||||
&state_ids_compressed
|
||||
|
@ -1815,7 +1813,7 @@ impl Rooms {
|
|||
.map_or_else(|| Ok(Vec::new()), |p| self.load_shortstatehash_info(p))?;
|
||||
|
||||
let shortstatekey =
|
||||
self.get_or_create_shortstatekey(&new_pdu.kind, &state_key, globals)?;
|
||||
self.get_or_create_shortstatekey(&new_pdu.kind, state_key, globals)?;
|
||||
|
||||
let new = self.compress_state_event(shortstatekey, &new_pdu.event_id, globals)?;
|
||||
|
||||
|
@ -1840,7 +1838,7 @@ impl Rooms {
|
|||
|
||||
let mut statediffremoved = HashSet::new();
|
||||
if let Some(replaces) = replaces {
|
||||
statediffremoved.insert(replaces.clone());
|
||||
statediffremoved.insert(*replaces);
|
||||
}
|
||||
|
||||
self.save_state_from_diff(
|
||||
|
@ -1953,12 +1951,12 @@ impl Rooms {
|
|||
} = pdu_builder;
|
||||
|
||||
let prev_events = self
|
||||
.get_pdu_leaves(&room_id)?
|
||||
.get_pdu_leaves(room_id)?
|
||||
.into_iter()
|
||||
.take(20)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let create_event = self.room_state_get(&room_id, &EventType::RoomCreate, "")?;
|
||||
let create_event = self.room_state_get(room_id, &EventType::RoomCreate, "")?;
|
||||
|
||||
let create_event_content = create_event
|
||||
.as_ref()
|
||||
|
@ -1988,13 +1986,8 @@ impl Rooms {
|
|||
});
|
||||
let room_version = RoomVersion::new(&room_version_id).expect("room version is supported");
|
||||
|
||||
let auth_events = self.get_auth_events(
|
||||
&room_id,
|
||||
&event_type,
|
||||
&sender,
|
||||
state_key.as_deref(),
|
||||
&content,
|
||||
)?;
|
||||
let auth_events =
|
||||
self.get_auth_events(room_id, &event_type, sender, state_key.as_deref(), &content)?;
|
||||
|
||||
// Our depth is the maximum depth of prev_events + 1
|
||||
let depth = prev_events
|
||||
|
@ -2006,7 +1999,7 @@ impl Rooms {
|
|||
|
||||
let mut unsigned = unsigned.unwrap_or_default();
|
||||
if let Some(state_key) = &state_key {
|
||||
if let Some(prev_pdu) = self.room_state_get(&room_id, &event_type, &state_key)? {
|
||||
if let Some(prev_pdu) = self.room_state_get(room_id, &event_type, state_key)? {
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.content.clone());
|
||||
unsigned.insert(
|
||||
"prev_sender".to_owned(),
|
||||
|
@ -2109,7 +2102,7 @@ impl Rooms {
|
|||
|
||||
// We set the room state after inserting the pdu, so that we never have a moment in time
|
||||
// where events in the current room state do not exist
|
||||
self.set_room_state(&room_id, statehashid)?;
|
||||
self.set_room_state(room_id, statehashid)?;
|
||||
|
||||
for server in self
|
||||
.room_servers(room_id)
|
||||
|
@ -2154,10 +2147,10 @@ impl Rooms {
|
|||
&& pdu
|
||||
.state_key
|
||||
.as_ref()
|
||||
.map_or(false, |state_key| users.is_match(&state_key))
|
||||
.map_or(false, |state_key| users.is_match(state_key))
|
||||
};
|
||||
let matching_aliases = |aliases: &Regex| {
|
||||
self.room_aliases(&room_id)
|
||||
self.room_aliases(room_id)
|
||||
.filter_map(|r| r.ok())
|
||||
.any(|room_alias| aliases.is_match(room_alias.as_str()))
|
||||
};
|
||||
|
@ -2300,7 +2293,7 @@ impl Rooms {
|
|||
let mut pdu = self
|
||||
.get_pdu_from_id(&pdu_id)?
|
||||
.ok_or_else(|| Error::bad_database("PDU ID points to invalid PDU."))?;
|
||||
pdu.redact(&reason)?;
|
||||
pdu.redact(reason)?;
|
||||
self.replace_pdu(&pdu_id, &pdu)?;
|
||||
Ok(())
|
||||
} else {
|
||||
|
@ -2348,13 +2341,13 @@ impl Rooms {
|
|||
match &membership {
|
||||
member::MembershipState::Join => {
|
||||
// Check if the user never joined this room
|
||||
if !self.once_joined(&user_id, &room_id)? {
|
||||
if !self.once_joined(user_id, room_id)? {
|
||||
// Add the user ID to the join list then
|
||||
self.roomuseroncejoinedids.insert(&userroom_id, &[])?;
|
||||
|
||||
// Check if the room has a predecessor
|
||||
if let Some(predecessor) = self
|
||||
.room_state_get(&room_id, &EventType::RoomCreate, "")?
|
||||
.room_state_get(room_id, &EventType::RoomCreate, "")?
|
||||
.and_then(|create| {
|
||||
serde_json::from_value::<
|
||||
Raw<ruma::events::room::create::CreateEventContent>,
|
||||
|
@ -2455,12 +2448,12 @@ impl Rooms {
|
|||
let is_ignored = db
|
||||
.account_data
|
||||
.get::<ignored_user_list::IgnoredUserListEvent>(
|
||||
None, // Ignored users are in global account data
|
||||
&user_id, // Receiver
|
||||
None, // Ignored users are in global account data
|
||||
user_id, // Receiver
|
||||
EventType::IgnoredUserList,
|
||||
)?
|
||||
.map_or(false, |ignored| {
|
||||
ignored.content.ignored_users.contains(&sender)
|
||||
ignored.content.ignored_users.contains(sender)
|
||||
});
|
||||
|
||||
if is_ignored {
|
||||
|
@ -2522,7 +2515,7 @@ impl Rooms {
|
|||
let mut joined_servers = HashSet::new();
|
||||
let mut real_users = HashSet::new();
|
||||
|
||||
for joined in self.room_members(&room_id).filter_map(|r| r.ok()) {
|
||||
for joined in self.room_members(room_id).filter_map(|r| r.ok()) {
|
||||
joined_servers.insert(joined.server_name().to_owned());
|
||||
if joined.server_name() == db.globals.server_name()
|
||||
&& !db.users.is_deactivated(&joined).unwrap_or(true)
|
||||
|
@ -2532,7 +2525,7 @@ impl Rooms {
|
|||
joinedcount += 1;
|
||||
}
|
||||
|
||||
for invited in self.room_members_invited(&room_id).filter_map(|r| r.ok()) {
|
||||
for invited in self.room_members_invited(room_id).filter_map(|r| r.ok()) {
|
||||
joined_servers.insert(invited.server_name().to_owned());
|
||||
invitedcount += 1;
|
||||
}
|
||||
|
@ -2601,7 +2594,7 @@ impl Rooms {
|
|||
if let Some(users) = maybe {
|
||||
Ok(users)
|
||||
} else {
|
||||
self.update_joined_count(room_id, &db)?;
|
||||
self.update_joined_count(room_id, db)?;
|
||||
Ok(Arc::clone(
|
||||
self.our_real_users_cache
|
||||
.read()
|
||||
|
@ -2650,7 +2643,7 @@ impl Rooms {
|
|||
|
||||
let in_room = bridge_user_id
|
||||
.map_or(false, |id| self.is_joined(&id, room_id).unwrap_or(false))
|
||||
|| self.room_members(&room_id).any(|userid| {
|
||||
|| self.room_members(room_id).any(|userid| {
|
||||
userid.map_or(false, |userid| {
|
||||
users.iter().any(|r| r.is_match(userid.as_str()))
|
||||
})
|
||||
|
@ -2890,21 +2883,21 @@ impl Rooms {
|
|||
if let Some(room_id) = room_id {
|
||||
// New alias
|
||||
self.alias_roomid
|
||||
.insert(&alias.alias().as_bytes(), room_id.as_bytes())?;
|
||||
.insert(alias.alias().as_bytes(), room_id.as_bytes())?;
|
||||
let mut aliasid = room_id.as_bytes().to_vec();
|
||||
aliasid.push(0xff);
|
||||
aliasid.extend_from_slice(&globals.next_count()?.to_be_bytes());
|
||||
self.aliasid_alias.insert(&aliasid, &*alias.as_bytes())?;
|
||||
} else {
|
||||
// room_id=None means remove alias
|
||||
if let Some(room_id) = self.alias_roomid.get(&alias.alias().as_bytes())? {
|
||||
if let Some(room_id) = self.alias_roomid.get(alias.alias().as_bytes())? {
|
||||
let mut prefix = room_id.to_vec();
|
||||
prefix.push(0xff);
|
||||
|
||||
for (key, _) in self.aliasid_alias.scan_prefix(prefix) {
|
||||
self.aliasid_alias.remove(&key)?;
|
||||
}
|
||||
self.alias_roomid.remove(&alias.alias().as_bytes())?;
|
||||
self.alias_roomid.remove(alias.alias().as_bytes())?;
|
||||
} else {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
|
@ -3077,7 +3070,7 @@ impl Rooms {
|
|||
self.roomserverids.scan_prefix(prefix).map(|(key, _)| {
|
||||
Box::<ServerName>::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3110,7 +3103,7 @@ impl Rooms {
|
|||
self.serverroomids.scan_prefix(prefix).map(|(key, _)| {
|
||||
RoomId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3132,7 +3125,7 @@ impl Rooms {
|
|||
self.roomuserid_joined.scan_prefix(prefix).map(|(key, _)| {
|
||||
UserId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3146,26 +3139,24 @@ impl Rooms {
|
|||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
Ok(self
|
||||
.roomid_joinedcount
|
||||
self.roomid_joinedcount
|
||||
.get(room_id.as_bytes())?
|
||||
.map(|b| {
|
||||
utils::u64_from_bytes(&b)
|
||||
.map_err(|_| Error::bad_database("Invalid joinedcount in db."))
|
||||
})
|
||||
.transpose()?)
|
||||
.transpose()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn room_invited_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
Ok(self
|
||||
.roomid_invitedcount
|
||||
self.roomid_invitedcount
|
||||
.get(room_id.as_bytes())?
|
||||
.map(|b| {
|
||||
utils::u64_from_bytes(&b)
|
||||
.map_err(|_| Error::bad_database("Invalid joinedcount in db."))
|
||||
})
|
||||
.transpose()?)
|
||||
.transpose()
|
||||
}
|
||||
|
||||
/// Returns an iterator over all User IDs who ever joined a room.
|
||||
|
@ -3182,7 +3173,7 @@ impl Rooms {
|
|||
.map(|(key, _)| {
|
||||
UserId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3208,7 +3199,7 @@ impl Rooms {
|
|||
.map(|(key, _)| {
|
||||
UserId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3261,7 +3252,7 @@ impl Rooms {
|
|||
.map(|(key, _)| {
|
||||
RoomId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3287,7 +3278,7 @@ impl Rooms {
|
|||
.map(|(key, state)| {
|
||||
let room_id = RoomId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3312,7 +3303,7 @@ impl Rooms {
|
|||
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&room_id.as_bytes());
|
||||
key.extend_from_slice(room_id.as_bytes());
|
||||
|
||||
self.userroomid_invitestate
|
||||
.get(&key)?
|
||||
|
@ -3333,7 +3324,7 @@ impl Rooms {
|
|||
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&room_id.as_bytes());
|
||||
key.extend_from_slice(room_id.as_bytes());
|
||||
|
||||
self.userroomid_leftstate
|
||||
.get(&key)?
|
||||
|
@ -3360,7 +3351,7 @@ impl Rooms {
|
|||
.map(|(key, state)| {
|
||||
let room_id = RoomId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
|
|
@ -60,7 +60,7 @@ impl RoomEdus {
|
|||
let mut room_latest_id = prefix;
|
||||
room_latest_id.extend_from_slice(&globals.next_count()?.to_be_bytes());
|
||||
room_latest_id.push(0xff);
|
||||
room_latest_id.extend_from_slice(&user_id.as_bytes());
|
||||
room_latest_id.extend_from_slice(user_id.as_bytes());
|
||||
|
||||
self.readreceiptid_readreceipt.insert(
|
||||
&room_latest_id,
|
||||
|
@ -126,7 +126,7 @@ impl RoomEdus {
|
|||
) -> Result<()> {
|
||||
let mut key = room_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&user_id.as_bytes());
|
||||
key.extend_from_slice(user_id.as_bytes());
|
||||
|
||||
self.roomuserid_privateread
|
||||
.insert(&key, &count.to_be_bytes())?;
|
||||
|
@ -142,7 +142,7 @@ impl RoomEdus {
|
|||
pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> {
|
||||
let mut key = room_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&user_id.as_bytes());
|
||||
key.extend_from_slice(user_id.as_bytes());
|
||||
|
||||
self.roomuserid_privateread
|
||||
.get(&key)?
|
||||
|
@ -157,7 +157,7 @@ impl RoomEdus {
|
|||
pub fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
|
||||
let mut key = room_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&user_id.as_bytes());
|
||||
key.extend_from_slice(user_id.as_bytes());
|
||||
|
||||
Ok(self
|
||||
.roomuserid_lastprivatereadupdate
|
||||
|
@ -193,7 +193,7 @@ impl RoomEdus {
|
|||
.insert(&room_typing_id, &*user_id.as_bytes())?;
|
||||
|
||||
self.roomid_lasttypingupdate
|
||||
.insert(&room_id.as_bytes(), &count)?;
|
||||
.insert(room_id.as_bytes(), &count)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ impl RoomEdus {
|
|||
|
||||
if found_outdated {
|
||||
self.roomid_lasttypingupdate
|
||||
.insert(&room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
.insert(room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -268,7 +268,7 @@ impl RoomEdus {
|
|||
|
||||
if found_outdated {
|
||||
self.roomid_lasttypingupdate
|
||||
.insert(&room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
.insert(room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -285,7 +285,7 @@ impl RoomEdus {
|
|||
|
||||
Ok(self
|
||||
.roomid_lasttypingupdate
|
||||
.get(&room_id.as_bytes())?
|
||||
.get(room_id.as_bytes())?
|
||||
.map_or(Ok::<_, Error>(None), |bytes| {
|
||||
Ok(Some(utils::u64_from_bytes(&bytes).map_err(|_| {
|
||||
Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.")
|
||||
|
@ -342,7 +342,7 @@ impl RoomEdus {
|
|||
presence_id.push(0xff);
|
||||
presence_id.extend_from_slice(&count);
|
||||
presence_id.push(0xff);
|
||||
presence_id.extend_from_slice(&presence.sender.as_bytes());
|
||||
presence_id.extend_from_slice(presence.sender.as_bytes());
|
||||
|
||||
self.presenceid_presence.insert(
|
||||
&presence_id,
|
||||
|
@ -361,7 +361,7 @@ impl RoomEdus {
|
|||
#[tracing::instrument(skip(self))]
|
||||
pub fn ping_presence(&self, user_id: &UserId) -> Result<()> {
|
||||
self.userid_lastpresenceupdate.insert(
|
||||
&user_id.as_bytes(),
|
||||
user_id.as_bytes(),
|
||||
&utils::millis_since_unix_epoch().to_be_bytes(),
|
||||
)?;
|
||||
|
||||
|
@ -371,7 +371,7 @@ impl RoomEdus {
|
|||
/// Returns the timestamp of the last presence update of this user in millis since the unix epoch.
|
||||
pub fn last_presence_update(&self, user_id: &UserId) -> Result<Option<u64>> {
|
||||
self.userid_lastpresenceupdate
|
||||
.get(&user_id.as_bytes())?
|
||||
.get(user_id.as_bytes())?
|
||||
.map(|bytes| {
|
||||
utils::u64_from_bytes(&bytes).map_err(|_| {
|
||||
Error::bad_database("Invalid timestamp in userid_lastpresenceupdate.")
|
||||
|
@ -394,7 +394,7 @@ impl RoomEdus {
|
|||
presence_id.push(0xff);
|
||||
presence_id.extend_from_slice(&last_update.to_be_bytes());
|
||||
presence_id.push(0xff);
|
||||
presence_id.extend_from_slice(&user_id.as_bytes());
|
||||
presence_id.extend_from_slice(user_id.as_bytes());
|
||||
|
||||
self.presenceid_presence
|
||||
.get(&presence_id)?
|
||||
|
@ -480,7 +480,7 @@ impl RoomEdus {
|
|||
}
|
||||
|
||||
self.userid_lastpresenceupdate.insert(
|
||||
&user_id.as_bytes(),
|
||||
user_id.as_bytes(),
|
||||
&utils::millis_since_unix_epoch().to_be_bytes(),
|
||||
)?;
|
||||
}
|
||||
|
|
|
@ -58,9 +58,9 @@ impl OutgoingKind {
|
|||
}
|
||||
OutgoingKind::Push(user, pushkey) => {
|
||||
let mut p = b"$".to_vec();
|
||||
p.extend_from_slice(&user);
|
||||
p.extend_from_slice(user);
|
||||
p.push(0xff);
|
||||
p.extend_from_slice(&pushkey);
|
||||
p.extend_from_slice(pushkey);
|
||||
p
|
||||
}
|
||||
OutgoingKind::Normal(server) => {
|
||||
|
@ -179,8 +179,8 @@ impl Sending {
|
|||
// Insert pdus we found
|
||||
for (e, key) in &new_events {
|
||||
let value = if let SendingEventType::Edu(value) = &e.1 { &**value } else { &[] };
|
||||
guard.sending.servercurrentevent_data.insert(&key, value).unwrap();
|
||||
guard.sending.servernameevent_data.remove(&key).unwrap();
|
||||
guard.sending.servercurrentevent_data.insert(key, value).unwrap();
|
||||
guard.sending.servernameevent_data.remove(key).unwrap();
|
||||
}
|
||||
|
||||
drop(guard);
|
||||
|
@ -345,7 +345,7 @@ impl Sending {
|
|||
}
|
||||
|
||||
let event =
|
||||
serde_json::from_str::<AnySyncEphemeralRoomEvent>(&read_receipt.json().get())
|
||||
serde_json::from_str::<AnySyncEphemeralRoomEvent>(read_receipt.json().get())
|
||||
.map_err(|_| Error::bad_database("Invalid edu event in read_receipts."))?;
|
||||
let federation_event = match event {
|
||||
AnySyncEphemeralRoomEvent::Receipt(r) => {
|
||||
|
@ -486,7 +486,7 @@ impl Sending {
|
|||
match event {
|
||||
SendingEventType::Pdu(pdu_id) => {
|
||||
pdu_jsons.push(db.rooms
|
||||
.get_pdu_from_id(&pdu_id)
|
||||
.get_pdu_from_id(pdu_id)
|
||||
.map_err(|e| (kind.clone(), e))?
|
||||
.ok_or_else(|| {
|
||||
(
|
||||
|
@ -543,7 +543,7 @@ impl Sending {
|
|||
SendingEventType::Pdu(pdu_id) => {
|
||||
pdus.push(
|
||||
db.rooms
|
||||
.get_pdu_from_id(&pdu_id)
|
||||
.get_pdu_from_id(pdu_id)
|
||||
.map_err(|e| (kind.clone(), e))?
|
||||
.ok_or_else(|| {
|
||||
(
|
||||
|
@ -636,7 +636,7 @@ impl Sending {
|
|||
// TODO: check room version and remove event_id if needed
|
||||
let raw = PduEvent::convert_to_outgoing_federation_event(
|
||||
db.rooms
|
||||
.get_pdu_json_from_id(&pdu_id)
|
||||
.get_pdu_json_from_id(pdu_id)
|
||||
.map_err(|e| (OutgoingKind::Normal(server.clone()), e))?
|
||||
.ok_or_else(|| {
|
||||
(
|
||||
|
@ -711,7 +711,7 @@ impl Sending {
|
|||
let event = parts
|
||||
.next()
|
||||
.ok_or_else(|| Error::bad_database("Invalid bytes in servercurrentpdus."))?;
|
||||
let server = utils::string_from_bytes(&server).map_err(|_| {
|
||||
let server = utils::string_from_bytes(server).map_err(|_| {
|
||||
Error::bad_database("Invalid server bytes in server_currenttransaction")
|
||||
})?;
|
||||
|
||||
|
@ -750,7 +750,7 @@ impl Sending {
|
|||
let event = parts
|
||||
.next()
|
||||
.ok_or_else(|| Error::bad_database("Invalid bytes in servercurrentpdus."))?;
|
||||
let server = utils::string_from_bytes(&server).map_err(|_| {
|
||||
let server = utils::string_from_bytes(server).map_err(|_| {
|
||||
Error::bad_database("Invalid server bytes in server_currenttransaction")
|
||||
})?;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ impl Uiaa {
|
|||
) -> Result<(bool, UiaaInfo)> {
|
||||
let mut uiaainfo = auth
|
||||
.session()
|
||||
.map(|session| self.get_uiaa_session(&user_id, &device_id, session))
|
||||
.map(|session| self.get_uiaa_session(user_id, device_id, session))
|
||||
.unwrap_or_else(|| Ok(uiaainfo.clone()))?;
|
||||
|
||||
if uiaainfo.session.is_none() {
|
||||
|
|
|
@ -81,13 +81,13 @@ impl Users {
|
|||
})?;
|
||||
|
||||
Ok(Some((
|
||||
UserId::try_from(utils::string_from_bytes(&user_bytes).map_err(|_| {
|
||||
UserId::try_from(utils::string_from_bytes(user_bytes).map_err(|_| {
|
||||
Error::bad_database("User ID in token_userdeviceid is invalid unicode.")
|
||||
})?)
|
||||
.map_err(|_| {
|
||||
Error::bad_database("User ID in token_userdeviceid is invalid.")
|
||||
})?,
|
||||
utils::string_from_bytes(&device_bytes).map_err(|_| {
|
||||
utils::string_from_bytes(device_bytes).map_err(|_| {
|
||||
Error::bad_database("Device ID in token_userdeviceid is invalid.")
|
||||
})?,
|
||||
)))
|
||||
|
@ -121,7 +121,7 @@ impl Users {
|
|||
#[tracing::instrument(skip(self, user_id, password))]
|
||||
pub fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> {
|
||||
if let Some(password) = password {
|
||||
if let Ok(hash) = utils::calculate_hash(&password) {
|
||||
if let Ok(hash) = utils::calculate_hash(password) {
|
||||
self.userid_password
|
||||
.insert(user_id.as_bytes(), hash.as_bytes())?;
|
||||
Ok(())
|
||||
|
@ -245,7 +245,7 @@ impl Users {
|
|||
.expect("Device::to_string never fails."),
|
||||
)?;
|
||||
|
||||
self.set_token(user_id, &device_id, token)?;
|
||||
self.set_token(user_id, device_id, token)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ impl Users {
|
|||
.scan_prefix(prefix)
|
||||
.map(|(bytes, _)| {
|
||||
Ok(utils::string_from_bytes(
|
||||
&bytes
|
||||
bytes
|
||||
.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.ok_or_else(|| Error::bad_database("UserDevice ID in db is invalid."))?,
|
||||
|
@ -357,7 +357,7 @@ impl Users {
|
|||
// TODO: Use DeviceKeyId::to_string when it's available (and update everything,
|
||||
// because there are no wrapping quotation marks anymore)
|
||||
key.extend_from_slice(
|
||||
&serde_json::to_string(one_time_key_key)
|
||||
serde_json::to_string(one_time_key_key)
|
||||
.expect("DeviceKeyId::to_string always works")
|
||||
.as_bytes(),
|
||||
);
|
||||
|
@ -368,7 +368,7 @@ impl Users {
|
|||
)?;
|
||||
|
||||
self.userid_lastonetimekeyupdate
|
||||
.insert(&user_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
.insert(user_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ impl Users {
|
|||
#[tracing::instrument(skip(self, user_id))]
|
||||
pub fn last_one_time_keys_update(&self, user_id: &UserId) -> Result<u64> {
|
||||
self.userid_lastonetimekeyupdate
|
||||
.get(&user_id.as_bytes())?
|
||||
.get(user_id.as_bytes())?
|
||||
.map(|bytes| {
|
||||
utils::u64_from_bytes(&bytes).map_err(|_| {
|
||||
Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.")
|
||||
|
@ -402,7 +402,7 @@ impl Users {
|
|||
prefix.push(b':');
|
||||
|
||||
self.userid_lastonetimekeyupdate
|
||||
.insert(&user_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
.insert(user_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
|
||||
self.onetimekeyid_onetimekeys
|
||||
.scan_prefix(prefix)
|
||||
|
@ -680,7 +680,7 @@ impl Users {
|
|||
globals: &super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
let count = globals.next_count()?.to_be_bytes();
|
||||
for room_id in rooms.rooms_joined(&user_id).filter_map(|r| r.ok()) {
|
||||
for room_id in rooms.rooms_joined(user_id).filter_map(|r| r.ok()) {
|
||||
// Don't send key updates to unencrypted rooms
|
||||
if rooms
|
||||
.room_state_get(&room_id, &EventType::RoomEncryption, "")?
|
||||
|
@ -961,7 +961,7 @@ impl Users {
|
|||
pub fn deactivate_account(&self, user_id: &UserId) -> Result<()> {
|
||||
// Remove all associated devices
|
||||
for device_id in self.all_device_ids(user_id) {
|
||||
self.remove_device(&user_id, &device_id?)?;
|
||||
self.remove_device(user_id, &device_id?)?;
|
||||
}
|
||||
|
||||
// Set the password to "" to indicate a deactivated account. Hashes will never result in an
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue