From 816281c225e1d07602aa4f6d87d5ffbbc8dfbb7a Mon Sep 17 00:00:00 2001 From: r Date: Sun, 5 Sep 2021 17:17:59 +0000 Subject: Add quick reply --- service/service.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ service/transport.go | 17 ++++++++++++++-- 2 files changed, 71 insertions(+), 2 deletions(-) (limited to 'service') diff --git a/service/service.go b/service/service.go index d548342..03f0ff3 100644 --- a/service/service.go +++ b/service/service.go @@ -321,6 +321,62 @@ func (s *service) ThreadPage(c *client, id string, reply bool) (err error) { return s.renderer.Render(c.rctx, c.w, renderer.ThreadPage, data) } +func (s *service) QuickReplyPage(c *client, id string) (err error) { + status, err := c.GetStatus(c.ctx, id) + if err != nil { + return + } + + var ancestor *mastodon.Status + if status.InReplyToID != nil { + ancestor, err = c.GetStatus(c.ctx, status.InReplyToID.(string)) + if err != nil { + return + } + } + + var content string + if c.s.UserID != status.Account.ID { + content += "@" + status.Account.Acct + " " + } + for i := range status.Mentions { + if status.Mentions[i].ID != c.s.UserID && + status.Mentions[i].ID != status.Account.ID { + content += "@" + status.Mentions[i].Acct + " " + } + } + + var visibility string + isDirect := status.Visibility == "direct" + if isDirect || c.s.Settings.CopyScope { + visibility = status.Visibility + } else { + visibility = c.s.Settings.DefaultVisibility + } + + pctx := model.PostContext{ + DefaultVisibility: visibility, + DefaultFormat: c.s.Settings.DefaultFormat, + Formats: s.postFormats, + ReplyContext: &model.ReplyContext{ + InReplyToID: id, + InReplyToName: status.Account.Acct, + QuickReply: true, + ReplyContent: content, + ForceVisibility: isDirect, + }, + } + + cdata := s.cdata(c, "post by "+status.Account.DisplayName, 0, 0, "") + data := &renderer.QuickReplyData{ + Ancestor: ancestor, + Status: status, + PostContext: pctx, + CommonData: cdata, + } + return s.renderer.Render(c.rctx, c.w, renderer.QuickReplyPage, data) +} + func (s *service) LikedByPage(c *client, id string) (err error) { likers, err := c.GetFavouritedBy(c.ctx, id, nil) if err != nil { diff --git a/service/transport.go b/service/transport.go index f448cc3..42b371a 100644 --- a/service/transport.go +++ b/service/transport.go @@ -177,6 +177,11 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return s.ThreadPage(c, id, len(reply) > 1) }, SESSION, HTML) + quickReplyPage := handle(func(c *client) error { + id, _ := mux.Vars(c.r)["id"] + return s.QuickReplyPage(c, id) + }, SESSION, HTML) + likedByPage := handle(func(c *client) error { id, _ := mux.Vars(c.r)["id"] return s.LikedByPage(c, id) @@ -263,6 +268,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { format := c.r.FormValue("format") visibility := c.r.FormValue("visibility") isNSFW := c.r.FormValue("is_nsfw") == "true" + quickReply := c.r.FormValue("quickreply") == "true" files := c.r.MultipartForm.File["attachments"] id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, files) @@ -270,9 +276,15 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return err } - location := c.r.FormValue("referrer") + var location string if len(replyToID) > 0 { - location = "/thread/" + replyToID + "#status-" + id + if quickReply { + location = "/quickreply/" + id + "#status-" + id + } else { + location = "/thread/" + replyToID + "#status-" + id + } + } else { + location = c.r.FormValue("referrer") } redirect(c, location) return nil @@ -626,6 +638,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/timeline/{type}", timelinePage).Methods(http.MethodGet) r.HandleFunc("/timeline", defaultTimelinePage).Methods(http.MethodGet) r.HandleFunc("/thread/{id}", threadPage).Methods(http.MethodGet) + r.HandleFunc("/quickreply/{id}", quickReplyPage).Methods(http.MethodGet) r.HandleFunc("/likedby/{id}", likedByPage).Methods(http.MethodGet) r.HandleFunc("/retweetedby/{id}", retweetedByPage).Methods(http.MethodGet) r.HandleFunc("/notifications", notificationsPage).Methods(http.MethodGet) -- cgit v1.2.3 From 7d389d22581cc785005a42d655eb7f9c32aac3ec Mon Sep 17 00:00:00 2001 From: r Date: Sat, 23 Oct 2021 13:41:41 +0000 Subject: Show signin button in case of an auth error --- service/service.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'service') diff --git a/service/service.go b/service/service.go index 03f0ff3..244fd81 100644 --- a/service/service.go +++ b/service/service.go @@ -114,7 +114,8 @@ func (s *service) ErrorPage(c *client, err error, retry bool) error { var sessionErr bool if err != nil { errStr = err.Error() - if err == errInvalidSession || err == errInvalidCSRFToken { + if me, ok := err.(mastodon.Error); ok && me.IsAuthError() || + err == errInvalidSession || err == errInvalidCSRFToken { sessionErr = true } } -- cgit v1.2.3 From 4d68062f2d0525a9d2a40e50d60ea9b25daae9ad Mon Sep 17 00:00:00 2001 From: r Date: Fri, 29 Oct 2021 14:20:15 +0000 Subject: Add "mute (keep notifications)" button --- service/service.go | 4 ++-- service/transport.go | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'service') diff --git a/service/service.go b/service/service.go index 244fd81..7122666 100644 --- a/service/service.go +++ b/service/service.go @@ -907,8 +907,8 @@ func (s *service) Reject(c *client, id string) (err error) { return c.FollowRequestReject(c.ctx, id) } -func (s *service) Mute(c *client, id string) (err error) { - _, err = c.AccountMute(c.ctx, id) +func (s *service) Mute(c *client, id string, notifications *bool) (err error) { + _, err = c.AccountMute(c.ctx, id, notifications) return } diff --git a/service/transport.go b/service/transport.go index 42b371a..a7912e6 100644 --- a/service/transport.go +++ b/service/transport.go @@ -406,7 +406,13 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { mute := handle(func(c *client) error { id, _ := mux.Vars(c.r)["id"] - err := s.Mute(c, id) + q := c.r.URL.Query() + var notifications *bool + if r, ok := q["notifications"]; ok && len(r) > 0 { + notifications = new(bool) + *notifications = r[0] == "true" + } + err := s.Mute(c, id, notifications) if err != nil { return err } -- cgit v1.2.3 From db29c3d87404677c9c02f62097d8a0307cd8d5da Mon Sep 17 00:00:00 2001 From: r Date: Mon, 13 Dec 2021 13:58:15 +0000 Subject: Add an option to hide unsupported notifications --- service/service.go | 17 ++++++++++++++--- service/transport.go | 24 +++++++++++++----------- 2 files changed, 27 insertions(+), 14 deletions(-) (limited to 'service') diff --git a/service/service.go b/service/service.go index 7122666..9cad731 100644 --- a/service/service.go +++ b/service/service.go @@ -410,18 +410,29 @@ func (s *service) NotificationPage(c *client, maxID string, var nextLink string var unreadCount int var readID string - var excludes []string + var includes, excludes []string var pg = mastodon.Pagination{ MaxID: maxID, MinID: minID, Limit: 20, } + if c.s.Settings.HideUnsupportedNotifs { + // Explicitly include the supported types. + // For now, only Pleroma supports this option, Mastadon + // will simply ignore the unknown params. + includes = []string{"follow", "follow_request", "mention", "reblog", "favourite"} + + // Explicitly exclude the unsupported types. + // Pleroma prioritizes includes over excludes, but we + // still specify excludes to make it work with Mastadon. + excludes = []string{"poll"} + } if c.s.Settings.AntiDopamineMode { - excludes = []string{"follow", "favourite", "reblog"} + excludes = append(excludes, "follow", "favourite", "reblog") } - notifications, err := c.GetNotifications(c.ctx, &pg, excludes) + notifications, err := c.GetNotifications(c.ctx, &pg, includes, excludes) if err != nil { return } diff --git a/service/transport.go b/service/transport.go index a7912e6..615fe2a 100644 --- a/service/transport.go +++ b/service/transport.go @@ -481,20 +481,22 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { fluorideMode := c.r.FormValue("fluoride_mode") == "true" darkMode := c.r.FormValue("dark_mode") == "true" antiDopamineMode := c.r.FormValue("anti_dopamine_mode") == "true" + hideUnsupportedNotifs := c.r.FormValue("hide_unsupported_notifs") == "true" css := c.r.FormValue("css") settings := &model.Settings{ - DefaultVisibility: visibility, - DefaultFormat: format, - CopyScope: copyScope, - ThreadInNewTab: threadInNewTab, - HideAttachments: hideAttachments, - MaskNSFW: maskNSFW, - NotificationInterval: ni, - FluorideMode: fluorideMode, - DarkMode: darkMode, - AntiDopamineMode: antiDopamineMode, - CSS: css, + DefaultVisibility: visibility, + DefaultFormat: format, + CopyScope: copyScope, + ThreadInNewTab: threadInNewTab, + HideAttachments: hideAttachments, + MaskNSFW: maskNSFW, + NotificationInterval: ni, + FluorideMode: fluorideMode, + DarkMode: darkMode, + AntiDopamineMode: antiDopamineMode, + HideUnsupportedNotifs: hideUnsupportedNotifs, + CSS: css, } err := s.SaveSettings(c, settings) -- cgit v1.2.3 From 556a87e8e81025559d6009293b1aa4fca4371677 Mon Sep 17 00:00:00 2001 From: r Date: Mon, 13 Dec 2021 14:31:20 +0000 Subject: Remove poll type from notification exclude --- service/service.go | 5 ----- 1 file changed, 5 deletions(-) (limited to 'service') diff --git a/service/service.go b/service/service.go index 9cad731..8297764 100644 --- a/service/service.go +++ b/service/service.go @@ -422,11 +422,6 @@ func (s *service) NotificationPage(c *client, maxID string, // For now, only Pleroma supports this option, Mastadon // will simply ignore the unknown params. includes = []string{"follow", "follow_request", "mention", "reblog", "favourite"} - - // Explicitly exclude the unsupported types. - // Pleroma prioritizes includes over excludes, but we - // still specify excludes to make it work with Mastadon. - excludes = []string{"poll"} } if c.s.Settings.AntiDopamineMode { excludes = append(excludes, "follow", "favourite", "reblog") -- cgit v1.2.3