2018-07-12 13:44:46 +03:00
|
|
|
package bug
|
|
|
|
|
2018-07-19 19:10:45 +03:00
|
|
|
import (
|
2020-07-01 20:39:02 +03:00
|
|
|
"github.com/dustin/go-humanize"
|
|
|
|
|
2019-08-11 15:08:03 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entity"
|
2018-11-21 20:56:12 +03:00
|
|
|
"github.com/MichaelMure/git-bug/identity"
|
2020-07-01 20:39:02 +03:00
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
2019-02-25 01:05:03 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/timestamp"
|
2018-07-19 19:10:45 +03:00
|
|
|
)
|
2018-07-17 21:51:09 +03:00
|
|
|
|
2018-08-13 16:28:16 +03:00
|
|
|
// Comment represent a comment in a Bug
|
2018-07-12 13:44:46 +03:00
|
|
|
type Comment struct {
|
2019-08-11 15:08:03 +03:00
|
|
|
id entity.Id
|
2018-11-21 20:56:12 +03:00
|
|
|
Author identity.Interface
|
2018-08-01 03:15:40 +03:00
|
|
|
Message string
|
2020-07-01 20:39:02 +03:00
|
|
|
Files []repository.Hash
|
2018-07-14 23:18:40 +03:00
|
|
|
|
|
|
|
// 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.
|
2019-02-25 01:05:03 +03:00
|
|
|
UnixTime timestamp.Timestamp
|
2018-07-12 13:44:46 +03:00
|
|
|
}
|
2018-07-17 21:51:09 +03:00
|
|
|
|
2019-03-28 03:21:41 +03:00
|
|
|
// Id return the Comment identifier
|
2019-08-11 15:08:03 +03:00
|
|
|
func (c Comment) Id() entity.Id {
|
2019-03-28 03:21:41 +03:00
|
|
|
if c.id == "" {
|
|
|
|
// simply panic as it would be a coding error
|
|
|
|
// (using an id of an identity not stored yet)
|
|
|
|
panic("no id yet")
|
|
|
|
}
|
|
|
|
return c.id
|
|
|
|
}
|
|
|
|
|
2018-09-15 21:30:31 +03:00
|
|
|
// FormatTimeRel format the UnixTime of the comment for human consumption
|
|
|
|
func (c Comment) FormatTimeRel() string {
|
2018-09-30 12:00:39 +03:00
|
|
|
return humanize.Time(c.UnixTime.Time())
|
2018-07-17 21:51:09 +03:00
|
|
|
}
|
2018-09-15 21:30:31 +03:00
|
|
|
|
|
|
|
func (c Comment) FormatTime() string {
|
2018-09-30 12:00:39 +03:00
|
|
|
return c.UnixTime.Time().Format("Mon Jan 2 15:04:05 2006 +0200")
|
2018-09-15 21:30:31 +03:00
|
|
|
}
|
2018-12-23 19:11:37 +03:00
|
|
|
|
|
|
|
// Sign post method for gqlgen
|
|
|
|
func (c Comment) IsAuthored() {}
|