|
|
|
@ -34,7 +34,7 @@ impl RoomEdus { |
|
|
|
event: EduEvent, |
|
|
|
event: EduEvent, |
|
|
|
globals: &super::super::globals::Globals, |
|
|
|
globals: &super::super::globals::Globals, |
|
|
|
) -> Result<()> { |
|
|
|
) -> Result<()> { |
|
|
|
let mut prefix = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut prefix = room_id.as_bytes().to_vec(); |
|
|
|
prefix.push(0xff); |
|
|
|
prefix.push(0xff); |
|
|
|
|
|
|
|
|
|
|
|
// Remove old entry
|
|
|
|
// Remove old entry
|
|
|
|
@ -49,7 +49,7 @@ impl RoomEdus { |
|
|
|
key.rsplit(|&b| b == 0xff) |
|
|
|
key.rsplit(|&b| b == 0xff) |
|
|
|
.next() |
|
|
|
.next() |
|
|
|
.expect("rsplit always returns an element") |
|
|
|
.expect("rsplit always returns an element") |
|
|
|
== user_id.to_string().as_bytes() |
|
|
|
== user_id.as_bytes() |
|
|
|
}) |
|
|
|
}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// This is the old room_latest
|
|
|
|
// This is the old room_latest
|
|
|
|
@ -59,7 +59,7 @@ impl RoomEdus { |
|
|
|
let mut room_latest_id = prefix; |
|
|
|
let mut room_latest_id = prefix; |
|
|
|
room_latest_id.extend_from_slice(&globals.next_count()?.to_be_bytes()); |
|
|
|
room_latest_id.extend_from_slice(&globals.next_count()?.to_be_bytes()); |
|
|
|
room_latest_id.push(0xff); |
|
|
|
room_latest_id.push(0xff); |
|
|
|
room_latest_id.extend_from_slice(&user_id.to_string().as_bytes()); |
|
|
|
room_latest_id.extend_from_slice(&user_id.as_bytes()); |
|
|
|
|
|
|
|
|
|
|
|
self.readreceiptid_readreceipt.insert( |
|
|
|
self.readreceiptid_readreceipt.insert( |
|
|
|
room_latest_id, |
|
|
|
room_latest_id, |
|
|
|
@ -76,7 +76,7 @@ impl RoomEdus { |
|
|
|
room_id: &RoomId, |
|
|
|
room_id: &RoomId, |
|
|
|
since: u64, |
|
|
|
since: u64, |
|
|
|
) -> Result<impl Iterator<Item = Result<Raw<ruma::events::AnySyncEphemeralRoomEvent>>>> { |
|
|
|
) -> Result<impl Iterator<Item = Result<Raw<ruma::events::AnySyncEphemeralRoomEvent>>>> { |
|
|
|
let mut prefix = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut prefix = room_id.as_bytes().to_vec(); |
|
|
|
prefix.push(0xff); |
|
|
|
prefix.push(0xff); |
|
|
|
|
|
|
|
|
|
|
|
let mut first_possible_edu = prefix.clone(); |
|
|
|
let mut first_possible_edu = prefix.clone(); |
|
|
|
@ -102,9 +102,9 @@ impl RoomEdus { |
|
|
|
count: u64, |
|
|
|
count: u64, |
|
|
|
globals: &super::super::globals::Globals, |
|
|
|
globals: &super::super::globals::Globals, |
|
|
|
) -> Result<()> { |
|
|
|
) -> Result<()> { |
|
|
|
let mut key = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut key = room_id.as_bytes().to_vec(); |
|
|
|
key.push(0xff); |
|
|
|
key.push(0xff); |
|
|
|
key.extend_from_slice(&user_id.to_string().as_bytes()); |
|
|
|
key.extend_from_slice(&user_id.as_bytes()); |
|
|
|
|
|
|
|
|
|
|
|
self.roomuserid_privateread |
|
|
|
self.roomuserid_privateread |
|
|
|
.insert(&key, &count.to_be_bytes())?; |
|
|
|
.insert(&key, &count.to_be_bytes())?; |
|
|
|
@ -118,9 +118,9 @@ impl RoomEdus { |
|
|
|
/// Returns the private read marker.
|
|
|
|
/// Returns the private read marker.
|
|
|
|
#[tracing::instrument(skip(self))] |
|
|
|
#[tracing::instrument(skip(self))] |
|
|
|
pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> { |
|
|
|
pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> { |
|
|
|
let mut key = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut key = room_id.as_bytes().to_vec(); |
|
|
|
key.push(0xff); |
|
|
|
key.push(0xff); |
|
|
|
key.extend_from_slice(&user_id.to_string().as_bytes()); |
|
|
|
key.extend_from_slice(&user_id.as_bytes()); |
|
|
|
|
|
|
|
|
|
|
|
self.roomuserid_privateread.get(key)?.map_or(Ok(None), |v| { |
|
|
|
self.roomuserid_privateread.get(key)?.map_or(Ok(None), |v| { |
|
|
|
Ok(Some(utils::u64_from_bytes(&v).map_err(|_| { |
|
|
|
Ok(Some(utils::u64_from_bytes(&v).map_err(|_| { |
|
|
|
@ -131,9 +131,9 @@ impl RoomEdus { |
|
|
|
|
|
|
|
|
|
|
|
/// Returns the count of the last typing update in this room.
|
|
|
|
/// Returns the count of the last typing update in this room.
|
|
|
|
pub fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> { |
|
|
|
pub fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> { |
|
|
|
let mut key = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut key = room_id.as_bytes().to_vec(); |
|
|
|
key.push(0xff); |
|
|
|
key.push(0xff); |
|
|
|
key.extend_from_slice(&user_id.to_string().as_bytes()); |
|
|
|
key.extend_from_slice(&user_id.as_bytes()); |
|
|
|
|
|
|
|
|
|
|
|
Ok(self |
|
|
|
Ok(self |
|
|
|
.roomuserid_lastprivatereadupdate |
|
|
|
.roomuserid_lastprivatereadupdate |
|
|
|
@ -155,7 +155,7 @@ impl RoomEdus { |
|
|
|
timeout: u64, |
|
|
|
timeout: u64, |
|
|
|
globals: &super::super::globals::Globals, |
|
|
|
globals: &super::super::globals::Globals, |
|
|
|
) -> Result<()> { |
|
|
|
) -> Result<()> { |
|
|
|
let mut prefix = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut prefix = room_id.as_bytes().to_vec(); |
|
|
|
prefix.push(0xff); |
|
|
|
prefix.push(0xff); |
|
|
|
|
|
|
|
|
|
|
|
let count = globals.next_count()?.to_be_bytes(); |
|
|
|
let count = globals.next_count()?.to_be_bytes(); |
|
|
|
@ -166,10 +166,10 @@ impl RoomEdus { |
|
|
|
room_typing_id.extend_from_slice(&count); |
|
|
|
room_typing_id.extend_from_slice(&count); |
|
|
|
|
|
|
|
|
|
|
|
self.typingid_userid |
|
|
|
self.typingid_userid |
|
|
|
.insert(&room_typing_id, &*user_id.to_string().as_bytes())?; |
|
|
|
.insert(&room_typing_id, &*user_id.as_bytes())?; |
|
|
|
|
|
|
|
|
|
|
|
self.roomid_lasttypingupdate |
|
|
|
self.roomid_lasttypingupdate |
|
|
|
.insert(&room_id.to_string().as_bytes(), &count)?; |
|
|
|
.insert(&room_id.as_bytes(), &count)?; |
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -181,7 +181,7 @@ impl RoomEdus { |
|
|
|
room_id: &RoomId, |
|
|
|
room_id: &RoomId, |
|
|
|
globals: &super::super::globals::Globals, |
|
|
|
globals: &super::super::globals::Globals, |
|
|
|
) -> Result<()> { |
|
|
|
) -> Result<()> { |
|
|
|
let mut prefix = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut prefix = room_id.as_bytes().to_vec(); |
|
|
|
prefix.push(0xff); |
|
|
|
prefix.push(0xff); |
|
|
|
|
|
|
|
|
|
|
|
let user_id = user_id.to_string(); |
|
|
|
let user_id = user_id.to_string(); |
|
|
|
@ -200,10 +200,8 @@ impl RoomEdus { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if found_outdated { |
|
|
|
if found_outdated { |
|
|
|
self.roomid_lasttypingupdate.insert( |
|
|
|
self.roomid_lasttypingupdate |
|
|
|
&room_id.to_string().as_bytes(), |
|
|
|
.insert(&room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?; |
|
|
|
&globals.next_count()?.to_be_bytes(), |
|
|
|
|
|
|
|
)?; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
@ -215,7 +213,7 @@ impl RoomEdus { |
|
|
|
room_id: &RoomId, |
|
|
|
room_id: &RoomId, |
|
|
|
globals: &super::super::globals::Globals, |
|
|
|
globals: &super::super::globals::Globals, |
|
|
|
) -> Result<()> { |
|
|
|
) -> Result<()> { |
|
|
|
let mut prefix = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut prefix = room_id.as_bytes().to_vec(); |
|
|
|
prefix.push(0xff); |
|
|
|
prefix.push(0xff); |
|
|
|
|
|
|
|
|
|
|
|
let current_timestamp = utils::millis_since_unix_epoch(); |
|
|
|
let current_timestamp = utils::millis_since_unix_epoch(); |
|
|
|
@ -248,10 +246,8 @@ impl RoomEdus { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if found_outdated { |
|
|
|
if found_outdated { |
|
|
|
self.roomid_lasttypingupdate.insert( |
|
|
|
self.roomid_lasttypingupdate |
|
|
|
&room_id.to_string().as_bytes(), |
|
|
|
.insert(&room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?; |
|
|
|
&globals.next_count()?.to_be_bytes(), |
|
|
|
|
|
|
|
)?; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
@ -268,7 +264,7 @@ impl RoomEdus { |
|
|
|
|
|
|
|
|
|
|
|
Ok(self |
|
|
|
Ok(self |
|
|
|
.roomid_lasttypingupdate |
|
|
|
.roomid_lasttypingupdate |
|
|
|
.get(&room_id.to_string().as_bytes())? |
|
|
|
.get(&room_id.as_bytes())? |
|
|
|
.map_or(Ok::<_, Error>(None), |bytes| { |
|
|
|
.map_or(Ok::<_, Error>(None), |bytes| { |
|
|
|
Ok(Some(utils::u64_from_bytes(&bytes).map_err(|_| { |
|
|
|
Ok(Some(utils::u64_from_bytes(&bytes).map_err(|_| { |
|
|
|
Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.") |
|
|
|
Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.") |
|
|
|
@ -281,7 +277,7 @@ impl RoomEdus { |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
room_id: &RoomId, |
|
|
|
room_id: &RoomId, |
|
|
|
) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> { |
|
|
|
) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> { |
|
|
|
let mut prefix = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut prefix = room_id.as_bytes().to_vec(); |
|
|
|
prefix.push(0xff); |
|
|
|
prefix.push(0xff); |
|
|
|
|
|
|
|
|
|
|
|
let mut user_ids = Vec::new(); |
|
|
|
let mut user_ids = Vec::new(); |
|
|
|
@ -322,11 +318,11 @@ impl RoomEdus { |
|
|
|
|
|
|
|
|
|
|
|
let count = globals.next_count()?.to_be_bytes(); |
|
|
|
let count = globals.next_count()?.to_be_bytes(); |
|
|
|
|
|
|
|
|
|
|
|
let mut presence_id = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut presence_id = room_id.as_bytes().to_vec(); |
|
|
|
presence_id.push(0xff); |
|
|
|
presence_id.push(0xff); |
|
|
|
presence_id.extend_from_slice(&count); |
|
|
|
presence_id.extend_from_slice(&count); |
|
|
|
presence_id.push(0xff); |
|
|
|
presence_id.push(0xff); |
|
|
|
presence_id.extend_from_slice(&presence.sender.to_string().as_bytes()); |
|
|
|
presence_id.extend_from_slice(&presence.sender.as_bytes()); |
|
|
|
|
|
|
|
|
|
|
|
self.presenceid_presence.insert( |
|
|
|
self.presenceid_presence.insert( |
|
|
|
presence_id, |
|
|
|
presence_id, |
|
|
|
@ -334,7 +330,7 @@ impl RoomEdus { |
|
|
|
)?; |
|
|
|
)?; |
|
|
|
|
|
|
|
|
|
|
|
self.userid_lastpresenceupdate.insert( |
|
|
|
self.userid_lastpresenceupdate.insert( |
|
|
|
&user_id.to_string().as_bytes(), |
|
|
|
&user_id.as_bytes(), |
|
|
|
&utils::millis_since_unix_epoch().to_be_bytes(), |
|
|
|
&utils::millis_since_unix_epoch().to_be_bytes(), |
|
|
|
)?; |
|
|
|
)?; |
|
|
|
|
|
|
|
|
|
|
|
@ -345,7 +341,7 @@ impl RoomEdus { |
|
|
|
#[tracing::instrument(skip(self))] |
|
|
|
#[tracing::instrument(skip(self))] |
|
|
|
pub fn ping_presence(&self, user_id: &UserId) -> Result<()> { |
|
|
|
pub fn ping_presence(&self, user_id: &UserId) -> Result<()> { |
|
|
|
self.userid_lastpresenceupdate.insert( |
|
|
|
self.userid_lastpresenceupdate.insert( |
|
|
|
&user_id.to_string().as_bytes(), |
|
|
|
&user_id.as_bytes(), |
|
|
|
&utils::millis_since_unix_epoch().to_be_bytes(), |
|
|
|
&utils::millis_since_unix_epoch().to_be_bytes(), |
|
|
|
)?; |
|
|
|
)?; |
|
|
|
|
|
|
|
|
|
|
|
@ -355,7 +351,7 @@ impl RoomEdus { |
|
|
|
/// Returns the timestamp of the last presence update of this user in millis since the unix epoch.
|
|
|
|
/// 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>> { |
|
|
|
pub fn last_presence_update(&self, user_id: &UserId) -> Result<Option<u64>> { |
|
|
|
self.userid_lastpresenceupdate |
|
|
|
self.userid_lastpresenceupdate |
|
|
|
.get(&user_id.to_string().as_bytes())? |
|
|
|
.get(&user_id.as_bytes())? |
|
|
|
.map(|bytes| { |
|
|
|
.map(|bytes| { |
|
|
|
utils::u64_from_bytes(&bytes).map_err(|_| { |
|
|
|
utils::u64_from_bytes(&bytes).map_err(|_| { |
|
|
|
Error::bad_database("Invalid timestamp in userid_lastpresenceupdate.") |
|
|
|
Error::bad_database("Invalid timestamp in userid_lastpresenceupdate.") |
|
|
|
@ -398,7 +394,7 @@ impl RoomEdus { |
|
|
|
.try_into() |
|
|
|
.try_into() |
|
|
|
.map_err(|_| Error::bad_database("Invalid UserId in userid_lastpresenceupdate."))?; |
|
|
|
.map_err(|_| Error::bad_database("Invalid UserId in userid_lastpresenceupdate."))?; |
|
|
|
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()) { |
|
|
|
let mut presence_id = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut presence_id = room_id.as_bytes().to_vec(); |
|
|
|
presence_id.push(0xff); |
|
|
|
presence_id.push(0xff); |
|
|
|
presence_id.extend_from_slice(&count); |
|
|
|
presence_id.extend_from_slice(&count); |
|
|
|
presence_id.push(0xff); |
|
|
|
presence_id.push(0xff); |
|
|
|
@ -424,7 +420,7 @@ impl RoomEdus { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.userid_lastpresenceupdate.insert( |
|
|
|
self.userid_lastpresenceupdate.insert( |
|
|
|
&user_id.to_string().as_bytes(), |
|
|
|
&user_id.as_bytes(), |
|
|
|
&utils::millis_since_unix_epoch().to_be_bytes(), |
|
|
|
&utils::millis_since_unix_epoch().to_be_bytes(), |
|
|
|
)?; |
|
|
|
)?; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -443,7 +439,7 @@ impl RoomEdus { |
|
|
|
) -> Result<HashMap<UserId, PresenceEvent>> { |
|
|
|
) -> Result<HashMap<UserId, PresenceEvent>> { |
|
|
|
self.presence_maintain(rooms, globals)?; |
|
|
|
self.presence_maintain(rooms, globals)?; |
|
|
|
|
|
|
|
|
|
|
|
let mut prefix = room_id.to_string().as_bytes().to_vec(); |
|
|
|
let mut prefix = room_id.as_bytes().to_vec(); |
|
|
|
prefix.push(0xff); |
|
|
|
prefix.push(0xff); |
|
|
|
|
|
|
|
|
|
|
|
let mut first_possible_edu = prefix.clone(); |
|
|
|
let mut first_possible_edu = prefix.clone(); |
|
|
|
|