api/frontend/src/models/taskComment.ts
kolaente a5c51d4b1e feat: emoji reactions for tasks and comments (#2196)
This PR adds reactions for tasks and comments, similar to what you can do on Gitea, GitHub, Slack and plenty of other tools.

Reviewed-on: vikunja/vikunja#2196
Co-authored-by: kolaente <k@knt.li>
Co-committed-by: kolaente <k@knt.li>
2024-03-12 19:25:58 +00:00

34 lines
919 B
TypeScript

import AbstractModel from './abstractModel'
import UserModel from './user'
import type {ITaskComment} from '@/modelTypes/ITaskComment'
import type {ITask} from '@/modelTypes/ITask'
import type {IUser} from '@/modelTypes/IUser'
export default class TaskCommentModel extends AbstractModel<ITaskComment> implements ITaskComment {
id = 0
taskId: ITask['id'] = 0
comment = ''
author: IUser = UserModel
reactions = {}
created: Date = null
updated: Date = null
constructor(data: Partial<ITaskComment> = {}) {
super()
this.assignData(data)
this.author = new UserModel(this.author)
this.created = new Date(this.created)
this.updated = new Date(this.updated)
// We can't convert emojis to camel case, hence we do this manually
this.reactions = {}
Object.keys(data.reactions || {}).forEach(reaction => {
this.reactions[reaction] = data.reactions[reaction].map(u => new UserModel(u))
})
}
}