50

I would like to see two new features added to the chatrooms on Stack Overflow with regards to access requests. I am a room owner of the Android chatroom, which operates in Gallery mode to prevent the room from being flooded by help-vampires. Thus every new person to the room must request access, and as a room owner, the access request appears on the top of the screen.

I would like to, as a room owner, be able to:

  1. Grant or deny explicit write access without having to visit a different screen than the chatroom. Currently I need to click on the 'info' link for the room, then the access tab, and then click on the drop-down for that user's request. Instead, where the notification screen says "user has requested write access", I'd like to just have buttons, like [approve] [deny]

  2. When one of the other room owners acts on the request, I'd like to have the notification for that request automatically close, instead of having to go to the 'info' access tab to determine whether the request is still valid or not.

3
  • 35
    While you're here, I rooted my Galaxy Note 3 and now it's bricked. Can you help me? :) Feb 9, 2015 at 20:58
  • 20
    Yes, go buy a better phone. Feb 9, 2015 at 21:02
  • 5
    This is a good idea. In the mean time, you could always user script it :)
    – Travis J
    Feb 9, 2015 at 21:06

1 Answer 1

19

Since these things can sometimes take time, this is just a temporary work around. I understand if you don't want to use it or feel it is excessive, but here it is.

This user script will overwrite the popup functionality. It will only work for room owners. It modifies the popup when you click on a user image to include the link

enter image description here

The link will not show if you click on a room owner. I could not unfortunately find out how to detect if a user already had write access, so it is possible that the user already has access and the link will still show. There is no harm in granting it again.

Once clicked, an alert with the user's SO profile will show

enter image description here

Once you click okay the alert goes away and the popup closes. An ajax post already occurred so at that point the user will show up in the write access area of the chat channel.

enter image description here

So, without further ado, here is the script. You may run it from the console, preface it with javascript: in the url, or make a bookmarklet out of it by creating a bookmark with any name and the url value of javascript: plus all the code pasted.

var popUp = function(b, e, f, a) {
    a || $(".popup").remove();
    a = {};
    b -= $(window).scrollLeft();
    e -= $(window).scrollTop();
    b < $(window).width() / 2 ? a.left = b : a.right = $(window).width() - b;
    e < $(window).height() / 2 ? a.top = e : a.bottom = $(window).height() - e;
    var d = div("popup").css(a).hide();
    $("<div class='btn-close'>X</div>").click(function() {
        $(this).closest(".popup").fadeOut(200, function() {
            $(this).remove()
        })
    }).prependTo(d);
    d.appendTo(f || $("body")).fadeIn(200);
    if (f == undefined && CHAT.RoomUsers.current().is_owner) {
        $(document).one("ajaxStart", function() {
            $(document).one("ajaxStop", function() {
                if (d.hasClass('user-popup')) {
                    var glink = d.find("img:first")[0].src;
                    glink = glink.substr(0, glink.indexOf("?"));
                    var dat = $('.user-container', '#sidebar').filter(function() {
                        var dlink = $(this).find("img:first")[0].src;
                        dlink = dlink.substr(0, dlink.indexOf("?"));
                        return dlink == glink;
                    });
                    var h = dat.data("user"),
                    g = CHAT.RoomUsers.all().filter(function(a) {
                        return a.id == h;
                    }).toArray()[0];
                    if (g.is_owner) {
                        return;
                    }
                    var userLink = d.find("a:first")[0].href;
                    var finalLink = $("<div/>");
                    finalLink.append($("<a/>").text("grant write access to this user")
                    .attr("href", "#").click(function(b) {
                        b.preventDefault();
                        var dataobj = {};
                        dataobj.userAccess = "read-write";
                        dataobj.fkey = fkey().fkey;
                        dataobj.aclUserId = userLink;
                        $.ajax({
                            type: "POST",
                            url: "/rooms/setuseraccess/" + CHAT.CURRENT_ROOM_ID,
                            data: dataobj,
                            success: function() {
                                alert("Granted write access to " + userLink);
                                d.close();
                            }
                        });
                    }));
                    finalLink.insertAfter(d.find('h5').eq(1));
                }   
            });
        });
    }
    d.close=function(){d.fadeOut(200,function(){d.remove();})};
    return d;
}
2
  • 8
    You have way too much free time :) Feb 10, 2015 at 0:00
  • 5
    @BradleyDotNET - Luckily I already had most of this code handy. The only part that was required to modify was waiting for the ajax round trip and figuring out the url to post to. I have written quite a few of these user scripts :)
    – Travis J
    Feb 10, 2015 at 0:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .