[Feature] Mute User Debugging Thread

A number of reports indicate that the Mute User feature may be bugged.

Affected browsers appear to be Firefox 53-55, on Windows and Mac OSX. I was able to replicate the bug thusly:

  1. Open Multiple Cafe tabs
  2. Muted myself in a tab, then closed it.
  3. Opened thread in existing second tab.
  4. Mute script fails to execute.

I think the bug was introduced with the Battery-Saver update of the Mute Script. Attempting a fix, will report back with results.

2 Likes

Update: fixed!

Rewrote the code, will update the code on Github.

Key code changes:

  • move cookie name variable into main script
  • copied hide_ids so it gets ids to hide on page load
  • moved the scroll listener out of MakeMagic
  • set scroll listener so it runs MakeMagic only in topic threads
<script type="text/javascript">
var run_script = false;

$(document).ready(function(){
    if (window.location.href.indexOf("/t/") > 0) {
        run_script = true;
        MakeMagic();
    }
});    

if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
    this.GM_getValue=function (key,def) {
        return localStorage[key] || def;
    };
    this.GM_setValue=function (key,value) {
        return localStorage[key]=value;
    };
    this.GM_deleteValue=function (key) {
        return delete localStorage[key];
    };
}

var GR_COOKIE_NAME = 'elsewhere_mute_users';
var hide_ids = $.parseJSON(GM_getValue(GR_COOKIE_NAME, '{}'));

document.addEventListener("wheel", function(event) { 
    setTimeout(RecastSpell, 1000);
});

function RecastSpell(){
    if (run_script == true) {
        MakeMagic();
    }
}

function MakeMagic(){
    hide_ids = $.parseJSON(GM_getValue(GR_COOKIE_NAME, '{}'));
	function handle_post_node(node){
		var tid = node.getAttribute('data-user-id');
		var name = $('[data-user-id="'+tid+'"]').find('.username a').first().text();
		function mute_foo(){
		    //var name = $(node).find('.names').text;
		    var confirmString = "Really mute " + name + "?";  
		    if (confirm(confirmString) == true) {
                serveJustice();
                this.innerHTML = "Unmute;"
			$(node).find('.contents').hide();
			$(node).find('.names').hide();
			$(node).find('.avatar').hide();
			$(this).unbind('click', mute_foo);
			$(this).click(umute_foo);
			hide_ids[tid] = 1;
			GM_setValue(GR_COOKIE_NAME, JSON.stringify(hide_ids));
			$('[data-user-id="'+tid+'"]').find('.mute_btn').remove();
			$('[data-user-id="'+tid+'"]').each(function(){ handle_post_node(this) });
		        setTimeout(endAnimation, 3000);            
		    }
		}

		function serveJustice() {
		    var overlay = jQuery('<div id="overlay" class="overlay"> </div>');
            overlay.appendTo(document.body);
		}
		function endAnimation(){
		 	$( ".overlay" ).remove();
		}
		function umute_foo(){
		    var confirmString = "Unmute " + name + "?";  
		    if (confirm(confirmString) == true) {
			this.innerHTML = "Mute";
			$(node).find('.contents').show();
			$(node).find('.names').show();
			$(node).find('.avatar').show();
			$(this).unbind('click', umute_foo);
			$(this).click(mute_foo);
			delete hide_ids[tid];
			GM_setValue(GR_COOKIE_NAME, JSON.stringify(hide_ids));
			$('[data-user-id="'+tid+'"]').find('.umute_btn').remove();
			$('[data-user-id="'+tid+'"]').each(function(){ $(this).find('.contents').show(); handle_post_node(this) });
		    }
		}
		if(hide_ids[tid]){			
			$(node).find('.contents').hide();
			$(node).find('.names').hide();
			$(node).find('.avatar').hide();
			if($(node).find('.umute_btn').length > 0) return;
			var btn = $('<button class="umute_btn" title="Unmute this user." style="background-color: Transparent; background-repeat:no-repeat; border: none; cursor:pointer; overflow: hidden; outline:none; margin-left: 3px; "><i class="fa fa-microphone"></i></button>');
			$(node).find('.post-info').first().prepend(btn);
			btn.click(umute_foo);
		}else {
			if($(node).find('.mute_btn').length > 0) return;
			var btn = $('<button title="Mute this user." style="background: none;" class="mute_btn"><i class="fa fa-microphone-slash"></i></button>');
			btn.insertBefore($(node).find('.create').last());
			btn.click(mute_foo);
		}
	}
	
	$('article').each(function(){handle_post_node(this)});
	var observer = new MutationObserver(function(mutations) {
		for(var i=0; i < mutations.length; ++i){
			var mutation = mutations[i];
			for(var j=0; j < mutation.addedNodes.length; ++j){
				if(mutation.addedNodes[j].nodeName == "#text") continue;
				var node = mutation.addedNodes[j];
				//console.log(node);
				if(node.className == 'container posts'){
					$(node).find('article').each(function(){handle_post_node(this)});
					continue;
				}
				// just to be sure (TODO: sometimes when jumping to a thread via notification the posts aren't handled.
				// This "hack" (should) ensure that all posts are handled )
				if(node.className == 'topic-link'){
					$(window.document).find('article').each(function(){handle_post_node(this)});
					continue;
				}
				if(node.className == 'ember-view post-cloak'){
					node = $(node).find('article').get(0);
				}
				if(node.nodeName == "ARTICLE" && node.getAttribute('data-user-id')){
					handle_post_node(node);	
				}
			}
		}
	});
	observer.observe(document, { subtree: true, childList: true});
}
</script>

Welp, new bug: mute check not running on new post. Shit.

Update: Fixed. Code in earlier post updated.

2 Likes

I ran into an issue. It’s replicable. When I try to bookmark a post, it also tries to mute the person who posted the thing I was trying to bookmark.

48 PM
58 PM

Chrome, Version 60.0.3112.113 (Official Build) (64-bit), on Mac OS Sierra 10.12.6 (16G29). (Running in Incognito with no plugins enabled for Incognito mode so it should be just about pristine in terms of browser environment.)

It’s not a deal breaker for me but it’s a bit irritating.

ETA: Apologies if this isn’t the best thread to report issues in. I saw the other thread but it seemed to be more philosophical discussion about muting than a good place for a bug report. :cold_sweat:

2 Likes

Samsung Galaxy S4 phone, with Android Lollipop 5.0.1 and stock browser… I haven’t seen the microphone/mute icon in a couple of days, at least. Of course, I’ve got a recurring caching issue that doesn’t keep track of Read posts/topics properly, so you might take any issues I report with a grain or two of salt. :wink:

4 Likes

Oh no. I haven’t tested on stock.

OnScroll events aren’t firing for me on Chrome (Lollipop 5, Chrome Beta). Strange stuff like Reply replacing mute after clicking the More button occurs.

Fixed. Added check for mobile devices. Mobile device now runs on a timer, executing every three seconds or so. I know there’s a jQuery .on() method I could use instead, but for now, it gets the job done.

EDIT:
On Earthtones, I’m currently testing moving the mute to the header, beside the date information. It doesn’t have any funky interactions there, but it is easy to overlook. (And maybe, that’s the way it should be - present and usable if needed but not in the way of conversation).

Couldn’t find a way to add it to the show-more button; there’s so much jquery abuse going on that I wasn’t able to find where in the Discourse code the show-more contents are generated. :dizzy_face:

EDIT2:
Rolled out a new solution, that fires on the addition of new posts (or loading thereof).

Thanks to this crazy web dev: http://www.backalleycoder.com/2012/04/25/i-want-a-damnodeinserted/

2 Likes

I’ll fix the animation code in seven hours or so. I hit the sack

1 Like

Fixes:

  • Moved mute button to beside post info.
    (This should fix any bugs)
1 Like

I think it’s as you say, and a good thing.

1 Like

Button has disappeared, and previously muted poster unmuted.

Firefox for Android 55.0.2.

Will revert in ten minutes. My apologies.

1 Like

My apologies for the disruption. Issue has been resolved (restored script from known good state, applied fixes and testing).

3 Likes

Thread will close on Monday if no further reports if breakage are made.

3 Likes

Thank you for all your work on this. It is greatly appreciated!

8 Likes

I can report no bug. Pure feature. A great intermeidate step between muting a whole thread and muting a user in the preferences. Sometimes folks you like just fine have a thread where you don’t appreciate their contributions, and this button turns out to be a solid software backup to a wetware solution. Surely a nicer solution than telling someone they are unwelcome in a whole thread (a really controlling thing to say in a shared space), when one can just make that someone else unwelcome in ones own browser window (a really appropriate way to shut someone else up is to stop listening), for a whole thread. Genius!

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.