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 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 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
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: 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
147 changes: 147 additions & 0 deletions src/home/room_read_receipt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
use crate::shared::avatar::Avatar;
use makepad_widgets::*;
use std::cmp;
live_design! {
import makepad_draw::shader::std::*;
import crate::shared::avatar::*;

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
}
}

#[derive(Live, Widget)]
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,
#[rust]
buttons: Vec<Avatar>,
#[rust]
count: usize,
alanpoon marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Clone, Debug, DefaultNone)]
pub enum AvatarRowAction {
HoverIn(Rect),
HoverOut,
None,
}
impl LiveHook for AvatarRow {
fn after_apply(&mut self, cx: &mut Cx, apply: &mut Apply, index: usize, nodes: &[LiveNode]) {
for button in self.buttons.iter_mut() {
if let Some(index) = nodes.child_by_name(index, live_id!(button).as_field()) {
button.apply(cx, apply, index, nodes);
}
}
self.area.redraw(cx);
}
}
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.

match button.hit(cx, event, self.area) {
Hit::FingerHoverIn(finger_event) => {
let rect = Rect {
pos: finger_event.abs,
size: DVec2::new(),
};
cx.widget_action(uid, &scope.path, AvatarRowAction::HoverIn(rect));
}
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);
}
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 {
pub fn set_range(&mut self, cx: &mut Cx, count: usize) {
if count != self.buttons.len() {
self.buttons.clear();
for _ in 0..cmp::min(5, count) {
self.buttons.push(Avatar::new_from_ptr(cx, self.button));
}
}
self.count = count;
}

pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, Avatar> {
alanpoon marked this conversation as resolved.
Show resolved Hide resolved
self.buttons.iter_mut()
}
}
impl AvatarRowRef {
pub fn set_range(&self, cx: &mut Cx, count: usize) {
if let Some(ref mut inner) = self.borrow_mut() {
inner.set_range(cx, count);
}
}
pub fn len(&self) -> usize {
if let Some(ref mut inner) = self.borrow_mut() {
inner.count
} else {
0
}
}
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
}
}
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
}
}
}
Loading