Move server user presence handling to presence service
This commit is contained in:
@@ -40,6 +40,15 @@ impl crate::Service for Service {
|
||||
}
|
||||
|
||||
async fn worker(self: Arc<Self>) -> Result {
|
||||
// reset dormant online/away statuses to offline, and set the server user as
|
||||
// online
|
||||
if self.services.server.config.allow_local_presence && !self.services.db.is_read_only() {
|
||||
self.unset_all_presence().await;
|
||||
_ = self
|
||||
.ping_presence(&self.services.globals.server_user, &PresenceState::Online)
|
||||
.await;
|
||||
}
|
||||
|
||||
let receiver = self.timer_channel.1.clone();
|
||||
|
||||
let mut presence_timers = FuturesUnordered::new();
|
||||
@@ -62,6 +71,13 @@ impl crate::Service for Service {
|
||||
}
|
||||
|
||||
async fn interrupt(&self) {
|
||||
// set the server user as offline
|
||||
if self.services.server.config.allow_local_presence && !self.services.db.is_read_only() {
|
||||
_ = self
|
||||
.ping_presence(&self.services.globals.server_user, &PresenceState::Offline)
|
||||
.await;
|
||||
}
|
||||
|
||||
let (timer_sender, _) = &self.timer_channel;
|
||||
if !timer_sender.is_closed() {
|
||||
timer_sender.close();
|
||||
|
||||
@@ -160,16 +160,6 @@ impl Services {
|
||||
.start()
|
||||
.await?;
|
||||
|
||||
// reset dormant online/away statuses to offline, and set the server user as
|
||||
// online
|
||||
if self.server.config.allow_local_presence && !self.db.is_read_only() {
|
||||
self.presence.unset_all_presence().await;
|
||||
_ = self
|
||||
.presence
|
||||
.ping_presence(&self.globals.server_user, &ruma::presence::PresenceState::Online)
|
||||
.await;
|
||||
}
|
||||
|
||||
debug_info!("Services startup complete.");
|
||||
|
||||
Ok(Arc::clone(self))
|
||||
@@ -178,14 +168,6 @@ impl Services {
|
||||
pub async fn stop(&self) {
|
||||
info!("Shutting down services...");
|
||||
|
||||
// set the server user as offline
|
||||
if self.server.config.allow_local_presence && !self.db.is_read_only() {
|
||||
_ = self
|
||||
.presence
|
||||
.ping_presence(&self.globals.server_user, &ruma::presence::PresenceState::Offline)
|
||||
.await;
|
||||
}
|
||||
|
||||
self.interrupt().await;
|
||||
if let Some(manager) = self.manager.lock().await.as_ref() {
|
||||
manager.stop().await;
|
||||
|
||||
Reference in New Issue
Block a user