diff options
Diffstat (limited to 'renderer')
-rw-r--r-- | renderer/model.go | 22 | ||||
-rw-r--r-- | renderer/renderer.go | 14 |
2 files changed, 27 insertions, 9 deletions
diff --git a/renderer/model.go b/renderer/model.go index 4ff73c3..842dd71 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -31,6 +31,15 @@ type CommonData struct { NavbarData *NavbarData } +func (c CommonData) IsCurrentUser(id string) bool { + if c.NavbarData != nil && + c.NavbarData.User != nil && + c.NavbarData.User.ID == id { + return true + } + return false +} + type ErrorData struct { *CommonData Error string @@ -69,12 +78,13 @@ type NotificationData struct { type UserData struct { *CommonData - User *mastodon.Account - Type string - Users []*mastodon.Account - Statuses []*mastodon.Status - NextLink string - DarkMode bool + User *mastodon.Account + IsCurrent bool + Type string + Users []*mastodon.Account + Statuses []*mastodon.Status + NextLink string + DarkMode bool } type UserSearchData struct { diff --git a/renderer/renderer.go b/renderer/renderer.go index 0eb229c..bd9ccd8 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -43,6 +43,7 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) { "StatusContentFilter": StatusContentFilter, "DisplayInteractionCount": DisplayInteractionCount, "TimeSince": TimeSince, + "TimeUntil": TimeUntil, "FormatTimeRFC3339": FormatTimeRFC3339, "FormatTimeRFC822": FormatTimeRFC822, "WithContext": WithContext, @@ -86,7 +87,7 @@ func (r *renderer) RenderUserPage(ctx *Context, writer io.Writer, return r.template.ExecuteTemplate(writer, "user.tmpl", WithContext(data, ctx)) } -func (r *renderer) RenderUserSearchPage(ctx *Context, writer io.Writer, +func (r *renderer) RenderUserSearchPage(ctx *Context, writer io.Writer, data *UserSearchData) (err error) { return r.template.ExecuteTemplate(writer, "usersearch.tmpl", WithContext(data, ctx)) } @@ -158,8 +159,7 @@ func DisplayInteractionCount(c int64) string { return "" } -func TimeSince(t time.Time) string { - dur := time.Since(t) +func DurToStr(dur time.Duration) string { s := dur.Seconds() if s < 60 { return strconv.Itoa(int(s)) + "s" @@ -184,6 +184,14 @@ func TimeSince(t time.Time) string { return strconv.Itoa(int(y)) + "y" } +func TimeSince(t time.Time) string { + return DurToStr(time.Since(t)) +} + +func TimeUntil(t time.Time) string { + return DurToStr(time.Until(t)) +} + func FormatTimeRFC3339(t time.Time) string { return t.Format(time.RFC3339) } |