kusold / todoist-habitrpg

One way sync from Todoist -> HabitRPG
120 stars 14 forks source link

completed To-Dos are not given a dateCompleted value #32

Closed Alys closed 9 years ago

Alys commented 9 years ago

I am not certain this issue is being caused by todoist-habitrpg, but I think it's likely based on this conversation with @cygnoir.

The issue is that some To-Dos that have been marked as completed do not have a dateCompleted attribute. Every completed To-Do should be given this attribute and its value should be the time at which the To-Do was ticked off. If a completed To-Do is later marked as uncompleted, the attribute needs to be removed.

This is important because HabitRPG uses the dateCompleted value to determine when a To-Do should be archived (currently, three days after completion; and archived To-Dos are not included amongst those shown in the browser). Without this information, all the user's completed To-Dos will keep on appearing in the user's completed To-Do tab and the browser performance will get worse and worse over time as the number of tasks increases.

Here is a full example of a completed To-Do:

        {
            "text": ":red_circle: Tidying: bathroom: +1",
            "dateCompleted": "2015-01-12T11:01:44.148Z",
            "challenge": {},
            "attribute": "str",
            "priority": 1,
            "value": 1,
            "tags": {
                "50155ebc-26d5-4e2f-8f23-38a518399ff1": true
            },
            "notes": "",
            "dateCreated": "2015-01-11T21:18:30.197Z",
            "id": "9616f71a-a3ec-4d7c-878e-501e16671c7a",
            "checklist": [],
            "collapseChecklist": false,
            "completed": true,
            "type": "todo"
        },

Could you please check todoist-habitrpg to see if it is causing this issue? If it is, could you please adjust the module?

Also, if todoist-habitrpg is causing this, do you have any way of reliably fixing all existing completed To-Dos for all your users so that they are all given a dateCompleted value? Please tell me if you are not able to do that so that I can write a script to modify the tasks in HabitRPG's own database. Obviously, the dateCompleted value you/I give to the tasks won't be accurate, but it would be enough to give it a value for the current date and time.

crookedneighbor commented 9 years ago

I can confirm that todoist-habitrpg does not specifically designate a dateCompleted attribute: here is the object for a task saved in my .todoist-history file (each task has a todoist object and a habitrpg object):

     "26240534":{  
         "todoist":{  
            "due_date":null,
            "day_order":-1,
            "assigned_by_uid":2094081,
            "is_archived":0,
            "labels":[  

            ],
            "sync_id":null,
            "in_history":1,
            "has_notifications":0,
            "indent":1,
            "checked":1,
            "date_added":"Sun 24 Aug 2014 21:27:20 +0000",
            "id":26240534,
            "content":"Jonathan Strange and Mr. Norrel",
            "user_id":2094081,
            "due_date_utc":null,
            "children":null,
            "priority":1,
            "item_order":12,
            "is_deleted":0,
            "responsible_uid":null,
            "project_id":123744352,
            "collapsed":0,
            "date_string":""
         },
         "habitrpg":{  
            "text":"Jonathan Strange and Mr. Norrel",
            "challenge":{  

            },
            "attribute":"str",
            "priority":1,
            "value":-11.3598999082337,
            "tags":{  

            },
            "notes":"",
            "dateCreated":"2014-08-24T21:27:20.000Z",
            "id":"d5e582a7-2260-418e-8dc9-21e722085f3a",
            "checklist":[  

            ],
            "collapseChecklist":false,
            "completed":true,
            "type":"todo"
         }
      }

And here is the object for the same task from the habitrpg api:

{
  "text": "Jonathan Strange and Mr. Norrel",
  "dateCompleted": "2014-12-08T06:00:04.375Z",
  "challenge": {},
  "attribute": "str",
  "priority": 1,
  "value": -10.021996649406402,
  "tags": {},
  "notes": "",
  "dateCreated": "2014-08-24T21:27:20.000Z",
  "id": "d5e582a7-2260-418e-8dc9-21e722085f3a",
  "checklist": [],
  "collapseChecklist": false,
  "completed": true,
  "type": "todo"
}

So the dateCompleted attribute does get applied somewhere, in the scoring mechanism here, in this line in the shared repo. The scoring method is invoked here in the todoist module. Should score up if task is completed, and score down if task was completed and is now not completed.

If I'm reading it correctly, according to the coffeescript file in shared, if a todo is scored up, it should have a dateCompleted date set. If it's scored down (unchecked), dateCompleted should be set to undefined.

I don't see anything obvious in the todoist module code that would be causing these todos to be marked as completed, but not send the score, which is the only way I can think of for a todo to be completed and not have a dateCompleted attribute. It'd probably be a good idea regardless to set a dateCompleted attribute and just let it be overwritten by the scoring mechanism.

For my reference later, here is the line where todos are archived after 3 days.

kusold commented 9 years ago

Can I get confirmation that my PR will fix this issue? Also, I haven't come up with a clean migration idea for old tasks. I'm open to any ideas before having the HabitRPG admins create a script to clean up this mistake.

Alys commented 9 years ago

I'm not able to confirm if it will fix the issue because for a proper test I'd need to install your code locally, get it running, etc and I'm afraid I don't have time. Can you test it locally? Use (I assume) Todoist to complete a To-Do, sync to HabitRPG, and examine the effect on that To-Do using the HabitRPG API. Then use HabitRPG itself to complete a To-Do and examine the effect. If the two effects are identical (with slight differences in the time completed, obviously), then the code is probably good. Also repeat both tests for marking the To-Dos as uncompleted, and ensure the effects are identical.

Fixing old tasks would mean, probably, a function in your sync module that is automatically executed for all users using the module. It would read all of their completed To-Dos and assign dateCompleted values to any that did not already have a value.