Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display read receipts next to each message as a row of Avatars for users who have seen that message #162

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5c54512
read_receipt_display
alanpoon Sep 26, 2024
4a78a93
Merge branch 'main' into read_receipt_display
alanpoon Sep 27, 2024
4ad555a
merge main
alanpoon Oct 3, 2024
22638d9
touchup whitespace
alanpoon Oct 4, 2024
0ccb874
Merge branch 'main' into read_receipt_display
alanpoon Oct 4, 2024
f4de445
added avatar img in read_receipts
alanpoon Oct 10, 2024
e4e9b1d
fixed tooltip position
alanpoon Oct 10, 2024
961a00f
code formating
alanpoon Oct 10, 2024
2ff7f7d
Merge branch 'main' into read_receipt_display
alanpoon Oct 10, 2024
d4fd338
Merge branch 'main' into read_receipt_display
alanpoon Oct 10, 2024
c15e8da
fix merge issue
alanpoon Oct 10, 2024
3571b1e
change sender_id to generic avatar_id
alanpoon Oct 10, 2024
0c6dd14
Merge branch 'main' into read_receipt_display
alanpoon Oct 12, 2024
24daf6e
fix conflicts
alanpoon Oct 12, 2024
e5f6943
Merge branch 'main' into read_receipt_display
alanpoon Nov 4, 2024
687bb70
Update src/profile/user_profile.rs
alanpoon Nov 4, 2024
17d1bec
remove unneccessary portal_list
alanpoon Nov 4, 2024
fa5f166
Change tooltip
alanpoon Nov 4, 2024
0e6ae80
Merge branch 'main' into read_receipt_display
alanpoon Nov 5, 2024
a36049f
changed to avatarref
alanpoon Nov 6, 2024
b3d75b9
format fix
alanpoon Nov 6, 2024
7935ffb
Merge branch 'read_receipt_display' of https://github.com/alanpoon/ro…
alanpoon Nov 6, 2024
9a7af7a
moved set_avatar_and_get_username into avatar file
alanpoon Nov 7, 2024
7fa6f39
added plus label at the end of avatarrow
alanpoon Nov 7, 2024
b81e51a
clean up
alanpoon Nov 7, 2024
eeb3384
Merge branch 'main' of https://github.com/project-robius/robrix into …
alanpoon Nov 25, 2024
29c010b
added import
alanpoon Dec 3, 2024
49798ca
Merge branch 'main' of https://github.com/project-robius/robrix into …
alanpoon Dec 3, 2024
3005aea
code cleanup and resolve conflict
alanpoon Dec 3, 2024
38ae816
shorten tooltip's width
alanpoon Dec 4, 2024
e7ca500
fix formating
alanpoon Dec 9, 2024
b1e6d14
removed generic in set_avatar_row
alanpoon Dec 9, 2024
edbcbf3
Merge branch 'read_receipt_display' of https://github.com/alanpoon/ro…
alanpoon Dec 9, 2024
567d2f7
fixed clippy
alanpoon Dec 9, 2024
d0a3cfb
fix doc
alanpoon Dec 9, 2024
07b5fc7
Create a generic RoomScreenTooltipActions
alanpoon Dec 10, 2024
08d2391
avatarrow cleanup
alanpoon Dec 10, 2024
efa3eed
z
alanpoon Dec 12, 2024
ad8d053
minor cleanup
alanpoon Dec 12, 2024
22aa294
Added human_readable name in read_receipt tooltip
alanpoon Dec 13, 2024
6fe7749
Adding avatarRef and its drawn status
alanpoon Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ unicode-segmentation = "1.11.0"
url = "2.5.0"
emojis = "0.6.1"
bytesize = "1.3.0"

indexmap = "2.6.0"

###################################################################################################
#### Note: we now enable the usage of `rustls-tls` and the `bundled-sqlite` features in the 2 ####
Expand Down
1 change: 0 additions & 1 deletion src/avatar_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub fn get_or_fetch_avatar(
},
Entry::Occupied(occupied) => return occupied.get().clone(),
}

submit_async_request(MatrixRequest::FetchAvatar {
mxc_uri,
on_fetched: enqueue_avatar_update,
Expand Down
2 changes: 2 additions & 0 deletions src/home/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod main_desktop_ui;
pub mod main_mobile_ui;
pub mod room_preview;
pub mod room_screen;
pub mod room_read_receipt;
pub mod rooms_list;
pub mod rooms_sidebar;
pub mod spaces_dock;
Expand All @@ -18,6 +19,7 @@ pub fn live_design(cx: &mut Cx) {
rooms_list::live_design(cx);
room_preview::live_design(cx);
room_screen::live_design(cx);
room_read_receipt::live_design(cx);
rooms_sidebar::live_design(cx);
main_mobile_ui::live_design(cx);
main_desktop_ui::live_design(cx);
Expand Down
181 changes: 181 additions & 0 deletions src/home/room_read_receipt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
use crate::shared::avatar::{AvatarRef, AvatarWidgetRefExt};
use crate::home::room_screen::RoomScreenTooltipActions;
use crate::utils::human_readable_list;
use indexmap::IndexMap;
use makepad_widgets::*;
use matrix_sdk::ruma::{events::receipt::Receipt, EventId, OwnedUserId, RoomId};
use std::cmp;
const MAX_VISIBLE_AVATARS_IN_READ_RECEIPT_ROW : usize = 5;
live_design! {
import makepad_draw::shader::std::*;
import makepad_widgets::base::*;
import makepad_widgets::theme_desktop_dark::*;
import crate::shared::avatar::*;
import crate::shared::styles::*;

AvatarRow = {{AvatarRow}} {
button: <Avatar> {
width: 15.0,
height: 15.0,
text_view = { text = { draw_text: {
text_style: { font_size: 6.0 }
}}}
}
margin: {top: 3, right: 10, bottom: 3, left: 10}
width: 100,
height: 50,
plus: <Label> {
draw_text: {
color: #x0,
text_style: <TITLE_TEXT>{ font_size: 11}
}
text: ""
}
}
}

#[derive(Live, Widget, LiveHook)]
pub struct AvatarRow {
#[redraw]
#[live]
draw_text: DrawText,
#[deref]
pub deref: View,
#[walk]
walk: Walk,
#[live]
button: Option<LivePtr>,
#[layout]
layout: Layout,
#[live]
plus: Option<LivePtr>,
// A vector containing its avatarRef and its drawn status
// Storing the drawn status helps prevent unnessary user profile request in the draw_walk function

Check warning on line 53 in src/home/room_read_receipt.rs

View workflow job for this annotation

GitHub Actions / Check for typos

"unnessary" should be "unnecessary".
#[rust]
buttons: Vec<(AvatarRef, bool)>,
#[rust]
label: Option<LabelRef>,
#[rust]
total_num_seen: usize,
#[redraw] #[rust] area: Area,
#[rust]
human_readable_usernames: String,
}

impl Widget for AvatarRow {
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
let uid = self.widget_uid();
if self.total_num_seen == 0 { return; }
match event.hits(cx, self.area) {
Hit::FingerHoverIn(finger_event) => {
// Temporary hack to improve the issue that the tooltip is cut off by the right side of the screen
// As the width of the tooltip not currently calculated, it is difficult to prevent the tooltip from being cut off
// If the mouse position is too close to right side of the screen, the tooltip will be left-aligned to the reaction button
let tooltip_pos = if finger_event.abs.x > cx.default_window_size().x - 80.0 {
Rect {
pos: DVec2 {
x: self.area.rect(cx).pos.x,
y: finger_event.abs.y
},
size: DVec2::new(),
}
} else {
Rect {
pos: finger_event.abs,
size: DVec2::new(),
}
};
cx.widget_action(uid, &scope.path, RoomScreenTooltipActions::HoverIn(tooltip_pos, format!("Seen by {:?}\n{}", self.total_num_seen, self.human_readable_usernames)));
}
Hit::FingerHoverOut(_) => {
cx.widget_action(uid, &scope.path, RoomScreenTooltipActions::HoverOut);
}
_ => {}
}
}

fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
cx.begin_turtle(walk, Layout::default());
for (avatar_ref, _) in self.buttons.iter_mut() {
let _ = avatar_ref.draw(cx, scope);
}
if self.total_num_seen > MAX_VISIBLE_AVATARS_IN_READ_RECEIPT_ROW {
if let Some(label) = &mut self.label {
label.set_text(&format!(" + {:?}", self.total_num_seen - MAX_VISIBLE_AVATARS_IN_READ_RECEIPT_ROW));
let _ = label.draw(cx, scope);
}
}
cx.end_turtle_with_area(&mut self.area);
DrawStep::done()
}
}
impl AvatarRow {

/// Set a row of Avatars based on receipt index map
///
/// Given a sequence of receipts, this will set each of the first MAX_VISIBLE_AVATARS_IN_READ_RECEIPT_ROW
/// Avatars in this row to the corresponding user's avatar, and
/// display the given number of total receipts as a label. The
/// index map is expected to yield tuples of (user_id, receipt),
/// where the receipt is ignored.
fn set_avatar_row(
&mut self,
cx: &mut Cx,
room_id: &RoomId,
event_id: Option<&EventId>,
receipts_map: &IndexMap<OwnedUserId, Receipt>) {
if receipts_map.len() != self.buttons.len() {
self.buttons.clear();
for _ in 0..cmp::min(MAX_VISIBLE_AVATARS_IN_READ_RECEIPT_ROW, receipts_map.len()) {
self.buttons.push((WidgetRef::new_from_ptr(cx, self.button).as_avatar(), false));
}
}
self.total_num_seen = receipts_map.len();
self.label = Some(WidgetRef::new_from_ptr(cx, self.plus).as_label());
let mut usernames_arr = vec![];
for ((avatar_ref, drawn), (user_id, _)) in self.buttons.iter_mut().zip(receipts_map) {
// Set avatar_profile_opt to be None so that the function may fetch the user profile from profile cache
if !*drawn {
let (username, drawn_status) = avatar_ref.set_avatar_and_get_username(cx, room_id, user_id, None, event_id);
*drawn = drawn_status;
usernames_arr.push(username);
}
}
self.human_readable_usernames = human_readable_list(usernames_arr);
}
}
impl AvatarRowRef {
/// Handles hover in action
pub fn hover_in(&self, actions: &Actions) -> Option<(Rect, String)> {
if let Some(item) = actions.find_widget_action(self.widget_uid()) {
match item.cast() {
RoomScreenTooltipActions::HoverIn(tooltip_pos, tooltip_text) => Some((tooltip_pos, tooltip_text)),
_ => None,
}
} else {
None
}
}
/// Handles hover out action
pub fn hover_out(&self, actions: &Actions) -> bool {
if let Some(item) = actions.find_widget_action(self.widget_uid()) {
matches!(item.cast(), RoomScreenTooltipActions::HoverOut)
} else {
false
}
}
/// Get the total number of people seen
pub fn total_num_seen(&self) -> usize {
if let Some(ref mut inner) = self.borrow() {
inner.total_num_seen
} else {
0
}
}
/// Set a row of Avatars based on receipt's index map
pub fn set_avatar_row(&mut self, cx: &mut Cx, room_id: &RoomId, event_id: Option<&EventId>, receipts_map: &IndexMap<OwnedUserId, Receipt>) {
if let Some(ref mut inner) = self.borrow_mut() {
inner.set_avatar_row(cx, room_id, event_id, receipts_map);
}
}
}
Loading
Loading