SteemPlus [2.17.6] - Multiple instances of following indication being provided to user upon multiple author name clicks

in #utopian-io6 years ago

Project Information

Repository: https://github.com/stoodkev/SteemPlus/
Project Name: SteemPlus
Publisher: @stoodkev

Expected behavior

When I have the "Author Popup Information Enabled" and when clicking on an author, I should be given an indication of whether or not that author is following me or not following me. I should only be given one instance of this information no matter how many times I press the author button.

Actual behaviour

When I have the "Author Information Pop Up" enabled and when clicking on an author, I should be given an indication of whether or not that author is following me. When you press the author's name multiple times, you will get multiple instances of whether or not the user is following you.

How to reproduce

  1. From a fresh install download SteemPlus here
  2. Complete the on-boarding flow and sign in via SteemConnect
  3. You will be redirected to Steemit.com (if you're already on the site, refresh to ensure the SteemPlus extension is working as expected)
  4. Go to settings ensure you have “Author Information Pop Up” enabled within the settings shown in extensions pop up window, this should be enabled by default.
  5. Go to any post.
  6. Go down to the bottom bar, if you have floating bottom bar enabled (enabled by default) it will show straight away.
  7. Click on the author's name who made this post 5 times.
  8. Note that whether or not they're following you will be shown 5 times.

Recording of issue

The following video shows the issue in more detail:

Environment

  • Browser: Google Chrome (Version 65.0.3325.162 (Official Build) (64-bit))
  • Device: MacBook Pro (Retina, 15-inch, Late 2013)
  • Operating system: MacOS HighSierra Version 10.13
  • Application Version of Testing: Version: 2.17.6

Issue Resolution

Everytime that you click the author on SteemPlus it calls openAuthorPopupInfo(element) in author_popup_info.js. The first thing it looks to do is create the container which holds the information, this can be seen here:

if (isSteemit) {
        userAuthorPopupInfo = element[0].pathname.replace('/@', '');
        $('.Author__dropdown').append('<hr><div class="author-popup-message"></div>');

Once created it will make an ajax request to gather various information about the author you clicked on, following the ajax request the following will take place:

if (isFollowing !== undefined) {
                $('.author-popup-message').append('<span class="author-popup-witness">Following you</span><br>');
            }
            // If not
            else {
                $('.author-popup-message').append('<span class="author-popup-witness">Not following you</span><br>');
            }

As you can see, upon each being returned it will append to .author-popup-message therefore for each ajax request it append a new result and this is why you will get multiple instances occuring.

This could be resolved by aborting the current request if a new request takes places. The following steps show how this could be completed.

First, we will define a new variable outside of openAuthorPopupInfo(element) and set this to null, this will look like this:

let currentRequest = null;

following this we will then assign the variable to that of the ajax request, as seen below:

// Get followers from steemSQL
    currentRequest = $.ajax({
        type: "GET",
        beforeSend: function (xhttp) {
            xhttp.setRequestHeader("Content-type", "application/json");
            xhttp.setRequestHeader("X-Parse-Application-Id", chrome.runtime.id);
        }, 

and then finally we will add an if statement into beforeSend which will check if the current request is not null and abort the current request if so. This will look like the following:

beforeSend: function (xhttp) {
            xhttp.setRequestHeader("Content-type", "application/json");
            xhttp.setRequestHeader("X-Parse-Application-Id", chrome.runtime.id);
            if (currentRequest != null) {
                currentRequest.abort();
            }
        },

The only problem with this solution is that it could take a little while to display the result in the scenario a user presses the author numerous times successively, however, in that event, the API would return a 429 and therefore you get the same experience.

The following video shows the resolution in place, before and after.


This issue has now been resolved in the following commit:

https://github.com/stoodkev/SteemPlus/commit/33b46c5846b0c892b2df960eb189b73575787c61

from the following pull request:

https://github.com/stoodkev/SteemPlus/pull/114

Proof of work

My GitHub account: https://github.com/tobias-g1
The issue has been reported here: https://github.com/stoodkev/SteemPlus/issues/116


Sort:  

Hello @tobias-g,

It's great reading your report. The way you styled it and added the resolution.

It gives me immense pleasure to Staff-pick your bug-report.

  • Correct grammar
  • A great Fix with an explanation
  • Shows that you went in depth to reduce the multiple ajax calls
  • This fix could be used outside this particular project and is valuable to other projects.

Hope you had fun contributing to this project.
Thank you!!

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

You have a minor misspelling in the following sentence:

author-popup-message` therefore for each ajax request it append a new result and this is why you will get multiple instances occuring.
It should be occurring instead of occuring.

Hey @tobias-g
Thanks for contributing on Utopian.
Congratulations! Your contribution was Staff Picked to receive a maximum vote for the bug-hunting category on Utopian for being of significant value to the project and the open source community.

We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 60309.00
ETH 2342.16
USDT 1.00
SBD 2.55