comment.go

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