2019-12-13 18:08:26 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2023-10-15 15:53:44 +00:00
|
|
|
"crypto/sha256"
|
|
|
|
"encoding/base64"
|
2019-12-13 18:08:26 +00:00
|
|
|
"errors"
|
2019-12-25 04:39:34 +00:00
|
|
|
"fmt"
|
2020-10-19 06:51:23 +00:00
|
|
|
"mime/multipart"
|
2019-12-13 18:08:26 +00:00
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
|
2020-02-01 11:31:44 +00:00
|
|
|
"bloat/mastodon"
|
2020-01-01 15:58:27 +00:00
|
|
|
"bloat/model"
|
|
|
|
"bloat/renderer"
|
|
|
|
"bloat/util"
|
2022-10-19 16:15:52 +00:00
|
|
|
|
|
|
|
"github.com/enescakir/emoji"
|
2019-12-13 18:08:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-03-20 05:12:48 +00:00
|
|
|
errInvalidArgument = errors.New("invalid argument")
|
|
|
|
errInvalidSession = errors.New("invalid session")
|
|
|
|
errInvalidCSRFToken = errors.New("invalid csrf token")
|
2019-12-13 18:08:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type service struct {
|
2021-03-20 05:12:48 +00:00
|
|
|
cname string
|
|
|
|
cscope string
|
|
|
|
cwebsite string
|
|
|
|
css string
|
|
|
|
instance string
|
|
|
|
postFormats []model.PostFormat
|
|
|
|
renderer renderer.Renderer
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewService(cname string, cscope string, cwebsite string,
|
|
|
|
css string, instance string, postFormats []model.PostFormat,
|
2022-11-11 22:20:49 +00:00
|
|
|
renderer renderer.Renderer) *service {
|
2019-12-13 18:08:26 +00:00
|
|
|
return &service{
|
2021-03-20 05:12:48 +00:00
|
|
|
cname: cname,
|
|
|
|
cscope: cscope,
|
|
|
|
cwebsite: cwebsite,
|
|
|
|
css: css,
|
|
|
|
instance: instance,
|
|
|
|
postFormats: postFormats,
|
|
|
|
renderer: renderer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) cdata(c *client, title string, count int, rinterval int,
|
|
|
|
target string) (data *renderer.CommonData) {
|
2020-02-18 22:15:37 +00:00
|
|
|
data = &renderer.CommonData{
|
2021-03-20 05:12:48 +00:00
|
|
|
Title: title + " - " + s.cname,
|
|
|
|
CustomCSS: s.css,
|
|
|
|
Count: count,
|
|
|
|
RefreshInterval: rinterval,
|
|
|
|
Target: target,
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
if c != nil && c.s.IsLoggedIn() {
|
|
|
|
data.CSRFToken = c.s.CSRFToken
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
2020-01-28 17:51:00 +00:00
|
|
|
return
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
|
|
|
|
2021-04-03 06:39:06 +00:00
|
|
|
func (s *service) ErrorPage(c *client, err error, retry bool) error {
|
2019-12-26 09:11:24 +00:00
|
|
|
var errStr string
|
2021-04-03 06:39:06 +00:00
|
|
|
var sessionErr bool
|
2019-12-26 09:11:24 +00:00
|
|
|
if err != nil {
|
|
|
|
errStr = err.Error()
|
2021-10-23 13:41:41 +00:00
|
|
|
if me, ok := err.(mastodon.Error); ok && me.IsAuthError() ||
|
|
|
|
err == errInvalidSession || err == errInvalidCSRFToken {
|
2021-04-03 06:39:06 +00:00
|
|
|
sessionErr = true
|
|
|
|
}
|
2019-12-26 09:11:24 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(nil, "error", 0, 0, "")
|
2019-12-26 09:11:24 +00:00
|
|
|
data := &renderer.ErrorData{
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2021-04-03 06:39:06 +00:00
|
|
|
Err: errStr,
|
|
|
|
Retry: retry,
|
|
|
|
SessionErr: sessionErr,
|
2019-12-26 09:11:24 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.ErrorPage, data)
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) SigninPage(c *client) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(nil, "signin", 0, 0, "")
|
2019-12-26 09:11:24 +00:00
|
|
|
data := &renderer.SigninData{
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2019-12-26 09:11:24 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.SigninPage, data)
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) RootPage(c *client) (err error) {
|
2020-02-18 22:15:37 +00:00
|
|
|
data := &renderer.RootData{
|
2021-03-20 05:12:48 +00:00
|
|
|
Title: s.cname,
|
2020-02-18 22:15:37 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.RootPage, data)
|
2020-02-18 22:15:37 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) NavPage(c *client) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
u, err := c.GetAccountCurrentUser(c.ctx)
|
2020-02-18 22:15:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
pctx := model.PostContext{
|
|
|
|
DefaultVisibility: c.s.Settings.DefaultVisibility,
|
|
|
|
DefaultFormat: c.s.Settings.DefaultFormat,
|
2020-11-22 17:29:58 +00:00
|
|
|
Formats: s.postFormats,
|
2020-02-18 22:15:37 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, "nav", 0, 0, "main")
|
2020-02-18 22:15:37 +00:00
|
|
|
data := &renderer.NavData{
|
|
|
|
User: u,
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
|
|
|
PostContext: pctx,
|
2020-02-18 22:15:37 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.NavPage, data)
|
2020-02-18 22:15:37 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 11:18:02 +00:00
|
|
|
func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
|
2022-10-17 01:48:46 +00:00
|
|
|
minID string, tag string) (err error) {
|
2019-12-13 18:08:26 +00:00
|
|
|
|
2020-01-28 17:51:00 +00:00
|
|
|
var nextLink, prevLink, title string
|
2022-10-17 17:01:11 +00:00
|
|
|
var statuses []*mastodon.Status
|
|
|
|
var reactions []*mastodon.ReactionsPleroma
|
2019-12-13 18:08:26 +00:00
|
|
|
var pg = mastodon.Pagination{
|
2019-12-15 06:55:13 +00:00
|
|
|
MaxID: maxID,
|
|
|
|
MinID: minID,
|
|
|
|
Limit: 20,
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 17:51:00 +00:00
|
|
|
switch tType {
|
2019-12-25 04:30:21 +00:00
|
|
|
default:
|
2020-01-28 17:51:00 +00:00
|
|
|
return errInvalidArgument
|
2019-12-25 04:30:21 +00:00
|
|
|
case "home":
|
2021-03-20 05:12:48 +00:00
|
|
|
statuses, err = c.GetTimelineHome(c.ctx, &pg)
|
2022-02-11 11:18:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-12-25 04:30:21 +00:00
|
|
|
title = "Timeline"
|
2020-01-28 20:56:15 +00:00
|
|
|
case "direct":
|
2021-03-20 05:12:48 +00:00
|
|
|
statuses, err = c.GetTimelineDirect(c.ctx, &pg)
|
2022-02-11 11:18:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-07-28 13:36:57 +00:00
|
|
|
title = "Direct Timeline"
|
2019-12-25 04:30:21 +00:00
|
|
|
case "local":
|
2021-03-20 05:12:48 +00:00
|
|
|
statuses, err = c.GetTimelinePublic(c.ctx, true, "", &pg)
|
2022-02-11 11:18:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-12-25 04:30:21 +00:00
|
|
|
title = "Local Timeline"
|
2021-01-23 08:44:05 +00:00
|
|
|
case "remote":
|
|
|
|
if len(instance) > 0 {
|
2023-10-12 12:15:07 +00:00
|
|
|
statuses, err = c.GetTimelinePublic(c.ctx, true, instance, &pg)
|
2022-02-11 11:18:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-23 08:44:05 +00:00
|
|
|
}
|
|
|
|
title = "Remote Timeline"
|
2023-10-12 12:15:07 +00:00
|
|
|
case "tremote":
|
|
|
|
if len(instance) > 0 {
|
|
|
|
statuses, err = c.TrueRemoteTimeline(c.ctx, instance, &pg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
title = "True Remote Timeline"
|
2019-12-25 04:30:21 +00:00
|
|
|
case "twkn":
|
2021-03-20 05:12:48 +00:00
|
|
|
statuses, err = c.GetTimelinePublic(c.ctx, false, "", &pg)
|
2022-02-11 11:18:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-12-25 04:30:21 +00:00
|
|
|
title = "The Whole Known Network"
|
2022-10-17 01:48:46 +00:00
|
|
|
case "tag":
|
2022-12-13 23:56:26 +00:00
|
|
|
if len(tag) > 0 {
|
|
|
|
statuses, err = c.GetTimelineHashtag(c.ctx, tag, false, &pg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-10-17 01:48:46 +00:00
|
|
|
}
|
|
|
|
title = "Tag timeline"
|
|
|
|
|
2022-02-11 11:18:02 +00:00
|
|
|
case "list":
|
|
|
|
statuses, err = c.GetTimelineList(c.ctx, listId, &pg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
list, err := c.GetList(c.ctx, listId)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
title = "List Timeline - " + list.Title
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 11:32:24 +00:00
|
|
|
for i := range statuses {
|
2019-12-31 11:00:21 +00:00
|
|
|
if statuses[i].Reblog != nil {
|
2020-01-05 18:55:37 +00:00
|
|
|
statuses[i].Reblog.RetweetedByID = statuses[i].ID
|
2019-12-31 11:00:21 +00:00
|
|
|
}
|
2022-10-17 17:01:11 +00:00
|
|
|
if statuses[i].Pleroma.Reactions == nil && statuses[i].Account.Pleroma != nil {
|
|
|
|
if statuses[i].Reblog != nil {
|
|
|
|
reactions, err = c.GetReactedBy(c.ctx, statuses[i].Reblog.ID)
|
|
|
|
} else {
|
|
|
|
reactions, err = c.GetReactedBy(c.ctx, statuses[i].ID)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
statuses[i].Pleroma.Reactions = reactions
|
|
|
|
}
|
2019-12-29 11:32:24 +00:00
|
|
|
}
|
|
|
|
|
2021-01-23 07:02:12 +00:00
|
|
|
if (len(maxID) > 0 || len(minID) > 0) && len(statuses) > 0 {
|
2021-01-23 08:44:05 +00:00
|
|
|
v := make(url.Values)
|
|
|
|
v.Set("min_id", statuses[0].ID)
|
|
|
|
if len(instance) > 0 {
|
|
|
|
v.Set("instance", instance)
|
|
|
|
}
|
2022-12-13 23:56:26 +00:00
|
|
|
if len(tag) > 0 {
|
|
|
|
v.Set("tag", tag)
|
|
|
|
}
|
2022-02-11 11:18:02 +00:00
|
|
|
if len(listId) > 0 {
|
|
|
|
v.Set("list", listId)
|
|
|
|
}
|
2021-01-23 08:44:05 +00:00
|
|
|
prevLink = "/timeline/" + tType + "?" + v.Encode()
|
2019-12-15 06:55:13 +00:00
|
|
|
}
|
2020-01-28 17:51:00 +00:00
|
|
|
|
2021-01-23 07:02:12 +00:00
|
|
|
if len(minID) > 0 || (len(pg.MaxID) > 0 && len(statuses) == 20) {
|
2021-01-23 08:44:05 +00:00
|
|
|
v := make(url.Values)
|
|
|
|
v.Set("max_id", pg.MaxID)
|
|
|
|
if len(instance) > 0 {
|
|
|
|
v.Set("instance", instance)
|
|
|
|
}
|
2022-12-13 23:56:26 +00:00
|
|
|
if len(tag) > 0 {
|
|
|
|
v.Set("tag", tag)
|
|
|
|
}
|
2022-02-11 11:18:02 +00:00
|
|
|
if len(listId) > 0 {
|
|
|
|
v.Set("list", listId)
|
|
|
|
}
|
2021-01-23 08:44:05 +00:00
|
|
|
nextLink = "/timeline/" + tType + "?" + v.Encode()
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, tType+" timeline ", 0, 0, "")
|
2019-12-25 14:13:59 +00:00
|
|
|
data := &renderer.TimelineData{
|
2020-02-18 22:15:37 +00:00
|
|
|
Title: title,
|
2021-01-23 08:44:05 +00:00
|
|
|
Type: tType,
|
|
|
|
Instance: instance,
|
2020-02-18 22:15:37 +00:00
|
|
|
Statuses: statuses,
|
|
|
|
NextLink: nextLink,
|
|
|
|
PrevLink: prevLink,
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2019-12-25 14:13:59 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.TimelinePage, data)
|
|
|
|
}
|
2020-01-28 17:51:00 +00:00
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
func addToReplyMap(m map[string][]mastodon.ReplyInfo, key interface{},
|
|
|
|
val string, number int) {
|
|
|
|
if key == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
keyStr, ok := key.(string)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, ok = m[keyStr]
|
|
|
|
if !ok {
|
|
|
|
m[keyStr] = []mastodon.ReplyInfo{}
|
|
|
|
}
|
|
|
|
m[keyStr] = append(m[keyStr], mastodon.ReplyInfo{val, number})
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2019-12-25 14:13:59 +00:00
|
|
|
|
2022-02-11 11:18:02 +00:00
|
|
|
func (s *service) ListsPage(c *client) (err error) {
|
|
|
|
lists, err := c.GetLists(c.ctx)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cdata := s.cdata(c, "Lists", 0, 0, "")
|
|
|
|
data := renderer.ListsData{
|
|
|
|
Lists: lists,
|
|
|
|
CommonData: cdata,
|
|
|
|
}
|
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.ListsPage, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) AddList(c *client, title string) (err error) {
|
|
|
|
_, err = c.CreateList(c.ctx, title)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) RemoveList(c *client, id string) (err error) {
|
|
|
|
return c.DeleteList(c.ctx, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) RenameList(c *client, id, title string) (err error) {
|
|
|
|
_, err = c.RenameList(c.ctx, id, title)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) ListPage(c *client, id string, q string) (err error) {
|
|
|
|
list, err := c.GetList(c.ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
accounts, err := c.GetListAccounts(c.ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var searchAccounts []*mastodon.Account
|
|
|
|
if len(q) > 0 {
|
|
|
|
result, err := c.Search(c.ctx, q, "accounts", 20, true, 0, id, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
searchAccounts = result.Accounts
|
|
|
|
}
|
|
|
|
cdata := s.cdata(c, "List "+list.Title, 0, 0, "")
|
|
|
|
data := renderer.ListData{
|
|
|
|
List: list,
|
|
|
|
Accounts: accounts,
|
|
|
|
Q: q,
|
|
|
|
SearchAccounts: searchAccounts,
|
|
|
|
CommonData: cdata,
|
|
|
|
}
|
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.ListPage, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) ListAddUser(c *client, id string, uid string) (err error) {
|
|
|
|
return c.AddToList(c.ctx, id, uid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) ListRemoveUser(c *client, id string, uid string) (err error) {
|
|
|
|
return c.RemoveFromList(c.ctx, id, uid)
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) ThreadPage(c *client, id string, reply bool) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
var pctx model.PostContext
|
2019-12-13 18:08:26 +00:00
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
status, err := c.GetStatus(c.ctx, id)
|
2019-12-13 18:08:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-13 20:33:20 +00:00
|
|
|
if reply {
|
2022-10-16 22:46:26 +00:00
|
|
|
var spoilerText string
|
2019-12-21 08:36:44 +00:00
|
|
|
var content string
|
2020-01-28 17:51:00 +00:00
|
|
|
var visibility string
|
2022-10-16 22:46:26 +00:00
|
|
|
spoilerText = status.SpoilerText
|
2021-03-20 05:12:48 +00:00
|
|
|
if c.s.UserID != status.Account.ID {
|
2019-12-14 17:47:14 +00:00
|
|
|
content += "@" + status.Account.Acct + " "
|
|
|
|
}
|
2019-12-18 22:14:02 +00:00
|
|
|
for i := range status.Mentions {
|
2021-03-20 05:12:48 +00:00
|
|
|
if status.Mentions[i].ID != c.s.UserID &&
|
2020-01-28 17:51:00 +00:00
|
|
|
status.Mentions[i].ID != status.Account.ID {
|
2019-12-18 22:14:02 +00:00
|
|
|
content += "@" + status.Mentions[i].Acct + " "
|
2019-12-14 17:47:14 +00:00
|
|
|
}
|
2019-12-13 20:33:20 +00:00
|
|
|
}
|
2019-12-21 13:26:31 +00:00
|
|
|
|
2020-07-28 13:36:57 +00:00
|
|
|
isDirect := status.Visibility == "direct"
|
2021-03-20 05:12:48 +00:00
|
|
|
if isDirect || c.s.Settings.CopyScope {
|
2020-06-18 05:02:45 +00:00
|
|
|
visibility = status.Visibility
|
2019-12-27 08:06:43 +00:00
|
|
|
} else {
|
2021-03-20 05:12:48 +00:00
|
|
|
visibility = c.s.Settings.DefaultVisibility
|
2019-12-21 13:26:31 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 23:34:00 +00:00
|
|
|
replyLanguage := status.Language
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
pctx = model.PostContext{
|
2019-12-27 08:06:43 +00:00
|
|
|
DefaultVisibility: visibility,
|
2021-03-20 05:12:48 +00:00
|
|
|
DefaultFormat: c.s.Settings.DefaultFormat,
|
2020-11-22 17:29:58 +00:00
|
|
|
Formats: s.postFormats,
|
2019-12-21 13:26:31 +00:00
|
|
|
ReplyContext: &model.ReplyContext{
|
2020-06-18 05:02:45 +00:00
|
|
|
InReplyToID: id,
|
|
|
|
InReplyToName: status.Account.Acct,
|
2022-10-16 22:46:26 +00:00
|
|
|
ReplySpoiler: spoilerText,
|
2020-06-18 05:02:45 +00:00
|
|
|
ReplyContent: content,
|
|
|
|
ForceVisibility: isDirect,
|
2023-11-09 23:34:00 +00:00
|
|
|
ReplyLanguage: replyLanguage,
|
2019-12-21 13:26:31 +00:00
|
|
|
},
|
2019-12-21 08:36:44 +00:00
|
|
|
}
|
2019-12-13 20:33:20 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
context, err := c.GetStatusContext(c.ctx, id)
|
2019-12-18 22:14:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
statuses := append(append(context.Ancestors, status), context.Descendants...)
|
2020-01-28 17:51:00 +00:00
|
|
|
replies := make(map[string][]mastodon.ReplyInfo)
|
2020-06-05 06:27:59 +00:00
|
|
|
idNumbers := make(map[string]int)
|
2019-12-18 22:14:02 +00:00
|
|
|
|
|
|
|
for i := range statuses {
|
|
|
|
statuses[i].ShowReplies = true
|
2020-06-05 06:27:59 +00:00
|
|
|
|
|
|
|
statuses[i].IDNumbers = idNumbers
|
|
|
|
idNumbers[statuses[i].ID] = i + 1
|
|
|
|
|
|
|
|
statuses[i].IDReplies = replies
|
2020-06-18 05:02:45 +00:00
|
|
|
addToReplyMap(replies, statuses[i].InReplyToID, statuses[i].ID, i+1)
|
2019-12-18 22:14:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, "post by "+status.Account.DisplayName, 0, 0, "")
|
2019-12-25 14:13:59 +00:00
|
|
|
data := &renderer.ThreadData{
|
|
|
|
Statuses: statuses,
|
2021-03-20 05:12:48 +00:00
|
|
|
PostContext: pctx,
|
2020-01-28 17:51:00 +00:00
|
|
|
ReplyMap: replies,
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2019-12-25 14:13:59 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.ThreadPage, data)
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
|
|
|
|
2021-09-05 17:17:59 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) LikedByPage(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
likers, err := c.GetFavouritedBy(c.ctx, id, nil)
|
2020-01-28 17:51:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
2019-12-15 17:37:58 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, "likes", 0, 0, "")
|
2020-01-28 17:51:00 +00:00
|
|
|
data := &renderer.LikedByData{
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2020-01-28 17:51:00 +00:00
|
|
|
Users: likers,
|
2019-12-15 17:37:58 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.LikedByPage, data)
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2019-12-15 17:37:58 +00:00
|
|
|
|
2022-10-19 14:33:43 +00:00
|
|
|
func (s *service) ReactedByPage(c *client, id string) (err error) {
|
|
|
|
reactions, err := c.GetReactedBy(c.ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cdata := s.cdata(c, "reactions", 0, 0, "")
|
|
|
|
data := &renderer.ReactedByData{
|
|
|
|
CommonData: cdata,
|
2022-10-19 16:15:52 +00:00
|
|
|
ID: id,
|
2022-10-19 14:33:43 +00:00
|
|
|
Reactions: reactions,
|
2022-10-19 16:15:52 +00:00
|
|
|
ReactionEmojis: emoji.Map(),
|
2022-10-19 14:33:43 +00:00
|
|
|
}
|
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.ReactedByPage, data)
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) RetweetedByPage(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
retweeters, err := c.GetRebloggedBy(c.ctx, id, nil)
|
2019-12-15 17:37:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, "retweets", 0, 0, "")
|
2020-01-28 17:51:00 +00:00
|
|
|
data := &renderer.RetweetedByData{
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2020-01-28 17:51:00 +00:00
|
|
|
Users: retweeters,
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.RetweetedByPage, data)
|
2019-12-15 17:37:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) NotificationPage(c *client, maxID string,
|
2020-05-24 04:38:34 +00:00
|
|
|
minID string) (err error) {
|
2020-01-28 17:51:00 +00:00
|
|
|
|
|
|
|
var nextLink string
|
|
|
|
var unreadCount int
|
2020-02-18 22:15:37 +00:00
|
|
|
var readID string
|
2021-12-13 13:58:15 +00:00
|
|
|
var includes, excludes []string
|
2020-01-28 17:51:00 +00:00
|
|
|
var pg = mastodon.Pagination{
|
|
|
|
MaxID: maxID,
|
|
|
|
MinID: minID,
|
|
|
|
Limit: 20,
|
2019-12-26 09:11:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-13 13:58:15 +00:00
|
|
|
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"}
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
if c.s.Settings.AntiDopamineMode {
|
2021-12-13 13:58:15 +00:00
|
|
|
excludes = append(excludes, "follow", "favourite", "reblog")
|
2020-09-02 17:50:48 +00:00
|
|
|
}
|
|
|
|
|
2021-12-13 13:58:15 +00:00
|
|
|
notifications, err := c.GetNotifications(c.ctx, &pg, includes, excludes)
|
2019-12-26 09:11:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 17:51:00 +00:00
|
|
|
for i := range notifications {
|
|
|
|
if notifications[i].Pleroma != nil && !notifications[i].Pleroma.IsSeen {
|
|
|
|
unreadCount++
|
|
|
|
}
|
2019-12-26 09:11:24 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 17:51:00 +00:00
|
|
|
if unreadCount > 0 {
|
2020-02-18 22:15:37 +00:00
|
|
|
readID = notifications[0].ID
|
2019-12-26 09:11:24 +00:00
|
|
|
}
|
2020-02-18 22:15:37 +00:00
|
|
|
if len(notifications) == 20 && len(pg.MaxID) > 0 {
|
2020-01-28 17:51:00 +00:00
|
|
|
nextLink = "/notifications?max_id=" + pg.MaxID
|
2019-12-26 09:11:24 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, "notifications", unreadCount,
|
|
|
|
c.s.Settings.NotificationInterval, "main")
|
2020-01-28 17:51:00 +00:00
|
|
|
data := &renderer.NotificationData{
|
|
|
|
Notifications: notifications,
|
2020-02-18 22:15:37 +00:00
|
|
|
UnreadCount: unreadCount,
|
|
|
|
ReadID: readID,
|
2020-01-28 17:51:00 +00:00
|
|
|
NextLink: nextLink,
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2019-12-26 09:11:24 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.NotificationPage, data)
|
2019-12-26 09:11:24 +00:00
|
|
|
}
|
2019-12-26 19:18:09 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) UserPage(c *client, id string, pageType string,
|
2020-05-24 04:38:34 +00:00
|
|
|
maxID string, minID string) (err error) {
|
2020-01-28 17:51:00 +00:00
|
|
|
|
2019-12-29 03:43:57 +00:00
|
|
|
var nextLink string
|
2020-01-31 03:38:49 +00:00
|
|
|
var statuses []*mastodon.Status
|
|
|
|
var users []*mastodon.Account
|
2019-12-29 03:43:57 +00:00
|
|
|
var pg = mastodon.Pagination{
|
|
|
|
MaxID: maxID,
|
|
|
|
MinID: minID,
|
|
|
|
Limit: 20,
|
|
|
|
}
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
user, err := c.GetAccount(c.ctx, id)
|
2019-12-29 03:43:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
isCurrent := c.s.UserID == user.ID
|
2019-12-29 03:43:57 +00:00
|
|
|
|
2020-01-31 03:38:49 +00:00
|
|
|
switch pageType {
|
|
|
|
case "":
|
2022-10-25 21:44:22 +00:00
|
|
|
statuses, err = c.GetAccountStatuses(c.ctx, id, false, false, &pg)
|
2020-01-31 03:38:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(statuses) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s?max_id=%s", id,
|
|
|
|
pg.MaxID)
|
|
|
|
}
|
|
|
|
case "following":
|
2021-03-20 05:12:48 +00:00
|
|
|
users, err = c.GetAccountFollowing(c.ctx, id, &pg)
|
2020-01-31 03:38:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(users) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s/following?max_id=%s",
|
|
|
|
id, pg.MaxID)
|
|
|
|
}
|
|
|
|
case "followers":
|
2021-03-20 05:12:48 +00:00
|
|
|
users, err = c.GetAccountFollowers(c.ctx, id, &pg)
|
2020-01-31 03:38:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(users) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s/followers?max_id=%s",
|
|
|
|
id, pg.MaxID)
|
|
|
|
}
|
|
|
|
case "media":
|
2022-10-25 21:44:22 +00:00
|
|
|
statuses, err = c.GetAccountStatuses(c.ctx, id, true, false, &pg)
|
2020-01-31 03:38:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(statuses) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s/media?max_id=%s",
|
|
|
|
id, pg.MaxID)
|
|
|
|
}
|
2022-10-25 21:44:22 +00:00
|
|
|
case "pinned":
|
|
|
|
statuses, err = c.GetAccountStatuses(c.ctx, id, false, true, &pg)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(statuses) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s/pinned?max_id=%s",
|
|
|
|
id, pg.MaxID)
|
|
|
|
}
|
2020-09-27 09:29:17 +00:00
|
|
|
case "bookmarks":
|
|
|
|
if !isCurrent {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
statuses, err = c.GetBookmarks(c.ctx, &pg)
|
2020-09-27 09:29:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(statuses) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s/bookmarks?max_id=%s",
|
|
|
|
id, pg.MaxID)
|
|
|
|
}
|
2020-09-27 09:44:52 +00:00
|
|
|
case "mutes":
|
|
|
|
if !isCurrent {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
users, err = c.GetMutes(c.ctx, &pg)
|
2020-09-27 09:44:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(users) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s/mutes?max_id=%s",
|
|
|
|
id, pg.MaxID)
|
|
|
|
}
|
2020-09-27 09:50:04 +00:00
|
|
|
case "blocks":
|
|
|
|
if !isCurrent {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
users, err = c.GetBlocks(c.ctx, &pg)
|
2020-09-27 09:50:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(users) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s/blocks?max_id=%s",
|
|
|
|
id, pg.MaxID)
|
|
|
|
}
|
2020-09-27 10:04:56 +00:00
|
|
|
case "likes":
|
|
|
|
if !isCurrent {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
statuses, err = c.GetFavourites(c.ctx, &pg)
|
2020-09-27 10:04:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(statuses) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s/likes?max_id=%s",
|
|
|
|
id, pg.MaxID)
|
|
|
|
}
|
2021-01-16 09:10:02 +00:00
|
|
|
case "requests":
|
|
|
|
if !isCurrent {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
users, err = c.GetFollowRequests(c.ctx, &pg)
|
2021-01-16 09:10:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(users) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s/requests?max_id=%s",
|
|
|
|
id, pg.MaxID)
|
|
|
|
}
|
2020-01-31 03:38:49 +00:00
|
|
|
default:
|
|
|
|
return errInvalidArgument
|
2019-12-29 03:43:57 +00:00
|
|
|
}
|
|
|
|
|
2020-10-19 10:01:59 +00:00
|
|
|
for i := range statuses {
|
|
|
|
if statuses[i].Reblog != nil {
|
|
|
|
statuses[i].Reblog.RetweetedByID = statuses[i].ID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, user.DisplayName+" @"+user.Acct, 0, 0, "")
|
2020-01-28 17:51:00 +00:00
|
|
|
data := &renderer.UserData{
|
|
|
|
User: user,
|
2020-09-27 09:29:17 +00:00
|
|
|
IsCurrent: isCurrent,
|
2020-01-31 03:38:49 +00:00
|
|
|
Type: pageType,
|
|
|
|
Users: users,
|
2020-01-28 17:51:00 +00:00
|
|
|
Statuses: statuses,
|
2019-12-29 03:43:57 +00:00
|
|
|
NextLink: nextLink,
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2019-12-29 03:43:57 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.UserPage, data)
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2019-12-29 03:43:57 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) UserSearchPage(c *client,
|
2020-01-30 15:32:37 +00:00
|
|
|
id string, q string, offset int) (err error) {
|
|
|
|
|
|
|
|
var nextLink string
|
|
|
|
var title = "search"
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
user, err := c.GetAccount(c.ctx, id)
|
2020-01-30 15:32:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-19 06:05:59 +00:00
|
|
|
var results *mastodon.Results
|
|
|
|
if len(q) > 0 {
|
2022-02-11 11:18:02 +00:00
|
|
|
results, err = c.Search(c.ctx, q, "statuses", 20, true, offset, id, false)
|
2020-10-19 06:05:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
results = &mastodon.Results{}
|
2020-01-30 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(results.Statuses) == 20 {
|
|
|
|
offset += 20
|
2021-01-17 05:44:07 +00:00
|
|
|
nextLink = fmt.Sprintf("/usersearch/%s?q=%s&offset=%d", id,
|
2022-03-30 15:52:30 +00:00
|
|
|
q, offset)
|
2020-01-30 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(q) > 0 {
|
2021-04-23 10:19:09 +00:00
|
|
|
title += " \"" + q + "\""
|
2020-01-30 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, title, 0, 0, "")
|
2020-01-30 15:32:37 +00:00
|
|
|
data := &renderer.UserSearchData{
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2020-01-30 15:32:37 +00:00
|
|
|
User: user,
|
2021-04-23 10:19:09 +00:00
|
|
|
Q: q,
|
2020-01-30 15:32:37 +00:00
|
|
|
Statuses: results.Statuses,
|
|
|
|
NextLink: nextLink,
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.UserSearchPage, data)
|
2020-01-30 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 08:26:51 +00:00
|
|
|
func (s *service) MutePage(c *client, id string) (err error) {
|
|
|
|
user, err := c.GetAccount(c.ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-09-08 14:46:40 +00:00
|
|
|
cdata := s.cdata(c, "Mute "+user.DisplayName+" @"+user.Acct, 0, 0, "")
|
2022-12-17 08:26:51 +00:00
|
|
|
data := &renderer.UserData{
|
|
|
|
User: user,
|
|
|
|
CommonData: cdata,
|
|
|
|
}
|
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.MutePage, data)
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) AboutPage(c *client) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, "about", 0, 0, "")
|
2020-01-28 17:51:00 +00:00
|
|
|
data := &renderer.AboutData{
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2019-12-29 03:43:57 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.AboutPage, data)
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 10:34:41 +00:00
|
|
|
func (s *service) AboutInstance(c *client) (err error) {
|
|
|
|
cdata := s.cdata(c, "about", 0, 0, "")
|
|
|
|
instance, err := c.GetInstance(c.ctx)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2022-10-12 22:41:34 +00:00
|
|
|
peers, err := c.GetInstancePeers(c.ctx)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-12 10:34:41 +00:00
|
|
|
data := &renderer.AboutInstanceData{
|
|
|
|
CommonData: cdata,
|
|
|
|
Instance: instance,
|
2022-10-12 22:41:34 +00:00
|
|
|
Peers: peers,
|
2022-10-12 10:34:41 +00:00
|
|
|
}
|
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.AboutInstance, data)
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) EmojiPage(c *client) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
emojis, err := c.GetInstanceEmojis(c.ctx)
|
2019-12-29 03:43:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, "emojis", 0, 0, "")
|
2020-01-28 17:51:00 +00:00
|
|
|
data := &renderer.EmojiData{
|
|
|
|
Emojis: emojis,
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2019-12-29 03:43:57 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.EmojiPage, data)
|
2019-12-29 03:43:57 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) SearchPage(c *client,
|
2020-01-28 17:51:00 +00:00
|
|
|
q string, qType string, offset int) (err error) {
|
|
|
|
|
2019-12-26 19:18:09 +00:00
|
|
|
var nextLink string
|
2020-01-28 17:51:00 +00:00
|
|
|
var title = "search"
|
2019-12-26 19:18:09 +00:00
|
|
|
|
2020-10-19 06:05:59 +00:00
|
|
|
var results *mastodon.Results
|
|
|
|
if len(q) > 0 {
|
2022-02-11 11:18:02 +00:00
|
|
|
results, err = c.Search(c.ctx, q, qType, 20, true, offset, "", false)
|
2020-10-19 06:05:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
results = &mastodon.Results{}
|
2019-12-26 19:18:09 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 17:51:00 +00:00
|
|
|
if (qType == "accounts" && len(results.Accounts) == 20) ||
|
|
|
|
(qType == "statuses" && len(results.Statuses) == 20) {
|
2019-12-26 19:18:09 +00:00
|
|
|
offset += 20
|
2021-01-17 05:44:07 +00:00
|
|
|
nextLink = fmt.Sprintf("/search?q=%s&type=%s&offset=%d",
|
2022-03-30 15:52:30 +00:00
|
|
|
q, qType, offset)
|
2019-12-26 19:18:09 +00:00
|
|
|
}
|
|
|
|
|
2020-01-10 03:53:02 +00:00
|
|
|
if len(q) > 0 {
|
2021-04-23 10:19:09 +00:00
|
|
|
title += " \"" + q + "\""
|
2020-01-10 03:53:02 +00:00
|
|
|
}
|
2020-01-28 17:51:00 +00:00
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, title, 0, 0, "")
|
2019-12-26 19:18:09 +00:00
|
|
|
data := &renderer.SearchData{
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2021-04-23 10:19:09 +00:00
|
|
|
Q: q,
|
2019-12-26 19:18:09 +00:00
|
|
|
Type: qType,
|
|
|
|
Users: results.Accounts,
|
|
|
|
Statuses: results.Statuses,
|
|
|
|
NextLink: nextLink,
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.SearchPage, data)
|
2019-12-26 19:18:09 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 17:55:42 +00:00
|
|
|
func (s *service) UserEditPage(c *client) (err error) {
|
|
|
|
cdata := s.cdata(c, "useredit", 0, 0, "")
|
|
|
|
u, err := c.GetAccountCurrentUser(c.ctx)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
data := &renderer.UserEditData{
|
|
|
|
CommonData: cdata,
|
|
|
|
User: u,
|
|
|
|
}
|
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.UserEditPage, data)
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) SettingsPage(c *client) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := s.cdata(c, "settings", 0, 0, "")
|
2019-12-27 08:06:43 +00:00
|
|
|
data := &renderer.SettingsData{
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
|
|
|
Settings: &c.s.Settings,
|
2020-11-22 17:29:58 +00:00
|
|
|
PostFormats: s.postFormats,
|
2019-12-27 08:06:43 +00:00
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return s.renderer.Render(c.rctx, c.w, renderer.SettingsPage, data)
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
2019-12-27 08:06:43 +00:00
|
|
|
|
2021-01-30 16:51:09 +00:00
|
|
|
func (svc *service) FiltersPage(c *client) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
filters, err := c.GetFilters(c.ctx)
|
2021-01-30 16:51:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
cdata := svc.cdata(c, "filters", 0, 0, "")
|
2021-01-30 16:51:09 +00:00
|
|
|
data := &renderer.FiltersData{
|
2021-03-20 05:12:48 +00:00
|
|
|
CommonData: cdata,
|
2021-01-30 16:51:09 +00:00
|
|
|
Filters: filters,
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
return svc.renderer.Render(c.rctx, c.w, renderer.FiltersPage, data)
|
2021-01-30 16:51:09 +00:00
|
|
|
}
|
|
|
|
|
2023-10-01 13:04:07 +00:00
|
|
|
func (svc *service) ProfilePage(c *client) (err error) {
|
|
|
|
u, err := c.GetAccountCurrentUser(c.ctx)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Some instances allow more than 4 fields, but make sure that there are
|
|
|
|
// at least 4 fields in the slice because the template depends on it.
|
|
|
|
if u.Source.Fields == nil {
|
|
|
|
u.Source.Fields = new([]mastodon.Field)
|
|
|
|
}
|
|
|
|
for len(*u.Source.Fields) < 4 {
|
|
|
|
*u.Source.Fields = append(*u.Source.Fields, mastodon.Field{})
|
|
|
|
}
|
|
|
|
cdata := svc.cdata(c, "edit profile", 0, 0, "")
|
|
|
|
data := &renderer.ProfileData{
|
|
|
|
CommonData: cdata,
|
|
|
|
User: u,
|
|
|
|
}
|
|
|
|
return svc.renderer.Render(c.rctx, c.w, renderer.ProfilePage, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) ProfileUpdate(c *client, name, bio string, avatar, banner *multipart.FileHeader,
|
|
|
|
fields []mastodon.Field, locked bool) (err error) {
|
|
|
|
// Need to pass empty data to clear fields
|
|
|
|
if len(fields) == 0 {
|
|
|
|
fields = append(fields, mastodon.Field{})
|
|
|
|
}
|
|
|
|
p := &mastodon.Profile{
|
|
|
|
DisplayName: &name,
|
|
|
|
Note: &bio,
|
|
|
|
Avatar: avatar,
|
|
|
|
Header: banner,
|
|
|
|
Fields: &fields,
|
|
|
|
Locked: &locked,
|
|
|
|
}
|
|
|
|
_, err = c.AccountUpdate(c.ctx, p)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) ProfileDelAvatar(c *client) (err error) {
|
|
|
|
_, err = c.AccountDeleteAvatar(c.ctx)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) ProfileDelBanner(c *client) (err error) {
|
|
|
|
_, err = c.AccountDeleteHeader(c.ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) SingleInstance() (instance string, ok bool) {
|
2021-03-20 05:12:48 +00:00
|
|
|
if len(s.instance) > 0 {
|
|
|
|
instance = s.instance
|
2020-04-19 08:18:36 +00:00
|
|
|
ok = true
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-11 22:20:49 +00:00
|
|
|
func (s *service) NewSession(c *client, instance string) (rurl string, sess *model.Session, err error) {
|
2020-01-28 17:51:00 +00:00
|
|
|
var instanceURL string
|
|
|
|
if strings.HasPrefix(instance, "https://") {
|
|
|
|
instanceURL = instance
|
|
|
|
instance = strings.TrimPrefix(instance, "https://")
|
|
|
|
} else {
|
|
|
|
instanceURL = "https://" + instance
|
|
|
|
}
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
csrf, err := util.NewCSRFToken()
|
2019-12-27 08:06:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-11 22:20:49 +00:00
|
|
|
app, err := mastodon.RegisterApp(c.ctx, &mastodon.AppConfig{
|
|
|
|
Server: instanceURL,
|
|
|
|
ClientName: s.cname,
|
|
|
|
Scopes: s.cscope,
|
|
|
|
Website: s.cwebsite,
|
|
|
|
RedirectURIs: s.cwebsite + "/oauth_callback",
|
|
|
|
})
|
2019-12-27 08:06:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-10-07 09:19:56 +00:00
|
|
|
rurl = app.AuthURI
|
2022-11-11 22:20:49 +00:00
|
|
|
sess = &model.Session{
|
|
|
|
Instance: instance,
|
|
|
|
ClientID: app.ClientID,
|
|
|
|
ClientSecret: app.ClientSecret,
|
|
|
|
CSRFToken: csrf,
|
|
|
|
Settings: *model.NewSettings(),
|
2019-12-25 14:13:59 +00:00
|
|
|
}
|
2019-12-13 18:08:26 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
func (s *service) Signin(c *client, code string) (err error) {
|
2020-01-28 17:51:00 +00:00
|
|
|
if len(code) < 1 {
|
|
|
|
err = errInvalidArgument
|
2020-01-08 18:16:06 +00:00
|
|
|
return
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
err = c.AuthenticateToken(c.ctx, code, s.cwebsite+"/oauth_callback")
|
2020-01-08 18:16:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
u, err := c.GetAccountCurrentUser(c.ctx)
|
2020-02-02 08:30:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-03-20 05:12:48 +00:00
|
|
|
c.s.AccessToken = c.GetAccessToken(c.ctx)
|
|
|
|
c.s.UserID = u.ID
|
2022-11-11 22:20:49 +00:00
|
|
|
return c.setSession(c.s)
|
2020-03-04 15:59:59 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 06:44:26 +00:00
|
|
|
func (s *service) Signout(c *client) (err error) {
|
|
|
|
return c.RevokeToken(c.ctx)
|
|
|
|
}
|
2022-11-12 21:00:02 +00:00
|
|
|
|
2021-01-17 05:44:07 +00:00
|
|
|
func (s *service) Post(c *client, content string, replyToID string,
|
2022-10-16 22:46:26 +00:00
|
|
|
format string, visibility string, isNSFW bool, spoilerText string,
|
2023-11-09 22:27:22 +00:00
|
|
|
files []*multipart.FileHeader, edit string, language string, expiresIn int, scheduledAt string) (id string, err error) {
|
2020-01-28 17:51:00 +00:00
|
|
|
|
|
|
|
var mediaIDs []string
|
2019-12-14 20:19:02 +00:00
|
|
|
for _, f := range files {
|
2021-03-20 05:12:48 +00:00
|
|
|
a, err := c.UploadMediaFromMultipartFileHeader(c.ctx, f)
|
2019-12-14 20:19:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2020-01-28 17:51:00 +00:00
|
|
|
mediaIDs = append(mediaIDs, a.ID)
|
2019-12-14 20:19:02 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 20:14:42 +00:00
|
|
|
expiresIn = expiresIn * 3600
|
|
|
|
|
2019-12-13 18:08:26 +00:00
|
|
|
tweet := &mastodon.Toot{
|
2022-10-16 22:46:26 +00:00
|
|
|
SpoilerText: spoilerText,
|
2019-12-13 18:08:26 +00:00
|
|
|
Status: content,
|
|
|
|
InReplyToID: replyToID,
|
2020-01-28 17:51:00 +00:00
|
|
|
MediaIDs: mediaIDs,
|
2019-12-26 11:25:29 +00:00
|
|
|
ContentType: format,
|
2019-12-21 13:26:31 +00:00
|
|
|
Visibility: visibility,
|
2019-12-22 16:27:49 +00:00
|
|
|
Sensitive: isNSFW,
|
2022-10-31 15:26:16 +00:00
|
|
|
Edit: edit,
|
2023-11-09 20:14:42 +00:00
|
|
|
Language: language,
|
|
|
|
ExpiresIn: expiresIn, // pleroma compatible
|
2023-11-09 22:27:22 +00:00
|
|
|
ScheduledAt: scheduledAt,
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
2023-11-09 20:14:42 +00:00
|
|
|
|
2021-03-20 05:12:48 +00:00
|
|
|
st, err := c.PostStatus(c.ctx, tweet)
|
2019-12-14 18:12:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
return st.ID, nil
|
2019-12-13 18:08:26 +00:00
|
|
|
}
|
2019-12-18 22:14:02 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) Like(c *client, id string) (count int64, err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
st, err := c.Favourite(c.ctx, id)
|
2020-01-28 17:51:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
count = st.FavouritesCount
|
2019-12-20 18:30:20 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) UnLike(c *client, id string) (count int64, err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
st, err := c.Unfavourite(c.ctx, id)
|
2020-01-28 17:51:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
count = st.FavouritesCount
|
2022-10-17 17:01:11 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) PutReact(c *client, id string, emoji string) (count int64, err error) {
|
|
|
|
st, err := c.PutReaction(c.ctx, id, emoji)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
count = st.FavouritesCount
|
2022-10-19 12:47:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) UnReact(c *client, id string, emoji string) (count int64, err error) {
|
|
|
|
st, err := c.UnReaction(c.ctx, id, emoji)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
count = st.FavouritesCount
|
2019-12-20 18:30:20 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-02 01:45:19 +00:00
|
|
|
func (s *service) Retweet(c *client, id string, visibility string) (count int64, err error) {
|
|
|
|
st, err := c.Reblog(c.ctx, id, visibility)
|
2020-01-28 17:51:00 +00:00
|
|
|
if err != nil {
|
2019-12-18 22:14:02 +00:00
|
|
|
return
|
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
if st.Reblog != nil {
|
|
|
|
count = st.Reblog.ReblogsCount
|
2020-01-28 17:51:00 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2019-12-21 11:13:21 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) UnRetweet(c *client, id string) (
|
2020-01-28 17:51:00 +00:00
|
|
|
count int64, err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
st, err := c.Unreblog(c.ctx, id)
|
2020-01-28 17:51:00 +00:00
|
|
|
if err != nil {
|
2019-12-18 22:14:02 +00:00
|
|
|
return
|
|
|
|
}
|
2020-11-22 17:29:58 +00:00
|
|
|
count = st.ReblogsCount
|
2020-01-28 17:51:00 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) Vote(c *client, id string, choices []string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.Vote(c.ctx, id, choices)
|
2020-02-09 13:42:16 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) Follow(c *client, id string, reblogs *bool) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.AccountFollow(c.ctx, id, reblogs)
|
2020-01-28 17:51:00 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) UnFollow(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.AccountUnfollow(c.ctx, id)
|
2020-01-28 17:51:00 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-16 09:10:02 +00:00
|
|
|
func (s *service) Accept(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
return c.FollowRequestAuthorize(c.ctx, id)
|
2021-01-16 09:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) Reject(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
return c.FollowRequestReject(c.ctx, id)
|
2021-01-16 09:10:02 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 08:26:51 +00:00
|
|
|
func (s *service) Mute(c *client, id string, notifications bool, duration int) (err error) {
|
|
|
|
_, err = c.AccountMute(c.ctx, id, notifications, duration)
|
2020-02-08 10:49:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) UnMute(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.AccountUnmute(c.ctx, id)
|
2020-02-08 10:49:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) Block(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.AccountBlock(c.ctx, id)
|
2020-02-08 10:49:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) UnBlock(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.AccountUnblock(c.ctx, id)
|
2020-02-08 10:49:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) Subscribe(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.Subscribe(c.ctx, id)
|
2020-04-17 17:19:11 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) UnSubscribe(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.UnSubscribe(c.ctx, id)
|
2020-04-17 17:19:11 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) SaveSettings(c *client, settings *model.Settings) (err error) {
|
|
|
|
switch settings.NotificationInterval {
|
2020-11-14 14:08:16 +00:00
|
|
|
case 0, 30, 60, 120, 300, 600:
|
|
|
|
default:
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
2023-10-15 15:53:44 +00:00
|
|
|
if len(settings.CSS) > 0 {
|
|
|
|
if len(settings.CSS) > 1<<20 {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
// For some reason, browsers convert CRLF to LF before calculating
|
|
|
|
// the hash of the inline resources.
|
2023-10-22 11:11:21 +00:00
|
|
|
settings.CSS = strings.Replace(settings.CSS, "\x0d\x0a", "\x0a", -1)
|
2023-10-15 15:53:44 +00:00
|
|
|
|
|
|
|
h := sha256.Sum256([]byte(settings.CSS))
|
|
|
|
settings.CSSHash = base64.StdEncoding.EncodeToString(h[:])
|
|
|
|
} else {
|
|
|
|
settings.CSSHash = ""
|
2021-04-03 09:22:43 +00:00
|
|
|
}
|
2022-11-11 22:20:49 +00:00
|
|
|
c.s.Settings = *settings
|
|
|
|
return c.setSession(c.s)
|
2019-12-18 22:14:02 +00:00
|
|
|
}
|
2020-02-02 07:24:06 +00:00
|
|
|
|
2022-11-04 17:55:42 +00:00
|
|
|
func (s *service) UserSave(c *client, usersettings mastodon.Profile) (err error) {
|
|
|
|
_, err = c.AccountUpdate(c.ctx, &usersettings)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) MuteConversation(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.MuteConversation(c.ctx, id)
|
2020-02-02 07:24:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) UnMuteConversation(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.UnmuteConversation(c.ctx, id)
|
2020-02-02 07:24:06 +00:00
|
|
|
return
|
|
|
|
}
|
2020-02-02 08:30:40 +00:00
|
|
|
|
2022-10-31 12:43:36 +00:00
|
|
|
func (s *service) Pin(c *client, id string) (err error) {
|
|
|
|
return c.Pin(c.ctx, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) UnPin(c *client, id string) (err error) {
|
|
|
|
return c.UnPin(c.ctx, id)
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) Delete(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
return c.DeleteStatus(c.ctx, id)
|
2020-02-02 08:30:40 +00:00
|
|
|
}
|
2020-02-18 22:15:37 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) ReadNotifications(c *client, maxID string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
return c.ReadNotifications(c.ctx, maxID)
|
2020-02-18 22:15:37 +00:00
|
|
|
}
|
2020-09-27 09:29:17 +00:00
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) Bookmark(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.Bookmark(c.ctx, id)
|
2020-09-27 09:29:17 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-22 17:29:58 +00:00
|
|
|
func (s *service) UnBookmark(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
_, err = c.Unbookmark(c.ctx, id)
|
2020-09-27 09:29:17 +00:00
|
|
|
return
|
|
|
|
}
|
2021-01-30 16:51:09 +00:00
|
|
|
|
|
|
|
func (svc *service) Filter(c *client, phrase string, wholeWord bool) (err error) {
|
|
|
|
fctx := []string{"home", "notifications", "public", "thread"}
|
2021-03-20 05:12:48 +00:00
|
|
|
return c.AddFilter(c.ctx, phrase, fctx, true, wholeWord, nil)
|
2021-01-30 16:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (svc *service) UnFilter(c *client, id string) (err error) {
|
2021-03-20 05:12:48 +00:00
|
|
|
return c.RemoveFilter(c.ctx, id)
|
2021-01-30 16:51:09 +00:00
|
|
|
}
|