Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Failed to send thanks" notification, but thank actually sent successfully #3559

Closed
nicolas-raoul opened this issue Mar 21, 2020 · 13 comments · Fixed by #4202
Closed

"Failed to send thanks" notification, but thank actually sent successfully #3559

nicolas-raoul opened this issue Mar 21, 2020 · 13 comments · Fixed by #4202

Comments

@nicolas-raoul
Copy link
Member

Steps to reproduce:

  • Compile and run latest master.
  • Tap "Review"
  • If the picture is good, tap to end a thank
  • See notification, it says "Failed to send thanks"

Example:
Screenshot_20200321-162122_Commons

Even though the thank has actually been sent successfully:
Screen Shot 2020-03-21 at 16 38 03

@sivaraam
Copy link
Member

I've seen this too.

@gupta-anmol
Copy link
Contributor

Can I try to work on this?

I was able to reproduce this issue for betaDebug. I observed that we get the same failure notification when the thanks is recorded and when it actually fails (I did this by turning off the WiFi just before sending thanks).

@nicolas-raoul
Copy link
Member Author

@6point022 Yes it's yours! Please use "prodDebug" instead. Thanks :-)

@gupta-anmol
Copy link
Contributor

gupta-anmol commented Mar 21, 2020

I'll really appreciate some help with this.

This is from the ThankClient.java file

/**
* Handles the Thanking logic
* @param revesionID The revision ID you would like to thank someone for
* @return if thanks was successfully sent to intended recepient, returned as a boolean observable
*/

public Observable<Boolean> thank(long revisionId) {
        try {
            return service.thank(String.valueOf(revisionId), null,
                csrfTokenClient.getTokenBlocking(),
                CommonsApplication.getInstance().getUserAgent())
                .map(mwQueryResponse -> mwQueryResponse.getSuccessVal() == 1);;
        } catch (Throwable throwable) {
            Log.d("Thanked", "Inside throwable");
            return Observable.just(false);
        }
    }

I tried to see what getSuccessVal() will return.

public class MwPostResponse extends MwResponse {
    @Nullable @SuppressWarnings("unused") private String options;
    @SuppressWarnings("unused") private int success;

    public boolean success(@Nullable String result) {
        return "success".equals(result);
    }

    @Nullable public String getOptions() {
        return options;
    }

    public int getSuccessVal() {
        return success;
    }
}

I could be way off here (I am just learning!!), but I think the reason for failure could be that it is actually returning 0, since the default value of success will be 0 and we are never initialising it to anything else. So, in ThankClient.java, Instead of checking the returned value for 1, we should check for 0. Does this seem correct?

@sivaraam
Copy link
Member

@6point022 It's a good thing you shared your doubts here :) I'm not so familiar with the code base but I'll share my views here assuming others will correct me if I'm wrong.

... but I think the reason for failure could be that it is actually returning 0, since the default value of success will be 0 and we are never initialising it to anything else

You won't find the code that initializes the value of success anywhere in the app or in the data-client library. It's automatically set when you receive the response for the query (I believe it's done by Retrofit). So, don't worry about the value not being initialized. It would be :)

I think you're in the right track, though. If I were to just go by the example pointed to by the API page, the value of success would be 1 for a successful thank. But the example might be outdated or there might be other values that indicate success. So, I would suggest that you check for what values of success we're incorrectly getting the thank failed notification.

Hope this helps.

@gupta-anmol
Copy link
Contributor

@sivaraam Thanks a lot for the response. ^_^

So, I would suggest that you check for what values of success we're incorrectly getting the thank failed notification.

So, I checked for two cases.

  1. When the thanks is sent successfully, getSuccessVal() returns 0, and we're checking for a 1. This is the reason for the incorrect notification.
  2. I tried to generate a failure by turning off the phone's WiFi before sending the thanks. In this case, we actually get a throwable and move into the catch block and get the correct notification.

Can you help me understand in what case getSuccessVal() could return a number other than 0, and how to check for them? Also, is it safe to assume that it will only return 0 when there's a success?

@sivaraam
Copy link
Member

When the thanks is sent successfully, getSuccessVal() returns 0, and we're checking for a 1. This is the reason for the incorrect notification.

How do you know that the thank succeeded? Did you check the thank log (Special:Log?type=thanks) of the corresponding wiki? I just tried using the API sandbox and could see that the value of success is 1 for a successful thank:

image

I tried to generate a failure by turning off the phone's WiFi before sending the thanks. In this case, we actually get a throwable and move into the catch block and get the correct notification.

Well, that's what would happen when the app could not connect to the network. But we're actually interested in a different kind of failure here. We have to send a request that reaches the server and the server would respond to us indicating that for some reason the server could not complete the request. It's easier to check that via the API:Sandbox. You can try a thank API request using the following link. Make sure you're logged in before you visit the link.

https://commons.wikimedia.org/wiki/Special:ApiSandbox#action=thank&format=json

I'm not sure for what cases we would be able to see a different value for success though.

Can you help me understand in what case getSuccessVal() could return a number other than 0, and how to check for them?

Ideally it should be present in the API documentation. Unfortunately, the API page doesn't help us here as it doesn't have an exhaustive list of values that success could have.

Also, is it safe to assume that it will only return 0 when there's a success?

It doesn't seem to be returning 0 on success as you could see from the API response above. But if we do get 0 for getSuccessVal() then I think the issue is somewhere else and we would have to figure it out. My knowledge is limited. We'll see if @maskaravivek, @ashishkumar468 or @misaochan could help us here.

I'll just note one thing I observed when checking for this. I was checking if the Wikipedia app (which also uses the data client library albeit a different version, I suppose) was correctly receiving the success value correctly in a MwPostResponse object. I observed that it was indeed getting the value appropriately (MwPostResponse#getSuccessVal() returns 1). Beware that I was checking the response of a different API query [1] [2] and NOT the response of a thank API query.

@gupta-anmol
Copy link
Contributor

Thanks a lot for taking out the time to explain, it's really helpful. 😄

How do you know that the thank succeeded? Did you check the thank log (Special:Log?type=thanks) of the corresponding wiki?

Yes, I checked the thank log and if the thank appeared in it, I considered it a success. If the thank is successful, the value of success returned by getSuccessVal() is actually 0, and not 1.

But if we do get 0 for getSuccessVal() then I think the issue is somewhere else and we would have to figure it out. My knowledge is limited.

Even I am not sure how to proceed from here. Let's see if someone else can help us. :)

@Daykeras
Copy link

Daykeras commented Sep 20, 2020

I'd like to try my hand at figuring out what's going on.

Edit: Actually, there seem to be a lot of bugs involving the JSON being sent to the API. I just noticed that there are other tickets reporting that number of Thanks is also returning 0. I suspect these are related issues.

@misaochan
Copy link
Member

Please feel free, @Daykeras !

@Prince-kushwaha
Copy link
Contributor

can i work on this issue

@Daykeras
Copy link

Daykeras commented Jan 21, 2021 via email

@Prince-kushwaha
Copy link
Contributor

ok

neslihanturan pushed a commit that referenced this issue Feb 8, 2021
…ly sent successfully

I create another Model Class->"MwThankPostResponse.java" to store the Result of Post Request POST(MW_API_PREFIX+"action=thank")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants