aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src/logic/disconnect.rs
blob: bbff8be0bcfdd0e8fb63b1da9e04b88cac20a7a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// SPDX-FileCopyrightText: 2025 cel <cel@bunny.garden>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

use lampada::Connected;
use stanza::client::Stanza;

use crate::{UpdateMessage, files::FileStore, presence::Offline};

use super::ClientLogic;

pub async fn handle_disconnect<Fs: FileStore + Clone>(
    logic: ClientLogic<Fs>,
    connection: Connected,
) {
    // TODO: be able to set offline status message
    let offline_presence: stanza::client::presence::Presence = Offline::default().into_stanza(None);
    let stanza = Stanza::Presence(offline_presence);
    // TODO: timeout and error check
    connection.write_handle().write(stanza).await;
    let _ = logic
        .update_sender()
        .send(UpdateMessage::Offline(Offline::default()))
        .await;
}