From 7faaff93f3e2f75d32f0b153cc9401bb2583f5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sat, 4 Nov 2023 11:22:55 +0100 Subject: [PATCH] Revert "room: Expose the language of a room" This reverts commit c4c74c8abac5300210981426dc14274b5cb10568. --- po/POTFILES.in | 2 +- src/session/model/room/mod.rs | 124 ++----------------------- src/utils/{matrix/mod.rs => matrix.rs} | 2 - src/utils/matrix/custom_events.rs | 14 --- 4 files changed, 10 insertions(+), 132 deletions(-) rename src/utils/{matrix/mod.rs => matrix.rs} (99%) delete mode 100644 src/utils/matrix/custom_events.rs diff --git a/po/POTFILES.in b/po/POTFILES.in index 41219a83..61acb991 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -108,7 +108,7 @@ src/session/view/sidebar/room_row.rs src/session/view/sidebar/row.rs src/shortcuts.ui src/user_facing_error.rs -src/utils/matrix/mod.rs +src/utils/matrix.rs src/utils/media.rs src/utils/message_dialog.rs src/window.rs diff --git a/src/session/model/room/mod.rs b/src/session/model/room/mod.rs index b49a6e7f..39912ae1 100644 --- a/src/session/model/room/mod.rs +++ b/src/session/model/room/mod.rs @@ -21,7 +21,6 @@ use matrix_sdk::{ DisplayName, HttpError, Result as MatrixResult, RoomInfo, RoomMemberships, RoomState, }; use ruma::{ - api::client::config::set_room_account_data, events::{ reaction::ReactionEventContent, receipt::{ReceiptEventContent, ReceiptType}, @@ -35,7 +34,6 @@ use ruma::{ AnyMessageLikeEventContent, AnyRoomAccountDataEvent, AnySyncStateEvent, AnySyncTimelineEvent, SyncEphemeralRoomEvent, SyncStateEvent, }, - serde::Raw, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, }; use tracing::{debug, error, warn}; @@ -55,13 +53,7 @@ use super::{ room_list::RoomMetainfo, AvatarData, AvatarImage, AvatarUriSource, IdentityVerification, Session, SidebarItem, SidebarItemImpl, User, }; -use crate::{ - components::Pill, - gettext_f, - prelude::*, - spawn, spawn_tokio, - utils::matrix::custom_events::{LanguageEvent, LanguageEventContent}, -}; +use crate::{components::Pill, gettext_f, prelude::*, spawn, spawn_tokio}; mod imp { use std::cell::Cell; @@ -113,8 +105,6 @@ mod imp { pub typing_list: TypingList, /// Whether anyone can join this room. pub is_join_rule_public: Cell, - /// The language to spell check in this room. - pub language: RefCell>, } #[glib::object_subclass] @@ -193,9 +183,6 @@ mod imp { glib::ParamSpecBoolean::builder("is-join-rule-public") .explicit_notify() .build(), - glib::ParamSpecString::builder("language") - .read_only() - .build(), ] }); @@ -244,7 +231,6 @@ mod imp { "encrypted" => obj.is_encrypted().to_value(), "typing-list" => obj.typing_list().to_value(), "is-join-rule-public" => obj.is_join_rule_public().to_value(), - "language" => obj.language().to_value(), _ => unimplemented!(), } } @@ -374,10 +360,6 @@ impl Room { self.setup_receipts(); self.setup_typing(); - spawn!(clone!(@weak self as obj => async move { - obj.load_language().await; - })); - spawn!(clone!(@weak self as obj => async move { obj.watch_room_info().await; })); @@ -1332,26 +1314,19 @@ impl Room { } pub fn handle_left_response(&self, response_room: LeftRoom) { - self.update_for_room_account_data(response_room.account_data); self.update_for_events(response_room.timeline.events); } pub fn handle_joined_response(&self, response_room: JoinedRoom) { - self.update_for_room_account_data(response_room.account_data); - self.update_for_events(response_room.timeline.events); - } - - fn update_for_room_account_data(&self, room_account_data: Vec>) { - for raw in room_account_data { - if let Ok(AnyRoomAccountDataEvent::Tag(_)) = raw.deserialize() { - self.load_category(); - continue; - } - - if let Ok(language) = raw.deserialize_as::() { - self.set_language_inner(Some(language.content.input_language)); - } + if response_room + .account_data + .iter() + .any(|e| matches!(e.deserialize(), Ok(AnyRoomAccountDataEvent::Tag(_)))) + { + self.load_category(); } + + self.update_for_events(response_room.timeline.events); } /// Connect to the signal sent when a room was forgotten. @@ -1726,85 +1701,4 @@ impl Room { self.imp().is_join_rule_public.set(is_public); self.notify("is-join-rule-public"); } - - async fn load_language(&self) { - let matrix_room = self.matrix_room(); - - let handle = spawn_tokio!(async move { - matrix_room - .account_data_static::() - .await - }); - - let raw = match handle.await.unwrap() { - Ok(Some(raw)) => raw, - Ok(None) => return, - Err(error) => { - error!(room_id = %self.room_id(), "Failed to load language room account data: {error}"); - return; - } - }; - - match raw.deserialize() { - Ok(ev) => { - self.set_language_inner(Some(ev.content.input_language)); - } - Err(error) => { - error!(room_id = %self.room_id(), "Failed to deserialize language room account data: {error}"); - } - } - } - - /// The language to spell check in this room. - pub fn language(&self) -> Option { - self.imp().language.borrow().clone() - } - - /// Set the language to spell check in this room. - pub fn set_language(&self, language: Option) { - if !self.set_language_inner(language.clone()) { - return; - } - - if let Some(language) = language { - spawn!(clone!(@weak self as obj => async move { - obj.set_room_account_data_language(language).await; - })); - } - } - - fn set_language_inner(&self, language: Option) -> bool { - let imp = self.imp(); - if imp.language.borrow().as_ref() == language.as_ref() { - return false; - } - - imp.language.replace(language.clone()); - self.notify("language"); - true - } - - async fn set_room_account_data_language(&self, input_language: String) { - let client = self.session().client(); - let user_id = client.user_id().unwrap().to_owned(); - let room_id = self.room_id().to_owned(); - - let request = match set_room_account_data::v3::Request::new( - user_id, - room_id, - &LanguageEventContent { input_language }, - ) { - Ok(req) => req, - Err(error) => { - error!(room_id = %self.room_id(), "Failed to build request for language room account data: {error}"); - return; - } - }; - - let handle = spawn_tokio!(async move { client.send(request, None,).await }); - - if let Err(error) = handle.await.unwrap() { - error!(room_id = %self.room_id(), "Failed to send language room account data: {error}"); - } - } } diff --git a/src/utils/matrix/mod.rs b/src/utils/matrix.rs similarity index 99% rename from src/utils/matrix/mod.rs rename to src/utils/matrix.rs index 369f359c..91d69334 100644 --- a/src/utils/matrix/mod.rs +++ b/src/utils/matrix.rs @@ -13,8 +13,6 @@ use ruma::{ }; use thiserror::Error; -pub mod custom_events; - use super::media::filename_for_mime; use crate::{ components::{Pill, DEFAULT_PLACEHOLDER}, diff --git a/src/utils/matrix/custom_events.rs b/src/utils/matrix/custom_events.rs deleted file mode 100644 index a35dce3d..00000000 --- a/src/utils/matrix/custom_events.rs +++ /dev/null @@ -1,14 +0,0 @@ -use ruma::events::macros::EventContent; -use serde::{Deserialize, Serialize}; - -/// The content of an `org.gnome.fractal.language` event. -/// -/// The language used in a room. -/// -/// It is used to change the spell checker's language per room. -#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "org.gnome.fractal.language", kind = RoomAccountData)] -pub struct LanguageEventContent { - /// The language to spell check. - pub input_language: String, -}