2013-08-11 21:21:47 +02:00
|
|
|
var compose_fade = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var focused_recipient;
|
2013-08-12 17:40:55 +02:00
|
|
|
var normal_display = false;
|
2013-08-11 21:21:47 +02:00
|
|
|
|
2013-08-11 23:54:50 +02:00
|
|
|
exports.set_focused_recipient = function (msg_type) {
|
2013-08-12 17:40:55 +02:00
|
|
|
if (msg_type === undefined) {
|
|
|
|
focused_recipient = undefined;
|
|
|
|
}
|
|
|
|
|
2013-08-11 23:54:50 +02:00
|
|
|
// Construct focused_recipient as a mocked up element which has all the
|
|
|
|
// fields of a message used by util.same_recipient()
|
|
|
|
focused_recipient = {
|
|
|
|
type: msg_type
|
|
|
|
};
|
|
|
|
|
|
|
|
if (focused_recipient.type === "stream") {
|
|
|
|
focused_recipient.stream = $('#stream').val();
|
|
|
|
focused_recipient.subject = $('#subject').val();
|
|
|
|
} else {
|
|
|
|
// Normalize the recipient list so it matches the one used when
|
|
|
|
// adding the message (see add_message_metadata(), zulip.js).
|
|
|
|
focused_recipient.reply_to = util.normalize_recipients(
|
|
|
|
$('#private_message_recipient').val());
|
|
|
|
}
|
2013-08-11 21:21:47 +02:00
|
|
|
};
|
|
|
|
|
2013-08-12 17:40:55 +02:00
|
|
|
function _display_messages_normally() {
|
2013-08-11 21:21:47 +02:00
|
|
|
rows.get_table(current_msg_list.table_name).find(".recipient_row, .message_row")
|
2013-08-12 17:40:55 +02:00
|
|
|
.removeClass("faded").removeClass("unfaded");
|
2013-08-11 21:34:05 +02:00
|
|
|
|
2013-08-12 17:40:55 +02:00
|
|
|
normal_display = true;
|
2013-08-11 21:21:47 +02:00
|
|
|
ui.update_floating_recipient_bar();
|
2013-08-12 17:40:55 +02:00
|
|
|
}
|
2013-08-11 21:21:47 +02:00
|
|
|
|
2013-08-12 17:40:55 +02:00
|
|
|
function _fade_messages() {
|
2013-08-11 21:21:47 +02:00
|
|
|
var i;
|
|
|
|
var all_elts = rows.get_table(current_msg_list.table_name).find(".recipient_row, .message_row");
|
|
|
|
var should_fade_message = false;
|
2013-08-12 17:40:55 +02:00
|
|
|
|
|
|
|
normal_display = false;
|
|
|
|
|
2013-08-11 21:21:47 +02:00
|
|
|
// Note: The below algorithm relies on the fact that all_elts is
|
|
|
|
// sorted as it would be displayed in the message view
|
|
|
|
for (i = 0; i < all_elts.length; i++) {
|
|
|
|
var elt = $(all_elts[i]);
|
|
|
|
if (elt.hasClass("recipient_row")) {
|
|
|
|
should_fade_message = !util.same_recipient(focused_recipient, current_msg_list.get(rows.id(elt)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (should_fade_message) {
|
2013-08-12 17:40:55 +02:00
|
|
|
elt.removeClass("unfaded").addClass("faded");
|
2013-08-11 21:21:47 +02:00
|
|
|
} else {
|
2013-08-12 17:40:55 +02:00
|
|
|
elt.removeClass("faded").addClass("unfaded");
|
2013-08-11 21:21:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.update_floating_recipient_bar();
|
|
|
|
}
|
|
|
|
|
2013-08-12 17:40:55 +02:00
|
|
|
function _want_normal_display() {
|
|
|
|
// If we're not composing show a normal display.
|
|
|
|
if (focused_recipient === undefined) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the user really hasn't specified anything let, then we want a normal display
|
|
|
|
if ((focused_recipient.type === "stream" && focused_recipient.subject === "") ||
|
|
|
|
(focused_recipient.type === "private" && focused_recipient.reply_to === "")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _update_faded_messages() {
|
|
|
|
// See also update_faded_messages(), which just wraps this with a debounce.
|
|
|
|
if (_want_normal_display()) {
|
|
|
|
if (!normal_display) {
|
|
|
|
_display_messages_normally();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_fade_messages();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-11 21:21:47 +02:00
|
|
|
// See trac #1633. For fast typists, calls to _update_faded_messages can
|
|
|
|
// cause typing sluggishness.
|
2013-08-13 00:02:56 +02:00
|
|
|
exports.update_faded_messages = _.debounce(_update_faded_messages, 50, true);
|
2013-08-11 21:21:47 +02:00
|
|
|
|
2013-08-12 17:40:55 +02:00
|
|
|
exports.start_compose = function (msg_type) {
|
2013-08-12 00:08:36 +02:00
|
|
|
exports.set_focused_recipient(msg_type);
|
|
|
|
_update_faded_messages();
|
|
|
|
};
|
|
|
|
|
2013-08-12 17:40:55 +02:00
|
|
|
exports.clear_compose = function () {
|
|
|
|
focused_recipient = undefined;
|
|
|
|
_display_messages_normally();
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.update_message_list = function () {
|
|
|
|
if (_want_normal_display()) {
|
|
|
|
_display_messages_normally();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_fade_messages();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-11 21:21:47 +02:00
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|