Skip to content

Commit f84aa99

Browse files
committed
Implement room picture changing
1 parent 2ffe343 commit f84aa99

8 files changed

Lines changed: 516 additions & 62 deletions

File tree

‎Cargo.lock‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ ringbuffer = "0.16"
4949
raw-window-handle = "0.6"
5050
rustc-hash = "2"
5151
qrcode = { version = "0.14", features = ["image"] }
52-
rodio = "0.22"
52+
rodio = "0.22"
53+
mimetype-detector = "0.3"

‎thegrid/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ keyring = { workspace = true }
3939
getrandom = { workspace = true }
4040
base64 = { workspace = true }
4141
qrcode = { workspace = true }
42+
mimetype-detector = { workspace = true }
4243

4344
[build-dependencies]
4445
cntp_i18n_gen = { workspace = true }

‎thegrid/src/chat/chat_room/room_settings.rs‎

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::chat::chat_room::open_room::OpenRoom;
2+
use crate::upload_mxc_dialog::{upload_mxc_dialog, UploadMxcAcceptEvent};
23
use cntp_i18n::{tr, I18nString};
34
use contemporary::components::button::{button, ButtonMenuOpenPolicy};
45
use contemporary::components::constrainer::constrainer;
@@ -19,8 +20,9 @@ use gpui::{
1920
ElementId, Entity, InteractiveElement, IntoElement, ParentElement, Render, Styled, WeakEntity, Window,
2021
};
2122
use matrix_sdk::ruma::api::client::room::Visibility;
23+
use matrix_sdk::ruma::events::room::avatar::ImageInfo;
2224
use matrix_sdk::ruma::room::JoinRule;
23-
use matrix_sdk::ruma::{OwnedRoomAliasId, RoomAliasId};
25+
use matrix_sdk::ruma::{OwnedRoomAliasId, RoomAliasId, UInt};
2426
use matrix_sdk::HttpError;
2527
use std::rc::Rc;
2628
use thegrid_common::mxc_image::{mxc_image, SizePolicy};
@@ -32,6 +34,7 @@ pub struct RoomSettings {
3234
on_back_click: Rc<Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>>,
3335
on_members_click: Rc<Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>>,
3436
edit_room_name_open: bool,
37+
edit_room_image_open: bool,
3538
new_name_text_field: Entity<TextField>,
3639
enable_encryption_open: bool,
3740
busy: bool,
@@ -85,6 +88,7 @@ impl RoomSettings {
8588
}),
8689

8790
edit_room_name_open: false,
91+
edit_room_image_open: false,
8892
enable_encryption_open: false,
8993
busy: false,
9094
published_to_directory: false,
@@ -711,10 +715,17 @@ impl Render for RoomSettings {
711715
cx.notify()
712716
})),
713717
)
714-
.child(button("room-change-profile-picture").child(icon_text(
715-
"edit-rename".into(),
716-
tr!("ROOM_CHANGE_PICTURE", "Change Picture").into(),
717-
)))
718+
.child(
719+
button("room-change-profile-picture")
720+
.child(icon_text(
721+
"edit-rename".into(),
722+
tr!("ROOM_CHANGE_PICTURE", "Change Picture").into(),
723+
))
724+
.on_click(cx.listener(move |this, _, _, cx| {
725+
this.edit_room_image_open = true;
726+
cx.notify()
727+
})),
728+
)
718729
.child(
719730
button("room-view-members")
720731
.child(icon_text(
@@ -921,6 +932,52 @@ impl Render for RoomSettings {
921932
})),
922933
),
923934
)
935+
.child(upload_mxc_dialog(
936+
tr!("ROOM_CHANGE_PICTURE"),
937+
self.edit_room_image_open,
938+
"dialog-ok".into(),
939+
tr!("ROOM_CHANGE_PICTURE").into(),
940+
cx.listener(move |this, _, _, cx| {
941+
this.edit_room_image_open = false;
942+
cx.notify();
943+
}),
944+
cx.listener({
945+
let room = room.clone();
946+
move |this, event: &UploadMxcAcceptEvent, _, cx| {
947+
let mxc_url = event.mxc_url.clone();
948+
949+
let mut image_info = ImageInfo::new();
950+
image_info.height = UInt::new(event.height);
951+
image_info.width = UInt::new(event.width);
952+
image_info.blurhash = event.blur_hash.clone();
953+
image_info.size = UInt::new(event.file_size);
954+
cx.spawn({
955+
let room = room.clone();
956+
async move |this: WeakEntity<Self>, cx: &mut AsyncApp| {
957+
if cx
958+
.spawn_tokio(async move {
959+
room.set_avatar_url(&mxc_url, Some(image_info)).await
960+
})
961+
.await
962+
.is_err()
963+
{
964+
this.update(cx, |this, cx| {
965+
this.edit_room_image_open = false;
966+
cx.notify()
967+
})
968+
} else {
969+
this.update(cx, |this, cx| {
970+
this.edit_room_image_open = false;
971+
cx.notify()
972+
})
973+
}
974+
}
975+
})
976+
.detach();
977+
cx.notify()
978+
}
979+
}),
980+
))
924981
.child(
925982
dialog_box("enable-encryption")
926983
.visible(self.enable_encryption_open)
@@ -929,10 +986,10 @@ impl Render for RoomSettings {
929986
.content(tr!(
930987
"ROOM_ENCRYPTION_ENABLE_DESCRIPTION",
931988
"By enabling encryption, you will prevent anyone joining the room \
932-
from being able to read message history. If there are any bots or \
933-
services in this room, they may also stop working.\n\n\
934-
Once enabled, encryption cannot be turned off.\n\n\
935-
Do you want to enable encryption for this room?"
989+
from being able to read message history. If there are any bots or \
990+
services in this room, they may also stop working.\n\n\
991+
Once enabled, encryption cannot be turned off.\n\n\
992+
Do you want to enable encryption for this room?"
936993
))
937994
.standard_button(
938995
StandardButton::Cancel,

‎thegrid/src/main.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod utilities;
1111

1212
mod account_settings;
1313
mod uiaa_client;
14+
mod upload_mxc_dialog;
1415

1516
use crate::actions::{
1617
register_actions, AccountSettings, AccountSwitcher, CreateRoom, CreateSpace, DirectJoinRoom,

0 commit comments

Comments
 (0)