2019-12-13 20:08:26 +02:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2019-12-25 06:39:34 +02:00
|
|
|
"fmt"
|
2019-12-14 22:19:02 +02:00
|
|
|
"mime/multipart"
|
2019-12-13 20:08:26 +02:00
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
|
2020-02-01 13:31:44 +02:00
|
|
|
"bloat/mastodon"
|
2020-01-01 17:58:27 +02:00
|
|
|
"bloat/model"
|
|
|
|
"bloat/renderer"
|
|
|
|
"bloat/util"
|
2019-12-13 20:08:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-01-28 19:51:00 +02:00
|
|
|
errInvalidArgument = errors.New("invalid argument")
|
2019-12-13 20:08:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Service interface {
|
2020-01-28 19:51:00 +02:00
|
|
|
ServeErrorPage(ctx context.Context, c *model.Client, err error)
|
|
|
|
ServeSigninPage(ctx context.Context, c *model.Client) (err error)
|
2020-02-19 00:15:37 +02:00
|
|
|
ServeRootPage(ctx context.Context, c *model.Client) (err error)
|
|
|
|
ServeNavPage(ctx context.Context, c *model.Client) (err error)
|
2020-01-28 19:51:00 +02:00
|
|
|
ServeTimelinePage(ctx context.Context, c *model.Client, tType string, maxID string, minID string) (err error)
|
|
|
|
ServeThreadPage(ctx context.Context, c *model.Client, id string, reply bool) (err error)
|
|
|
|
ServeLikedByPage(ctx context.Context, c *model.Client, id string) (err error)
|
|
|
|
ServeRetweetedByPage(ctx context.Context, c *model.Client, id string) (err error)
|
|
|
|
ServeNotificationPage(ctx context.Context, c *model.Client, maxID string, minID string) (err error)
|
2020-01-31 05:38:49 +02:00
|
|
|
ServeUserPage(ctx context.Context, c *model.Client, id string, pageType string,
|
|
|
|
maxID string, minID string) (err error)
|
2020-01-28 19:51:00 +02:00
|
|
|
ServeAboutPage(ctx context.Context, c *model.Client) (err error)
|
|
|
|
ServeEmojiPage(ctx context.Context, c *model.Client) (err error)
|
|
|
|
ServeSearchPage(ctx context.Context, c *model.Client, q string, qType string, offset int) (err error)
|
2020-01-30 17:32:37 +02:00
|
|
|
ServeUserSearchPage(ctx context.Context, c *model.Client, id string, q string, offset int) (err error)
|
2020-01-28 19:51:00 +02:00
|
|
|
ServeSettingsPage(ctx context.Context, c *model.Client) (err error)
|
|
|
|
NewSession(ctx context.Context, instance string) (redirectUrl string, sessionID string, err error)
|
2020-02-08 12:49:06 +02:00
|
|
|
Signin(ctx context.Context, c *model.Client, sessionID string,
|
2020-02-02 10:30:40 +02:00
|
|
|
code string) (token string, userID string, err error)
|
2020-03-04 17:59:59 +02:00
|
|
|
Signout(ctx context.Context, c *model.Client) (err error)
|
2020-01-28 19:51:00 +02:00
|
|
|
Post(ctx context.Context, c *model.Client, content string, replyToID string, format string,
|
|
|
|
visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error)
|
|
|
|
Like(ctx context.Context, c *model.Client, id string) (count int64, err error)
|
|
|
|
UnLike(ctx context.Context, c *model.Client, id string) (count int64, err error)
|
|
|
|
Retweet(ctx context.Context, c *model.Client, id string) (count int64, err error)
|
|
|
|
UnRetweet(ctx context.Context, c *model.Client, id string) (count int64, err error)
|
2020-02-09 15:42:16 +02:00
|
|
|
Vote(ctx context.Context, c *model.Client, id string, choices []string) (err error)
|
2020-01-28 19:51:00 +02:00
|
|
|
Follow(ctx context.Context, c *model.Client, id string) (err error)
|
|
|
|
UnFollow(ctx context.Context, c *model.Client, id string) (err error)
|
2020-02-08 12:49:06 +02:00
|
|
|
Mute(ctx context.Context, c *model.Client, id string) (err error)
|
|
|
|
UnMute(ctx context.Context, c *model.Client, id string) (err error)
|
|
|
|
Block(ctx context.Context, c *model.Client, id string) (err error)
|
|
|
|
UnBlock(ctx context.Context, c *model.Client, id string) (err error)
|
2020-04-17 20:19:11 +03:00
|
|
|
Subscribe(ctx context.Context, c *model.Client, id string) (err error)
|
|
|
|
UnSubscribe(ctx context.Context, c *model.Client, id string) (err error)
|
2020-01-28 19:51:00 +02:00
|
|
|
SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error)
|
2020-02-02 09:24:06 +02:00
|
|
|
MuteConversation(ctx context.Context, c *model.Client, id string) (err error)
|
|
|
|
UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error)
|
2020-02-02 10:30:40 +02:00
|
|
|
Delete(ctx context.Context, c *model.Client, id string) (err error)
|
2020-02-19 00:15:37 +02:00
|
|
|
ReadNotifications(ctx context.Context, c *model.Client, maxID string) (err error)
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type service struct {
|
|
|
|
clientName string
|
|
|
|
clientScope string
|
|
|
|
clientWebsite string
|
2019-12-25 18:38:47 +02:00
|
|
|
customCSS string
|
2019-12-26 13:25:29 +02:00
|
|
|
postFormats []model.PostFormat
|
2019-12-13 20:08:26 +02:00
|
|
|
renderer renderer.Renderer
|
2020-01-28 19:51:00 +02:00
|
|
|
sessionRepo model.SessionRepo
|
|
|
|
appRepo model.AppRepo
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func NewService(clientName string,
|
|
|
|
clientScope string,
|
|
|
|
clientWebsite string,
|
|
|
|
customCSS string,
|
|
|
|
postFormats []model.PostFormat,
|
|
|
|
renderer renderer.Renderer,
|
|
|
|
sessionRepo model.SessionRepo,
|
|
|
|
appRepo model.AppRepo,
|
|
|
|
) Service {
|
2019-12-13 20:08:26 +02:00
|
|
|
return &service{
|
|
|
|
clientName: clientName,
|
|
|
|
clientScope: clientScope,
|
|
|
|
clientWebsite: clientWebsite,
|
2019-12-25 18:38:47 +02:00
|
|
|
customCSS: customCSS,
|
2019-12-26 13:25:29 +02:00
|
|
|
postFormats: postFormats,
|
2019-12-13 20:08:26 +02:00
|
|
|
renderer: renderer,
|
|
|
|
sessionRepo: sessionRepo,
|
|
|
|
appRepo: appRepo,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-25 12:07:06 +02:00
|
|
|
func getRendererContext(c *model.Client) *renderer.Context {
|
|
|
|
var settings model.Settings
|
|
|
|
var session model.Session
|
|
|
|
if c != nil {
|
|
|
|
settings = c.Session.Settings
|
|
|
|
session = c.Session
|
|
|
|
} else {
|
|
|
|
settings = *model.NewSettings()
|
|
|
|
}
|
2020-01-14 18:57:16 +02:00
|
|
|
return &renderer.Context{
|
2020-01-25 12:07:06 +02:00
|
|
|
MaskNSFW: settings.MaskNSFW,
|
|
|
|
ThreadInNewTab: settings.ThreadInNewTab,
|
|
|
|
FluorideMode: settings.FluorideMode,
|
|
|
|
DarkMode: settings.DarkMode,
|
|
|
|
CSRFToken: session.CSRFToken,
|
2020-02-02 10:30:40 +02:00
|
|
|
UserID: session.UserID,
|
2020-01-14 18:57:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func addToReplyMap(m map[string][]mastodon.ReplyInfo, key interface{},
|
|
|
|
val string, number int) {
|
|
|
|
if key == nil {
|
2019-12-13 20:08:26 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
keyStr, ok := key.(string)
|
|
|
|
if !ok {
|
2019-12-13 20:08:26 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
_, ok = m[keyStr]
|
|
|
|
if !ok {
|
|
|
|
m[keyStr] = []mastodon.ReplyInfo{}
|
|
|
|
}
|
2019-12-13 20:08:26 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
m[keyStr] = append(m[keyStr], mastodon.ReplyInfo{val, number})
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) getCommonData(ctx context.Context, c *model.Client,
|
2020-02-19 00:15:37 +02:00
|
|
|
title string) (data *renderer.CommonData) {
|
|
|
|
data = &renderer.CommonData{
|
|
|
|
Title: title + " - " + svc.clientName,
|
|
|
|
CustomCSS: svc.customCSS,
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
2020-02-19 00:15:37 +02:00
|
|
|
if c != nil && c.Session.IsLoggedIn() {
|
|
|
|
data.CSRFToken = c.Session.CSRFToken
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
return
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeErrorPage(ctx context.Context, c *model.Client, err error) {
|
2019-12-26 11:11:24 +02:00
|
|
|
var errStr string
|
|
|
|
if err != nil {
|
|
|
|
errStr = err.Error()
|
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, nil, "error")
|
2019-12-26 11:11:24 +02:00
|
|
|
data := &renderer.ErrorData{
|
|
|
|
CommonData: commonData,
|
|
|
|
Error: errStr,
|
|
|
|
}
|
|
|
|
|
2020-01-25 12:07:06 +02:00
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
svc.renderer.Render(rCtx, c.Writer, renderer.ErrorPage, data)
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeSigninPage(ctx context.Context, c *model.Client) (
|
|
|
|
err error) {
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, nil, "signin")
|
2019-12-26 11:11:24 +02:00
|
|
|
data := &renderer.SigninData{
|
|
|
|
CommonData: commonData,
|
|
|
|
}
|
|
|
|
|
2020-01-25 12:07:06 +02:00
|
|
|
rCtx := getRendererContext(nil)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.SigninPage, data)
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
func (svc *service) ServeRootPage(ctx context.Context, c *model.Client) (err error) {
|
|
|
|
data := &renderer.RootData{
|
|
|
|
Title: svc.clientName,
|
|
|
|
}
|
|
|
|
|
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.RootPage, data)
|
2020-02-19 00:15:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (svc *service) ServeNavPage(ctx context.Context, c *model.Client) (err error) {
|
|
|
|
u, err := c.GetAccountCurrentUser(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
postContext := model.PostContext{
|
|
|
|
DefaultVisibility: c.Session.Settings.DefaultVisibility,
|
|
|
|
Formats: svc.postFormats,
|
|
|
|
}
|
|
|
|
|
|
|
|
commonData := svc.getCommonData(ctx, c, "Nav")
|
2020-02-23 15:26:39 +02:00
|
|
|
commonData.Target = "main"
|
2020-02-19 00:15:37 +02:00
|
|
|
data := &renderer.NavData{
|
|
|
|
User: u,
|
|
|
|
CommonData: commonData,
|
|
|
|
PostContext: postContext,
|
|
|
|
}
|
|
|
|
|
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.NavPage, data)
|
2020-02-19 00:15:37 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeTimelinePage(ctx context.Context, c *model.Client,
|
|
|
|
tType string, maxID string, minID string) (err error) {
|
2019-12-13 20:08:26 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
var nextLink, prevLink, title string
|
|
|
|
var statuses []*mastodon.Status
|
2019-12-13 20:08:26 +02:00
|
|
|
var pg = mastodon.Pagination{
|
2019-12-15 08:55:13 +02:00
|
|
|
MaxID: maxID,
|
|
|
|
MinID: minID,
|
|
|
|
Limit: 20,
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
switch tType {
|
2019-12-25 06:30:21 +02:00
|
|
|
default:
|
2020-01-28 19:51:00 +02:00
|
|
|
return errInvalidArgument
|
2019-12-25 06:30:21 +02:00
|
|
|
case "home":
|
|
|
|
statuses, err = c.GetTimelineHome(ctx, &pg)
|
|
|
|
title = "Timeline"
|
2020-01-28 22:56:15 +02:00
|
|
|
case "direct":
|
|
|
|
statuses, err = c.GetTimelineDirect(ctx, &pg)
|
|
|
|
title = "Local Timeline"
|
2019-12-25 06:30:21 +02:00
|
|
|
case "local":
|
|
|
|
statuses, err = c.GetTimelinePublic(ctx, true, &pg)
|
|
|
|
title = "Local Timeline"
|
|
|
|
case "twkn":
|
|
|
|
statuses, err = c.GetTimelinePublic(ctx, false, &pg)
|
|
|
|
title = "The Whole Known Network"
|
|
|
|
}
|
2019-12-13 20:08:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-29 13:32:24 +02:00
|
|
|
for i := range statuses {
|
2019-12-31 13:00:21 +02:00
|
|
|
if statuses[i].Reblog != nil {
|
2020-01-05 20:55:37 +02:00
|
|
|
statuses[i].Reblog.RetweetedByID = statuses[i].ID
|
2019-12-31 13:00:21 +02:00
|
|
|
}
|
2019-12-29 13:32:24 +02:00
|
|
|
}
|
|
|
|
|
2019-12-15 08:55:13 +02:00
|
|
|
if len(maxID) > 0 && len(statuses) > 0 {
|
2020-01-28 19:51:00 +02:00
|
|
|
prevLink = fmt.Sprintf("/timeline/%s?min_id=%s", tType,
|
|
|
|
statuses[0].ID)
|
2019-12-15 08:55:13 +02:00
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
|
2019-12-15 08:55:13 +02:00
|
|
|
if len(minID) > 0 && len(pg.MinID) > 0 {
|
2020-01-28 19:51:00 +02:00
|
|
|
newPg := &mastodon.Pagination{MinID: pg.MinID, Limit: 20}
|
|
|
|
newStatuses, err := c.GetTimelineHome(ctx, newPg)
|
2019-12-15 08:55:13 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
newLen := len(newStatuses)
|
|
|
|
if newLen == 20 {
|
|
|
|
prevLink = fmt.Sprintf("/timeline/%s?min_id=%s",
|
|
|
|
tType, pg.MinID)
|
2019-12-15 08:55:13 +02:00
|
|
|
} else {
|
2020-01-28 19:51:00 +02:00
|
|
|
i := 20 - newLen - 1
|
2019-12-15 08:55:13 +02:00
|
|
|
if len(statuses) > i {
|
2020-01-28 19:51:00 +02:00
|
|
|
prevLink = fmt.Sprintf("/timeline/%s?min_id=%s",
|
|
|
|
tType, statuses[i].ID)
|
2019-12-15 08:55:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
|
2019-12-13 20:08:26 +02:00
|
|
|
if len(pg.MaxID) > 0 {
|
2020-01-28 19:51:00 +02:00
|
|
|
nextLink = fmt.Sprintf("/timeline/%s?max_id=%s", tType, pg.MaxID)
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, tType+" timeline ")
|
2019-12-25 16:13:59 +02:00
|
|
|
data := &renderer.TimelineData{
|
2020-02-19 00:15:37 +02:00
|
|
|
Title: title,
|
|
|
|
Statuses: statuses,
|
|
|
|
NextLink: nextLink,
|
|
|
|
PrevLink: prevLink,
|
|
|
|
CommonData: commonData,
|
2019-12-25 16:13:59 +02:00
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
|
2020-01-25 12:07:06 +02:00
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.TimelinePage, data)
|
2020-01-28 19:51:00 +02:00
|
|
|
}
|
2019-12-25 16:13:59 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeThreadPage(ctx context.Context, c *model.Client,
|
|
|
|
id string, reply bool) (err error) {
|
2019-12-13 20:08:26 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
var postContext model.PostContext
|
2019-12-13 20:08:26 +02:00
|
|
|
|
|
|
|
status, err := c.GetStatus(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-14 19:47:14 +02:00
|
|
|
u, err := c.GetAccountCurrentUser(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-13 22:33:20 +02:00
|
|
|
if reply {
|
2019-12-21 10:36:44 +02:00
|
|
|
var content string
|
2020-01-28 19:51:00 +02:00
|
|
|
var visibility string
|
2019-12-14 19:47:14 +02:00
|
|
|
if u.ID != status.Account.ID {
|
|
|
|
content += "@" + status.Account.Acct + " "
|
|
|
|
}
|
2019-12-19 00:14:02 +02:00
|
|
|
for i := range status.Mentions {
|
2020-01-28 19:51:00 +02:00
|
|
|
if status.Mentions[i].ID != u.ID &&
|
|
|
|
status.Mentions[i].ID != status.Account.ID {
|
2019-12-19 00:14:02 +02:00
|
|
|
content += "@" + status.Mentions[i].Acct + " "
|
2019-12-14 19:47:14 +02:00
|
|
|
}
|
2019-12-13 22:33:20 +02:00
|
|
|
}
|
2019-12-21 15:26:31 +02:00
|
|
|
|
2019-12-27 10:06:43 +02:00
|
|
|
if c.Session.Settings.CopyScope {
|
|
|
|
s, err := c.GetStatus(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
visibility = s.Visibility
|
|
|
|
} else {
|
|
|
|
visibility = c.Session.Settings.DefaultVisibility
|
2019-12-21 15:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
postContext = model.PostContext{
|
2019-12-27 10:06:43 +02:00
|
|
|
DefaultVisibility: visibility,
|
2019-12-26 13:25:29 +02:00
|
|
|
Formats: svc.postFormats,
|
2019-12-21 15:26:31 +02:00
|
|
|
ReplyContext: &model.ReplyContext{
|
|
|
|
InReplyToID: id,
|
|
|
|
InReplyToName: status.Account.Acct,
|
|
|
|
ReplyContent: content,
|
|
|
|
},
|
2020-01-12 19:16:57 +02:00
|
|
|
DarkMode: c.Session.Settings.DarkMode,
|
2019-12-21 10:36:44 +02:00
|
|
|
}
|
2019-12-13 22:33:20 +02:00
|
|
|
}
|
|
|
|
|
2019-12-19 00:14:02 +02:00
|
|
|
context, err := c.GetStatusContext(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
statuses := append(append(context.Ancestors, status), context.Descendants...)
|
2020-01-28 19:51:00 +02:00
|
|
|
replies := make(map[string][]mastodon.ReplyInfo)
|
2019-12-19 00:14:02 +02:00
|
|
|
|
|
|
|
for i := range statuses {
|
|
|
|
statuses[i].ShowReplies = true
|
2020-01-28 19:51:00 +02:00
|
|
|
statuses[i].ReplyMap = replies
|
2020-02-26 13:27:42 +02:00
|
|
|
statuses[i].ReplyNumber = i
|
2020-01-28 19:51:00 +02:00
|
|
|
addToReplyMap(replies, statuses[i].InReplyToID, statuses[i].ID, i+1)
|
2019-12-19 00:14:02 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, "post by "+status.Account.DisplayName)
|
2019-12-25 16:13:59 +02:00
|
|
|
data := &renderer.ThreadData{
|
|
|
|
Statuses: statuses,
|
|
|
|
PostContext: postContext,
|
2020-01-28 19:51:00 +02:00
|
|
|
ReplyMap: replies,
|
2019-12-25 18:38:47 +02:00
|
|
|
CommonData: commonData,
|
2019-12-25 16:13:59 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.ThreadPage, data)
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeLikedByPage(ctx context.Context, c *model.Client,
|
|
|
|
id string) (err error) {
|
2019-12-15 19:37:58 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
likers, err := c.GetFavouritedBy(ctx, id, nil)
|
|
|
|
if err != nil {
|
|
|
|
return
|
2019-12-15 19:37:58 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, "likes")
|
2020-01-28 19:51:00 +02:00
|
|
|
data := &renderer.LikedByData{
|
|
|
|
CommonData: commonData,
|
|
|
|
Users: likers,
|
2019-12-15 19:37:58 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.LikedByPage, data)
|
2020-01-28 19:51:00 +02:00
|
|
|
}
|
2019-12-15 19:37:58 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeRetweetedByPage(ctx context.Context, c *model.Client,
|
|
|
|
id string) (err error) {
|
2019-12-15 19:37:58 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
retweeters, err := c.GetRebloggedBy(ctx, id, nil)
|
2019-12-15 19:37:58 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, "retweets")
|
2020-01-28 19:51:00 +02:00
|
|
|
data := &renderer.RetweetedByData{
|
|
|
|
CommonData: commonData,
|
|
|
|
Users: retweeters,
|
|
|
|
}
|
|
|
|
|
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.RetweetedByPage, data)
|
2019-12-15 19:37:58 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeNotificationPage(ctx context.Context, c *model.Client,
|
|
|
|
maxID string, minID string) (err error) {
|
|
|
|
|
|
|
|
var nextLink string
|
|
|
|
var unreadCount int
|
2020-02-19 00:15:37 +02:00
|
|
|
var readID string
|
2020-01-28 19:51:00 +02:00
|
|
|
var pg = mastodon.Pagination{
|
|
|
|
MaxID: maxID,
|
|
|
|
MinID: minID,
|
|
|
|
Limit: 20,
|
2019-12-26 11:11:24 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
notifications, err := c.GetNotifications(ctx, &pg)
|
2019-12-26 11:11:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
for i := range notifications {
|
|
|
|
if notifications[i].Pleroma != nil && !notifications[i].Pleroma.IsSeen {
|
|
|
|
unreadCount++
|
|
|
|
}
|
2019-12-26 11:11:24 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
if unreadCount > 0 {
|
2020-02-19 00:15:37 +02:00
|
|
|
readID = notifications[0].ID
|
2019-12-26 11:11:24 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
if len(notifications) == 20 && len(pg.MaxID) > 0 {
|
2020-01-28 19:51:00 +02:00
|
|
|
nextLink = "/notifications?max_id=" + pg.MaxID
|
2019-12-26 11:11:24 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, "notifications")
|
|
|
|
commonData.AutoRefresh = c.Session.Settings.AutoRefreshNotifications
|
2020-02-23 15:26:39 +02:00
|
|
|
commonData.Target = "main"
|
2020-02-26 12:27:17 +02:00
|
|
|
commonData.Count = unreadCount
|
2020-01-28 19:51:00 +02:00
|
|
|
data := &renderer.NotificationData{
|
|
|
|
Notifications: notifications,
|
2020-02-19 00:15:37 +02:00
|
|
|
UnreadCount: unreadCount,
|
|
|
|
ReadID: readID,
|
2020-01-28 19:51:00 +02:00
|
|
|
NextLink: nextLink,
|
|
|
|
CommonData: commonData,
|
2019-12-26 11:11:24 +02:00
|
|
|
}
|
2020-01-25 12:07:06 +02:00
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.NotificationPage, data)
|
2019-12-26 11:11:24 +02:00
|
|
|
}
|
2019-12-26 21:18:09 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeUserPage(ctx context.Context, c *model.Client,
|
2020-01-31 05:38:49 +02:00
|
|
|
id string, pageType string, maxID string, minID string) (err error) {
|
2020-01-28 19:51:00 +02:00
|
|
|
|
2019-12-29 05:43:57 +02:00
|
|
|
var nextLink string
|
2020-01-31 05:38:49 +02:00
|
|
|
var statuses []*mastodon.Status
|
|
|
|
var users []*mastodon.Account
|
2019-12-29 05:43:57 +02:00
|
|
|
var pg = mastodon.Pagination{
|
|
|
|
MaxID: maxID,
|
|
|
|
MinID: minID,
|
|
|
|
Limit: 20,
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
user, err := c.GetAccount(ctx, id)
|
2019-12-29 05:43:57 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-31 05:38:49 +02:00
|
|
|
switch pageType {
|
|
|
|
case "":
|
|
|
|
statuses, err = c.GetAccountStatuses(ctx, id, false, &pg)
|
|
|
|
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":
|
|
|
|
users, err = c.GetAccountFollowing(ctx, id, &pg)
|
|
|
|
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":
|
|
|
|
users, err = c.GetAccountFollowers(ctx, id, &pg)
|
|
|
|
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":
|
|
|
|
statuses, err = c.GetAccountStatuses(ctx, id, true, &pg)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(statuses) == 20 && len(pg.MaxID) > 0 {
|
|
|
|
nextLink = fmt.Sprintf("/user/%s/media?max_id=%s",
|
|
|
|
id, pg.MaxID)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return errInvalidArgument
|
2019-12-29 05:43:57 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, user.DisplayName)
|
2020-01-28 19:51:00 +02:00
|
|
|
data := &renderer.UserData{
|
|
|
|
User: user,
|
2020-02-19 00:15:37 +02:00
|
|
|
IsCurrent: c.Session.UserID == user.ID,
|
2020-01-31 05:38:49 +02:00
|
|
|
Type: pageType,
|
|
|
|
Users: users,
|
2020-01-28 19:51:00 +02:00
|
|
|
Statuses: statuses,
|
2019-12-29 05:43:57 +02:00
|
|
|
NextLink: nextLink,
|
2020-01-28 19:51:00 +02:00
|
|
|
CommonData: commonData,
|
2019-12-29 05:43:57 +02:00
|
|
|
}
|
2020-01-25 12:07:06 +02:00
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.UserPage, data)
|
2020-01-28 19:51:00 +02:00
|
|
|
}
|
2019-12-29 05:43:57 +02:00
|
|
|
|
2020-01-30 17:32:37 +02:00
|
|
|
func (svc *service) ServeUserSearchPage(ctx context.Context, c *model.Client,
|
|
|
|
id string, q string, offset int) (err error) {
|
|
|
|
|
|
|
|
var nextLink string
|
|
|
|
var title = "search"
|
|
|
|
|
|
|
|
user, err := c.GetAccount(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
results, err := c.Search(ctx, q, "statuses", 20, true, offset, id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(results.Statuses) == 20 {
|
|
|
|
offset += 20
|
|
|
|
nextLink = fmt.Sprintf("/usersearch/%s?q=%s&offset=%d", id, q, offset)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(q) > 0 {
|
|
|
|
title += " \"" + q + "\""
|
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, title)
|
2020-01-30 17:32:37 +02:00
|
|
|
data := &renderer.UserSearchData{
|
|
|
|
CommonData: commonData,
|
|
|
|
User: user,
|
|
|
|
Q: q,
|
|
|
|
Statuses: results.Statuses,
|
|
|
|
NextLink: nextLink,
|
|
|
|
}
|
|
|
|
|
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.UserSearchPage, data)
|
2020-01-30 17:32:37 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeAboutPage(ctx context.Context, c *model.Client) (err error) {
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, "about")
|
2020-01-28 19:51:00 +02:00
|
|
|
data := &renderer.AboutData{
|
|
|
|
CommonData: commonData,
|
2019-12-29 05:43:57 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.AboutPage, data)
|
2020-01-28 19:51:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (svc *service) ServeEmojiPage(ctx context.Context, c *model.Client) (err error) {
|
|
|
|
emojis, err := c.GetInstanceEmojis(ctx)
|
2019-12-29 05:43:57 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, "emojis")
|
2020-01-28 19:51:00 +02:00
|
|
|
data := &renderer.EmojiData{
|
|
|
|
Emojis: emojis,
|
2019-12-29 05:43:57 +02:00
|
|
|
CommonData: commonData,
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.EmojiPage, data)
|
2019-12-29 05:43:57 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeSearchPage(ctx context.Context, c *model.Client,
|
|
|
|
q string, qType string, offset int) (err error) {
|
|
|
|
|
2019-12-26 21:18:09 +02:00
|
|
|
var nextLink string
|
2020-01-28 19:51:00 +02:00
|
|
|
var title = "search"
|
2019-12-26 21:18:09 +02:00
|
|
|
|
2020-01-30 17:32:37 +02:00
|
|
|
results, err := c.Search(ctx, q, qType, 20, true, offset, "")
|
2019-12-26 21:18:09 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
if (qType == "accounts" && len(results.Accounts) == 20) ||
|
|
|
|
(qType == "statuses" && len(results.Statuses) == 20) {
|
2019-12-26 21:18:09 +02:00
|
|
|
offset += 20
|
|
|
|
nextLink = fmt.Sprintf("/search?q=%s&type=%s&offset=%d", q, qType, offset)
|
|
|
|
}
|
|
|
|
|
2020-01-10 05:53:02 +02:00
|
|
|
if len(q) > 0 {
|
|
|
|
title += " \"" + q + "\""
|
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, title)
|
2019-12-26 21:18:09 +02:00
|
|
|
data := &renderer.SearchData{
|
|
|
|
CommonData: commonData,
|
|
|
|
Q: q,
|
|
|
|
Type: qType,
|
|
|
|
Users: results.Accounts,
|
|
|
|
Statuses: results.Statuses,
|
|
|
|
NextLink: nextLink,
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.SearchPage, data)
|
2019-12-26 21:18:09 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) ServeSettingsPage(ctx context.Context, c *model.Client) (err error) {
|
2020-02-19 00:15:37 +02:00
|
|
|
commonData := svc.getCommonData(ctx, c, "settings")
|
2019-12-27 10:06:43 +02:00
|
|
|
data := &renderer.SettingsData{
|
|
|
|
CommonData: commonData,
|
|
|
|
Settings: &c.Session.Settings,
|
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
|
2020-01-25 12:07:06 +02:00
|
|
|
rCtx := getRendererContext(c)
|
2020-02-23 21:51:42 +02:00
|
|
|
return svc.renderer.Render(rCtx, c.Writer, renderer.SettingsPage, data)
|
2020-01-28 19:51:00 +02:00
|
|
|
}
|
2019-12-27 10:06:43 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) NewSession(ctx context.Context, instance string) (
|
|
|
|
redirectUrl string, sessionID string, err error) {
|
|
|
|
|
|
|
|
var instanceURL string
|
|
|
|
if strings.HasPrefix(instance, "https://") {
|
|
|
|
instanceURL = instance
|
|
|
|
instance = strings.TrimPrefix(instance, "https://")
|
|
|
|
} else {
|
|
|
|
instanceURL = "https://" + instance
|
|
|
|
}
|
|
|
|
|
|
|
|
sessionID, err = util.NewSessionID()
|
2019-12-27 10:06:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
csrfToken, err := util.NewCSRFToken()
|
2019-12-27 10:06:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
session := model.Session{
|
|
|
|
ID: sessionID,
|
|
|
|
InstanceDomain: instance,
|
|
|
|
CSRFToken: csrfToken,
|
|
|
|
Settings: *model.NewSettings(),
|
|
|
|
}
|
|
|
|
|
2019-12-27 10:06:43 +02:00
|
|
|
err = svc.sessionRepo.Add(session)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
app, err := svc.appRepo.Get(instance)
|
|
|
|
if err != nil {
|
|
|
|
if err != model.ErrAppNotFound {
|
|
|
|
return
|
|
|
|
}
|
2019-12-15 19:37:58 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
mastoApp, err := mastodon.RegisterApp(ctx, &mastodon.AppConfig{
|
|
|
|
Server: instanceURL,
|
|
|
|
ClientName: svc.clientName,
|
|
|
|
Scopes: svc.clientScope,
|
|
|
|
Website: svc.clientWebsite,
|
|
|
|
RedirectURIs: svc.clientWebsite + "/oauth_callback",
|
|
|
|
})
|
2019-12-25 18:38:47 +02:00
|
|
|
if err != nil {
|
2020-01-28 19:51:00 +02:00
|
|
|
return "", "", err
|
2019-12-15 19:37:58 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
app = model.App{
|
|
|
|
InstanceDomain: instance,
|
|
|
|
InstanceURL: instanceURL,
|
|
|
|
ClientID: mastoApp.ClientID,
|
|
|
|
ClientSecret: mastoApp.ClientSecret,
|
2019-12-25 18:38:47 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
err = svc.appRepo.Add(app)
|
2019-12-25 18:38:47 +02:00
|
|
|
if err != nil {
|
2020-01-28 19:51:00 +02:00
|
|
|
return "", "", err
|
2019-12-25 18:38:47 +02:00
|
|
|
}
|
2019-12-25 16:13:59 +02:00
|
|
|
}
|
2019-12-15 19:37:58 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
u, err := url.Parse("/oauth/authorize")
|
2020-01-08 20:16:06 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2019-12-13 20:08:26 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
q := make(url.Values)
|
|
|
|
q.Set("scope", "read write follow")
|
|
|
|
q.Set("client_id", app.ClientID)
|
|
|
|
q.Set("response_type", "code")
|
|
|
|
q.Set("redirect_uri", svc.clientWebsite+"/oauth_callback")
|
|
|
|
u.RawQuery = q.Encode()
|
|
|
|
|
|
|
|
redirectUrl = instanceURL + u.String()
|
|
|
|
|
2019-12-13 20:08:26 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) Signin(ctx context.Context, c *model.Client,
|
2020-02-02 10:30:40 +02:00
|
|
|
sessionID string, code string) (token string, userID string, err error) {
|
2020-01-28 19:51:00 +02:00
|
|
|
|
|
|
|
if len(code) < 1 {
|
|
|
|
err = errInvalidArgument
|
2020-01-08 20:16:06 +02:00
|
|
|
return
|
|
|
|
}
|
2019-12-13 20:08:26 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
err = c.AuthenticateToken(ctx, code, svc.clientWebsite+"/oauth_callback")
|
2020-01-08 20:16:06 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
token = c.GetAccessToken(ctx)
|
|
|
|
|
2020-02-02 10:30:40 +02:00
|
|
|
u, err := c.GetAccountCurrentUser(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
userID = u.ID
|
|
|
|
|
2019-12-13 20:08:26 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:59:59 +02:00
|
|
|
func (svc *service) Signout(ctx context.Context, c *model.Client) (err error) {
|
|
|
|
svc.sessionRepo.Remove(c.Session.ID)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) Post(ctx context.Context, c *model.Client, content string,
|
|
|
|
replyToID string, format string, visibility string, isNSFW bool,
|
|
|
|
files []*multipart.FileHeader) (id string, err error) {
|
|
|
|
|
|
|
|
var mediaIDs []string
|
2019-12-14 22:19:02 +02:00
|
|
|
for _, f := range files {
|
|
|
|
a, err := c.UploadMediaFromMultipartFileHeader(ctx, f)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
mediaIDs = append(mediaIDs, a.ID)
|
2019-12-14 22:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-12-13 20:08:26 +02:00
|
|
|
tweet := &mastodon.Toot{
|
|
|
|
Status: content,
|
|
|
|
InReplyToID: replyToID,
|
2020-01-28 19:51:00 +02:00
|
|
|
MediaIDs: mediaIDs,
|
2019-12-26 13:25:29 +02:00
|
|
|
ContentType: format,
|
2019-12-21 15:26:31 +02:00
|
|
|
Visibility: visibility,
|
2019-12-22 18:27:49 +02:00
|
|
|
Sensitive: isNSFW,
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
2019-12-14 20:12:48 +02:00
|
|
|
|
|
|
|
s, err := c.PostStatus(ctx, tweet)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.ID, nil
|
2019-12-13 20:08:26 +02:00
|
|
|
}
|
2019-12-19 00:14:02 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) Like(ctx context.Context, c *model.Client, id string) (
|
|
|
|
count int64, err error) {
|
|
|
|
s, err := c.Favourite(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
count = s.FavouritesCount
|
2019-12-20 20:30:20 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) UnLike(ctx context.Context, c *model.Client, id string) (
|
|
|
|
count int64, err error) {
|
|
|
|
s, err := c.Unfavourite(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
count = s.FavouritesCount
|
2019-12-20 20:30:20 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) Retweet(ctx context.Context, c *model.Client, id string) (
|
|
|
|
count int64, err error) {
|
|
|
|
s, err := c.Reblog(ctx, id)
|
|
|
|
if err != nil {
|
2019-12-19 00:14:02 +02:00
|
|
|
return
|
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
if s.Reblog != nil {
|
|
|
|
count = s.Reblog.ReblogsCount
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2019-12-21 13:13:21 +02:00
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) UnRetweet(ctx context.Context, c *model.Client, id string) (
|
|
|
|
count int64, err error) {
|
|
|
|
s, err := c.Unreblog(ctx, id)
|
|
|
|
if err != nil {
|
2019-12-19 00:14:02 +02:00
|
|
|
return
|
|
|
|
}
|
2020-01-28 19:51:00 +02:00
|
|
|
count = s.ReblogsCount
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-09 15:42:16 +02:00
|
|
|
func (svc *service) Vote(ctx context.Context, c *model.Client, id string,
|
|
|
|
choices []string) (err error) {
|
|
|
|
_, err = c.Vote(ctx, id, choices)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) Follow(ctx context.Context, c *model.Client, id string) (err error) {
|
|
|
|
_, err = c.AccountFollow(ctx, id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc *service) UnFollow(ctx context.Context, c *model.Client, id string) (err error) {
|
|
|
|
_, err = c.AccountUnfollow(ctx, id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-08 12:49:06 +02:00
|
|
|
func (svc *service) Mute(ctx context.Context, c *model.Client, id string) (err error) {
|
|
|
|
_, err = c.AccountMute(ctx, id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc *service) UnMute(ctx context.Context, c *model.Client, id string) (err error) {
|
|
|
|
_, err = c.AccountUnmute(ctx, id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc *service) Block(ctx context.Context, c *model.Client, id string) (err error) {
|
|
|
|
_, err = c.AccountBlock(ctx, id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc *service) UnBlock(ctx context.Context, c *model.Client, id string) (err error) {
|
|
|
|
_, err = c.AccountUnblock(ctx, id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-17 20:19:11 +03:00
|
|
|
func (svc *service) Subscribe(ctx context.Context, c *model.Client, id string) (err error) {
|
|
|
|
_, err = c.Subscribe(ctx, id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc *service) UnSubscribe(ctx context.Context, c *model.Client, id string) (err error) {
|
|
|
|
_, err = c.UnSubscribe(ctx, id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
func (svc *service) SaveSettings(ctx context.Context, c *model.Client,
|
|
|
|
settings *model.Settings) (err error) {
|
|
|
|
|
|
|
|
session, err := svc.sessionRepo.Get(c.Session.ID)
|
|
|
|
if err != nil {
|
|
|
|
return
|
2019-12-19 00:14:02 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:51:00 +02:00
|
|
|
session.Settings = *settings
|
|
|
|
return svc.sessionRepo.Add(session)
|
2019-12-19 00:14:02 +02:00
|
|
|
}
|
2020-02-02 09:24:06 +02:00
|
|
|
|
2020-02-02 10:30:40 +02:00
|
|
|
func (svc *service) MuteConversation(ctx context.Context, c *model.Client,
|
2020-02-02 09:24:06 +02:00
|
|
|
id string) (err error) {
|
|
|
|
_, err = c.MuteConversation(ctx, id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-02 10:30:40 +02:00
|
|
|
func (svc *service) UnMuteConversation(ctx context.Context, c *model.Client,
|
2020-02-02 09:24:06 +02:00
|
|
|
id string) (err error) {
|
|
|
|
_, err = c.UnmuteConversation(ctx, id)
|
|
|
|
return
|
|
|
|
}
|
2020-02-02 10:30:40 +02:00
|
|
|
|
|
|
|
func (svc *service) Delete(ctx context.Context, c *model.Client,
|
|
|
|
id string) (err error) {
|
|
|
|
return c.DeleteStatus(ctx, id)
|
|
|
|
}
|
2020-02-19 00:15:37 +02:00
|
|
|
|
|
|
|
func (svc *service) ReadNotifications(ctx context.Context, c *model.Client,
|
|
|
|
maxID string) (err error) {
|
|
|
|
return c.ReadNotifications(ctx, maxID)
|
|
|
|
}
|