Merge branch 'Nyaaori/cleanup-presence' into 'presence'
Cleanup presence branch See merge request famedly/conduit!429
This commit is contained in:
commit
a6d5bfe35f
3 changed files with 12 additions and 9 deletions
|
@ -268,7 +268,7 @@ fn default_turn_ttl() -> u64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_presence_idle_timeout() -> u64 {
|
fn default_presence_idle_timeout() -> u64 {
|
||||||
1 * 60
|
60
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_presence_offline_timeout() -> u64 {
|
fn default_presence_offline_timeout() -> u64 {
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
||||||
|
|
||||||
self.userid_presenceupdate.insert(
|
self.userid_presenceupdate.insert(
|
||||||
user_id.as_bytes(),
|
user_id.as_bytes(),
|
||||||
&*PresenceUpdate {
|
&PresenceUpdate {
|
||||||
count: services().globals.next_count()?,
|
count: services().globals.next_count()?,
|
||||||
prev_timestamp: timestamp,
|
prev_timestamp: timestamp,
|
||||||
curr_timestamp: timestamp,
|
curr_timestamp: timestamp,
|
||||||
|
@ -120,7 +120,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.userid_presenceupdate
|
self.userid_presenceupdate
|
||||||
.insert(user_id.as_bytes(), &*new_presence.to_be_bytes())?;
|
.insert(user_id.as_bytes(), &new_presence.to_be_bytes())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
||||||
.filter_map(move |(roomuserid_bytes, presence_bytes)| {
|
.filter_map(move |(roomuserid_bytes, presence_bytes)| {
|
||||||
let user_id_bytes = roomuserid_bytes.split(|byte| *byte == 0xff).last()?;
|
let user_id_bytes = roomuserid_bytes.split(|byte| *byte == 0xff).last()?;
|
||||||
let user_id: OwnedUserId = UserId::parse(
|
let user_id: OwnedUserId = UserId::parse(
|
||||||
utils::string_from_bytes(&user_id_bytes)
|
utils::string_from_bytes(user_id_bytes)
|
||||||
.expect("UserID bytes are a valid string"),
|
.expect("UserID bytes are a valid string"),
|
||||||
)
|
)
|
||||||
.expect("UserID bytes from database are a valid UserID");
|
.expect("UserID bytes from database are a valid UserID");
|
||||||
|
@ -329,7 +329,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
||||||
Some(user_id)
|
Some(user_id)
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
match userid_presenceupdate.remove(&*user_id.as_bytes()) {
|
match userid_presenceupdate.remove(user_id.as_bytes()) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("An errord occured while removing a stale presence update: {e}")
|
error!("An errord occured while removing a stale presence update: {e}")
|
||||||
|
@ -343,7 +343,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
||||||
.filter_map(|room_id| room_id.ok())
|
.filter_map(|room_id| room_id.ok())
|
||||||
{
|
{
|
||||||
match roomuserid_presenceevent
|
match roomuserid_presenceevent
|
||||||
.remove(&*[room_id.as_bytes(), &[0xff], user_id.as_bytes()].concat())
|
.remove(&[room_id.as_bytes(), &[0xff], user_id.as_bytes()].concat())
|
||||||
{
|
{
|
||||||
Ok(_) => removed_events += 1,
|
Ok(_) => removed_events += 1,
|
||||||
Err(e) => error!(
|
Err(e) => error!(
|
||||||
|
@ -380,13 +380,13 @@ fn parse_presence_event(bytes: &[u8], presence_timestamp: u64) -> Result<Presenc
|
||||||
fn determine_presence_state(last_active_ago: u64) -> PresenceState {
|
fn determine_presence_state(last_active_ago: u64) -> PresenceState {
|
||||||
let globals = &services().globals;
|
let globals = &services().globals;
|
||||||
|
|
||||||
return if last_active_ago < globals.presence_idle_timeout() * 1000 {
|
if last_active_ago < globals.presence_idle_timeout() * 1000 {
|
||||||
PresenceState::Online
|
PresenceState::Online
|
||||||
} else if last_active_ago < globals.presence_offline_timeout() * 1000 {
|
} else if last_active_ago < globals.presence_offline_timeout() * 1000 {
|
||||||
PresenceState::Unavailable
|
PresenceState::Unavailable
|
||||||
} else {
|
} else {
|
||||||
PresenceState::Offline
|
PresenceState::Offline
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the timestamp representing last_active_ago to a diff from now.
|
/// Translates the timestamp representing last_active_ago to a diff from now.
|
||||||
|
|
|
@ -295,7 +295,10 @@ impl Service {
|
||||||
user_id,
|
user_id,
|
||||||
presence: presence_event.content.presence,
|
presence: presence_event.content.presence,
|
||||||
status_msg: presence_event.content.status_msg,
|
status_msg: presence_event.content.status_msg,
|
||||||
last_active_ago: presence_event.content.last_active_ago.unwrap_or(uint!(0)),
|
last_active_ago: presence_event
|
||||||
|
.content
|
||||||
|
.last_active_ago
|
||||||
|
.unwrap_or_else(|| uint!(0)),
|
||||||
currently_active: presence_event.content.currently_active.unwrap_or(false),
|
currently_active: presence_event.content.currently_active.unwrap_or(false),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
Loading…
Add table
Reference in a new issue