utils: Add message dialog to confirm leaving a room

This commit is contained in:
Kévin Commaille 2023-10-27 13:45:07 +02:00
parent 28b2a45477
commit 1e8f1fe769
No known key found for this signature in database
GPG key ID: 29A48C1F03620416
3 changed files with 54 additions and 1 deletions

View file

@ -108,6 +108,7 @@ src/session/view/sidebar/room_row.rs
src/session/view/sidebar/row.rs src/session/view/sidebar/row.rs
src/shortcuts.ui src/shortcuts.ui
src/user_facing_error.rs src/user_facing_error.rs
src/utils/media.rs
src/utils/matrix.rs src/utils/matrix.rs
src/utils/media.rs
src/utils/message_dialog.rs
src/window.rs src/window.rs

View file

@ -0,0 +1,51 @@
//! Common message dialogs.
use adw::prelude::*;
use gettextrs::gettext;
use crate::session::model::{Room, RoomType};
/// Show a dialog to confirm leaving a room.
///
/// This supports both leaving a joined room and rejecting an invite.
pub async fn confirm_leave_room(room: &Room, transient_for: &gtk::Window) -> bool {
let (heading, body, response) = if room.category() == RoomType::Invited {
// We are rejecting an invite.
let heading = gettext("Decline Invite?");
let body = if room.is_join_rule_public() {
gettext("Do you really want to decline this invite? You can join this room on you own later.")
} else {
gettext(
"Do you really want to decline this invite? You wont be able to join this room without it.",
)
};
let response = gettext("Decline");
(heading, body, response)
} else {
// We are leaving a room that was joined.
let heading = gettext("Leave Room?");
let body = if room.is_join_rule_public() {
gettext("Do you really want to leave this room? You can come back later.")
} else {
gettext(
"Do you really want to leave this room? You wont be able to come back without an invitation.",
)
};
let response = gettext("Leave");
(heading, body, response)
};
// Ask for confirmation.
let confirm_dialog = adw::MessageDialog::builder()
.transient_for(transient_for)
.default_response("cancel")
.heading(heading)
.body(body)
.build();
confirm_dialog.add_responses(&[("cancel", &gettext("Cancel")), ("leave", &response)]);
confirm_dialog.set_response_appearance("leave", adw::ResponseAppearance::Destructive);
confirm_dialog.choose_future().await == "leave"
}

View file

@ -4,6 +4,7 @@ mod expression_list_model;
pub mod macros; pub mod macros;
pub mod matrix; pub mod matrix;
pub mod media; pub mod media;
pub mod message_dialog;
pub mod notifications; pub mod notifications;
pub mod sourceview; pub mod sourceview;
pub mod template_callbacks; pub mod template_callbacks;