1package bug
2
3import (
4 "github.com/dustin/go-humanize"
5
6 "github.com/MichaelMure/git-bug/entity"
7 "github.com/MichaelMure/git-bug/repository"
8 "github.com/MichaelMure/git-bug/util/timestamp"
9)
10
11// Comment represent a comment in a Bug
12type Comment struct {
13 // combinedId should be the result of entity.CombineIds with the Bug id and the id
14 // of the Operation that created the comment
15 combinedId entity.CombinedId
16
17 // targetId is the Id of the Operation that originally created that Comment
18 targetId entity.Id
19
20 Author entity.Identity
21 Message string
22 Files []repository.Hash
23
24 // Creation time of the comment.
25 // Should be used only for human display, never for ordering as we can't rely on it in a distributed system.
26 unixTime timestamp.Timestamp
27}
28
29func (c Comment) CombinedId() entity.CombinedId {
30 if c.combinedId == "" {
31 // simply panic as it would be a coding error (no id provided at construction)
32 panic("no combined id")
33 }
34 return c.combinedId
35}
36
37func (c Comment) TargetId() entity.Id {
38 return c.targetId
39}
40
41// FormatTimeRel format the unixTime of the comment for human consumption
42func (c Comment) FormatTimeRel() string {
43 return humanize.Time(c.unixTime.Time())
44}
45
46func (c Comment) FormatTime() string {
47 return c.unixTime.Time().Format("Mon Jan 2 15:04:05 2006 +0200")
48}
49
50// IsAuthored is a sign post method for gqlgen
51func (c Comment) IsAuthored() {}