2019-07-16 20:19:11 +02:00
|
|
|
var autosize = require('autosize');
|
|
|
|
|
2016-04-20 22:37:26 +02:00
|
|
|
var message_list = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2016-04-25 23:45:25 +02:00
|
|
|
exports.narrowed = undefined;
|
2018-08-04 08:30:52 +02:00
|
|
|
exports.set_narrowed = function (value) {
|
|
|
|
exports.narrowed = value;
|
|
|
|
};
|
2016-04-25 23:45:25 +02:00
|
|
|
|
2018-05-14 15:46:25 +02:00
|
|
|
exports.MessageList = function (opts) {
|
2018-05-14 17:47:14 +02:00
|
|
|
if (opts.data) {
|
|
|
|
this.muting_enabled = opts.data.muting_enabled;
|
|
|
|
this.data = opts.data;
|
|
|
|
} else {
|
|
|
|
var filter = opts.filter;
|
|
|
|
|
|
|
|
this.muting_enabled = opts.muting_enabled;
|
|
|
|
this.data = new MessageListData({
|
|
|
|
muting_enabled: this.muting_enabled,
|
|
|
|
filter: filter,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-14 15:46:25 +02:00
|
|
|
_.extend(opts, {
|
2013-07-25 22:08:16 +02:00
|
|
|
collapse_messages: true,
|
2018-05-14 15:46:25 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
var collapse_messages = opts.collapse_messages;
|
|
|
|
var table_name = opts.table_name;
|
|
|
|
this.view = new MessageListView(this, table_name, collapse_messages);
|
2018-05-04 12:44:28 +02:00
|
|
|
this.fetch_status = FetchStatus();
|
2012-12-05 23:54:49 +01:00
|
|
|
this.table_name = table_name;
|
2013-11-06 17:35:24 +01:00
|
|
|
this.narrowed = this.table_name === "zfilt";
|
2013-08-14 23:48:28 +02:00
|
|
|
this.num_appends = 0;
|
2013-12-19 17:03:08 +01:00
|
|
|
|
2012-12-05 23:54:49 +01:00
|
|
|
return this;
|
2016-04-20 22:37:26 +02:00
|
|
|
};
|
2013-02-26 23:30:13 +01:00
|
|
|
|
2016-04-20 22:37:26 +02:00
|
|
|
exports.MessageList.prototype = {
|
2014-01-22 22:20:36 +01:00
|
|
|
add_messages: function MessageList_add_messages(messages, opts) {
|
2013-09-22 16:41:33 +02:00
|
|
|
var self = this;
|
2018-05-14 12:39:34 +02:00
|
|
|
|
|
|
|
// This adds all messages to our data, but only returns
|
|
|
|
// the currently viewable ones.
|
|
|
|
var info = this.data.add_messages(messages);
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
var top_messages = info.top_messages;
|
|
|
|
var bottom_messages = info.bottom_messages;
|
|
|
|
var interior_messages = info.interior_messages;
|
2013-09-22 16:41:33 +02:00
|
|
|
|
message scrolling: Fix "Scroll down to view" warning.
We recently added a feature to warn users that they
may need to scroll down to view messages that they
just sent, but it was broken due to various complexities
in the rendering code path.
Now we compute it a bit more rigorously.
It requires us to pass some info about rendering up
and down the stack, which is why it's kind of a long
commit, but the bulk of the logic is in these JS files:
* message_list_view.js
* notifications.js
I choose to pass structs around instead of booleans,
because I anticipate we may eventually add more metadata
about rendering to it, plus bools are just kinda brittle.
(The exceptions are that `_maybe_autoscroll`, which
is at the bottom of the stack, just passes back a simple
boolean, and `notify_local_mixes`, also at the bottom
of the stack, just accepts a simple boolean.)
This errs on the side of warning the user, even if the
new message is partially visible.
Fixes #11138
2019-01-07 21:00:03 +01:00
|
|
|
// Currently we only need data back from rendering to
|
|
|
|
// tell us whether users needs to scroll, which only
|
|
|
|
// applies for `append_to_view`, but this may change over
|
|
|
|
// time.
|
|
|
|
var render_info;
|
|
|
|
|
2013-09-22 16:41:33 +02:00
|
|
|
if (interior_messages.length > 0) {
|
2019-09-18 20:38:07 +02:00
|
|
|
self.view.rerender_preserving_scrolltop(true);
|
2013-09-22 16:41:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (top_messages.length > 0) {
|
2018-05-13 22:46:25 +02:00
|
|
|
self.view.prepend(top_messages);
|
2013-09-22 16:41:33 +02:00
|
|
|
}
|
2018-05-04 12:44:28 +02:00
|
|
|
|
2013-09-22 16:41:33 +02:00
|
|
|
if (bottom_messages.length > 0) {
|
message scrolling: Fix "Scroll down to view" warning.
We recently added a feature to warn users that they
may need to scroll down to view messages that they
just sent, but it was broken due to various complexities
in the rendering code path.
Now we compute it a bit more rigorously.
It requires us to pass some info about rendering up
and down the stack, which is why it's kind of a long
commit, but the bulk of the logic is in these JS files:
* message_list_view.js
* notifications.js
I choose to pass structs around instead of booleans,
because I anticipate we may eventually add more metadata
about rendering to it, plus bools are just kinda brittle.
(The exceptions are that `_maybe_autoscroll`, which
is at the bottom of the stack, just passes back a simple
boolean, and `notify_local_mixes`, also at the bottom
of the stack, just accepts a simple boolean.)
This errs on the side of warning the user, even if the
new message is partially visible.
Fixes #11138
2019-01-07 21:00:03 +01:00
|
|
|
render_info = self.append_to_view(bottom_messages, opts);
|
2013-09-22 16:41:33 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 18:50:09 +02:00
|
|
|
if (self === exports.narrowed && !self.empty()) {
|
2013-09-22 16:41:33 +02:00
|
|
|
// If adding some new messages to the message tables caused
|
|
|
|
// our current narrow to no longer be empty, hide the empty
|
|
|
|
// feed placeholder text.
|
|
|
|
narrow.hide_empty_narrow_message();
|
2014-03-04 22:39:34 +01:00
|
|
|
}
|
|
|
|
|
2018-06-06 18:50:09 +02:00
|
|
|
if (self === exports.narrowed && !self.empty() &&
|
|
|
|
self.selected_id() === -1) {
|
2013-09-22 16:41:33 +02:00
|
|
|
// And also select the newly arrived message.
|
|
|
|
self.select_id(self.selected_id(), {then_scroll: true, use_closest: true});
|
|
|
|
}
|
message scrolling: Fix "Scroll down to view" warning.
We recently added a feature to warn users that they
may need to scroll down to view messages that they
just sent, but it was broken due to various complexities
in the rendering code path.
Now we compute it a bit more rigorously.
It requires us to pass some info about rendering up
and down the stack, which is why it's kind of a long
commit, but the bulk of the logic is in these JS files:
* message_list_view.js
* notifications.js
I choose to pass structs around instead of booleans,
because I anticipate we may eventually add more metadata
about rendering to it, plus bools are just kinda brittle.
(The exceptions are that `_maybe_autoscroll`, which
is at the bottom of the stack, just passes back a simple
boolean, and `notify_local_mixes`, also at the bottom
of the stack, just accepts a simple boolean.)
This errs on the side of warning the user, even if the
new message is partially visible.
Fixes #11138
2019-01-07 21:00:03 +01:00
|
|
|
|
|
|
|
return render_info;
|
2013-09-22 16:41:33 +02:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
get: function (id) {
|
|
|
|
return this.data.get(id);
|
2012-12-05 23:54:49 +01:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
num_items: function () {
|
|
|
|
return this.data.num_items();
|
2013-08-16 17:10:22 +02:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
empty: function () {
|
|
|
|
return this.data.empty();
|
2012-12-05 23:54:49 +01:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
first: function () {
|
|
|
|
return this.data.first();
|
2012-12-05 23:54:49 +01:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
last: function () {
|
|
|
|
return this.data.last();
|
2012-12-05 23:54:49 +01:00
|
|
|
},
|
|
|
|
|
2018-05-26 12:29:38 +02:00
|
|
|
prev: function () {
|
|
|
|
return this.data.prev();
|
|
|
|
},
|
|
|
|
|
|
|
|
next: function () {
|
|
|
|
return this.data.next();
|
|
|
|
},
|
|
|
|
|
2018-05-29 00:18:27 +02:00
|
|
|
is_at_end: function () {
|
|
|
|
return this.data.is_at_end();
|
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
nth_most_recent_id: function (n) {
|
|
|
|
return this.data.nth_most_recent_id(n);
|
2013-08-14 23:04:24 +02:00
|
|
|
},
|
|
|
|
|
2018-05-04 18:51:09 +02:00
|
|
|
is_search: function () {
|
2018-05-04 12:44:28 +02:00
|
|
|
return this.data.is_search();
|
2018-05-04 18:51:09 +02:00
|
|
|
},
|
|
|
|
|
2019-07-10 02:03:41 +02:00
|
|
|
can_mark_messages_read: function () {
|
|
|
|
return this.data.can_mark_messages_read();
|
|
|
|
},
|
|
|
|
|
2013-02-22 20:48:31 +01:00
|
|
|
clear: function MessageList_clear(opts) {
|
2013-07-30 05:11:50 +02:00
|
|
|
opts = _.extend({clear_selected_id: true}, opts);
|
2013-02-22 20:48:31 +01:00
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
this.data.clear();
|
2013-08-16 17:10:22 +02:00
|
|
|
this.view.clear_rendering_state(true);
|
2013-02-22 20:48:31 +01:00
|
|
|
|
|
|
|
if (opts.clear_selected_id) {
|
2018-05-04 12:44:28 +02:00
|
|
|
this.data.clear_selected_id();
|
2013-02-22 20:48:31 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
selected_id: function () {
|
|
|
|
return this.data.selected_id();
|
2013-02-20 18:26:50 +01:00
|
|
|
},
|
|
|
|
|
2013-02-20 18:33:04 +01:00
|
|
|
select_id: function MessageList_select_id(id, opts) {
|
2013-07-30 05:11:50 +02:00
|
|
|
opts = _.extend({
|
2018-05-06 21:43:17 +02:00
|
|
|
then_scroll: false,
|
|
|
|
target_scroll_offset: undefined,
|
|
|
|
use_closest: false,
|
|
|
|
empty_ok: false,
|
|
|
|
mark_read: true,
|
|
|
|
force_rerender: false,
|
|
|
|
}, opts, {
|
|
|
|
id: id,
|
|
|
|
msg_list: this,
|
|
|
|
previously_selected: this.data.selected_id(),
|
|
|
|
});
|
2013-07-03 19:15:07 +02:00
|
|
|
|
2017-03-27 19:26:30 +02:00
|
|
|
function convert_id(str_id) {
|
|
|
|
var id = parseFloat(str_id);
|
|
|
|
if (isNaN(id)) {
|
|
|
|
blueslip.fatal("Bad message id " + str_id);
|
|
|
|
}
|
|
|
|
return id;
|
2013-02-20 18:33:04 +01:00
|
|
|
}
|
2013-08-07 20:28:50 +02:00
|
|
|
|
2017-03-27 19:26:30 +02:00
|
|
|
id = convert_id(id);
|
|
|
|
|
2013-09-27 21:18:54 +02:00
|
|
|
var closest_id = this.closest_id(id);
|
|
|
|
|
2017-06-15 23:46:41 +02:00
|
|
|
var error_data;
|
|
|
|
|
2013-09-27 21:18:54 +02:00
|
|
|
// The name "use_closest" option is a bit legacy. We
|
|
|
|
// are always gonna move to the closest visible id; the flag
|
|
|
|
// just says whether we call blueslip.error or not. The caller
|
|
|
|
// sets use_closest to true when it expects us to move the
|
|
|
|
// pointer as needed, so only generate an error if the flag is
|
|
|
|
// false.
|
|
|
|
if (!opts.use_closest && closest_id !== id) {
|
2017-06-15 23:46:41 +02:00
|
|
|
error_data = {
|
2017-06-15 22:33:38 +02:00
|
|
|
table_name: this.table_name,
|
|
|
|
id: id,
|
|
|
|
closest_id: closest_id,
|
|
|
|
};
|
2013-09-27 21:18:54 +02:00
|
|
|
blueslip.error("Selected message id not in MessageList",
|
2017-06-15 22:33:38 +02:00
|
|
|
error_data);
|
2013-02-20 18:33:04 +01:00
|
|
|
}
|
2013-03-13 18:48:02 +01:00
|
|
|
|
2013-12-18 19:06:55 +01:00
|
|
|
if (closest_id === -1 && !opts.empty_ok) {
|
2017-06-15 23:46:41 +02:00
|
|
|
error_data = {
|
2013-12-02 21:40:49 +01:00
|
|
|
table_name: this.table_name,
|
|
|
|
id: id,
|
2018-05-04 12:44:28 +02:00
|
|
|
items_length: this.data.num_items(),
|
2013-12-02 21:40:49 +01:00
|
|
|
};
|
|
|
|
blueslip.fatal("Cannot select id -1", error_data);
|
2013-10-30 18:38:16 +01:00
|
|
|
}
|
|
|
|
|
2013-09-27 21:18:54 +02:00
|
|
|
id = closest_id;
|
|
|
|
opts.id = id;
|
2018-05-04 12:44:28 +02:00
|
|
|
this.data.set_selected_id(id);
|
2013-09-27 21:18:54 +02:00
|
|
|
|
2014-01-22 22:20:36 +01:00
|
|
|
if (opts.force_rerender) {
|
|
|
|
this.rerender();
|
|
|
|
} else if (!opts.from_rendering) {
|
2013-08-16 17:10:22 +02:00
|
|
|
this.view.maybe_rerender();
|
2013-07-03 19:53:27 +02:00
|
|
|
}
|
2013-03-04 20:22:09 +01:00
|
|
|
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).trigger($.Event('message_selected.zulip', opts));
|
2013-02-20 18:33:04 +01:00
|
|
|
},
|
|
|
|
|
2013-08-16 17:10:22 +02:00
|
|
|
reselect_selected_id: function MessageList_select_closest_id() {
|
2018-05-04 12:44:28 +02:00
|
|
|
this.select_id(this.data.selected_id(), {from_rendering: true});
|
2013-08-16 17:10:22 +02:00
|
|
|
},
|
|
|
|
|
2013-02-14 23:48:37 +01:00
|
|
|
selected_message: function MessageList_selected_message() {
|
2018-05-04 12:44:28 +02:00
|
|
|
return this.get(this.data.selected_id());
|
2013-02-14 23:48:37 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
selected_row: function MessageList_selected_row() {
|
2018-05-04 12:44:28 +02:00
|
|
|
return this.get_row(this.data.selected_id());
|
2013-02-20 00:49:21 +01:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
closest_id: function (id) {
|
|
|
|
return this.data.closest_id(id);
|
2013-07-24 22:33:06 +02:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
advance_past_messages: function (msg_ids) {
|
|
|
|
return this.data.advance_past_messages(msg_ids);
|
2012-12-05 23:54:49 +01:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
selected_idx: function () {
|
|
|
|
return this.data.selected_idx();
|
2013-04-10 18:30:36 +02:00
|
|
|
},
|
|
|
|
|
2014-02-05 16:55:24 +01:00
|
|
|
subscribed_bookend_content: function (stream_name) {
|
2017-06-06 01:54:56 +02:00
|
|
|
return i18n.t("You subscribed to stream __stream__",
|
|
|
|
{stream: stream_name});
|
2014-02-05 16:55:24 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
unsubscribed_bookend_content: function (stream_name) {
|
2017-06-06 01:54:56 +02:00
|
|
|
return i18n.t("You unsubscribed from stream __stream__",
|
|
|
|
{stream: stream_name});
|
2014-02-05 16:55:24 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
not_subscribed_bookend_content: function (stream_name) {
|
2017-06-06 01:54:56 +02:00
|
|
|
return i18n.t("You are not subscribed to stream __stream__",
|
|
|
|
{stream: stream_name});
|
2014-02-05 16:55:24 +01:00
|
|
|
},
|
|
|
|
|
2013-04-10 23:38:30 +02:00
|
|
|
// Maintains a trailing bookend element explaining any changes in
|
|
|
|
// your subscribed/unsubscribed status at the bottom of the
|
|
|
|
// message list.
|
|
|
|
update_trailing_bookend: function MessageList_update_trailing_bookend() {
|
2013-08-16 17:10:22 +02:00
|
|
|
this.view.clear_trailing_bookend();
|
2013-04-10 23:38:30 +02:00
|
|
|
if (!this.narrowed) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-15 10:55:40 +02:00
|
|
|
var stream_name = narrow_state.stream();
|
|
|
|
if (stream_name === undefined) {
|
2013-04-10 23:38:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-12-02 17:09:31 +01:00
|
|
|
var trailing_bookend_content;
|
2017-06-21 02:20:33 +02:00
|
|
|
var show_button = true;
|
2017-09-15 10:55:40 +02:00
|
|
|
var subscribed = stream_data.is_subscribed(stream_name);
|
2013-04-10 23:38:30 +02:00
|
|
|
if (subscribed) {
|
2017-09-15 10:55:40 +02:00
|
|
|
trailing_bookend_content = this.subscribed_bookend_content(stream_name);
|
2013-04-10 23:38:30 +02:00
|
|
|
} else {
|
|
|
|
if (!this.last_message_historical) {
|
2017-09-15 10:55:40 +02:00
|
|
|
trailing_bookend_content = this.unsubscribed_bookend_content(stream_name);
|
2017-06-21 02:20:33 +02:00
|
|
|
|
2017-09-15 10:56:34 +02:00
|
|
|
// For invite only streams or streams that no longer
|
|
|
|
// exist, hide the resubscribe button
|
2018-10-31 19:28:02 +01:00
|
|
|
// Hide button for guest users
|
2017-09-15 10:56:34 +02:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
|
|
|
if (sub !== undefined) {
|
2018-10-31 19:28:02 +01:00
|
|
|
show_button = !page_params.is_guest && !sub.invite_only;
|
2017-09-15 10:56:34 +02:00
|
|
|
} else {
|
|
|
|
show_button = false;
|
|
|
|
}
|
2013-04-10 23:38:30 +02:00
|
|
|
} else {
|
2017-09-15 10:55:40 +02:00
|
|
|
trailing_bookend_content = this.not_subscribed_bookend_content(stream_name);
|
2013-04-10 23:38:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (trailing_bookend_content !== undefined) {
|
2017-06-21 02:20:33 +02:00
|
|
|
this.view.render_trailing_bookend(trailing_bookend_content, subscribed, show_button);
|
2013-04-10 23:38:30 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
unmuted_messages: function (messages) {
|
|
|
|
return this.data.unmuted_messages(messages);
|
2013-09-19 00:43:59 +02:00
|
|
|
},
|
|
|
|
|
2014-01-22 22:20:36 +01:00
|
|
|
append: function MessageList_append(messages, opts) {
|
2018-05-04 12:44:28 +02:00
|
|
|
var viewable_messages = this.data.append(messages);
|
2018-05-13 23:03:16 +02:00
|
|
|
this.append_to_view(viewable_messages, opts);
|
|
|
|
},
|
|
|
|
|
|
|
|
append_to_view: function (messages, opts) {
|
2018-05-14 22:21:14 +02:00
|
|
|
opts = _.extend({messages_are_new: false}, opts);
|
2013-08-14 23:48:28 +02:00
|
|
|
|
|
|
|
this.num_appends += 1;
|
message scrolling: Fix "Scroll down to view" warning.
We recently added a feature to warn users that they
may need to scroll down to view messages that they
just sent, but it was broken due to various complexities
in the rendering code path.
Now we compute it a bit more rigorously.
It requires us to pass some info about rendering up
and down the stack, which is why it's kind of a long
commit, but the bulk of the logic is in these JS files:
* message_list_view.js
* notifications.js
I choose to pass structs around instead of booleans,
because I anticipate we may eventually add more metadata
about rendering to it, plus bools are just kinda brittle.
(The exceptions are that `_maybe_autoscroll`, which
is at the bottom of the stack, just passes back a simple
boolean, and `notify_local_mixes`, also at the bottom
of the stack, just accepts a simple boolean.)
This errs on the side of warning the user, even if the
new message is partially visible.
Fixes #11138
2019-01-07 21:00:03 +01:00
|
|
|
var render_info = this.view.append(messages, opts.messages_are_new);
|
|
|
|
return render_info;
|
2012-12-05 23:54:49 +01:00
|
|
|
},
|
|
|
|
|
2013-12-17 20:50:11 +01:00
|
|
|
remove_and_rerender: function MessageList_remove_and_rerender(messages) {
|
2018-05-04 12:44:28 +02:00
|
|
|
this.data.remove(messages);
|
2014-02-25 22:45:11 +01:00
|
|
|
this.rerender();
|
2013-12-17 20:50:11 +01:00
|
|
|
},
|
|
|
|
|
2013-05-15 00:22:16 +02:00
|
|
|
show_edit_message: function MessageList_show_edit_message(row, edit_obj) {
|
|
|
|
row.find(".message_edit_form").empty().append(edit_obj.form);
|
2018-12-29 20:24:59 +01:00
|
|
|
row.find(".message_content, .status-message, .message_controls").hide();
|
2017-09-11 01:35:14 +02:00
|
|
|
row.find(".message_edit").css("display", "block");
|
2019-07-16 20:19:11 +02:00
|
|
|
autosize(row.find(".message_edit_content"));
|
2013-05-15 00:22:16 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
hide_edit_message: function MessageList_hide_edit_message(row) {
|
2018-12-29 20:24:59 +01:00
|
|
|
row.find(".message_content, .status-message, .message_controls").show();
|
2013-05-15 00:22:16 +02:00
|
|
|
row.find(".message_edit").hide();
|
2017-06-15 18:15:09 +02:00
|
|
|
row.trigger("mouseleave");
|
2013-05-15 00:22:16 +02:00
|
|
|
},
|
|
|
|
|
2013-08-16 23:45:13 +02:00
|
|
|
show_edit_topic: function MessageList_show_edit_topic(recipient_row, form) {
|
|
|
|
recipient_row.find(".topic_edit_form").empty().append(form);
|
2018-07-04 01:15:30 +02:00
|
|
|
recipient_row.find('.fa-pencil').hide();
|
2013-08-16 23:45:13 +02:00
|
|
|
recipient_row.find(".stream_topic").hide();
|
|
|
|
recipient_row.find(".topic_edit").show();
|
|
|
|
},
|
|
|
|
|
|
|
|
hide_edit_topic: function MessageList_hide_edit_topic(recipient_row) {
|
|
|
|
recipient_row.find(".stream_topic").show();
|
2018-07-04 01:15:30 +02:00
|
|
|
recipient_row.find('.fa-pencil').show();
|
2013-08-16 23:45:13 +02:00
|
|
|
recipient_row.find(".topic_edit").hide();
|
|
|
|
},
|
|
|
|
|
2013-07-26 17:19:13 +02:00
|
|
|
show_message_as_read: function (message, options) {
|
2013-08-14 22:00:32 +02:00
|
|
|
var row = this.get_row(message.id);
|
2018-07-06 15:46:06 +02:00
|
|
|
if (options.from === 'pointer' || options.from === "server") {
|
2013-07-26 17:19:13 +02:00
|
|
|
row.find('.unread_marker').addClass('fast_fade');
|
|
|
|
} else {
|
|
|
|
row.find('.unread_marker').addClass('slow_fade');
|
|
|
|
}
|
|
|
|
row.removeClass('unread');
|
2013-07-01 23:28:27 +02:00
|
|
|
},
|
|
|
|
|
2013-05-14 21:18:11 +02:00
|
|
|
rerender: function MessageList_rerender() {
|
|
|
|
// We need to clear the rendering state, rather than just
|
2013-08-16 17:10:22 +02:00
|
|
|
// doing clear_table, since we want to potentially recollapse
|
2013-05-14 21:18:11 +02:00
|
|
|
// things.
|
2018-05-04 12:44:28 +02:00
|
|
|
this.data.reset_select_to_closest();
|
2013-08-16 17:10:22 +02:00
|
|
|
this.view.clear_rendering_state(false);
|
|
|
|
this.view.update_render_window(this.selected_idx(), false);
|
2018-04-14 00:36:14 +02:00
|
|
|
|
|
|
|
if (this === exports.narrowed) {
|
|
|
|
if (this.empty()) {
|
|
|
|
narrow.show_empty_narrow_message();
|
|
|
|
} else {
|
|
|
|
narrow.hide_empty_narrow_message();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:10:22 +02:00
|
|
|
this.view.rerender_preserving_scrolltop();
|
2018-05-04 12:44:28 +02:00
|
|
|
this.redo_selection();
|
|
|
|
},
|
|
|
|
|
|
|
|
redo_selection: function () {
|
|
|
|
var selected_id = this.data.selected_id();
|
|
|
|
|
|
|
|
if (selected_id !== -1) {
|
|
|
|
this.select_id(selected_id);
|
2013-06-04 22:07:44 +02:00
|
|
|
}
|
2013-05-14 21:18:11 +02:00
|
|
|
},
|
|
|
|
|
2018-04-27 17:35:02 +02:00
|
|
|
update_muting_and_rerender: function MessageList_update_muting_and_rerender() {
|
2018-05-04 23:08:57 +02:00
|
|
|
if (!this.muting_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-04 12:44:28 +02:00
|
|
|
this.data.update_items_for_muting();
|
2013-09-19 00:43:59 +02:00
|
|
|
this.rerender();
|
|
|
|
},
|
|
|
|
|
2016-04-23 00:56:44 +02:00
|
|
|
all_messages: function MessageList_all_messages() {
|
2018-05-04 12:44:28 +02:00
|
|
|
return this.data.all_messages();
|
2013-08-14 22:00:32 +02:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
first_unread_message_id: function () {
|
|
|
|
return this.data.first_unread_message_id();
|
2017-08-02 22:37:13 +02:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
message_range: function (start, end) {
|
|
|
|
return this.data.message_range(start, end);
|
2014-01-31 22:06:07 +01:00
|
|
|
},
|
|
|
|
|
2013-08-14 22:00:32 +02:00
|
|
|
get_row: function (id) {
|
2013-08-16 17:10:22 +02:00
|
|
|
return this.view.get_row(id);
|
2013-08-22 19:57:48 +02:00
|
|
|
},
|
|
|
|
|
2017-01-24 19:12:21 +01:00
|
|
|
update_user_full_name: function (user_id, full_name) {
|
2018-05-04 12:44:28 +02:00
|
|
|
this.data.update_user_full_name(user_id, full_name);
|
2018-04-03 03:24:36 +02:00
|
|
|
if (this.table_name !== undefined) {
|
|
|
|
this.view.rerender_preserving_scrolltop();
|
|
|
|
}
|
2017-01-24 19:12:21 +01:00
|
|
|
},
|
|
|
|
|
2017-02-23 00:31:34 +01:00
|
|
|
update_user_avatar: function (user_id, avatar_url) {
|
2018-05-04 12:44:28 +02:00
|
|
|
this.data.update_user_avatar(user_id, avatar_url);
|
2018-04-03 03:24:36 +02:00
|
|
|
if (this.table_name !== undefined) {
|
|
|
|
this.view.rerender_preserving_scrolltop();
|
|
|
|
}
|
2017-02-23 00:31:34 +01:00
|
|
|
},
|
|
|
|
|
2018-05-04 12:44:28 +02:00
|
|
|
update_stream_name: function (stream_id, new_stream_name) {
|
|
|
|
this.data.update_stream_name(stream_id, new_stream_name);
|
2018-04-03 03:24:36 +02:00
|
|
|
if (this.table_name !== undefined) {
|
|
|
|
this.view.rerender_preserving_scrolltop();
|
|
|
|
}
|
2013-12-19 17:03:08 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
change_message_id: function MessageList_change_message_id(old_id, new_id) {
|
|
|
|
var self = this;
|
2018-05-04 12:44:28 +02:00
|
|
|
var opts = {
|
|
|
|
is_current_list: function () {
|
|
|
|
return current_msg_list === self;
|
|
|
|
},
|
|
|
|
re_render: function () {
|
2014-02-25 21:50:31 +01:00
|
|
|
self.view.rerender_preserving_scrolltop();
|
2018-05-04 12:44:28 +02:00
|
|
|
self.redo_selection();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
this.data.change_message_id(old_id, new_id, opts);
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-11-23 05:06:34 +01:00
|
|
|
|
2017-03-27 18:00:31 +02:00
|
|
|
get_last_message_sent_by_me: function () {
|
2018-05-04 12:44:28 +02:00
|
|
|
return this.data.get_last_message_sent_by_me();
|
2016-11-23 05:06:34 +01:00
|
|
|
},
|
2012-12-05 23:54:49 +01:00
|
|
|
};
|
2013-04-09 19:59:15 +02:00
|
|
|
|
2018-05-14 15:46:25 +02:00
|
|
|
exports.all = new exports.MessageList({
|
|
|
|
muting_enabled: false,
|
|
|
|
});
|
2016-04-21 22:49:23 +02:00
|
|
|
|
2013-05-30 16:11:06 +02:00
|
|
|
// We stop autoscrolling when the user is clearly in the middle of
|
|
|
|
// doing something. Be careful, though, if you try to capture
|
|
|
|
// mousemove, then you will have to contend with the autoscroll
|
|
|
|
// itself generating mousemove events.
|
2018-12-04 19:08:26 +01:00
|
|
|
$(document).on('message_selected.zulip wheel', function () {
|
2017-03-10 23:48:51 +01:00
|
|
|
message_viewport.stop_auto_scrolling();
|
2013-04-09 19:59:15 +02:00
|
|
|
});
|
2016-04-20 22:37:26 +02:00
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
2013-02-26 23:30:13 +01:00
|
|
|
}());
|
2013-08-06 21:30:31 +02:00
|
|
|
if (typeof module !== 'undefined') {
|
2016-04-20 22:37:26 +02:00
|
|
|
module.exports = message_list;
|
2013-08-06 21:30:31 +02:00
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.message_list = message_list;
|