From b4b6fa14d3774610568d55743f49c6b318a74dbc Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 10 Sep 2013 14:07:24 -0400 Subject: [PATCH] Persist muting preferences to the back end (imported from commit db2d4362a0601f35a75b798cf6945556e44532fb) --- static/js/muting_ui.js | 24 ++++++++++++++++++++++++ static/js/popovers.js | 4 ++-- tools/jslint/check-all.js | 2 +- zproject/settings.py | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 static/js/muting_ui.js diff --git a/static/js/muting_ui.js b/static/js/muting_ui.js new file mode 100644 index 0000000000..abed5f92c0 --- /dev/null +++ b/static/js/muting_ui.js @@ -0,0 +1,24 @@ +var muting_ui = (function () { + +var exports = {}; + +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()) + }; + $.ajax({ + type: 'POST', + url: '/json/set_muted_topics', + data: data, + dataType: 'json' + }); +}; + +return exports; +}()); + diff --git a/static/js/popovers.js b/static/js/popovers.js index c17d84c050..498c86b995 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -385,7 +385,7 @@ exports.register_click_handlers = function () { var topic = $(e.currentTarget).data('msg-topic'); popovers.hide_actions_popover(); muting.mute_topic(stream, topic); - current_msg_list.rerender(); + muting_ui.persist_and_rerender(); e.stopPropagation(); e.preventDefault(); }); @@ -395,7 +395,7 @@ exports.register_click_handlers = function () { var topic = $(e.currentTarget).data('msg-topic'); popovers.hide_actions_popover(); muting.unmute_topic(stream, topic); - current_msg_list.rerender(); + muting_ui.persist_and_rerender(); e.stopPropagation(); e.preventDefault(); }); diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js index a450f6d757..638e6f3d2b 100644 --- a/tools/jslint/check-all.js +++ b/tools/jslint/check-all.js @@ -27,7 +27,7 @@ var globals = + ' invite ui util activity timerender MessageList MessageListView blueslip unread stream_list' + ' onboarding message_edit tab_bar emoji popovers navigate message_tour' + ' avatar feature_flags search_suggestion referral stream_color Dict' - + ' Filter summary admin stream_data muting WinChan' + + ' Filter summary admin stream_data muting WinChan muting_ui' // colorspace.js + ' colorspace' diff --git a/zproject/settings.py b/zproject/settings.py index 559bc0a6ce..668a32d8bc 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -368,6 +368,7 @@ JS_SPECS = { 'js/util.js', 'js/dict.js', 'js/muting.js', + 'js/muting_ui.js', 'js/setup.js', 'js/viewport.js', 'js/rows.js',