1package bug
 2
 3import (
 4	"github.com/dustin/go-humanize"
 5
 6	"github.com/MichaelMure/git-bug/entity"
 7	"github.com/MichaelMure/git-bug/identity"
 8	"github.com/MichaelMure/git-bug/repository"
 9	"github.com/MichaelMure/git-bug/util/timestamp"
10)
11
12// Comment represent a comment in a Bug
13type Comment struct {
14	id      entity.Id
15	Author  identity.Interface
16	Message string
17	Files   []repository.Hash
18
19	// Creation time of the comment.
20	// Should be used only for human display, never for ordering as we can't rely on it in a distributed system.
21	UnixTime timestamp.Timestamp
22}
23
24// Id return the Comment identifier
25func (c Comment) Id() entity.Id {
26	if c.id == "" {
27		// simply panic as it would be a coding error
28		// (using an id of an identity not stored yet)
29		panic("no id yet")
30	}
31	return c.id
32}
33
34// FormatTimeRel format the UnixTime of the comment for human consumption
35func (c Comment) FormatTimeRel() string {
36	return humanize.Time(c.UnixTime.Time())
37}
38
39func (c Comment) FormatTime() string {
40	return c.UnixTime.Time().Format("Mon Jan 2 15:04:05 2006 +0200")
41}
42
43// Sign post method for gqlgen
44func (c Comment) IsAuthored() {}