item_draft.go

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