mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 03:53:50 +00:00 
			
		
		
		
	We have been persisting muting preferences on the back end for a while, but we haven't been adding them to page_params for the client to have at reload/startup time. (imported from commit d9ca68aa0e4d22bfb0e6ce67fc0bc63981175c8b)
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| var muting_ui = (function () {
 | |
| 
 | |
| var exports = {};
 | |
| 
 | |
| function timestamp_ms() {
 | |
|     return (new Date()).getTime();
 | |
| }
 | |
| 
 | |
| var last_topic_update = 0;
 | |
| 
 | |
| exports.rerender = function () {
 | |
|     current_msg_list.rerender_after_muting_changes();
 | |
|     if (current_msg_list !== home_msg_list) {
 | |
|         home_msg_list.rerender_after_muting_changes();
 | |
|     }
 | |
| };
 | |
| 
 | |
| 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.
 | |
|     exports.rerender();
 | |
|     var data = {
 | |
|         muted_topics: JSON.stringify(muting.get_muted_topics())
 | |
|     };
 | |
|     last_topic_update = timestamp_ms();
 | |
|     $.ajax({
 | |
|         type: 'POST',
 | |
|         url: '/json/set_muted_topics',
 | |
|         data: data,
 | |
|         dataType: 'json'
 | |
|     });
 | |
| };
 | |
| 
 | |
| exports.handle_updates = function (muted_topics) {
 | |
|     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;
 | |
|     }
 | |
| 
 | |
|     muting.set_muted_topics(muted_topics);
 | |
|     exports.rerender();
 | |
| };
 | |
| 
 | |
| $(function () {
 | |
|     muting.set_muted_topics(page_params.muted_topics);
 | |
| });
 | |
| 
 | |
| return exports;
 | |
| }());
 | |
| 
 |