aboutsummaryrefslogtreecommitdiffstats
path: root/entities/bug/comment.go
blob: 99da635d0e8f3038fcc25c40de41d3b21244faac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package bug

import (
	"github.com/dustin/go-humanize"

	"github.com/git-bug/git-bug/entities/identity"
	"github.com/git-bug/git-bug/entity"
	"github.com/git-bug/git-bug/repository"
	"github.com/git-bug/git-bug/util/timestamp"
)

// Comment represent a comment in a Bug
type Comment struct {
	// combinedId should be the result of entity.CombineIds with the Bug id and the id
	// of the Operation that created the comment
	combinedId entity.CombinedId

	// targetId is the Id of the Operation that originally created that Comment
	targetId entity.Id

	Author  identity.Interface
	Message string
	Files   []repository.Hash

	// Creation time of the comment.
	// Should be used only for human display, never for ordering as we can't rely on it in a distributed system.
	unixTime timestamp.Timestamp
}

func (c Comment) CombinedId() entity.CombinedId {
	if c.combinedId == "" {
		// simply panic as it would be a coding error (no id provided at construction)
		panic("no combined id")
	}
	return c.combinedId
}

func (c Comment) TargetId() entity.Id {
	return c.targetId
}

// FormatTimeRel format the unixTime of the comment for human consumption
func (c Comment) FormatTimeRel() string {
	return humanize.Time(c.unixTime.Time())
}

func (c Comment) FormatTime() string {
	return c.unixTime.Time().Format("Mon Jan 2 15:04:05 2006 +0200")
}

// IsAuthored is a sign post method for gqlgen
func (c Comment) IsAuthored() {}