mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-22 20:59:21 +02:00
Add emojis page
This commit is contained in:
parent
967a9c954e
commit
08cc2a6ade
|
@ -63,3 +63,13 @@ func (c *Client) GetInstancePeers(ctx context.Context) ([]string, error) {
|
||||||
}
|
}
|
||||||
return peers, nil
|
return peers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetInstanceEmojis return instance emojis.
|
||||||
|
func (c *Client) GetInstanceEmojis(ctx context.Context) ([]*Emoji, error) {
|
||||||
|
var emojis []*Emoji
|
||||||
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/custom_emojis", nil, &emojis, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return emojis, nil
|
||||||
|
}
|
||||||
|
|
|
@ -97,3 +97,15 @@ func NewAboutPageTemplateData(navbarData *NavbarTemplateData) *AboutPageTemplate
|
||||||
NavbarData: navbarData,
|
NavbarData: navbarData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type EmojiPageTemplateData struct {
|
||||||
|
NavbarData *NavbarTemplateData
|
||||||
|
Emojis []*mastodon.Emoji
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmojiPageTemplateData(navbarData *NavbarTemplateData, emojis []*mastodon.Emoji) *EmojiPageTemplateData {
|
||||||
|
return &EmojiPageTemplateData{
|
||||||
|
NavbarData: navbarData,
|
||||||
|
Emojis: emojis,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ type Renderer interface {
|
||||||
RenderNotificationPage(ctx context.Context, writer io.Writer, data *NotificationPageTemplateData) (err error)
|
RenderNotificationPage(ctx context.Context, writer io.Writer, data *NotificationPageTemplateData) (err error)
|
||||||
RenderUserPage(ctx context.Context, writer io.Writer, data *UserPageTemplateData) (err error)
|
RenderUserPage(ctx context.Context, writer io.Writer, data *UserPageTemplateData) (err error)
|
||||||
RenderAboutPage(ctx context.Context, writer io.Writer, data *AboutPageTemplateData) (err error)
|
RenderAboutPage(ctx context.Context, writer io.Writer, data *AboutPageTemplateData) (err error)
|
||||||
|
RenderEmojiPage(ctx context.Context, writer io.Writer, data *EmojiPageTemplateData) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type renderer struct {
|
type renderer struct {
|
||||||
|
@ -76,6 +77,10 @@ func (r *renderer) RenderAboutPage(ctx context.Context, writer io.Writer, data *
|
||||||
return r.template.ExecuteTemplate(writer, "about.tmpl", data)
|
return r.template.ExecuteTemplate(writer, "about.tmpl", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *renderer) RenderEmojiPage(ctx context.Context, writer io.Writer, data *EmojiPageTemplateData) (err error) {
|
||||||
|
return r.template.ExecuteTemplate(writer, "emoji.tmpl", data)
|
||||||
|
}
|
||||||
|
|
||||||
func EmojiFilter(content string, emojis []mastodon.Emoji) string {
|
func EmojiFilter(content string, emojis []mastodon.Emoji) string {
|
||||||
var replacements []string
|
var replacements []string
|
||||||
for _, e := range emojis {
|
for _, e := range emojis {
|
||||||
|
|
|
@ -125,6 +125,14 @@ func (s *authService) ServeAboutPage(ctx context.Context, client io.Writer, c *m
|
||||||
return s.Service.ServeAboutPage(ctx, client, c)
|
return s.Service.ServeAboutPage(ctx, client, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *authService) ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
||||||
|
c, err = s.getClient(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.ServeEmojiPage(ctx, client, c)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *authService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
func (s *authService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -101,6 +101,14 @@ func (s *loggingService) ServeAboutPage(ctx context.Context, client io.Writer, c
|
||||||
return s.Service.ServeAboutPage(ctx, client, c)
|
return s.Service.ServeAboutPage(ctx, client, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *loggingService) ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
|
"ServeEmojiPage", time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.ServeEmojiPage(ctx, client, c)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *loggingService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
func (s *loggingService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
|
|
|
@ -34,6 +34,7 @@ type Service interface {
|
||||||
ServeNotificationPage(ctx context.Context, client io.Writer, c *model.Client, maxID string, minID string) (err error)
|
ServeNotificationPage(ctx context.Context, client io.Writer, c *model.Client, maxID string, minID string) (err error)
|
||||||
ServeUserPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error)
|
ServeUserPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error)
|
||||||
ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error)
|
ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error)
|
||||||
|
ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error)
|
||||||
Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||||
UnLike(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
UnLike(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||||
Retweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
Retweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||||
|
@ -444,6 +445,26 @@ func (svc *service) ServeAboutPage(ctx context.Context, client io.Writer, c *mod
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svc *service) ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
||||||
|
navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
emojis, err := c.GetInstanceEmojis(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := renderer.NewEmojiPageTemplateData(navbarData, emojis)
|
||||||
|
err = svc.renderer.RenderEmojiPage(ctx, client, data)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (svc *service) getNavbarTemplateData(ctx context.Context, client io.Writer, c *model.Client) (data *renderer.NavbarTemplateData, err error) {
|
func (svc *service) getNavbarTemplateData(ctx context.Context, client io.Writer, c *model.Client) (data *renderer.NavbarTemplateData, err error) {
|
||||||
notifications, err := c.GetNotifications(ctx, nil)
|
notifications, err := c.GetNotifications(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -241,6 +241,16 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
}
|
}
|
||||||
}).Methods(http.MethodGet)
|
}).Methods(http.MethodGet)
|
||||||
|
|
||||||
|
r.HandleFunc("/emojis", func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
ctx := getContextWithSession(context.Background(), req)
|
||||||
|
|
||||||
|
err := s.ServeEmojiPage(ctx, w, nil)
|
||||||
|
if err != nil {
|
||||||
|
s.ServeErrorPage(ctx, w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}).Methods(http.MethodGet)
|
||||||
|
|
||||||
r.HandleFunc("/signout", func(w http.ResponseWriter, req *http.Request) {
|
r.HandleFunc("/signout", func(w http.ResponseWriter, req *http.Request) {
|
||||||
// TODO remove session from database
|
// TODO remove session from database
|
||||||
w.Header().Add("Set-Cookie", fmt.Sprintf("session_id=;max-age=0"))
|
w.Header().Add("Set-Cookie", fmt.Sprintf("session_id=;max-age=0"))
|
||||||
|
|
|
@ -316,3 +316,22 @@
|
||||||
.post-form-field>* {
|
.post-form-field>* {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.emoji {
|
||||||
|
min-width: 220px;
|
||||||
|
display: inline-block;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.emoji-img {
|
||||||
|
height: 24px;
|
||||||
|
width: 24px;
|
||||||
|
object-fit: contain;
|
||||||
|
vertical-align: middle;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.emoji-shortcode {
|
||||||
|
vertical-align: middle;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
{{template "header.tmpl"}}
|
||||||
|
{{template "navigation.tmpl" .NavbarData}}
|
||||||
|
<div class="page-title"> Emojis </div>
|
||||||
|
|
||||||
|
<div class="emoji-list-container">
|
||||||
|
{{range .Emojis}}
|
||||||
|
<div class="emoji">
|
||||||
|
<img class="emoji-img" src="{{.URL}}" alt="{{.ShortCode}}" />
|
||||||
|
<div class="emoji-shortcode">:{{.ShortCode}}:</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{template "footer.tmpl"}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue