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	Message string
22
23	// Creation time of the comment.
24	// Should be used only for human display, never for ordering as we can't rely on it in a distributed system.
25	unixTime timestamp.Timestamp
26}
27
28func (d *Draft) CombinedId() entity.CombinedId {
29	if d.combinedId == "" || d.combinedId == entity.UnsetCombinedId {
30		// simply panic as it would be a coding error (no id provided at construction)
31		panic("no combined id")
32	}
33	return d.combinedId
34}
35
36func (d *Draft) Author() identity.Interface {
37	return d.author
38}
39
40func (d *Draft) Title() string {
41	return d.title
42}
43
44// FormatTimeRel format the UnixTime of the comment for human consumption
45func (d *Draft) FormatTimeRel() string {
46	return humanize.Time(d.unixTime.Time())
47}
48
49func (d *Draft) FormatTime() string {
50	return d.unixTime.Time().Format("Mon Jan 2 15:04:05 2006 +0200")
51}
52
53// IsAuthored is a sign post method for gqlgen
54func (d *Draft) IsAuthored() {}