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-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.
|
|
|
|
current_msg_list.rerender();
|
|
|
|
var data = {
|
|
|
|
muted_topics: JSON.stringify(muting.get_muted_topics())
|
|
|
|
};
|
2013-09-11 17:27:43 +02:00
|
|
|
last_topic_update = timestamp_ms();
|
2013-09-10 20:07:24 +02:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/json/set_muted_topics',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
current_msg_list.rerender();
|
|
|
|
};
|
|
|
|
|
2013-09-10 20:07:24 +02:00
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|