Add option to sort comments

Hello,

I’d like to propose an option to sort the comments on tasks.
Currently, the oldest comment is on the top and the newest at the bottom.

This is exactly the opposite as what we are used from trello.
Because we have many comments on tasks, scrolling to the bottom just to get the lastest update is cumbersome .

I’d propose adding a config value where these comments can be sorted either “asc” or “desc” by the time they were added.

I did not dig deeply into the code, but would it be sufficient to add a “sort by” statement here?

2 Likes

Changing this line vikunja/task_comments.go at a48ad6c9e1c03d101963bd5b477f70dc97670016 - vikunja - Gitea

to OrderBy(“task_comments.created desc”) orders the comments descending when the task is opened.
A config value foe either “asc” or “desc” should be simple to add.

However, when a comment is added, it is still added to the end of the list. So there is still a piece (probable in the frontend code) I am missing.

This seems to be the required part:

This should be changed to unshift() depending on asc or desc setting.

I like the idea, but this should be a user setting, not a global one.

I can see your point, but manually guiding all users to change this setting is not an option for us.
We migrated from Trello, so basically all users expect the comments to be in the other order.
Couldn’t it be both? Default value set in the config but overridable by the user?

1 Like

@kolaente If this gets implemented, is it somehow possible to also change the position of the editor to add new comments?
F.e. if the comments are newest to oldest it would make sense to also place the editor to add new comments to the top.

I am unfortunately not really familiar with vuejs, what could be the nicest way to achieve this (without duplicating html code)?

I tried adressing this issue as a user setting.

A simple solution I came up with was to simply add a computated value

<div
    v-for="c in orderedComments"
    :key="c.id"
    class="media comment"
>

const orderedComments = computed(() => {
	if (props.order === 'asc') {
      return comments.value;
    } else if (props.order === 'desc') {
      return comments.value.slice().reverse();
    }
})

It’s not the nicest possible solution but a quick and effective one.
Would you accept a pull request like this or is this style unprefered?

I’d rather sort the comments on the server only. Then the change would amount to passing the order set in the settings here, when loading the comments (via the authStore) and honoring the parameter here in the api.

@kolaente Do you want to append the api path like this
/tasks/:task/comments/:order
where order might be “asc” or “desc”?

Or passing the order as a param:
comments.value = await taskCommentService.getAll({taskId}, {order: order})

I may need some hints on how to adapt the ReadAll() function inside task_comments.go.

I tried to simply add the order param to the function

func (tc *TaskComment) ReadAll(s *xorm.Session, auth web.Auth, search string, page int, perPage int, order string) (result interface{}, resultCount int, numberOfTotalItems int64, err error)

but this results in errors for the web/handler as ReadAll does not any more follow the pattern

want ReadAll(*xorm.Session, web.Auth, string, int, int) (interface{}, int, int64, error)

I implemented the frontend stuff here: andileni/vikunja: The to-do app to organize your life. Public API Roadmap here: - vikunja - Gitea

I would add this as a query parameter, similar to how sorting works for tasks (look for the TaskCollection). Parameters with the query tag in Go structs are bound automatically.

@kolaente Thanks, I think I got it working.
Should I create a pull request or you you want to take a look at my repo first? andileni/vikunja: The to-do app to organize your life. Public API Roadmap here: - vikunja - Gitea

Please create a PR, makes it easier to review.

Done: #2307 - User setting to sort comments - vikunja - Gitea