2019-07-09 21:24:00 +02:00
|
|
|
var render_archive_message_group = require('../templates/archive_message_group.hbs');
|
|
|
|
|
2018-02-03 12:57:38 +01:00
|
|
|
var archive = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
function should_separate_into_groups(current_msg_time, next_msg_time) {
|
|
|
|
var current_time = new XDate(current_msg_time * 1000);
|
|
|
|
var next_time = new XDate(next_msg_time * 1000);
|
|
|
|
return current_time.toDateString() !== next_time.toDateString();
|
|
|
|
}
|
|
|
|
|
|
|
|
function all_message_timestamps_to_human_readable() {
|
|
|
|
$('.message_time').each(function () {
|
|
|
|
var time = new XDate(parseInt($(this).text(), 10) * 1000);
|
|
|
|
$(this).text(time.toString('h:mm TT'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.initialize = function () {
|
|
|
|
var all_message_groups = [];
|
|
|
|
var current_message_group = {};
|
|
|
|
var today = new XDate();
|
|
|
|
var recipient_and_topic = $('#display_recipient').html();
|
|
|
|
var stream_name = recipient_and_topic.split('-')[0];
|
|
|
|
var topic = recipient_and_topic.split('-')[1];
|
2018-11-28 23:12:40 +01:00
|
|
|
var recipient_color = color_data.pick_color();
|
2018-02-03 12:57:38 +01:00
|
|
|
current_message_group.message_containers = [];
|
2019-02-08 20:24:01 +01:00
|
|
|
current_message_group.show_group_date_divider = false;
|
2018-02-03 12:57:38 +01:00
|
|
|
current_message_group.display_recipient = stream_name;
|
2018-11-15 17:13:49 +01:00
|
|
|
current_message_group.topic = topic;
|
2018-02-03 12:57:38 +01:00
|
|
|
current_message_group.background_color = recipient_color;
|
|
|
|
|
|
|
|
function separate_into_groups(current_message_row, cur_msg_time, next_msg_time) {
|
|
|
|
var time = new XDate(next_msg_time * 1000);
|
|
|
|
var prev_time = new XDate(cur_msg_time * 1000);
|
|
|
|
current_message_group.message_containers.push(current_message_row[0].outerHTML);
|
|
|
|
var date_element = timerender.render_date(prev_time, undefined, today)[0];
|
|
|
|
current_message_group.date = date_element.outerHTML;
|
|
|
|
all_message_groups.push(current_message_group);
|
|
|
|
current_message_group = {};
|
|
|
|
current_message_group.message_containers = [];
|
2019-02-08 20:11:21 +01:00
|
|
|
current_message_group.group_date_divider_html =
|
2018-06-06 18:19:09 +02:00
|
|
|
timerender.render_date(time, prev_time, today)[0].outerHTML;
|
2019-02-08 20:24:01 +01:00
|
|
|
current_message_group.show_group_date_divider = true;
|
2018-02-03 12:57:38 +01:00
|
|
|
current_message_group.display_recipient = stream_name;
|
2018-11-15 17:13:49 +01:00
|
|
|
current_message_group.topic = topic;
|
2018-02-03 12:57:38 +01:00
|
|
|
current_message_group.background_color = recipient_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.message_row').each(function () {
|
|
|
|
var current_message_row = $(this);
|
|
|
|
var cur_msg_time = parseInt(current_message_row.find('.message_time').first().html(), 10);
|
|
|
|
var next_msg_time = parseInt(current_message_row.next().find('.message_time').first().html(), 10);
|
|
|
|
|
|
|
|
if (current_message_row.next().length === 0) {
|
|
|
|
separate_into_groups(current_message_row, cur_msg_time);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (should_separate_into_groups(cur_msg_time, next_msg_time)) {
|
|
|
|
separate_into_groups(current_message_row, cur_msg_time, next_msg_time);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
current_message_group.message_containers.push(current_message_row[0].outerHTML);
|
|
|
|
var time = new XDate(cur_msg_time * 1000);
|
|
|
|
var date_element = timerender.render_date(time, undefined, today)[0];
|
|
|
|
current_message_group.date = date_element.outerHTML;
|
|
|
|
});
|
|
|
|
|
|
|
|
var context = {
|
|
|
|
message_groups: all_message_groups,
|
|
|
|
};
|
2019-07-09 21:24:00 +02:00
|
|
|
var message_groups_html = render_archive_message_group(context);
|
2018-02-03 12:57:38 +01:00
|
|
|
$('.message_row').each(function () {
|
|
|
|
$(this).detach();
|
|
|
|
});
|
|
|
|
$('.message_table').prepend(message_groups_html);
|
|
|
|
$('.messagebox').css('box-shadow', 'inset 2px 0px 0px 0px ' + recipient_color);
|
|
|
|
$('#display_recipient').remove();
|
|
|
|
|
|
|
|
// Fixing include_sender after rendering groups.
|
|
|
|
var prev_sender;
|
|
|
|
$('.recipient_row').each(function () {
|
|
|
|
if (prev_sender !== undefined) {
|
|
|
|
var first_group_msg = $(this).find('.message_row').first();
|
|
|
|
var message_sender = first_group_msg.find('.message_sender');
|
2018-06-04 21:09:11 +02:00
|
|
|
if (!message_sender.find('.inline_profile_picture').length) {
|
2018-02-03 12:57:38 +01:00
|
|
|
message_sender.replaceWith(prev_sender.clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var all_senders = $(this).find('.message_sender').has('.inline_profile_picture');
|
|
|
|
prev_sender = all_senders.last();
|
|
|
|
});
|
2018-02-05 17:15:03 +01:00
|
|
|
|
|
|
|
$('.app').scrollTop($('.app').height());
|
2018-02-03 12:57:38 +01:00
|
|
|
all_message_timestamps_to_human_readable();
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
2018-02-05 17:15:03 +01:00
|
|
|
var current_msg_list = {
|
|
|
|
selected_row: function () {
|
|
|
|
return $('.message_row').last();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
var rows = {
|
|
|
|
get_message_recipient_row: function (message_row) {
|
|
|
|
return $(message_row).parent('.recipient_row');
|
|
|
|
},
|
|
|
|
first_message_in_group: function (message_group) {
|
2019-06-06 05:50:36 +02:00
|
|
|
return $('div.message_row', message_group).first();
|
2018-02-05 17:15:03 +01:00
|
|
|
},
|
|
|
|
id: function (message_row) {
|
|
|
|
return parseFloat(message_row.attr('zid'));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-02-03 12:57:38 +01:00
|
|
|
if (typeof module !== 'undefined') {
|
2018-02-05 17:15:03 +01:00
|
|
|
module.exports.current_msg_list = current_msg_list;
|
|
|
|
module.exports.rows = rows;
|
2018-02-03 12:57:38 +01:00
|
|
|
module.exports = archive;
|
|
|
|
}
|
|
|
|
|
2018-02-05 17:15:03 +01:00
|
|
|
var scroll_timer;
|
|
|
|
function scroll_finish() {
|
|
|
|
clearTimeout(scroll_timer);
|
|
|
|
scroll_timer = setTimeout(floating_recipient_bar.update, 100);
|
|
|
|
}
|
|
|
|
|
2018-02-03 12:57:38 +01:00
|
|
|
$(function () {
|
2018-02-05 17:15:03 +01:00
|
|
|
$.fn.safeOuterHeight = function () {
|
|
|
|
return $(this).outerHeight.apply(this, arguments) || 0;
|
|
|
|
};
|
|
|
|
$.fn.safeOuterWidth = function () {
|
|
|
|
return $(this).outerWidth.apply(this, arguments) || 0;
|
|
|
|
};
|
2018-05-16 20:42:42 +02:00
|
|
|
$('.app').scroll(_.throttle(function () {
|
2018-02-05 17:15:03 +01:00
|
|
|
scroll_finish();
|
2018-05-16 20:42:42 +02:00
|
|
|
}, 50));
|
2018-02-03 12:57:38 +01:00
|
|
|
archive.initialize();
|
|
|
|
});
|