2013-09-10 20:07:24 +02:00
|
|
|
var muting_ui = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-09-11 17:27:43 +02:00
|
|
|
function timestamp_ms() {
|
|
|
|
return (new Date()).getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
var last_topic_update = 0;
|
|
|
|
|
2013-09-27 16:26:04 +02:00
|
|
|
exports.rerender = function () {
|
2013-09-30 22:03:10 +02:00
|
|
|
stream_list.update_streams_sidebar();
|
2013-09-27 16:26:04 +02:00
|
|
|
current_msg_list.rerender_after_muting_changes();
|
|
|
|
if (current_msg_list !== home_msg_list) {
|
|
|
|
home_msg_list.rerender_after_muting_changes();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-10 20:07:24 +02:00
|
|
|
exports.persist_and_rerender = function () {
|
|
|
|
// Optimistically rerender our new muting preferences. The back
|
|
|
|
// end should eventually save it, and if it doesn't, it's a recoverable
|
|
|
|
// error--the user can just mute the topic again, and the topic might
|
|
|
|
// die down before the next reload anyway, making the muting moot.
|
2013-09-27 16:26:04 +02:00
|
|
|
exports.rerender();
|
2013-09-10 20:07:24 +02:00
|
|
|
var data = {
|
|
|
|
muted_topics: JSON.stringify(muting.get_muted_topics())
|
|
|
|
};
|
2013-09-11 17:27:43 +02:00
|
|
|
last_topic_update = timestamp_ms();
|
2013-12-18 19:55:18 +01:00
|
|
|
channel.post({
|
2013-09-10 20:07:24 +02:00
|
|
|
url: '/json/set_muted_topics',
|
2014-01-07 23:40:31 +01:00
|
|
|
idempotent: true,
|
2013-12-18 19:55:18 +01:00
|
|
|
data: data
|
2013-09-10 20:07:24 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-09-11 00:36:21 +02:00
|
|
|
exports.handle_updates = function (muted_topics) {
|
2013-09-11 17:27:43 +02:00
|
|
|
if (timestamp_ms() < last_topic_update + 1000) {
|
|
|
|
// This topic update is either the one that we just rendered, or,
|
|
|
|
// much less likely, it's coming from another device and would probably
|
|
|
|
// be overwriting this device's preferences with stale data.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-11 00:36:21 +02:00
|
|
|
muting.set_muted_topics(muted_topics);
|
2013-09-27 16:26:04 +02:00
|
|
|
exports.rerender();
|
2013-09-11 00:36:21 +02:00
|
|
|
};
|
|
|
|
|
2013-09-27 19:38:56 +02:00
|
|
|
$(function () {
|
|
|
|
muting.set_muted_topics(page_params.muted_topics);
|
|
|
|
});
|
|
|
|
|
2013-09-10 20:07:24 +02:00
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|