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 25 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
2 changes: 1 addition & 1 deletion src/avatar_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ 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 @@ -5,6 +5,7 @@ pub mod main_mobile_ui;
pub mod main_desktop_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 @@ -16,6 +17,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
170 changes: 170 additions & 0 deletions src/home/room_read_receipt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
use crate::shared::avatar::{AvatarRef, AvatarWidgetRefExt};
use makepad_widgets::*;
use matrix_sdk::ruma::{events::receipt::Receipt, EventId, OwnedUserId, RoomId};
use std::cmp;
use crate::shared::avatar::set_avatar_and_get_username;
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: Fit,
height: Fit,
plus: <Label> {
draw_text: {
color: #x0,
text_style: <TITLE_TEXT>{ font_size: 11}
}
text: ""
}
}
}

#[derive(Live, Widget, LiveHook)]
pub struct AvatarRow {
#[redraw]
#[rust]
area: Area,
#[redraw]
#[live]
draw_text: DrawText,
#[deref]
pub deref: View,
#[walk]
walk: Walk,
#[live]
button: Option<LivePtr>,
#[live(false)]
hover_actions_enabled: bool,
#[live]
plus: Option<LivePtr>,
#[rust]
buttons: Vec<AvatarRef>,
#[rust]
label: Option<LabelRef>,
#[rust]
total_num_seen: usize,

}

#[derive(Clone, Debug, DefaultNone)]
pub enum AvatarRowAction {
HoverIn(Rect),
HoverOut,
None,
}

impl Widget for AvatarRow {
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
let uid = self.widget_uid();
for button in self.buttons.iter_mut() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this a very expensive way to check for a hit? Surely we should just be checking the full area of the AvatarRow as a single "whole" entity, instead of checking each button.

Unless, that is, you're going to allow each mini avatar in the AvatarRow to be individually-clickable ... which is fine, but I don't think you're doing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

match button.hit(cx, event, self.area) {
Some(Hit::FingerHoverIn(finger_event)) => {
let rect = Rect {
pos: finger_event.abs,
size: DVec2::new(),
};
cx.widget_action(uid, &scope.path, AvatarRowAction::HoverIn(rect));
}
Some(Hit::FingerHoverOut(_)) => {
cx.widget_action(uid, &scope.path, AvatarRowAction::HoverOut);
}
_ => {}
}
}
}

fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
for v in self.buttons.iter_mut() {
let _ = v.draw(cx, scope);
}
if self.total_num_seen > 5 {
alanpoon marked this conversation as resolved.
Show resolved Hide resolved
if let Some(label) = &mut self.label {
label.set_text(&format!(" + {:?}", self.total_num_seen - 5));
let _ = label.draw(cx, scope);
}
}
DrawStep::done()
}

fn widget_to_data(
&self,
cx: &mut Cx,
actions: &Actions,
nodes: &mut LiveNodeVec,
path: &[LiveId],
) -> bool {
false
}

fn data_to_widget(&mut self, cx: &mut Cx, nodes: &[LiveNode], path: &[LiveId]) {}
}
impl AvatarRow {
fn set_range(&mut self, cx: &mut Cx, total_num_seen: usize) {
alanpoon marked this conversation as resolved.
Show resolved Hide resolved
if total_num_seen != self.buttons.len() {
self.buttons.clear();
for _ in 0..cmp::min(5, total_num_seen) {
self.buttons.push(WidgetRef::new_from_ptr(cx, self.button).as_avatar());
}
}
self.total_num_seen = total_num_seen;
self.label = Some(WidgetRef::new_from_ptr(cx, self.plus).as_label());
}

fn iter(&self) -> std::slice::Iter<'_, AvatarRef> {
self.buttons.iter()
}
}
impl AvatarRowRef {
/// Handles hover in action
pub fn hover_in(&self, actions: &Actions) -> Option<Rect> {
if let Some(item) = actions.find_widget_action(self.widget_uid()) {
match item.cast() {
AvatarRowAction::HoverIn(rect) => Some(rect),
_ => 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()) {
match item.cast() {
AvatarRowAction::HoverOut => true,
_ => false,
}
} 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 iterator
pub fn set_avatar_row<'a, T>(&mut self, cx: &mut Cx, room_id: &RoomId, event_id: Option<&EventId>, receipts_len: usize, receipts_iter: T)
where T:Iterator<Item = (&'a OwnedUserId, &'a Receipt)> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function can be simplified in two ways.

  1. There's no need for generics here. Just directly accept the IndexMap of read receipts, which will also allow you do to number 2 below.
  2. Remove the receipts_len parameter, since that is completely unnecessary and error-prone, as it's separate from (and redundant with) the IndexMap of read receipts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

if let Some(ref mut inner) = self.borrow_mut() {
inner.set_range(cx, receipts_len);
alanpoon marked this conversation as resolved.
Show resolved Hide resolved
for (avatar_ref, (user_id, _)) in inner.iter().zip(receipts_iter) {
set_avatar_and_get_username(cx, avatar_ref.clone(), room_id, &user_id, None, event_id);
}
}
}
}
Loading