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

Add unread highlighting mentions in the RoomPreview when a user menti… #349

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
17 changes: 13 additions & 4 deletions src/home/room_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
};

use super::rooms_list::{RoomPreviewAvatar, RoomsListEntry};

live_design! {
use link::theme::*;
use link::shaders::*;
Expand All @@ -19,6 +18,8 @@ live_design! {
use crate::shared::helpers::*;
use crate::shared::avatar::Avatar;
use crate::shared::html_or_plaintext::HtmlOrPlaintext;
pub UNREAD_HIGHLIGHT_COLOR = #FF0000;
pub UNREAD_DEFAULT_COLOR = #d8d8d8;

RoomName = <Label> {
width: Fill, height: Fit
Expand Down Expand Up @@ -105,12 +106,14 @@ live_design! {
show_bg: true
align: { x: 0.5, y: 0.5 }
draw_bg: {
instance background_color: (COLOR_TEXT_IDLE)
instance highlight: 0.0,
instance highlight_color: (UNREAD_HIGHLIGHT_COLOR),
instance default_color: (UNREAD_DEFAULT_COLOR),
fn pixel(self) -> vec4 {
let sdf = Sdf2d::viewport(self.pos * self.rect_size);
let c = self.rect_size * 0.5;
sdf.circle(c.x, c.x, c.x)
sdf.fill_keep(self.background_color);
sdf.fill_keep(mix(self.default_color, self.highlight_color, self.highlight));
return sdf.result
}
}
Expand Down Expand Up @@ -278,9 +281,14 @@ impl Widget for RoomPreviewContent {
}
}

let unread_badge = self.view(id!(unread_badge));
let unread_badge = self.view(id!(unread_badge));

if room_info.num_unread_messages > 0 {
if room_info.num_unread_metions > 0{
unread_badge.apply_over(cx, live!{draw_bg: {highlight: 1.0}});
}else{
unread_badge.apply_over(cx, live!{draw_bg: {highlight: 0.0}});
}
if room_info.num_unread_messages > 99 {
kevinaboos marked this conversation as resolved.
Show resolved Hide resolved
// We don't need to show unread messages over 99, so we show 99+ instead.
unread_badge.label(id!(unread_message_count)).set_text(cx, "99+");
Expand All @@ -290,6 +298,7 @@ impl Widget for RoomPreviewContent {
.set_text(cx, &room_info.num_unread_messages.to_string());
}
unread_badge.set_visible(cx, true);

} else {
unread_badge.set_visible(cx, false);
}
Expand Down
13 changes: 8 additions & 5 deletions src/home/rooms_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ pub enum RoomsListUpdate {
/// Update the number of unread messages for the given room.
UpdateNumUnreadMessages {
room_id: OwnedRoomId,
count: UnreadMessageCount
count: UnreadMessageCount,
unread_mentions: u64,
},
/// Update the displayable name for the given room.
UpdateRoomName {
Expand Down Expand Up @@ -149,6 +150,8 @@ pub struct RoomsListEntry {
pub room_name: Option<String>,
/// The number of unread messages in this room.
pub num_unread_messages: u64,
/// The number of unread mentions in this room.
pub num_unread_metions: u64,
kevinaboos marked this conversation as resolved.
Show resolved Hide resolved
/// The canonical alias for this room, if any.
pub canonical_alias: Option<OwnedRoomAliasId>,
/// The alternative aliases for this room, if any.
Expand Down Expand Up @@ -484,11 +487,11 @@ impl Widget for RoomsList {
error!("Error: couldn't find room {room_id} to update latest event");
}
}
RoomsListUpdate::UpdateNumUnreadMessages { room_id, count } => {
RoomsListUpdate::UpdateNumUnreadMessages { room_id, count , unread_mentions} => {
if let Some(room) = self.all_rooms.get_mut(&room_id) {
room.num_unread_messages = match count {
UnreadMessageCount::Unknown => 0,
UnreadMessageCount::Known(count) => count,
(room.num_unread_messages, room.num_unread_metions) = match count {
kevinaboos marked this conversation as resolved.
Show resolved Hide resolved
UnreadMessageCount::Unknown => (0, 0),
UnreadMessageCount::Known(count) => (count, unread_mentions),
};
} else {
error!("Error: couldn't find room {} to update unread messages count", room_id);
Expand Down
11 changes: 8 additions & 3 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ async fn async_worker(
}
enqueue_rooms_list_update(RoomsListUpdate::UpdateNumUnreadMessages {
room_id: room_id.clone(),
count: UnreadMessageCount::Known(timeline.room().num_unread_messages())
count: UnreadMessageCount::Known(timeline.room().num_unread_messages()),
unread_mentions:timeline.room().num_unread_mentions(),
});
});
}
Expand Down Expand Up @@ -871,7 +872,8 @@ async fn async_worker(
// Also update the number of unread messages in the room.
enqueue_rooms_list_update(RoomsListUpdate::UpdateNumUnreadMessages {
room_id: room_id.clone(),
count: UnreadMessageCount::Known(timeline.room().num_unread_messages())
count: UnreadMessageCount::Known(timeline.room().num_unread_messages()),
unread_mentions: timeline.room().num_unread_mentions()
});
});
},
Expand All @@ -895,7 +897,8 @@ async fn async_worker(
// Also update the number of unread messages in the room.
enqueue_rooms_list_update(RoomsListUpdate::UpdateNumUnreadMessages {
room_id: room_id.clone(),
count: UnreadMessageCount::Known(timeline.room().num_unread_messages())
count: UnreadMessageCount::Known(timeline.room().num_unread_messages()),
unread_mentions: timeline.room().num_unread_mentions()
});
});
},
Expand Down Expand Up @@ -1485,6 +1488,7 @@ async fn update_room(
enqueue_rooms_list_update(RoomsListUpdate::UpdateNumUnreadMessages {
room_id: new_room_id.clone(),
count: UnreadMessageCount::Known(new_room.num_unread_messages()),
unread_mentions: new_room.num_unread_mentions()
});

Ok(())
Expand Down Expand Up @@ -1578,6 +1582,7 @@ async fn add_new_room(room: &room_list_service::Room, room_list_service: &RoomLi
latest,
tags: room.tags().await.ok().flatten(),
num_unread_messages: room.num_unread_messages(),
num_unread_metions: room.num_unread_mentions(),
// start with a basic text avatar; the avatar image will be fetched asynchronously below.
avatar: avatar_from_room_name(room_name.as_deref().unwrap_or_default()),
room_name,
Expand Down