Using the API's route for scoring a task (https://habitica.com/api/v3/tasks/:taskId/score/:direction ), you can mark a Daily or To-Do complete multiple times (i.e., without toggling it back to incomplete each time).
If you test it, you see that all the effects of completing the task are applied each time: you gain XP for each completion, the task's value changes each time, for Dailies, the streak increases, etc.
Similarly, you can score a task down (mark it as incomplete) when it is already incomplete.
You can also test this bug by opening the website in two tabs, completing the same task in both, and then syncing to see that your XP has increased twice (the second gain in XP is not removed after syncing). A Daily is the best thing to use for this because then you can also see the streak increase by two.
I think the best fix for this would be for the API's score route to check to see if the task is complete / uncomplete and not allow the score to happen if it's not appropriate. I.e., if the task is complete, you cannot score up; if the task is uncompleted, you cannot score down.
Any change made for this should NOT affect Habits or Rewards, for which multiple scores in the same direction are appropriate.
I think this has something to do with the scoreTask() function. How could I check if a task is completed? Do I query a database, or does the task variable passed to the function have something that would let me know that?
There is a completed field and there is task history :D
Ok, thanks! I will get working on that!
How do you make a new notification message?
Many ways. What kind of notification are you wanting to create?
I'm trying to make a notification similar to the ones that say you got experience or gold. I want to create an alert that would tell the user that the task has already been checked off.
@JacksonCoder It might be better to force a sync if the session is stale, rather than just displaying a message. That way, the user would still see the +XP and +Gold notifications as a result of the click, which is in line with expected behavior.
@JacksonCoder This is the service you would use: https://github.com/HabitRPG/habitica/blob/develop/website/client-old/js/services/notificationServices.js. The _notify function creates the popups.
Although, I believe Alys suggested the fix for this be on the server side. So you will want to check for completion here: https://github.com/HabitRPG/habitica/blob/develop/website/server/controllers/api-v3/tasks.js#L511
@khipkin suggestion of syncing might also be helpful.
@TheHollidayInn I am already making the fix on the server side in the file you specified, but I needed a way to communicate to the user that the session is outdated. However, @khipkin had a good suggestion, and I probably should just force-sync the session. However, how can I sync the webpage with the server if the code is in the backend?
In the UserService there is a sync function that should handle user and task syncing.
@TheHollidayInn I'll get working on implementing that.
Should I request a sync when the scoreTask call returns an specific error? Should I make my own error class, (SyncError), that would prompt the front end to reload?
I would use NotAuthroized or BadRequest on the server
I made a pull request for this issue. Let me know if I need to change anything.
@JacksonCoder are you working on this right now? If not, I would like to give it a try
@asifmallik Please go ahead if you're still interested in working on this.
Most helpful comment
@JacksonCoder It might be better to force a sync if the session is stale, rather than just displaying a message. That way, the user would still see the +XP and +Gold notifications as a result of the click, which is in line with expected behavior.