Skip to content

Commit

Permalink
message_list: Track date better in floating recipient bar.
Browse files Browse the repository at this point in the history
We now use the date from the first message
that's at least partially visible on the screen.
  • Loading branch information
Steve Howell authored and timabbott committed Jan 4, 2019
1 parent cdcfbcb commit 37f609a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions static/js/floating_recipient_bar.js
Expand Up @@ -5,6 +5,48 @@ var exports = {};

var is_floating_recipient_bar_showing = false;

exports.first_visible_message = function (bar) {
var messages = bar.children('.message_row');
var frb_bottom = exports.frb_bottom();

for (var i = 0; i < messages.length; i += 1) {
var message = $(messages[i]);
var message_bottom = message.offset().top + message.safeOuterHeight();

if (message_bottom > frb_bottom) {
return message;
}

message = message.next('.message_row');
}
};

exports.copy_message_date = function (source_recipient_bar) {
var message_row = exports.first_visible_message(source_recipient_bar);

if (!message_row || !message_row.length) {
return;
}

var msg_id = rows.id(message_row);

if (msg_id === undefined) {
return;
}

var message = message_store.get(msg_id);

if (!message) {
return;
}

var time = new XDate(message.timestamp * 1000);
var today = new XDate();
var rendered_date = timerender.render_date(time, undefined, today)[0].outerHTML;

$('#floating_recipient_bar').find('.recipient_row_date').html(rendered_date);
};

exports.frb_bottom = function () {
var bar = $("#floating_recipient_bar");
var bar_top = bar.offset().top;
Expand Down Expand Up @@ -71,6 +113,8 @@ function replace_floating_recipient_bar(source_recipient_bar) {
new_label.toggleClass('message-fade', source_recipient_bar.hasClass('message-fade'));
old_source = source_recipient_bar;
}

exports.copy_message_date(source_recipient_bar);
show_floating_recipient_bar();
}

Expand Down

0 comments on commit 37f609a

Please sign in to comment.