feat(presence): add granular allow configuration

This commit is contained in:
Jakub Kubík 2023-09-08 14:36:39 +02:00 committed by girlbossceo
parent ba03edfae9
commit 58a83f06b1
9 changed files with 133 additions and 98 deletions

View file

@ -367,8 +367,16 @@ impl Service {
&self.config.emergency_password
}
pub fn allow_presence(&self) -> bool {
self.config.allow_presence
pub fn allow_local_presence(&self) -> bool {
self.config.allow_local_presence
}
pub fn allow_incoming_presence(&self) -> bool {
self.config.allow_incoming_presence
}
pub fn allow_outcoming_presence(&self) -> bool {
self.config.allow_outgoing_presence
}
pub fn presence_idle_timeout_s(&self) -> u64 {

View file

@ -286,39 +286,41 @@ impl Service {
.filter(|user_id| user_id.server_name() == services().globals.server_name()),
);
// Look for presence updates in this room
let mut presence_updates = Vec::new();
if services().globals.allow_outcoming_presence() {
// Look for presence updates in this room
let mut presence_updates = Vec::new();
for presence_data in services()
.rooms
.edus
.presence
.presence_since(&room_id, since)
{
let (user_id, count, presence_event) = presence_data?;
for presence_data in services()
.rooms
.edus
.presence
.presence_since(&room_id, since)
{
let (user_id, count, presence_event) = presence_data?;
if count > max_edu_count {
max_edu_count = count;
if count > max_edu_count {
max_edu_count = count;
}
if user_id.server_name() != services().globals.server_name() {
continue;
}
presence_updates.push(PresenceUpdate {
user_id,
presence: presence_event.content.presence,
currently_active: presence_event.content.currently_active.unwrap_or(false),
last_active_ago: presence_event.content.last_active_ago.unwrap_or(uint!(0)),
status_msg: presence_event.content.status_msg,
});
}
if user_id.server_name() != services().globals.server_name() {
continue;
}
presence_updates.push(PresenceUpdate {
user_id,
presence: presence_event.content.presence,
currently_active: presence_event.content.currently_active.unwrap_or(false),
last_active_ago: presence_event.content.last_active_ago.unwrap_or(uint!(0)),
status_msg: presence_event.content.status_msg,
});
let presence_content = Edu::Presence(PresenceContent::new(presence_updates));
events.push(
serde_json::to_vec(&presence_content).expect("PresenceEvent can be serialized"),
);
}
let presence_content = Edu::Presence(PresenceContent::new(presence_updates));
events.push(
serde_json::to_vec(&presence_content).expect("PresenceEvent can be serialized"),
);
// Look for read receipts in this room
for r in services()
.rooms