Commit c4bcea66 authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

app.rs: Add "New messages" divider

Closes https://gitlab.gnome.org/danigm/fractal/issues/133
parent d7981f3a
......@@ -72,6 +72,12 @@ struct TmpMsg {
pub widget: gtk::Widget,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum LastViewed {
Inline,
Last,
No,
}
pub struct AppOp {
pub gtk_builder: gtk::Builder,
......@@ -1316,10 +1322,21 @@ impl AppOp {
}
}
pub fn is_last_viewed(&self, msg: &Message) -> bool {
pub fn is_last_viewed(&self, msg: &Message) -> LastViewed {
match self.last_viewed_messages.get(&msg.room) {
Some(lvm) if lvm == msg => true,
_ => false,
Some(lvm) if lvm == msg => {
match self.rooms.get(&msg.room) {
Some(r) => {
let lastm = r.messages.last();
match lastm {
Some(m) if m == msg => LastViewed::Last,
_ => LastViewed::Inline,
}
},
_ => LastViewed::Inline,
}
},
_ => LastViewed::No,
}
}
......@@ -1328,7 +1345,7 @@ impl AppOp {
msgpos: MsgPos,
prev: Option<Message>,
force_full: bool,
last: bool) {
last: LastViewed) {
let msg_entry: gtk::Entry = self.gtk_builder
.get_object("msg_entry")
.expect("Couldn't find msg_entry in ui file.");
......@@ -1371,12 +1388,6 @@ impl AppOp {
}
}
if last {
if let Some(style) = m.get_style_context() {
style.add_class("msg-last-viewed-widget");
}
}
match msgpos {
MsgPos::Bottom => messages.add(&m),
MsgPos::Top => messages.insert(&m, 1),
......@@ -1384,6 +1395,10 @@ impl AppOp {
if !is_small_widget {
m.get_parent().unwrap().set_margin_top(12);
}
if last == LastViewed::Inline {
let divider: gtk::Box = widgets::divider::new("New Messages");
messages.add(&divider);
}
self.shown_messages += 1;
}
self.remove_tmp_room_message(&msg);
......@@ -3469,7 +3484,7 @@ fn backend_loop(rx: Receiver<BKResponse>) {
#[derive(Debug)]
pub enum InternalCommand {
AddRoomMessage(Message, MsgPos, Option<Message>, bool, bool),
AddRoomMessage(Message, MsgPos, Option<Message>, bool, LastViewed),
SetPanel(RoomPanel),
NotifyClicked(Message),
SelectRoom(Room),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment