-
Notifications
You must be signed in to change notification settings - Fork 19
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
alanpoon
wants to merge
41
commits into
project-robius:main
Choose a base branch
from
alanpoon:read_receipt_display
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+508
−136
Open
Display read receipts next to each message as a row of Avatars for users who have seen that message #162
Changes from 25 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
5c54512
read_receipt_display
alanpoon 4a78a93
Merge branch 'main' into read_receipt_display
alanpoon 4ad555a
merge main
alanpoon 22638d9
touchup whitespace
alanpoon 0ccb874
Merge branch 'main' into read_receipt_display
alanpoon f4de445
added avatar img in read_receipts
alanpoon e4e9b1d
fixed tooltip position
alanpoon 961a00f
code formating
alanpoon 2ff7f7d
Merge branch 'main' into read_receipt_display
alanpoon d4fd338
Merge branch 'main' into read_receipt_display
alanpoon c15e8da
fix merge issue
alanpoon 3571b1e
change sender_id to generic avatar_id
alanpoon 0c6dd14
Merge branch 'main' into read_receipt_display
alanpoon 24daf6e
fix conflicts
alanpoon e5f6943
Merge branch 'main' into read_receipt_display
alanpoon 687bb70
Update src/profile/user_profile.rs
alanpoon 17d1bec
remove unneccessary portal_list
alanpoon fa5f166
Change tooltip
alanpoon 0e6ae80
Merge branch 'main' into read_receipt_display
alanpoon a36049f
changed to avatarref
alanpoon b3d75b9
format fix
alanpoon 7935ffb
Merge branch 'read_receipt_display' of https://github.com/alanpoon/ro…
alanpoon 9a7af7a
moved set_avatar_and_get_username into avatar file
alanpoon 7fa6f39
added plus label at the end of avatarrow
alanpoon b81e51a
clean up
alanpoon eeb3384
Merge branch 'main' of https://github.com/project-robius/robrix into …
alanpoon 29c010b
added import
alanpoon 49798ca
Merge branch 'main' of https://github.com/project-robius/robrix into …
alanpoon 3005aea
code cleanup and resolve conflict
alanpoon 38ae816
shorten tooltip's width
alanpoon e7ca500
fix formating
alanpoon b1e6d14
removed generic in set_avatar_row
alanpoon edbcbf3
Merge branch 'read_receipt_display' of https://github.com/alanpoon/ro…
alanpoon 567d2f7
fixed clippy
alanpoon d0a3cfb
fix doc
alanpoon 07b5fc7
Create a generic RoomScreenTooltipActions
alanpoon 08d2391
avatarrow cleanup
alanpoon efa3eed
z
alanpoon ad8d053
minor cleanup
alanpoon 22aa294
Added human_readable name in read_receipt tooltip
alanpoon 6fe7749
Adding avatarRef and its drawn status
alanpoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
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)> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function can be simplified in two ways.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed