Merge branch 'master' into absolute_fluoride
This commit is contained in:
commit
4ab53547a8
21
Makefile
21
Makefile
@ -26,18 +26,19 @@ bloat.def.conf:
|
|||||||
< bloat.conf > bloat.def.conf
|
< bloat.conf > bloat.def.conf
|
||||||
|
|
||||||
install: bloat
|
install: bloat
|
||||||
mkdir -p $(BINPATH) $(SHAREPATH)/templates $(SHAREPATH)/static
|
mkdir -p $(DESTDIR)$(BINPATH) \
|
||||||
cp bloat $(BINPATH)/bloat
|
$(DESTDIR)$(SHAREPATH)/templates \
|
||||||
chmod 0755 $(BINPATH)/bloat
|
$(DESTDIR)$(SHAREPATH)/static
|
||||||
cp -r templates/* $(SHAREPATH)/templates
|
cp bloat $(DESTDIR)$(BINPATH)/bloat
|
||||||
chmod 0644 $(SHAREPATH)/templates/*
|
chmod 0755 $(DESTDIR)$(BINPATH)/bloat
|
||||||
cp -r static/* $(SHAREPATH)/static
|
cp -r templates/* $(DESTDIR)$(SHAREPATH)/templates
|
||||||
chmod 0644 $(SHAREPATH)/static/*
|
chmod 0644 $(DESTDIR)$(SHAREPATH)/templates/*
|
||||||
|
cp -r static/* $(DESTDIR)$(SHAREPATH)/static
|
||||||
|
chmod 0644 $(DESTDIR)$(SHAREPATH)/static/*
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(BINPATH)/bloat
|
rm -f $(DESTDIR)$(BINPATH)/bloat
|
||||||
rm -fr $(SHAREPATH)/templates
|
rm -fr $(DESTDIR)$(SHAREPATH)
|
||||||
rm -fr $(SHAREPATH)/static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f bloat
|
rm -f bloat
|
||||||
|
22
main.go
22
main.go
@ -4,12 +4,10 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"bloat/config"
|
"bloat/config"
|
||||||
"bloat/renderer"
|
"bloat/renderer"
|
||||||
@ -27,20 +25,6 @@ func errExit(err error) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupHttp() {
|
|
||||||
tr := http.DefaultTransport.(*http.Transport)
|
|
||||||
tr.MaxIdleConnsPerHost = 30
|
|
||||||
tr.MaxIdleConns = 300
|
|
||||||
tr.ForceAttemptHTTP2 = false
|
|
||||||
tr.DialContext = (&net.Dialer{
|
|
||||||
Timeout: 30 * time.Second,
|
|
||||||
KeepAlive: 3 * time.Minute,
|
|
||||||
DualStack: true,
|
|
||||||
}).DialContext
|
|
||||||
client := http.DefaultClient
|
|
||||||
client.Transport = tr
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
opts, _, err := util.Getopts(os.Args, "f:")
|
opts, _, err := util.Getopts(os.Args, "f:")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -108,11 +92,9 @@ func main() {
|
|||||||
logger = log.New(lf, "", log.LstdFlags)
|
logger = log.New(lf, "", log.LstdFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
setupHttp()
|
|
||||||
|
|
||||||
s := service.NewService(config.ClientName, config.ClientScope,
|
s := service.NewService(config.ClientName, config.ClientScope,
|
||||||
config.ClientWebsite, customCSS, config.PostFormats, renderer,
|
config.ClientWebsite, customCSS, config.SingleInstance,
|
||||||
sessionRepo, appRepo, config.SingleInstance)
|
config.PostFormats, renderer, sessionRepo, appRepo)
|
||||||
handler := service.NewHandler(s, logger, config.StaticDirectory)
|
handler := service.NewHandler(s, logger, config.StaticDirectory)
|
||||||
|
|
||||||
logger.Println("listening on", config.ListenAddress)
|
logger.Println("listening on", config.ListenAddress)
|
||||||
|
50
mastodon/filter.go
Normal file
50
mastodon/filter.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package mastodon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Filter struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Phrase string `json:"phrase"`
|
||||||
|
Context []string `json:"context"`
|
||||||
|
WholeWord bool `json:"whole_word"`
|
||||||
|
ExpiresAt *time.Time `json:"expires_at"`
|
||||||
|
Irreversible bool `json:"irreversible"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) GetFilters(ctx context.Context) ([]*Filter, error) {
|
||||||
|
var filters []*Filter
|
||||||
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/filters", nil, &filters, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return filters, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) AddFilter(ctx context.Context, phrase string, context []string, irreversible bool, wholeWord bool, expiresIn *time.Time) error {
|
||||||
|
params := url.Values{}
|
||||||
|
params.Set("phrase", phrase)
|
||||||
|
for i := range context {
|
||||||
|
params.Add("context[]", context[i])
|
||||||
|
}
|
||||||
|
params.Set("irreversible", strconv.FormatBool(irreversible))
|
||||||
|
params.Set("whole_word", strconv.FormatBool(wholeWord))
|
||||||
|
if expiresIn != nil {
|
||||||
|
params.Set("expires_in", expiresIn.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
err := c.doAPI(ctx, http.MethodPost, "/api/v1/filters", params, nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) RemoveFilter(ctx context.Context, id string) error {
|
||||||
|
return c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/filters/%s", id), nil, nil, nil)
|
||||||
|
}
|
@ -11,6 +11,7 @@ type Settings struct {
|
|||||||
FluorideMode bool `json:"fluoride_mode"`
|
FluorideMode bool `json:"fluoride_mode"`
|
||||||
DarkMode bool `json:"dark_mode"`
|
DarkMode bool `json:"dark_mode"`
|
||||||
AntiDopamineMode bool `json:"anti_dopamine_mode"`
|
AntiDopamineMode bool `json:"anti_dopamine_mode"`
|
||||||
|
CSS string `json:"css"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSettings() *Settings {
|
func NewSettings() *Settings {
|
||||||
@ -25,5 +26,6 @@ func NewSettings() *Settings {
|
|||||||
FluorideMode: false,
|
FluorideMode: false,
|
||||||
DarkMode: false,
|
DarkMode: false,
|
||||||
AntiDopamineMode: false,
|
AntiDopamineMode: false,
|
||||||
|
CSS: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,15 +14,10 @@ type Context struct {
|
|||||||
CSRFToken string
|
CSRFToken string
|
||||||
UserID string
|
UserID string
|
||||||
AntiDopamineMode bool
|
AntiDopamineMode bool
|
||||||
|
UserCSS string
|
||||||
Referrer string
|
Referrer string
|
||||||
}
|
}
|
||||||
|
|
||||||
type NavData struct {
|
|
||||||
CommonData *CommonData
|
|
||||||
User *mastodon.Account
|
|
||||||
PostContext model.PostContext
|
|
||||||
}
|
|
||||||
|
|
||||||
type CommonData struct {
|
type CommonData struct {
|
||||||
Title string
|
Title string
|
||||||
CustomCSS string
|
CustomCSS string
|
||||||
@ -32,9 +27,17 @@ type CommonData struct {
|
|||||||
Target string
|
Target string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NavData struct {
|
||||||
|
CommonData *CommonData
|
||||||
|
User *mastodon.Account
|
||||||
|
PostContext model.PostContext
|
||||||
|
}
|
||||||
|
|
||||||
type ErrorData struct {
|
type ErrorData struct {
|
||||||
*CommonData
|
*CommonData
|
||||||
Error string
|
Err string
|
||||||
|
Retry bool
|
||||||
|
SessionErr bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type HomePageData struct {
|
type HomePageData struct {
|
||||||
@ -132,3 +135,8 @@ type SettingsData struct {
|
|||||||
Settings *model.Settings
|
Settings *model.Settings
|
||||||
PostFormats []model.PostFormat
|
PostFormats []model.PostFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FiltersData struct {
|
||||||
|
*CommonData
|
||||||
|
Filters []*mastodon.Filter
|
||||||
|
}
|
||||||
|
@ -30,6 +30,7 @@ const (
|
|||||||
RetweetedByPage = "retweetedby.tmpl"
|
RetweetedByPage = "retweetedby.tmpl"
|
||||||
SearchPage = "search.tmpl"
|
SearchPage = "search.tmpl"
|
||||||
SettingsPage = "settings.tmpl"
|
SettingsPage = "settings.tmpl"
|
||||||
|
FiltersPage = "filters.tmpl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TemplateData struct {
|
type TemplateData struct {
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@ -16,146 +14,152 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ctx = context.Background()
|
errInvalidArgument = errors.New("invalid argument")
|
||||||
errInvalidArgument = errors.New("invalid argument")
|
errInvalidSession = errors.New("invalid session")
|
||||||
|
errInvalidCSRFToken = errors.New("invalid csrf token")
|
||||||
)
|
)
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
clientName string
|
cname string
|
||||||
clientScope string
|
cscope string
|
||||||
clientWebsite string
|
cwebsite string
|
||||||
customCSS string
|
css string
|
||||||
postFormats []model.PostFormat
|
instance string
|
||||||
renderer renderer.Renderer
|
postFormats []model.PostFormat
|
||||||
sessionRepo model.SessionRepo
|
renderer renderer.Renderer
|
||||||
appRepo model.AppRepo
|
sessionRepo model.SessionRepo
|
||||||
singleInstance string
|
appRepo model.AppRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(clientName string,
|
func NewService(cname string, cscope string, cwebsite string,
|
||||||
clientScope string,
|
css string, instance string, postFormats []model.PostFormat,
|
||||||
clientWebsite string,
|
renderer renderer.Renderer, sessionRepo model.SessionRepo,
|
||||||
customCSS string,
|
appRepo model.AppRepo) *service {
|
||||||
postFormats []model.PostFormat,
|
|
||||||
renderer renderer.Renderer,
|
|
||||||
sessionRepo model.SessionRepo,
|
|
||||||
appRepo model.AppRepo,
|
|
||||||
singleInstance string,
|
|
||||||
) *service {
|
|
||||||
return &service{
|
return &service{
|
||||||
clientName: clientName,
|
cname: cname,
|
||||||
clientScope: clientScope,
|
cscope: cscope,
|
||||||
clientWebsite: clientWebsite,
|
cwebsite: cwebsite,
|
||||||
customCSS: customCSS,
|
css: css,
|
||||||
postFormats: postFormats,
|
instance: instance,
|
||||||
renderer: renderer,
|
postFormats: postFormats,
|
||||||
sessionRepo: sessionRepo,
|
renderer: renderer,
|
||||||
appRepo: appRepo,
|
sessionRepo: sessionRepo,
|
||||||
singleInstance: singleInstance,
|
appRepo: appRepo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRendererContext(c *client) *renderer.Context {
|
func (s *service) authenticate(c *client, sid string, csrf string, ref string, t int) (err error) {
|
||||||
var settings model.Settings
|
var sett *model.Settings
|
||||||
var session model.Session
|
defer func() {
|
||||||
var referrer string
|
if sett == nil {
|
||||||
if c != nil {
|
sett = model.NewSettings()
|
||||||
settings = c.Session.Settings
|
}
|
||||||
session = c.Session
|
c.rctx = &renderer.Context{
|
||||||
referrer = c.url()
|
HideAttachments: sett.HideAttachments,
|
||||||
} else {
|
MaskNSFW: sett.MaskNSFW,
|
||||||
settings = *model.NewSettings()
|
ThreadInNewTab: sett.ThreadInNewTab,
|
||||||
}
|
FluorideMode: sett.FluorideMode,
|
||||||
return &renderer.Context{
|
DarkMode: sett.DarkMode,
|
||||||
HideAttachments: settings.HideAttachments,
|
CSRFToken: c.s.CSRFToken,
|
||||||
MaskNSFW: settings.MaskNSFW,
|
UserID: c.s.UserID,
|
||||||
ThreadInNewTab: settings.ThreadInNewTab,
|
AntiDopamineMode: sett.AntiDopamineMode,
|
||||||
FluorideMode: settings.FluorideMode,
|
UserCSS: sett.CSS,
|
||||||
DarkMode: settings.DarkMode,
|
Referrer: ref,
|
||||||
CSRFToken: session.CSRFToken,
|
}
|
||||||
UserID: session.UserID,
|
}()
|
||||||
AntiDopamineMode: settings.AntiDopamineMode,
|
if t < SESSION {
|
||||||
Referrer: referrer,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func addToReplyMap(m map[string][]mastodon.ReplyInfo, key interface{},
|
|
||||||
val string, number int) {
|
|
||||||
if key == nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
keyStr, ok := key.(string)
|
if len(sid) < 1 {
|
||||||
if !ok {
|
return errInvalidSession
|
||||||
return
|
|
||||||
}
|
}
|
||||||
_, ok = m[keyStr]
|
c.s, err = s.sessionRepo.Get(sid)
|
||||||
if !ok {
|
if err != nil {
|
||||||
m[keyStr] = []mastodon.ReplyInfo{}
|
return errInvalidSession
|
||||||
}
|
}
|
||||||
m[keyStr] = append(m[keyStr], mastodon.ReplyInfo{val, number})
|
sett = &c.s.Settings
|
||||||
}
|
app, err := s.appRepo.Get(c.s.InstanceDomain)
|
||||||
|
if err != nil {
|
||||||
func (s *service) getCommonData(c *client, title string) (data *renderer.CommonData) {
|
return err
|
||||||
data = &renderer.CommonData{
|
|
||||||
Title: title + " - " + s.clientName,
|
|
||||||
CustomCSS: s.customCSS,
|
|
||||||
}
|
}
|
||||||
if c != nil && c.Session.IsLoggedIn() {
|
c.Client = mastodon.NewClient(&mastodon.Config{
|
||||||
data.CSRFToken = c.Session.CSRFToken
|
Server: app.InstanceURL,
|
||||||
|
ClientID: app.ClientID,
|
||||||
|
ClientSecret: app.ClientSecret,
|
||||||
|
AccessToken: c.s.AccessToken,
|
||||||
|
})
|
||||||
|
if t >= CSRF && (len(csrf) < 1 || csrf != c.s.CSRFToken) {
|
||||||
|
return errInvalidCSRFToken
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) ErrorPage(c *client, err error) {
|
func (s *service) cdata(c *client, title string, count int, rinterval int,
|
||||||
|
target string) (data *renderer.CommonData) {
|
||||||
|
data = &renderer.CommonData{
|
||||||
|
Title: title + " - " + s.cname,
|
||||||
|
CustomCSS: s.css,
|
||||||
|
Count: count,
|
||||||
|
RefreshInterval: rinterval,
|
||||||
|
Target: target,
|
||||||
|
}
|
||||||
|
if c != nil && c.s.IsLoggedIn() {
|
||||||
|
data.CSRFToken = c.s.CSRFToken
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) ErrorPage(c *client, err error, retry bool) error {
|
||||||
var errStr string
|
var errStr string
|
||||||
|
var sessionErr bool
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errStr = err.Error()
|
errStr = err.Error()
|
||||||
|
if err == errInvalidSession || err == errInvalidCSRFToken {
|
||||||
|
sessionErr = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
commonData := s.getCommonData(nil, "error")
|
cdata := s.cdata(nil, "error", 0, 0, "")
|
||||||
data := &renderer.ErrorData{
|
data := &renderer.ErrorData{
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
Error: errStr,
|
Err: errStr,
|
||||||
|
Retry: retry,
|
||||||
|
SessionErr: sessionErr,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.ErrorPage, data)
|
||||||
s.renderer.Render(rCtx, c, renderer.ErrorPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) SigninPage(c *client) (err error) {
|
func (s *service) SigninPage(c *client) (err error) {
|
||||||
commonData := s.getCommonData(nil, "signin")
|
cdata := s.cdata(nil, "signin", 0, 0, "")
|
||||||
data := &renderer.SigninData{
|
data := &renderer.SigninData{
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(nil)
|
return s.renderer.Render(c.rctx, c.w, renderer.SigninPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.SigninPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) RootPage(c *client) (err error) {
|
func (s *service) RootPage(c *client) (err error) {
|
||||||
data := &renderer.RootData{
|
data := &renderer.RootData{
|
||||||
Title: s.clientName,
|
Title: s.cname,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.RootPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.RootPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) NavPage(c *client) (err error) {
|
func (s *service) NavPage(c *client) (err error) {
|
||||||
u, err := c.GetAccountCurrentUser(ctx)
|
u, err := c.GetAccountCurrentUser(c.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
postContext := model.PostContext{
|
pctx := model.PostContext{
|
||||||
DefaultVisibility: c.Session.Settings.DefaultVisibility,
|
DefaultVisibility: c.s.Settings.DefaultVisibility,
|
||||||
DefaultFormat: c.Session.Settings.DefaultFormat,
|
DefaultFormat: c.s.Settings.DefaultFormat,
|
||||||
Formats: s.postFormats,
|
Formats: s.postFormats,
|
||||||
}
|
}
|
||||||
commonData := s.getCommonData(c, "nav")
|
cdata := s.cdata(c, "nav", 0, 0, "main")
|
||||||
commonData.Target = "main"
|
|
||||||
data := &renderer.NavData{
|
data := &renderer.NavData{
|
||||||
User: u,
|
User: u,
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
PostContext: postContext,
|
PostContext: pctx,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.NavPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.NavPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) TimelinePage(c *client, tType string, instance string,
|
func (s *service) TimelinePage(c *client, tType string, instance string,
|
||||||
@ -173,21 +177,21 @@ func (s *service) TimelinePage(c *client, tType string, instance string,
|
|||||||
default:
|
default:
|
||||||
return errInvalidArgument
|
return errInvalidArgument
|
||||||
case "home":
|
case "home":
|
||||||
statuses, err = c.GetTimelineHome(ctx, &pg)
|
statuses, err = c.GetTimelineHome(c.ctx, &pg)
|
||||||
title = "Timeline"
|
title = "Timeline"
|
||||||
case "direct":
|
case "direct":
|
||||||
statuses, err = c.GetTimelineDirect(ctx, &pg)
|
statuses, err = c.GetTimelineDirect(c.ctx, &pg)
|
||||||
title = "Direct Timeline"
|
title = "Direct Timeline"
|
||||||
case "local":
|
case "local":
|
||||||
statuses, err = c.GetTimelinePublic(ctx, true, "", &pg)
|
statuses, err = c.GetTimelinePublic(c.ctx, true, "", &pg)
|
||||||
title = "Local Timeline"
|
title = "Local Timeline"
|
||||||
case "remote":
|
case "remote":
|
||||||
if len(instance) > 0 {
|
if len(instance) > 0 {
|
||||||
statuses, err = c.GetTimelinePublic(ctx, false, instance, &pg)
|
statuses, err = c.GetTimelinePublic(c.ctx, false, instance, &pg)
|
||||||
}
|
}
|
||||||
title = "Remote Timeline"
|
title = "Remote Timeline"
|
||||||
case "twkn":
|
case "twkn":
|
||||||
statuses, err = c.GetTimelinePublic(ctx, false, "", &pg)
|
statuses, err = c.GetTimelinePublic(c.ctx, false, "", &pg)
|
||||||
title = "The Whole Known Network"
|
title = "The Whole Known Network"
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -218,7 +222,7 @@ func (s *service) TimelinePage(c *client, tType string, instance string,
|
|||||||
nextLink = "/timeline/" + tType + "?" + v.Encode()
|
nextLink = "/timeline/" + tType + "?" + v.Encode()
|
||||||
}
|
}
|
||||||
|
|
||||||
commonData := s.getCommonData(c, tType+" timeline ")
|
cdata := s.cdata(c, tType+" timeline ", 0, 0, "")
|
||||||
data := &renderer.TimelineData{
|
data := &renderer.TimelineData{
|
||||||
Title: title,
|
Title: title,
|
||||||
Type: tType,
|
Type: tType,
|
||||||
@ -226,17 +230,31 @@ func (s *service) TimelinePage(c *client, tType string, instance string,
|
|||||||
Statuses: statuses,
|
Statuses: statuses,
|
||||||
NextLink: nextLink,
|
NextLink: nextLink,
|
||||||
PrevLink: prevLink,
|
PrevLink: prevLink,
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
}
|
}
|
||||||
|
return s.renderer.Render(c.rctx, c.w, renderer.TimelinePage, data)
|
||||||
|
}
|
||||||
|
|
||||||
rCtx := getRendererContext(c)
|
func addToReplyMap(m map[string][]mastodon.ReplyInfo, key interface{},
|
||||||
return s.renderer.Render(rCtx, c, renderer.TimelinePage, data)
|
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})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) ThreadPage(c *client, id string, reply bool) (err error) {
|
func (s *service) ThreadPage(c *client, id string, reply bool) (err error) {
|
||||||
var postContext model.PostContext
|
var pctx model.PostContext
|
||||||
|
|
||||||
status, err := c.GetStatus(ctx, id)
|
status, err := c.GetStatus(c.ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -244,26 +262,26 @@ func (s *service) ThreadPage(c *client, id string, reply bool) (err error) {
|
|||||||
if reply {
|
if reply {
|
||||||
var content string
|
var content string
|
||||||
var visibility string
|
var visibility string
|
||||||
if c.Session.UserID != status.Account.ID {
|
if c.s.UserID != status.Account.ID {
|
||||||
content += "@" + status.Account.Acct + " "
|
content += "@" + status.Account.Acct + " "
|
||||||
}
|
}
|
||||||
for i := range status.Mentions {
|
for i := range status.Mentions {
|
||||||
if status.Mentions[i].ID != c.Session.UserID &&
|
if status.Mentions[i].ID != c.s.UserID &&
|
||||||
status.Mentions[i].ID != status.Account.ID {
|
status.Mentions[i].ID != status.Account.ID {
|
||||||
content += "@" + status.Mentions[i].Acct + " "
|
content += "@" + status.Mentions[i].Acct + " "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isDirect := status.Visibility == "direct"
|
isDirect := status.Visibility == "direct"
|
||||||
if isDirect || c.Session.Settings.CopyScope {
|
if isDirect || c.s.Settings.CopyScope {
|
||||||
visibility = status.Visibility
|
visibility = status.Visibility
|
||||||
} else {
|
} else {
|
||||||
visibility = c.Session.Settings.DefaultVisibility
|
visibility = c.s.Settings.DefaultVisibility
|
||||||
}
|
}
|
||||||
|
|
||||||
postContext = model.PostContext{
|
pctx = model.PostContext{
|
||||||
DefaultVisibility: visibility,
|
DefaultVisibility: visibility,
|
||||||
DefaultFormat: c.Session.Settings.DefaultFormat,
|
DefaultFormat: c.s.Settings.DefaultFormat,
|
||||||
Formats: s.postFormats,
|
Formats: s.postFormats,
|
||||||
ReplyContext: &model.ReplyContext{
|
ReplyContext: &model.ReplyContext{
|
||||||
InReplyToID: id,
|
InReplyToID: id,
|
||||||
@ -274,7 +292,7 @@ func (s *service) ThreadPage(c *client, id string, reply bool) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context, err := c.GetStatusContext(ctx, id)
|
context, err := c.GetStatusContext(c.ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -293,16 +311,14 @@ func (s *service) ThreadPage(c *client, id string, reply bool) (err error) {
|
|||||||
addToReplyMap(replies, statuses[i].InReplyToID, statuses[i].ID, i+1)
|
addToReplyMap(replies, statuses[i].InReplyToID, statuses[i].ID, i+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
commonData := s.getCommonData(c, "post by "+status.Account.DisplayName)
|
cdata := s.cdata(c, "post by "+status.Account.DisplayName, 0, 0, "")
|
||||||
data := &renderer.ThreadData{
|
data := &renderer.ThreadData{
|
||||||
Statuses: statuses,
|
Statuses: statuses,
|
||||||
PostContext: postContext,
|
PostContext: pctx,
|
||||||
ReplyMap: replies,
|
ReplyMap: replies,
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
}
|
}
|
||||||
|
return s.renderer.Render(c.rctx, c.w, renderer.ThreadPage, data)
|
||||||
rCtx := getRendererContext(c)
|
|
||||||
return s.renderer.Render(rCtx, c, renderer.ThreadPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) StatusPopup(c *client, id string) (err error) {
|
func (svc *service) StatusPopup(c *client, id string) (err error) {
|
||||||
@ -315,31 +331,29 @@ func (svc *service) StatusPopup(c *client, id string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) LikedByPage(c *client, id string) (err error) {
|
func (s *service) LikedByPage(c *client, id string) (err error) {
|
||||||
likers, err := c.GetFavouritedBy(ctx, id, nil)
|
likers, err := c.GetFavouritedBy(c.ctx, id, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
commonData := s.getCommonData(c, "likes")
|
cdata := s.cdata(c, "likes", 0, 0, "")
|
||||||
data := &renderer.LikedByData{
|
data := &renderer.LikedByData{
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
Users: likers,
|
Users: likers,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.LikedByPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.LikedByPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) RetweetedByPage(c *client, id string) (err error) {
|
func (s *service) RetweetedByPage(c *client, id string) (err error) {
|
||||||
retweeters, err := c.GetRebloggedBy(ctx, id, nil)
|
retweeters, err := c.GetRebloggedBy(c.ctx, id, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
commonData := s.getCommonData(c, "retweets")
|
cdata := s.cdata(c, "retweets", 0, 0, "")
|
||||||
data := &renderer.RetweetedByData{
|
data := &renderer.RetweetedByData{
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
Users: retweeters,
|
Users: retweeters,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.RetweetedByPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.RetweetedByPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) NotificationPage(c *client, maxID string,
|
func (s *service) NotificationPage(c *client, maxID string,
|
||||||
@ -355,11 +369,11 @@ func (s *service) NotificationPage(c *client, maxID string,
|
|||||||
Limit: 20,
|
Limit: 20,
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Session.Settings.AntiDopamineMode {
|
if c.s.Settings.AntiDopamineMode {
|
||||||
excludes = []string{"follow", "favourite", "reblog"}
|
excludes = []string{"follow", "favourite", "reblog"}
|
||||||
}
|
}
|
||||||
|
|
||||||
notifications, err := c.GetNotifications(ctx, &pg, excludes)
|
notifications, err := c.GetNotifications(c.ctx, &pg, excludes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -377,19 +391,16 @@ func (s *service) NotificationPage(c *client, maxID string,
|
|||||||
nextLink = "/notifications?max_id=" + pg.MaxID
|
nextLink = "/notifications?max_id=" + pg.MaxID
|
||||||
}
|
}
|
||||||
|
|
||||||
commonData := s.getCommonData(c, "notifications")
|
cdata := s.cdata(c, "notifications", unreadCount,
|
||||||
commonData.RefreshInterval = c.Session.Settings.NotificationInterval
|
c.s.Settings.NotificationInterval, "main")
|
||||||
commonData.Target = "main"
|
|
||||||
commonData.Count = unreadCount
|
|
||||||
data := &renderer.NotificationData{
|
data := &renderer.NotificationData{
|
||||||
Notifications: notifications,
|
Notifications: notifications,
|
||||||
UnreadCount: unreadCount,
|
UnreadCount: unreadCount,
|
||||||
ReadID: readID,
|
ReadID: readID,
|
||||||
NextLink: nextLink,
|
NextLink: nextLink,
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.NotificationPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.NotificationPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) UserPage(c *client, id string, pageType string,
|
func (s *service) UserPage(c *client, id string, pageType string,
|
||||||
@ -404,15 +415,15 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
Limit: 20,
|
Limit: 20,
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := c.GetAccount(ctx, id)
|
user, err := c.GetAccount(c.ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isCurrent := c.Session.UserID == user.ID
|
isCurrent := c.s.UserID == user.ID
|
||||||
|
|
||||||
switch pageType {
|
switch pageType {
|
||||||
case "":
|
case "":
|
||||||
statuses, err = c.GetAccountStatuses(ctx, id, false, &pg)
|
statuses, err = c.GetAccountStatuses(c.ctx, id, false, &pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -421,7 +432,7 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
pg.MaxID)
|
pg.MaxID)
|
||||||
}
|
}
|
||||||
case "following":
|
case "following":
|
||||||
users, err = c.GetAccountFollowing(ctx, id, &pg)
|
users, err = c.GetAccountFollowing(c.ctx, id, &pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -430,7 +441,7 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
id, pg.MaxID)
|
id, pg.MaxID)
|
||||||
}
|
}
|
||||||
case "followers":
|
case "followers":
|
||||||
users, err = c.GetAccountFollowers(ctx, id, &pg)
|
users, err = c.GetAccountFollowers(c.ctx, id, &pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -439,7 +450,7 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
id, pg.MaxID)
|
id, pg.MaxID)
|
||||||
}
|
}
|
||||||
case "media":
|
case "media":
|
||||||
statuses, err = c.GetAccountStatuses(ctx, id, true, &pg)
|
statuses, err = c.GetAccountStatuses(c.ctx, id, true, &pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -451,7 +462,7 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
if !isCurrent {
|
if !isCurrent {
|
||||||
return errInvalidArgument
|
return errInvalidArgument
|
||||||
}
|
}
|
||||||
statuses, err = c.GetBookmarks(ctx, &pg)
|
statuses, err = c.GetBookmarks(c.ctx, &pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -463,7 +474,7 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
if !isCurrent {
|
if !isCurrent {
|
||||||
return errInvalidArgument
|
return errInvalidArgument
|
||||||
}
|
}
|
||||||
users, err = c.GetMutes(ctx, &pg)
|
users, err = c.GetMutes(c.ctx, &pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -475,7 +486,7 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
if !isCurrent {
|
if !isCurrent {
|
||||||
return errInvalidArgument
|
return errInvalidArgument
|
||||||
}
|
}
|
||||||
users, err = c.GetBlocks(ctx, &pg)
|
users, err = c.GetBlocks(c.ctx, &pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -487,7 +498,7 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
if !isCurrent {
|
if !isCurrent {
|
||||||
return errInvalidArgument
|
return errInvalidArgument
|
||||||
}
|
}
|
||||||
statuses, err = c.GetFavourites(ctx, &pg)
|
statuses, err = c.GetFavourites(c.ctx, &pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -499,7 +510,7 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
if !isCurrent {
|
if !isCurrent {
|
||||||
return errInvalidArgument
|
return errInvalidArgument
|
||||||
}
|
}
|
||||||
users, err = c.GetFollowRequests(ctx, &pg)
|
users, err = c.GetFollowRequests(c.ctx, &pg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -517,7 +528,7 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commonData := s.getCommonData(c, user.DisplayName)
|
cdata := s.cdata(c, user.DisplayName+" @"+user.Acct, 0, 0, "")
|
||||||
data := &renderer.UserData{
|
data := &renderer.UserData{
|
||||||
User: user,
|
User: user,
|
||||||
IsCurrent: isCurrent,
|
IsCurrent: isCurrent,
|
||||||
@ -525,10 +536,9 @@ func (s *service) UserPage(c *client, id string, pageType string,
|
|||||||
Users: users,
|
Users: users,
|
||||||
Statuses: statuses,
|
Statuses: statuses,
|
||||||
NextLink: nextLink,
|
NextLink: nextLink,
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.UserPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.UserPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) UserSearchPage(c *client,
|
func (s *service) UserSearchPage(c *client,
|
||||||
@ -537,14 +547,14 @@ func (s *service) UserSearchPage(c *client,
|
|||||||
var nextLink string
|
var nextLink string
|
||||||
var title = "search"
|
var title = "search"
|
||||||
|
|
||||||
user, err := c.GetAccount(ctx, id)
|
user, err := c.GetAccount(c.ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var results *mastodon.Results
|
var results *mastodon.Results
|
||||||
if len(q) > 0 {
|
if len(q) > 0 {
|
||||||
results, err = c.Search(ctx, q, "statuses", 20, true, offset, id)
|
results, err = c.Search(c.ctx, q, "statuses", 20, true, offset, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -558,44 +568,40 @@ func (s *service) UserSearchPage(c *client,
|
|||||||
url.QueryEscape(q), offset)
|
url.QueryEscape(q), offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
qq := template.HTMLEscapeString(q)
|
|
||||||
if len(q) > 0 {
|
if len(q) > 0 {
|
||||||
title += " \"" + qq + "\""
|
title += " \"" + q + "\""
|
||||||
}
|
}
|
||||||
|
|
||||||
commonData := s.getCommonData(c, title)
|
cdata := s.cdata(c, title, 0, 0, "")
|
||||||
data := &renderer.UserSearchData{
|
data := &renderer.UserSearchData{
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
User: user,
|
User: user,
|
||||||
Q: qq,
|
Q: q,
|
||||||
Statuses: results.Statuses,
|
Statuses: results.Statuses,
|
||||||
NextLink: nextLink,
|
NextLink: nextLink,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.UserSearchPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.UserSearchPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) AboutPage(c *client) (err error) {
|
func (s *service) AboutPage(c *client) (err error) {
|
||||||
commonData := s.getCommonData(c, "about")
|
cdata := s.cdata(c, "about", 0, 0, "")
|
||||||
data := &renderer.AboutData{
|
data := &renderer.AboutData{
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.AboutPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.AboutPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) EmojiPage(c *client) (err error) {
|
func (s *service) EmojiPage(c *client) (err error) {
|
||||||
emojis, err := c.GetInstanceEmojis(ctx)
|
emojis, err := c.GetInstanceEmojis(c.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
commonData := s.getCommonData(c, "emojis")
|
cdata := s.cdata(c, "emojis", 0, 0, "")
|
||||||
data := &renderer.EmojiData{
|
data := &renderer.EmojiData{
|
||||||
Emojis: emojis,
|
Emojis: emojis,
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.EmojiPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.EmojiPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) SearchPage(c *client,
|
func (s *service) SearchPage(c *client,
|
||||||
@ -606,7 +612,7 @@ func (s *service) SearchPage(c *client,
|
|||||||
|
|
||||||
var results *mastodon.Results
|
var results *mastodon.Results
|
||||||
if len(q) > 0 {
|
if len(q) > 0 {
|
||||||
results, err = c.Search(ctx, q, qType, 20, true, offset, "")
|
results, err = c.Search(c.ctx, q, qType, 20, true, offset, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -621,44 +627,54 @@ func (s *service) SearchPage(c *client,
|
|||||||
url.QueryEscape(q), qType, offset)
|
url.QueryEscape(q), qType, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
qq := template.HTMLEscapeString(q)
|
|
||||||
if len(q) > 0 {
|
if len(q) > 0 {
|
||||||
title += " \"" + qq + "\""
|
title += " \"" + q + "\""
|
||||||
}
|
}
|
||||||
|
|
||||||
commonData := s.getCommonData(c, title)
|
cdata := s.cdata(c, title, 0, 0, "")
|
||||||
data := &renderer.SearchData{
|
data := &renderer.SearchData{
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
Q: qq,
|
Q: q,
|
||||||
Type: qType,
|
Type: qType,
|
||||||
Users: results.Accounts,
|
Users: results.Accounts,
|
||||||
Statuses: results.Statuses,
|
Statuses: results.Statuses,
|
||||||
NextLink: nextLink,
|
NextLink: nextLink,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.SearchPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.SearchPage, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) SettingsPage(c *client) (err error) {
|
func (s *service) SettingsPage(c *client) (err error) {
|
||||||
commonData := s.getCommonData(c, "settings")
|
cdata := s.cdata(c, "settings", 0, 0, "")
|
||||||
data := &renderer.SettingsData{
|
data := &renderer.SettingsData{
|
||||||
CommonData: commonData,
|
CommonData: cdata,
|
||||||
Settings: &c.Session.Settings,
|
Settings: &c.s.Settings,
|
||||||
PostFormats: s.postFormats,
|
PostFormats: s.postFormats,
|
||||||
}
|
}
|
||||||
rCtx := getRendererContext(c)
|
return s.renderer.Render(c.rctx, c.w, renderer.SettingsPage, data)
|
||||||
return s.renderer.Render(rCtx, c, renderer.SettingsPage, data)
|
}
|
||||||
|
|
||||||
|
func (svc *service) FiltersPage(c *client) (err error) {
|
||||||
|
filters, err := c.GetFilters(c.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cdata := svc.cdata(c, "filters", 0, 0, "")
|
||||||
|
data := &renderer.FiltersData{
|
||||||
|
CommonData: cdata,
|
||||||
|
Filters: filters,
|
||||||
|
}
|
||||||
|
return svc.renderer.Render(c.rctx, c.w, renderer.FiltersPage, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) SingleInstance() (instance string, ok bool) {
|
func (s *service) SingleInstance() (instance string, ok bool) {
|
||||||
if len(s.singleInstance) > 0 {
|
if len(s.instance) > 0 {
|
||||||
instance = s.singleInstance
|
instance = s.instance
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) NewSession(instance string) (rurl string, sid string, err error) {
|
func (s *service) NewSession(c *client, instance string) (rurl string, sid string, err error) {
|
||||||
var instanceURL string
|
var instanceURL string
|
||||||
if strings.HasPrefix(instance, "https://") {
|
if strings.HasPrefix(instance, "https://") {
|
||||||
instanceURL = instance
|
instanceURL = instance
|
||||||
@ -671,18 +687,18 @@ func (s *service) NewSession(instance string) (rurl string, sid string, err erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
csrfToken, err := util.NewCSRFToken()
|
csrf, err := util.NewCSRFToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
session := model.Session{
|
sess := model.Session{
|
||||||
ID: sid,
|
ID: sid,
|
||||||
InstanceDomain: instance,
|
InstanceDomain: instance,
|
||||||
CSRFToken: csrfToken,
|
CSRFToken: csrf,
|
||||||
Settings: *model.NewSettings(),
|
Settings: *model.NewSettings(),
|
||||||
}
|
}
|
||||||
err = s.sessionRepo.Add(session)
|
err = s.sessionRepo.Add(sess)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -692,12 +708,12 @@ func (s *service) NewSession(instance string) (rurl string, sid string, err erro
|
|||||||
if err != model.ErrAppNotFound {
|
if err != model.ErrAppNotFound {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mastoApp, err := mastodon.RegisterApp(ctx, &mastodon.AppConfig{
|
mastoApp, err := mastodon.RegisterApp(c.ctx, &mastodon.AppConfig{
|
||||||
Server: instanceURL,
|
Server: instanceURL,
|
||||||
ClientName: s.clientName,
|
ClientName: s.cname,
|
||||||
Scopes: s.clientScope,
|
Scopes: s.cscope,
|
||||||
Website: s.clientWebsite,
|
Website: s.cwebsite,
|
||||||
RedirectURIs: s.clientWebsite + "/oauth_callback",
|
RedirectURIs: s.cwebsite + "/oauth_callback",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
@ -723,36 +739,33 @@ func (s *service) NewSession(instance string) (rurl string, sid string, err erro
|
|||||||
q.Set("scope", "read write follow")
|
q.Set("scope", "read write follow")
|
||||||
q.Set("client_id", app.ClientID)
|
q.Set("client_id", app.ClientID)
|
||||||
q.Set("response_type", "code")
|
q.Set("response_type", "code")
|
||||||
q.Set("redirect_uri", s.clientWebsite+"/oauth_callback")
|
q.Set("redirect_uri", s.cwebsite+"/oauth_callback")
|
||||||
u.RawQuery = q.Encode()
|
u.RawQuery = q.Encode()
|
||||||
|
|
||||||
rurl = instanceURL + u.String()
|
rurl = instanceURL + u.String()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Signin(c *client, code string) (token string,
|
func (s *service) Signin(c *client, code string) (err error) {
|
||||||
userID string, err error) {
|
|
||||||
|
|
||||||
if len(code) < 1 {
|
if len(code) < 1 {
|
||||||
err = errInvalidArgument
|
err = errInvalidArgument
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = c.AuthenticateToken(ctx, code, s.clientWebsite+"/oauth_callback")
|
err = c.AuthenticateToken(c.ctx, code, s.cwebsite+"/oauth_callback")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
token = c.GetAccessToken(ctx)
|
u, err := c.GetAccountCurrentUser(c.ctx)
|
||||||
|
|
||||||
u, err := c.GetAccountCurrentUser(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userID = u.ID
|
c.s.AccessToken = c.GetAccessToken(c.ctx)
|
||||||
return
|
c.s.UserID = u.ID
|
||||||
|
return s.sessionRepo.Add(c.s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Signout(c *client) (err error) {
|
func (s *service) Signout(c *client) (err error) {
|
||||||
s.sessionRepo.Remove(c.Session.ID)
|
s.sessionRepo.Remove(c.s.ID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -762,7 +775,7 @@ func (s *service) Post(c *client, content string, replyToID string,
|
|||||||
|
|
||||||
var mediaIDs []string
|
var mediaIDs []string
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
a, err := c.UploadMediaFromMultipartFileHeader(ctx, f)
|
a, err := c.UploadMediaFromMultipartFileHeader(c.ctx, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -777,7 +790,7 @@ func (s *service) Post(c *client, content string, replyToID string,
|
|||||||
Visibility: visibility,
|
Visibility: visibility,
|
||||||
Sensitive: isNSFW,
|
Sensitive: isNSFW,
|
||||||
}
|
}
|
||||||
st, err := c.PostStatus(ctx, tweet)
|
st, err := c.PostStatus(c.ctx, tweet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -785,7 +798,7 @@ func (s *service) Post(c *client, content string, replyToID string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Like(c *client, id string) (count int64, err error) {
|
func (s *service) Like(c *client, id string) (count int64, err error) {
|
||||||
st, err := c.Favourite(ctx, id)
|
st, err := c.Favourite(c.ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -794,7 +807,7 @@ func (s *service) Like(c *client, id string) (count int64, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) UnLike(c *client, id string) (count int64, err error) {
|
func (s *service) UnLike(c *client, id string) (count int64, err error) {
|
||||||
st, err := c.Unfavourite(ctx, id)
|
st, err := c.Unfavourite(c.ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -803,7 +816,7 @@ func (s *service) UnLike(c *client, id string) (count int64, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Retweet(c *client, id string) (count int64, err error) {
|
func (s *service) Retweet(c *client, id string) (count int64, err error) {
|
||||||
st, err := c.Reblog(ctx, id)
|
st, err := c.Reblog(c.ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -815,7 +828,7 @@ func (s *service) Retweet(c *client, id string) (count int64, err error) {
|
|||||||
|
|
||||||
func (s *service) UnRetweet(c *client, id string) (
|
func (s *service) UnRetweet(c *client, id string) (
|
||||||
count int64, err error) {
|
count int64, err error) {
|
||||||
st, err := c.Unreblog(ctx, id)
|
st, err := c.Unreblog(c.ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -824,55 +837,55 @@ func (s *service) UnRetweet(c *client, id string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Vote(c *client, id string, choices []string) (err error) {
|
func (s *service) Vote(c *client, id string, choices []string) (err error) {
|
||||||
_, err = c.Vote(ctx, id, choices)
|
_, err = c.Vote(c.ctx, id, choices)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Follow(c *client, id string, reblogs *bool) (err error) {
|
func (s *service) Follow(c *client, id string, reblogs *bool) (err error) {
|
||||||
_, err = c.AccountFollow(ctx, id, reblogs)
|
_, err = c.AccountFollow(c.ctx, id, reblogs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) UnFollow(c *client, id string) (err error) {
|
func (s *service) UnFollow(c *client, id string) (err error) {
|
||||||
_, err = c.AccountUnfollow(ctx, id)
|
_, err = c.AccountUnfollow(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Accept(c *client, id string) (err error) {
|
func (s *service) Accept(c *client, id string) (err error) {
|
||||||
return c.FollowRequestAuthorize(ctx, id)
|
return c.FollowRequestAuthorize(c.ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Reject(c *client, id string) (err error) {
|
func (s *service) Reject(c *client, id string) (err error) {
|
||||||
return c.FollowRequestReject(ctx, id)
|
return c.FollowRequestReject(c.ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Mute(c *client, id string) (err error) {
|
func (s *service) Mute(c *client, id string) (err error) {
|
||||||
_, err = c.AccountMute(ctx, id)
|
_, err = c.AccountMute(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) UnMute(c *client, id string) (err error) {
|
func (s *service) UnMute(c *client, id string) (err error) {
|
||||||
_, err = c.AccountUnmute(ctx, id)
|
_, err = c.AccountUnmute(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Block(c *client, id string) (err error) {
|
func (s *service) Block(c *client, id string) (err error) {
|
||||||
_, err = c.AccountBlock(ctx, id)
|
_, err = c.AccountBlock(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) UnBlock(c *client, id string) (err error) {
|
func (s *service) UnBlock(c *client, id string) (err error) {
|
||||||
_, err = c.AccountUnblock(ctx, id)
|
_, err = c.AccountUnblock(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Subscribe(c *client, id string) (err error) {
|
func (s *service) Subscribe(c *client, id string) (err error) {
|
||||||
_, err = c.Subscribe(ctx, id)
|
_, err = c.Subscribe(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) UnSubscribe(c *client, id string) (err error) {
|
func (s *service) UnSubscribe(c *client, id string) (err error) {
|
||||||
_, err = c.UnSubscribe(ctx, id)
|
_, err = c.UnSubscribe(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -882,38 +895,50 @@ func (s *service) SaveSettings(c *client, settings *model.Settings) (err error)
|
|||||||
default:
|
default:
|
||||||
return errInvalidArgument
|
return errInvalidArgument
|
||||||
}
|
}
|
||||||
session, err := s.sessionRepo.Get(c.Session.ID)
|
if len(settings.CSS) > 1<<20 {
|
||||||
|
return errInvalidArgument
|
||||||
|
}
|
||||||
|
sess, err := s.sessionRepo.Get(c.s.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
session.Settings = *settings
|
sess.Settings = *settings
|
||||||
return s.sessionRepo.Add(session)
|
return s.sessionRepo.Add(sess)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) MuteConversation(c *client, id string) (err error) {
|
func (s *service) MuteConversation(c *client, id string) (err error) {
|
||||||
_, err = c.MuteConversation(ctx, id)
|
_, err = c.MuteConversation(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) UnMuteConversation(c *client, id string) (err error) {
|
func (s *service) UnMuteConversation(c *client, id string) (err error) {
|
||||||
_, err = c.UnmuteConversation(ctx, id)
|
_, err = c.UnmuteConversation(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Delete(c *client, id string) (err error) {
|
func (s *service) Delete(c *client, id string) (err error) {
|
||||||
return c.DeleteStatus(ctx, id)
|
return c.DeleteStatus(c.ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) ReadNotifications(c *client, maxID string) (err error) {
|
func (s *service) ReadNotifications(c *client, maxID string) (err error) {
|
||||||
return c.ReadNotifications(ctx, maxID)
|
return c.ReadNotifications(c.ctx, maxID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Bookmark(c *client, id string) (err error) {
|
func (s *service) Bookmark(c *client, id string) (err error) {
|
||||||
_, err = c.Bookmark(ctx, id)
|
_, err = c.Bookmark(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) UnBookmark(c *client, id string) (err error) {
|
func (s *service) UnBookmark(c *client, id string) (err error) {
|
||||||
_, err = c.Unbookmark(ctx, id)
|
_, err = c.Unbookmark(c.ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svc *service) Filter(c *client, phrase string, wholeWord bool) (err error) {
|
||||||
|
fctx := []string{"home", "notifications", "public", "thread"}
|
||||||
|
return c.AddFilter(c.ctx, phrase, fctx, true, wholeWord, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (svc *service) UnFilter(c *client, id string) (err error) {
|
||||||
|
return c.RemoveFilter(c.ctx, id)
|
||||||
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -10,44 +10,34 @@ import (
|
|||||||
|
|
||||||
"bloat/mastodon"
|
"bloat/mastodon"
|
||||||
"bloat/model"
|
"bloat/model"
|
||||||
|
"bloat/renderer"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
errInvalidSession = errors.New("invalid session")
|
|
||||||
errInvalidCSRFToken = errors.New("invalid csrf token")
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sessionExp = 365 * 24 * time.Hour
|
sessionExp = 365 * 24 * time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
type respType int
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HTML respType = iota
|
HTML int = iota
|
||||||
JSON
|
JSON
|
||||||
)
|
)
|
||||||
|
|
||||||
type authType int
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NOAUTH authType = iota
|
NOAUTH int = iota
|
||||||
SESSION
|
SESSION
|
||||||
CSRF
|
CSRF
|
||||||
)
|
)
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
*mastodon.Client
|
*mastodon.Client
|
||||||
http.ResponseWriter
|
w http.ResponseWriter
|
||||||
Req *http.Request
|
r *http.Request
|
||||||
CSRFToken string
|
s model.Session
|
||||||
Session model.Session
|
csrf string
|
||||||
}
|
ctx context.Context
|
||||||
|
rctx *renderer.Context
|
||||||
func (c *client) url() string {
|
|
||||||
return c.Req.URL.RequestURI()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setSessionCookie(w http.ResponseWriter, sid string, exp time.Duration) {
|
func setSessionCookie(w http.ResponseWriter, sid string, exp time.Duration) {
|
||||||
@ -59,7 +49,7 @@ func setSessionCookie(w http.ResponseWriter, sid string, exp time.Duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeJson(c *client, data interface{}) error {
|
func writeJson(c *client, data interface{}) error {
|
||||||
return json.NewEncoder(c).Encode(map[string]interface{}{
|
return json.NewEncoder(c.w).Encode(map[string]interface{}{
|
||||||
"data": data,
|
"data": data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -74,60 +64,44 @@ func serveJsonError(w http.ResponseWriter, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func redirect(c *client, url string) {
|
func redirect(c *client, url string) {
|
||||||
c.Header().Add("Location", url)
|
c.w.Header().Add("Location", url)
|
||||||
c.WriteHeader(http.StatusFound)
|
c.w.WriteHeader(http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
|
|
||||||
writeError := func(c *client, err error, t respType) {
|
writeError := func(c *client, err error, t int, retry bool) {
|
||||||
switch t {
|
switch t {
|
||||||
case HTML:
|
case HTML:
|
||||||
c.WriteHeader(http.StatusInternalServerError)
|
c.w.WriteHeader(http.StatusInternalServerError)
|
||||||
s.ErrorPage(c, err)
|
s.ErrorPage(c, err, retry)
|
||||||
case JSON:
|
case JSON:
|
||||||
c.WriteHeader(http.StatusInternalServerError)
|
c.w.WriteHeader(http.StatusInternalServerError)
|
||||||
json.NewEncoder(c).Encode(map[string]string{
|
json.NewEncoder(c.w).Encode(map[string]string{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticate := func(c *client, t authType) error {
|
authenticate := func(c *client, t int) error {
|
||||||
if t >= SESSION {
|
var sid string
|
||||||
cookie, err := c.Req.Cookie("session_id")
|
if cookie, _ := c.r.Cookie("session_id"); cookie != nil {
|
||||||
if err != nil || len(cookie.Value) < 1 {
|
sid = cookie.Value
|
||||||
return errInvalidSession
|
|
||||||
}
|
|
||||||
c.Session, err = s.sessionRepo.Get(cookie.Value)
|
|
||||||
if err != nil {
|
|
||||||
return errInvalidSession
|
|
||||||
}
|
|
||||||
app, err := s.appRepo.Get(c.Session.InstanceDomain)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Client = mastodon.NewClient(&mastodon.Config{
|
|
||||||
Server: app.InstanceURL,
|
|
||||||
ClientID: app.ClientID,
|
|
||||||
ClientSecret: app.ClientSecret,
|
|
||||||
AccessToken: c.Session.AccessToken,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if t >= CSRF {
|
csrf := c.r.FormValue("csrf_token")
|
||||||
c.CSRFToken = c.Req.FormValue("csrf_token")
|
ref := c.r.URL.RequestURI()
|
||||||
if len(c.CSRFToken) < 1 || c.CSRFToken != c.Session.CSRFToken {
|
return s.authenticate(c, sid, csrf, ref, t)
|
||||||
return errInvalidCSRFToken
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handle := func(f func(c *client) error, at authType, rt respType) http.HandlerFunc {
|
handle := func(f func(c *client) error, at int, rt int) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, req *http.Request) {
|
return func(w http.ResponseWriter, req *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
c := &client{Req: req, ResponseWriter: w}
|
c := &client{
|
||||||
|
ctx: req.Context(),
|
||||||
|
w: w,
|
||||||
|
r: req,
|
||||||
|
}
|
||||||
|
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
logger.Printf("path=%s, err=%v, took=%v\n",
|
logger.Printf("path=%s, err=%v, took=%v\n",
|
||||||
@ -141,29 +115,24 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
case JSON:
|
case JSON:
|
||||||
ct = "application/json"
|
ct = "application/json"
|
||||||
}
|
}
|
||||||
c.Header().Add("Content-Type", ct)
|
c.w.Header().Add("Content-Type", ct)
|
||||||
|
|
||||||
err = authenticate(c, at)
|
err = authenticate(c, at)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(c, err, rt)
|
writeError(c, err, rt, req.Method == http.MethodGet)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = f(c)
|
err = f(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(c, err, rt)
|
writeError(c, err, rt, req.Method == http.MethodGet)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rootPage := handle(func(c *client) error {
|
rootPage := handle(func(c *client) error {
|
||||||
sid, _ := c.Req.Cookie("session_id")
|
err := authenticate(c, SESSION)
|
||||||
if sid == nil || len(sid.Value) < 0 {
|
|
||||||
redirect(c, "/signin")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
session, err := s.sessionRepo.Get(sid.Value)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == errInvalidSession {
|
if err == errInvalidSession {
|
||||||
redirect(c, "/signin")
|
redirect(c, "/signin")
|
||||||
@ -171,7 +140,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(session.AccessToken) < 1 {
|
if !c.s.IsLoggedIn() {
|
||||||
redirect(c, "/signin")
|
redirect(c, "/signin")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -187,18 +156,18 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return s.SigninPage(c)
|
return s.SigninPage(c)
|
||||||
}
|
}
|
||||||
url, sid, err := s.NewSession(instance)
|
url, sid, err := s.NewSession(c, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
setSessionCookie(c, sid, sessionExp)
|
setSessionCookie(c.w, sid, sessionExp)
|
||||||
redirect(c, url)
|
redirect(c, url)
|
||||||
return nil
|
return nil
|
||||||
}, NOAUTH, HTML)
|
}, NOAUTH, HTML)
|
||||||
|
|
||||||
timelinePage := handle(func(c *client) error {
|
timelinePage := handle(func(c *client) error {
|
||||||
tType, _ := mux.Vars(c.Req)["type"]
|
tType, _ := mux.Vars(c.r)["type"]
|
||||||
q := c.Req.URL.Query()
|
q := c.r.URL.Query()
|
||||||
instance := q.Get("instance")
|
instance := q.Get("instance")
|
||||||
maxID := q.Get("max_id")
|
maxID := q.Get("max_id")
|
||||||
minID := q.Get("min_id")
|
minID := q.Get("min_id")
|
||||||
@ -211,41 +180,41 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
}, SESSION, HTML)
|
}, SESSION, HTML)
|
||||||
|
|
||||||
threadPage := handle(func(c *client) error {
|
threadPage := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
q := c.Req.URL.Query()
|
q := c.r.URL.Query()
|
||||||
reply := q.Get("reply")
|
reply := q.Get("reply")
|
||||||
return s.ThreadPage(c, id, len(reply) > 1)
|
return s.ThreadPage(c, id, len(reply) > 1)
|
||||||
}, SESSION, HTML)
|
}, SESSION, HTML)
|
||||||
|
|
||||||
likedByPage := handle(func(c *client) error {
|
likedByPage := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
return s.LikedByPage(c, id)
|
return s.LikedByPage(c, id)
|
||||||
}, SESSION, HTML)
|
}, SESSION, HTML)
|
||||||
|
|
||||||
retweetedByPage := handle(func(c *client) error {
|
retweetedByPage := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
return s.RetweetedByPage(c, id)
|
return s.RetweetedByPage(c, id)
|
||||||
}, SESSION, HTML)
|
}, SESSION, HTML)
|
||||||
|
|
||||||
notificationsPage := handle(func(c *client) error {
|
notificationsPage := handle(func(c *client) error {
|
||||||
q := c.Req.URL.Query()
|
q := c.r.URL.Query()
|
||||||
maxID := q.Get("max_id")
|
maxID := q.Get("max_id")
|
||||||
minID := q.Get("min_id")
|
minID := q.Get("min_id")
|
||||||
return s.NotificationPage(c, maxID, minID)
|
return s.NotificationPage(c, maxID, minID)
|
||||||
}, SESSION, HTML)
|
}, SESSION, HTML)
|
||||||
|
|
||||||
userPage := handle(func(c *client) error {
|
userPage := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
pageType, _ := mux.Vars(c.Req)["type"]
|
pageType, _ := mux.Vars(c.r)["type"]
|
||||||
q := c.Req.URL.Query()
|
q := c.r.URL.Query()
|
||||||
maxID := q.Get("max_id")
|
maxID := q.Get("max_id")
|
||||||
minID := q.Get("min_id")
|
minID := q.Get("min_id")
|
||||||
return s.UserPage(c, id, pageType, maxID, minID)
|
return s.UserPage(c, id, pageType, maxID, minID)
|
||||||
}, SESSION, HTML)
|
}, SESSION, HTML)
|
||||||
|
|
||||||
userSearchPage := handle(func(c *client) error {
|
userSearchPage := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
q := c.Req.URL.Query()
|
q := c.r.URL.Query()
|
||||||
sq := q.Get("q")
|
sq := q.Get("q")
|
||||||
offset, _ := strconv.Atoi(q.Get("offset"))
|
offset, _ := strconv.Atoi(q.Get("offset"))
|
||||||
return s.UserSearchPage(c, id, sq, offset)
|
return s.UserSearchPage(c, id, sq, offset)
|
||||||
@ -260,7 +229,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
}, SESSION, HTML)
|
}, SESSION, HTML)
|
||||||
|
|
||||||
searchPage := handle(func(c *client) error {
|
searchPage := handle(func(c *client) error {
|
||||||
q := c.Req.URL.Query()
|
q := c.r.URL.Query()
|
||||||
sq := q.Get("q")
|
sq := q.Get("q")
|
||||||
qType := q.Get("type")
|
qType := q.Get("type")
|
||||||
offset, _ := strconv.Atoi(q.Get("offset"))
|
offset, _ := strconv.Atoi(q.Get("offset"))
|
||||||
@ -271,50 +240,46 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
return s.SettingsPage(c)
|
return s.SettingsPage(c)
|
||||||
}, SESSION, HTML)
|
}, SESSION, HTML)
|
||||||
|
|
||||||
|
filtersPage := handle(func(c *client) error {
|
||||||
|
return s.FiltersPage(c)
|
||||||
|
}, SESSION, HTML)
|
||||||
|
|
||||||
signin := handle(func(c *client) error {
|
signin := handle(func(c *client) error {
|
||||||
instance := c.Req.FormValue("instance")
|
instance := c.r.FormValue("instance")
|
||||||
url, sid, err := s.NewSession(instance)
|
url, sid, err := s.NewSession(c, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
setSessionCookie(c, sid, sessionExp)
|
setSessionCookie(c.w, sid, sessionExp)
|
||||||
redirect(c, url)
|
redirect(c, url)
|
||||||
return nil
|
return nil
|
||||||
}, NOAUTH, HTML)
|
}, NOAUTH, HTML)
|
||||||
|
|
||||||
oauthCallback := handle(func(c *client) error {
|
oauthCallback := handle(func(c *client) error {
|
||||||
q := c.Req.URL.Query()
|
q := c.r.URL.Query()
|
||||||
token := q.Get("code")
|
token := q.Get("code")
|
||||||
token, userID, err := s.Signin(c, token)
|
err := s.Signin(c, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Session.AccessToken = token
|
|
||||||
c.Session.UserID = userID
|
|
||||||
err = s.sessionRepo.Add(c.Session)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
redirect(c, "/")
|
redirect(c, "/")
|
||||||
return nil
|
return nil
|
||||||
}, SESSION, HTML)
|
}, SESSION, HTML)
|
||||||
|
|
||||||
post := handle(func(c *client) error {
|
post := handle(func(c *client) error {
|
||||||
content := c.Req.FormValue("content")
|
content := c.r.FormValue("content")
|
||||||
replyToID := c.Req.FormValue("reply_to_id")
|
replyToID := c.r.FormValue("reply_to_id")
|
||||||
format := c.Req.FormValue("format")
|
format := c.r.FormValue("format")
|
||||||
visibility := c.Req.FormValue("visibility")
|
visibility := c.r.FormValue("visibility")
|
||||||
isNSFW := c.Req.FormValue("is_nsfw") == "on"
|
isNSFW := c.r.FormValue("is_nsfw") == "true"
|
||||||
files := c.Req.MultipartForm.File["attachments"]
|
files := c.r.MultipartForm.File["attachments"]
|
||||||
|
|
||||||
id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, files)
|
id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, files)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
location := c.Req.FormValue("referrer")
|
location := c.r.FormValue("referrer")
|
||||||
if len(replyToID) > 0 {
|
if len(replyToID) > 0 {
|
||||||
location = "/thread/" + replyToID + "#status-" + id
|
location = "/thread/" + replyToID + "#status-" + id
|
||||||
}
|
}
|
||||||
@ -323,8 +288,8 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
like := handle(func(c *client) error {
|
like := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
rid := c.Req.FormValue("retweeted_by_id")
|
rid := c.r.FormValue("retweeted_by_id")
|
||||||
_, err := s.Like(c, id)
|
_, err := s.Like(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -332,13 +297,13 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
if len(rid) > 0 {
|
if len(rid) > 0 {
|
||||||
id = rid
|
id = rid
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer")+"#status-"+id)
|
redirect(c, c.r.FormValue("referrer")+"#status-"+id)
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
unlike := handle(func(c *client) error {
|
unlike := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
rid := c.Req.FormValue("retweeted_by_id")
|
rid := c.r.FormValue("retweeted_by_id")
|
||||||
_, err := s.UnLike(c, id)
|
_, err := s.UnLike(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -346,13 +311,13 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
if len(rid) > 0 {
|
if len(rid) > 0 {
|
||||||
id = rid
|
id = rid
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer")+"#status-"+id)
|
redirect(c, c.r.FormValue("referrer")+"#status-"+id)
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
retweet := handle(func(c *client) error {
|
retweet := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
rid := c.Req.FormValue("retweeted_by_id")
|
rid := c.r.FormValue("retweeted_by_id")
|
||||||
_, err := s.Retweet(c, id)
|
_, err := s.Retweet(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -360,13 +325,13 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
if len(rid) > 0 {
|
if len(rid) > 0 {
|
||||||
id = rid
|
id = rid
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer")+"#status-"+id)
|
redirect(c, c.r.FormValue("referrer")+"#status-"+id)
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
unretweet := handle(func(c *client) error {
|
unretweet := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
rid := c.Req.FormValue("retweeted_by_id")
|
rid := c.r.FormValue("retweeted_by_id")
|
||||||
_, err := s.UnRetweet(c, id)
|
_, err := s.UnRetweet(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -374,25 +339,25 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
if len(rid) > 0 {
|
if len(rid) > 0 {
|
||||||
id = rid
|
id = rid
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer")+"#status-"+id)
|
redirect(c, c.r.FormValue("referrer")+"#status-"+id)
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
vote := handle(func(c *client) error {
|
vote := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
statusID := c.Req.FormValue("status_id")
|
statusID := c.r.FormValue("status_id")
|
||||||
choices, _ := c.Req.PostForm["choices"]
|
choices, _ := c.r.PostForm["choices"]
|
||||||
err := s.Vote(c, id, choices)
|
err := s.Vote(c, id, choices)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer")+"#status-"+statusID)
|
redirect(c, c.r.FormValue("referrer")+"#status-"+statusID)
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
follow := handle(func(c *client) error {
|
follow := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
q := c.Req.URL.Query()
|
q := c.r.URL.Query()
|
||||||
var reblogs *bool
|
var reblogs *bool
|
||||||
if r, ok := q["reblogs"]; ok && len(r) > 0 {
|
if r, ok := q["reblogs"]; ok && len(r) > 0 {
|
||||||
reblogs = new(bool)
|
reblogs = new(bool)
|
||||||
@ -402,111 +367,112 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
unfollow := handle(func(c *client) error {
|
unfollow := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.UnFollow(c, id)
|
err := s.UnFollow(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
accept := handle(func(c *client) error {
|
accept := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.Accept(c, id)
|
err := s.Accept(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
reject := handle(func(c *client) error {
|
reject := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.Reject(c, id)
|
err := s.Reject(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
mute := handle(func(c *client) error {
|
mute := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.Mute(c, id)
|
err := s.Mute(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
unMute := handle(func(c *client) error {
|
unMute := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.UnMute(c, id)
|
err := s.UnMute(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
block := handle(func(c *client) error {
|
block := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.Block(c, id)
|
err := s.Block(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
unBlock := handle(func(c *client) error {
|
unBlock := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.UnBlock(c, id)
|
err := s.UnBlock(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
subscribe := handle(func(c *client) error {
|
subscribe := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.Subscribe(c, id)
|
err := s.Subscribe(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
unSubscribe := handle(func(c *client) error {
|
unSubscribe := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.UnSubscribe(c, id)
|
err := s.UnSubscribe(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
settings := handle(func(c *client) error {
|
settings := handle(func(c *client) error {
|
||||||
visibility := c.Req.FormValue("visibility")
|
visibility := c.r.FormValue("visibility")
|
||||||
format := c.Req.FormValue("format")
|
format := c.r.FormValue("format")
|
||||||
copyScope := c.Req.FormValue("copy_scope") == "true"
|
copyScope := c.r.FormValue("copy_scope") == "true"
|
||||||
threadInNewTab := c.Req.FormValue("thread_in_new_tab") == "true"
|
threadInNewTab := c.r.FormValue("thread_in_new_tab") == "true"
|
||||||
hideAttachments := c.Req.FormValue("hide_attachments") == "true"
|
hideAttachments := c.r.FormValue("hide_attachments") == "true"
|
||||||
maskNSFW := c.Req.FormValue("mask_nsfw") == "true"
|
maskNSFW := c.r.FormValue("mask_nsfw") == "true"
|
||||||
ni, _ := strconv.Atoi(c.Req.FormValue("notification_interval"))
|
ni, _ := strconv.Atoi(c.r.FormValue("notification_interval"))
|
||||||
fluorideMode := c.Req.FormValue("fluoride_mode") == "true"
|
fluorideMode := c.r.FormValue("fluoride_mode") == "true"
|
||||||
darkMode := c.Req.FormValue("dark_mode") == "true"
|
darkMode := c.r.FormValue("dark_mode") == "true"
|
||||||
antiDopamineMode := c.Req.FormValue("anti_dopamine_mode") == "true"
|
antiDopamineMode := c.r.FormValue("anti_dopamine_mode") == "true"
|
||||||
|
css := c.r.FormValue("css")
|
||||||
|
|
||||||
settings := &model.Settings{
|
settings := &model.Settings{
|
||||||
DefaultVisibility: visibility,
|
DefaultVisibility: visibility,
|
||||||
@ -519,6 +485,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
FluorideMode: fluorideMode,
|
FluorideMode: fluorideMode,
|
||||||
DarkMode: darkMode,
|
DarkMode: darkMode,
|
||||||
AntiDopamineMode: antiDopamineMode,
|
AntiDopamineMode: antiDopamineMode,
|
||||||
|
CSS: css,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := s.SaveSettings(c, settings)
|
err := s.SaveSettings(c, settings)
|
||||||
@ -530,49 +497,49 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
muteConversation := handle(func(c *client) error {
|
muteConversation := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.MuteConversation(c, id)
|
err := s.MuteConversation(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
unMuteConversation := handle(func(c *client) error {
|
unMuteConversation := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.UnMuteConversation(c, id)
|
err := s.UnMuteConversation(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
delete := handle(func(c *client) error {
|
delete := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
err := s.Delete(c, id)
|
err := s.Delete(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
readNotifications := handle(func(c *client) error {
|
readNotifications := handle(func(c *client) error {
|
||||||
q := c.Req.URL.Query()
|
q := c.r.URL.Query()
|
||||||
maxID := q.Get("max_id")
|
maxID := q.Get("max_id")
|
||||||
err := s.ReadNotifications(c, maxID)
|
err := s.ReadNotifications(c, maxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer"))
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
bookmark := handle(func(c *client) error {
|
bookmark := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
rid := c.Req.FormValue("retweeted_by_id")
|
rid := c.r.FormValue("retweeted_by_id")
|
||||||
err := s.Bookmark(c, id)
|
err := s.Bookmark(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -580,13 +547,13 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
if len(rid) > 0 {
|
if len(rid) > 0 {
|
||||||
id = rid
|
id = rid
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer")+"#status-"+id)
|
redirect(c, c.r.FormValue("referrer")+"#status-"+id)
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
unBookmark := handle(func(c *client) error {
|
unBookmark := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
rid := c.Req.FormValue("retweeted_by_id")
|
rid := c.r.FormValue("retweeted_by_id")
|
||||||
err := s.UnBookmark(c, id)
|
err := s.UnBookmark(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -594,19 +561,40 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
if len(rid) > 0 {
|
if len(rid) > 0 {
|
||||||
id = rid
|
id = rid
|
||||||
}
|
}
|
||||||
redirect(c, c.Req.FormValue("referrer")+"#status-"+id)
|
redirect(c, c.r.FormValue("referrer")+"#status-"+id)
|
||||||
|
return nil
|
||||||
|
}, CSRF, HTML)
|
||||||
|
|
||||||
|
filter := handle(func(c *client) error {
|
||||||
|
phrase := c.r.FormValue("phrase")
|
||||||
|
wholeWord := c.r.FormValue("whole_word") == "true"
|
||||||
|
err := s.Filter(c, phrase, wholeWord)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
|
return nil
|
||||||
|
}, CSRF, HTML)
|
||||||
|
|
||||||
|
unFilter := handle(func(c *client) error {
|
||||||
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
|
err := s.UnFilter(c, id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
redirect(c, c.r.FormValue("referrer"))
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
signout := handle(func(c *client) error {
|
signout := handle(func(c *client) error {
|
||||||
s.Signout(c)
|
s.Signout(c)
|
||||||
setSessionCookie(c, "", 0)
|
setSessionCookie(c.w, "", 0)
|
||||||
redirect(c, "/")
|
redirect(c, "/")
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, CSRF, HTML)
|
||||||
|
|
||||||
fLike := handle(func(c *client) error {
|
fLike := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
count, err := s.Like(c, id)
|
count, err := s.Like(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -615,7 +603,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
}, CSRF, JSON)
|
}, CSRF, JSON)
|
||||||
|
|
||||||
fUnlike := handle(func(c *client) error {
|
fUnlike := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
count, err := s.UnLike(c, id)
|
count, err := s.UnLike(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -624,7 +612,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
}, CSRF, JSON)
|
}, CSRF, JSON)
|
||||||
|
|
||||||
fRetweet := handle(func(c *client) error {
|
fRetweet := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
count, err := s.Retweet(c, id)
|
count, err := s.Retweet(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -633,7 +621,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
}, CSRF, JSON)
|
}, CSRF, JSON)
|
||||||
|
|
||||||
fUnretweet := handle(func(c *client) error {
|
fUnretweet := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.Req)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
count, err := s.UnRetweet(c, id)
|
count, err := s.UnRetweet(c, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -662,6 +650,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet)
|
r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet)
|
||||||
r.HandleFunc("/search", searchPage).Methods(http.MethodGet)
|
r.HandleFunc("/search", searchPage).Methods(http.MethodGet)
|
||||||
r.HandleFunc("/settings", settingsPage).Methods(http.MethodGet)
|
r.HandleFunc("/settings", settingsPage).Methods(http.MethodGet)
|
||||||
|
r.HandleFunc("/filters", filtersPage).Methods(http.MethodGet)
|
||||||
r.HandleFunc("/signin", signin).Methods(http.MethodPost)
|
r.HandleFunc("/signin", signin).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/oauth_callback", oauthCallback).Methods(http.MethodGet)
|
r.HandleFunc("/oauth_callback", oauthCallback).Methods(http.MethodGet)
|
||||||
r.HandleFunc("/post", post).Methods(http.MethodPost)
|
r.HandleFunc("/post", post).Methods(http.MethodPost)
|
||||||
@ -687,6 +676,8 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||||||
r.HandleFunc("/notifications/read", readNotifications).Methods(http.MethodPost)
|
r.HandleFunc("/notifications/read", readNotifications).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/bookmark/{id}", bookmark).Methods(http.MethodPost)
|
r.HandleFunc("/bookmark/{id}", bookmark).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/unbookmark/{id}", unBookmark).Methods(http.MethodPost)
|
r.HandleFunc("/unbookmark/{id}", unBookmark).Methods(http.MethodPost)
|
||||||
|
r.HandleFunc("/filter", filter).Methods(http.MethodPost)
|
||||||
|
r.HandleFunc("/unfilter/{id}", unFilter).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/signout", signout).Methods(http.MethodPost)
|
r.HandleFunc("/signout", signout).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost)
|
r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost)
|
r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost)
|
||||||
|
@ -270,6 +270,64 @@ function handleStatusLink(a) {
|
|||||||
a.target = "_blank";
|
a.target = "_blank";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setPos(el, cx, cy, mw, mh) {
|
||||||
|
var h = el.clientHeight;
|
||||||
|
var w = el.clientWidth;
|
||||||
|
var left, top;
|
||||||
|
if (cx < mw/2) {
|
||||||
|
if (w + cx + 20 < mw) {
|
||||||
|
left = cx + 20;
|
||||||
|
} else {
|
||||||
|
left = (mw - w);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (cx - w - 20 > 0) {
|
||||||
|
left = cx - w - 20;
|
||||||
|
} else {
|
||||||
|
left = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
top = (cy - (h/2));
|
||||||
|
if (top < 0) {
|
||||||
|
top = 0;
|
||||||
|
} else if (top + h > mh) {
|
||||||
|
top = (mh - h);
|
||||||
|
}
|
||||||
|
el.style.left = left + "px";
|
||||||
|
el.style.top = top + "px";
|
||||||
|
}
|
||||||
|
|
||||||
|
var imgPrev = null;
|
||||||
|
function handleImgPreview(a) {
|
||||||
|
a.onmouseenter = function(e) {
|
||||||
|
var mw = document.documentElement.clientWidth;
|
||||||
|
var mh = document.documentElement.clientHeight - 24;
|
||||||
|
var img = document.createElement("img");
|
||||||
|
img.id = "img-preview";
|
||||||
|
img.src = e.target.getAttribute("href");
|
||||||
|
img.style["max-width"] = mw + "px";
|
||||||
|
img.style["max-height"] = mh + "px";
|
||||||
|
img.onload = function(e2) {
|
||||||
|
setPos(e2.target, e.clientX, e.clientY, mw, mh);
|
||||||
|
}
|
||||||
|
document.body.appendChild(img);
|
||||||
|
imgPrev = img;
|
||||||
|
}
|
||||||
|
a.onmouseleave = function(e) {
|
||||||
|
var img = document.getElementById("img-preview");
|
||||||
|
if (img)
|
||||||
|
document.body.removeChild(img);
|
||||||
|
imgPrev = null;
|
||||||
|
}
|
||||||
|
a.onmousemove = function(e) {
|
||||||
|
if (!imgPrev)
|
||||||
|
return;
|
||||||
|
var mw = document.documentElement.clientWidth;
|
||||||
|
var mh = document.documentElement.clientHeight - 24;
|
||||||
|
setPos(imgPrev, e.clientX, e.clientY, mw, mh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
checkCSRFToken();
|
checkCSRFToken();
|
||||||
checkAntiDopamineMode();
|
checkAntiDopamineMode();
|
||||||
@ -303,6 +361,11 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
for (var j = 0; j < links.length; j++) {
|
for (var j = 0; j < links.length; j++) {
|
||||||
links[j].target = "_blank";
|
links[j].target = "_blank";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var links = document.querySelectorAll(".status-media-container .img-link");
|
||||||
|
for (var j = 0; j < links.length; j++) {
|
||||||
|
handleImgPreview(links[j]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// @license-end
|
// @license-end
|
||||||
|
@ -159,12 +159,20 @@ body {
|
|||||||
margin-left: 4px;
|
margin-left: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-content {
|
textarea {
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
font-size: 11pt;
|
font-size: 11pt;
|
||||||
font-family: initial;
|
font-family: initial;
|
||||||
width: 100%;
|
}
|
||||||
|
|
||||||
|
.post-content {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#css {
|
||||||
|
box-sizing: border-box;
|
||||||
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pagination {
|
.pagination {
|
||||||
@ -351,9 +359,10 @@ a:hover,
|
|||||||
}
|
}
|
||||||
|
|
||||||
.emoji-item-container {
|
.emoji-item-container {
|
||||||
min-width: 220px;
|
width: 220px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin: 4px 0;
|
margin: 4px 0;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.emoji-item {
|
.emoji-item {
|
||||||
@ -552,6 +561,20 @@ kbd {
|
|||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.filters {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filters td {
|
||||||
|
padding: 2px 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#img-preview {
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 2;
|
||||||
|
position: fixed;
|
||||||
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
background-color: #222222;
|
background-color: #222222;
|
||||||
background-image: none;
|
background-image: none;
|
||||||
@ -562,7 +585,7 @@ kbd {
|
|||||||
color: #81a2be;
|
color: #81a2be;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark #post-content {
|
.dark textarea {
|
||||||
background-color: #333333;
|
background-color: #333333;
|
||||||
border: 1px solid #444444;
|
border: 1px solid #444444;
|
||||||
color: #eaeaea;
|
color: #eaeaea;
|
||||||
|
@ -89,6 +89,10 @@
|
|||||||
<td> Read notifications </td>
|
<td> Read notifications </td>
|
||||||
<td> <kbd>C</kbd> </td>
|
<td> <kbd>C</kbd> </td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td> Refresh thread page </td>
|
||||||
|
<td> <kbd>T</kbd> </td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<p>
|
<p>
|
||||||
You can activate the shortcuts by pressing the associated key with your browser's <a href="https://en.wikipedia.org/wiki/Access_key#Access_in_different_browsers" target="_blank">accesskey modifier</a>,
|
You can activate the shortcuts by pressing the associated key with your browser's <a href="https://en.wikipedia.org/wiki/Access_key#Access_in_different_browsers" target="_blank">accesskey modifier</a>,
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<div class="emoji-item-container">
|
<div class="emoji-item-container">
|
||||||
<div class="emoji-item">
|
<div class="emoji-item">
|
||||||
<img class="emoji" src="{{.URL}}" alt="{{.ShortCode}}" height="32" />
|
<img class="emoji" src="{{.URL}}" alt="{{.ShortCode}}" height="32" />
|
||||||
<span class="emoji-shortcode">:{{.ShortCode}}:</span>
|
<span title=":{{.ShortCode}}:" class="emoji-shortcode">:{{.ShortCode}}:</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -2,10 +2,15 @@
|
|||||||
{{template "header.tmpl" (WithContext .CommonData $.Ctx)}}
|
{{template "header.tmpl" (WithContext .CommonData $.Ctx)}}
|
||||||
<div class="page-title"> Error </div>
|
<div class="page-title"> Error </div>
|
||||||
|
|
||||||
<div class="error-text"> {{.Error}} </div>
|
<div class="error-text"> {{.Err}} </div>
|
||||||
<div>
|
<div>
|
||||||
<a href="/timeline/home">Home</a>
|
<a href="/timeline/home">home</a>
|
||||||
<a href="/signin" target="_top">Sign In</a>
|
{{if .Retry}}
|
||||||
|
<a href="{{$.Ctx.Referrer}}">retry</a>
|
||||||
|
{{end}}
|
||||||
|
{{if .SessionErr}}
|
||||||
|
<a href="/signin" target="_top">signin</a>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{template "footer.tmpl"}}
|
{{template "footer.tmpl"}}
|
||||||
|
40
templates/filters.tmpl
Normal file
40
templates/filters.tmpl
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{{with .Data}}
|
||||||
|
{{template "header.tmpl" (WithContext .CommonData $.Ctx)}}
|
||||||
|
<div class="page-title"> Filters </div>
|
||||||
|
|
||||||
|
{{if .Filters}}
|
||||||
|
<table class="filters">
|
||||||
|
{{range .Filters}}
|
||||||
|
<tr>
|
||||||
|
<td> {{.Phrase}}{{if not .WholeWord}}*{{end}} </td>
|
||||||
|
<td>
|
||||||
|
<form action="/unfilter/{{.ID}}" method="POST">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||||
|
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
|
||||||
|
<button type="submit"> Delete </button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
|
</table>
|
||||||
|
{{else}}
|
||||||
|
<div class="filters"> No filters added </div>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
<div class="page-title"> Add filter </div>
|
||||||
|
<form action="/filter" method="POST">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||||
|
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
|
||||||
|
<span class="settings-form-field">
|
||||||
|
<label for="phrase"> Phrase </label>
|
||||||
|
<input id="phrase" name="phrase" required>
|
||||||
|
</span>
|
||||||
|
<span class="settings-form-field">
|
||||||
|
<input id="whole-word" name="whole_word" type="checkbox" value="true" checked>
|
||||||
|
<label for="whole-word"> Whole word </label>
|
||||||
|
</span>
|
||||||
|
<button type="submit"> Add </button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{{template "footer.tmpl"}}
|
||||||
|
{{end}}
|
@ -17,7 +17,7 @@
|
|||||||
{{if .RefreshInterval}}
|
{{if .RefreshInterval}}
|
||||||
<meta http-equiv="refresh" content="{{.RefreshInterval}}">
|
<meta http-equiv="refresh" content="{{.RefreshInterval}}">
|
||||||
{{end}}
|
{{end}}
|
||||||
<title> {{if gt .Count 0}}({{.Count}}){{end}} {{.Title}} </title>
|
<title> {{if gt .Count 0}}({{.Count}}){{end}} {{.Title | html}} </title>
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
{{if .CustomCSS}}
|
{{if .CustomCSS}}
|
||||||
<link rel="stylesheet" href="{{.CustomCSS}}">
|
<link rel="stylesheet" href="{{.CustomCSS}}">
|
||||||
@ -25,6 +25,9 @@
|
|||||||
{{if $.Ctx.FluorideMode}}
|
{{if $.Ctx.FluorideMode}}
|
||||||
<script src="/static/fluoride.js"></script>
|
<script src="/static/fluoride.js"></script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{if $.Ctx.UserCSS}}
|
||||||
|
<style>{{$.Ctx.UserCSS}}</style>
|
||||||
|
{{end}}
|
||||||
</head>
|
</head>
|
||||||
<body {{if $.Ctx.DarkMode}}class="dark"{{end}}>
|
<body {{if $.Ctx.DarkMode}}class="dark"{{end}}>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<div class="user-info">
|
<div class="user-info">
|
||||||
<div class="user-info-img-container">
|
<div class="user-info-img-container">
|
||||||
<a class="img-link" href="/timeline/home" title="Home (1)">
|
<a class="img-link" href="/timeline/home" title="Home (1)">
|
||||||
<img class="user-info-img" src="{{.User.AvatarStatic}}" alt="profile-avatar" height="64" />
|
<img class="user-info-img" src="{{.User.Avatar}}" alt="profile-avatar" height="64" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-info-details-container">
|
<div class="user-info-details-container">
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<div class="notification-follow-container">
|
<div class="notification-follow-container">
|
||||||
<div class="status-profile-img-container">
|
<div class="status-profile-img-container">
|
||||||
<a class="img-link" href="/user/{{.Account.ID}}">
|
<a class="img-link" href="/user/{{.Account.ID}}">
|
||||||
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" title="@{{.Account.Acct}}" alt="profile-avatar" height="48" />
|
<img class="status-profile-img" src="{{.Account.Avatar}}" title="@{{.Account.Acct}}" alt="profile-avatar" height="48" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="notification-follow">
|
<div class="notification-follow">
|
||||||
@ -43,7 +43,7 @@
|
|||||||
<div class="notification-follow-container">
|
<div class="notification-follow-container">
|
||||||
<div class="status-profile-img-container">
|
<div class="status-profile-img-container">
|
||||||
<a class="img-link" href="/user/{{.Account.ID}}">
|
<a class="img-link" href="/user/{{.Account.ID}}">
|
||||||
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" title="@{{.Account.Acct}}" alt="profile-avatar" height="48" />
|
<img class="status-profile-img" src="{{.Account.Avatar}}" title="@{{.Account.Acct}}" alt="profile-avatar" height="48" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="notification-follow">
|
<div class="notification-follow">
|
||||||
@ -76,7 +76,7 @@
|
|||||||
{{else if eq .Type "reblog"}}
|
{{else if eq .Type "reblog"}}
|
||||||
<div class="retweet-info">
|
<div class="retweet-info">
|
||||||
<a class="img-link" href="/user/{{.Account.ID}}">
|
<a class="img-link" href="/user/{{.Account.ID}}">
|
||||||
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" title="@{{.Account.Acct}}" alt="avatar" height="48" />
|
<img class="status-profile-img" src="{{.Account.Avatar}}" title="@{{.Account.Acct}}" alt="avatar" height="48" />
|
||||||
</a>
|
</a>
|
||||||
<a href="/user/{{.Account.ID}}">
|
<a href="/user/{{.Account.ID}}">
|
||||||
<span class="status-uname"> @{{.Account.Acct}} </span>
|
<span class="status-uname"> @{{.Account.Acct}} </span>
|
||||||
@ -90,7 +90,7 @@
|
|||||||
{{else if eq .Type "favourite"}}
|
{{else if eq .Type "favourite"}}
|
||||||
<div class="retweet-info">
|
<div class="retweet-info">
|
||||||
<a class="img-link" href="/user/{{.Account.ID}}">
|
<a class="img-link" href="/user/{{.Account.ID}}">
|
||||||
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" title="@{{.Account.Acct}}" alt="avatar" height="48" />
|
<img class="status-profile-img" src="{{.Account.Avatar}}" title="@{{.Account.Acct}}" alt="avatar" height="48" />
|
||||||
</a>
|
</a>
|
||||||
<a href="/user/{{.Account.ID}}">
|
<a href="/user/{{.Account.ID}}">
|
||||||
<span class="status-uname"> @{{.Account.Acct}} </span>
|
<span class="status-uname"> @{{.Account.Acct}} </span>
|
||||||
@ -104,7 +104,7 @@
|
|||||||
{{else}}
|
{{else}}
|
||||||
<div class="retweet-info">
|
<div class="retweet-info">
|
||||||
<a class="img-link" href="/user/{{.Account.ID}}">
|
<a class="img-link" href="/user/{{.Account.ID}}">
|
||||||
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" title="@{{.Account.Acct}}" alt="avatar" height="48" />
|
<img class="status-profile-img" src="{{.Account.Avatar}}" title="@{{.Account.Acct}}" alt="avatar" height="48" />
|
||||||
</a>
|
</a>
|
||||||
<a href="/user/{{.Account.ID}}">
|
<a href="/user/{{.Account.ID}}">
|
||||||
<span class="status-uname"> @{{.Account.Acct}} </span>
|
<span class="status-uname"> @{{.Account.Acct}} </span>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<textarea id="post-content" name="content" class="post-content" cols="34" rows="5" accesskey="E" title="Edit post (E)">{{if .ReplyContext}}{{.ReplyContext.ReplyContent}}{{end}}</textarea>
|
<textarea id="post-content" name="content" class="post-content" cols="34" rows="5" accesskey="E" title="Edit post (E)">{{if .ReplyContext}}{{.ReplyContext.ReplyContent}}{{end}}</textarea>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{{if gt (len .Formats) 0}}
|
{{if .Formats}}
|
||||||
<span class="post-form-field">
|
<span class="post-form-field">
|
||||||
{{$defFormat := .DefaultFormat}}
|
{{$defFormat := .DefaultFormat}}
|
||||||
<select id="post-format" name="format" accesskey="F" title="Format (F)">
|
<select id="post-format" name="format" accesskey="F" title="Format (F)">
|
||||||
@ -34,7 +34,7 @@
|
|||||||
</select>
|
</select>
|
||||||
</span>
|
</span>
|
||||||
<span class="post-form-field">
|
<span class="post-form-field">
|
||||||
<input type="checkbox" id="nsfw-checkbox" name="is_nsfw" value="on" accesskey="N" title="NSFW (N)">
|
<input type="checkbox" id="nsfw-checkbox" name="is_nsfw" value="true" accesskey="N" title="NSFW (N)">
|
||||||
<label for="nsfw-checkbox"> NSFW </label>
|
<label for="nsfw-checkbox"> NSFW </label>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<div class="user-list-item">
|
<div class="user-list-item">
|
||||||
<div class="user-list-profile-img">
|
<div class="user-list-profile-img">
|
||||||
<a class="img-link" href="/user/{{.ID}}">
|
<a class="img-link" href="/user/{{.ID}}">
|
||||||
<img class="status-profile-img" src="{{.AvatarStatic}}" title="@{{.Acct}}" alt="avatar" height="48" />
|
<img class="status-profile-img" src="{{.Avatar}}" title="@{{.Acct}}" alt="avatar" height="48" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-list-name">
|
<div class="user-list-name">
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<form class="search-form" action="/search" method="GET">
|
<form class="search-form" action="/search" method="GET">
|
||||||
<span class="post-form-field">
|
<span class="post-form-field">
|
||||||
<label for="query"> Query </label>
|
<label for="query"> Query </label>
|
||||||
<input id="query" name="q" value="{{.Q}}">
|
<input id="query" name="q" value="{{.Q | html}}">
|
||||||
</span>
|
</span>
|
||||||
<span class="post-form-field">
|
<span class="post-form-field">
|
||||||
<label for="type"> Type </label>
|
<label for="type"> Type </label>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<form id="settings-form" action="/settings" method="POST">
|
<form id="settings-form" action="/settings" method="POST">
|
||||||
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||||
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
|
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
|
||||||
|
{{if .PostFormats}}
|
||||||
<div class="settings-form-field">
|
<div class="settings-form-field">
|
||||||
<label for="visibility"> Default format </label>
|
<label for="visibility"> Default format </label>
|
||||||
{{$defFormat := .Settings.DefaultFormat}}
|
{{$defFormat := .Settings.DefaultFormat}}
|
||||||
@ -14,6 +15,7 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
{{end}}
|
||||||
<div class="settings-form-field">
|
<div class="settings-form-field">
|
||||||
<label for="visibility"> Default scope </label>
|
<label for="visibility"> Default scope </label>
|
||||||
<select id="visibility" name="visibility">
|
<select id="visibility" name="visibility">
|
||||||
@ -63,6 +65,12 @@
|
|||||||
<input id="dark-mode" name="dark_mode" type="checkbox" value="true" {{if .Settings.DarkMode}}checked{{end}}>
|
<input id="dark-mode" name="dark_mode" type="checkbox" value="true" {{if .Settings.DarkMode}}checked{{end}}>
|
||||||
<label for="dark-mode"> Use dark theme </label>
|
<label for="dark-mode"> Use dark theme </label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="settings-form-field">
|
||||||
|
<label for="css"> Custom CSS: </label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<textarea id="css" name="css" cols="80" rows="8">{{.Settings.CSS}}</textarea>
|
||||||
|
</div>
|
||||||
<button type="submit"> Save </button>
|
<button type="submit"> Save </button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{{if .Reblog}}
|
{{if .Reblog}}
|
||||||
<div class="retweet-info">
|
<div class="retweet-info">
|
||||||
<a class="img-link" href="/user/{{.Account.ID}}">
|
<a class="img-link" href="/user/{{.Account.ID}}">
|
||||||
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" title="@{{.Account.Acct}}" alt="avatar" height="24" />
|
<img class="status-profile-img" src="{{.Account.Avatar}}" title="@{{.Account.Acct}}" alt="avatar" height="24" />
|
||||||
</a>
|
</a>
|
||||||
<bdi class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </bdi>
|
<bdi class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </bdi>
|
||||||
<a href="/user/{{.Account.ID}}">
|
<a href="/user/{{.Account.ID}}">
|
||||||
@ -18,7 +18,7 @@
|
|||||||
<div class="status-container status-{{.ID}}" data-id="{{.ID}}">
|
<div class="status-container status-{{.ID}}" data-id="{{.ID}}">
|
||||||
<div class="status-profile-img-container">
|
<div class="status-profile-img-container">
|
||||||
<a class="img-link" href="/user/{{.Account.ID}}">
|
<a class="img-link" href="/user/{{.Account.ID}}">
|
||||||
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" title="@{{.Account.Acct}}" alt="avatar" height="48" />
|
<img class="status-profile-img" src="{{.Account.Avatar}}" title="@{{.Account.Acct}}" alt="avatar" height="48" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="status">
|
<div class="status">
|
||||||
@ -88,7 +88,7 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{if .Content}}
|
{{if .Content}}
|
||||||
<div class="status-content"> {{StatusContentFilter .SpoilerText .Content .Emojis .Mentions}} </div>
|
<div class="status-content"> {{StatusContentFilter (html .SpoilerText) .Content .Emojis .Mentions}} </div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .MediaAttachments}}
|
{{if .MediaAttachments}}
|
||||||
<div class="status-media-container">
|
<div class="status-media-container">
|
||||||
@ -101,7 +101,7 @@
|
|||||||
</a>
|
</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a class="img-link" href="{{.URL}}" target="_blank" title="{{.Description}}">
|
<a class="img-link" href="{{.URL}}" target="_blank" title="{{.Description}}">
|
||||||
<img class="status-image" src="{{.URL}}" alt="status-image" height="240" />
|
<img class="status-image" src="{{.PreviewURL}}" alt="status-image" height="240" />
|
||||||
{{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
|
{{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
|
||||||
<div class="status-nsfw-overlay"></div>
|
<div class="status-nsfw-overlay"></div>
|
||||||
{{end}}
|
{{end}}
|
||||||
@ -153,12 +153,12 @@
|
|||||||
{{range $i, $o := .Poll.Options}}
|
{{range $i, $o := .Poll.Options}}
|
||||||
<div class="poll-option">
|
<div class="poll-option">
|
||||||
{{if (or $s.Poll.Expired $s.Poll.Voted)}}
|
{{if (or $s.Poll.Expired $s.Poll.Voted)}}
|
||||||
<div> {{EmojiFilter $o.Title $s.Emojis}} - {{$o.VotesCount}} votes </div>
|
<div> {{EmojiFilter (html $o.Title) $s.Emojis}} - {{$o.VotesCount}} votes </div>
|
||||||
{{else}}
|
{{else}}
|
||||||
<input type="{{if $s.Poll.Multiple}}checkbox{{else}}radio{{end}}" name="choices"
|
<input type="{{if $s.Poll.Multiple}}checkbox{{else}}radio{{end}}" name="choices"
|
||||||
id="poll-{{$s.ID}}-{{$i}}" value="{{$i}}">
|
id="poll-{{$s.ID}}-{{$i}}" value="{{$i}}">
|
||||||
<label for="poll-{{$s.ID}}-{{$i}}">
|
<label for="poll-{{$s.ID}}-{{$i}}">
|
||||||
{{EmojiFilter $o.Title $s.Emojis}}
|
{{EmojiFilter (html $o.Title) $s.Emojis}}
|
||||||
</label>
|
</label>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
@ -193,24 +193,19 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="status-action">
|
<div class="status-action">
|
||||||
{{if or (eq .Visibility "private") (eq .Visibility "direct")}}
|
|
||||||
<a class="status-retweet" href="" title="this status cannot be retweeted">
|
|
||||||
retweet
|
|
||||||
</a>
|
|
||||||
{{else}}
|
|
||||||
{{$rt := "retweet"}} {{if .Reblogged}} {{$rt = "unretweet"}} {{end}}
|
{{$rt := "retweet"}} {{if .Reblogged}} {{$rt = "unretweet"}} {{end}}
|
||||||
<form class="status-retweet" data-action="{{$rt}}" action="/{{$rt}}/{{.ID}}" method="post" target="_self">
|
<form class="status-retweet" data-action="{{$rt}}" action="/{{$rt}}/{{.ID}}" method="post" target="_self">
|
||||||
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||||
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
|
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
|
||||||
<input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}">
|
<input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}">
|
||||||
<input type="submit" value="{{$rt}}" class="btn-link">
|
<input type="submit" value="{{$rt}}" class="btn-link"
|
||||||
|
{{if or (eq .Visibility "private") (eq .Visibility "direct")}}title="this status cannot be retweeted" disabled{{end}}>
|
||||||
<a class="status-retweet-count" href="/retweetedby/{{.ID}}" title="click to see the the list">
|
<a class="status-retweet-count" href="/retweetedby/{{.ID}}" title="click to see the the list">
|
||||||
{{if and (not $.Ctx.AntiDopamineMode) .ReblogsCount}}
|
{{if and (not $.Ctx.AntiDopamineMode) .ReblogsCount}}
|
||||||
({{DisplayInteractionCount .ReblogsCount}})
|
({{DisplayInteractionCount .ReblogsCount}})
|
||||||
{{end}}
|
{{end}}
|
||||||
</a>
|
</a>
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="status-action">
|
<div class="status-action">
|
||||||
{{$like := "like"}} {{if .Favourited}} {{$like = "unlike"}} {{end}}
|
{{$like := "like"}} {{if .Favourited}} {{$like = "unlike"}} {{end}}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
{{with $s := .Data}}
|
{{with $s := .Data}}
|
||||||
{{template "header.tmpl" (WithContext .CommonData $.Ctx)}}
|
{{template "header.tmpl" (WithContext .CommonData $.Ctx)}}
|
||||||
<div class="page-title"> Thread </div>
|
<div class="notification-title-container">
|
||||||
|
<span class="page-title"> Thread </span>
|
||||||
|
<a class="notification-refresh" href="{{$.Ctx.Referrer}}" accesskey="T" title="Refresh (T)">refresh</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
{{range .Statuses}}
|
{{range .Statuses}}
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
<div class="user-info-container">
|
<div class="user-info-container">
|
||||||
<div>
|
<div>
|
||||||
<div class="user-profile-img-container">
|
<div class="user-profile-img-container">
|
||||||
<a class="img-link" href="{{.User.AvatarStatic}}" target="_blank">
|
<a class="img-link" href="{{.User.Avatar}}" target="_blank">
|
||||||
<img class="user-profile-img" src="{{.User.AvatarStatic}}" alt="profile-avatar" height="96" />
|
<img class="user-profile-img" src="{{.User.Avatar}}" alt="profile-avatar" height="96" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-profile-details-container">
|
<div class="user-profile-details-container">
|
||||||
@ -119,11 +119,15 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
<div>
|
<div>
|
||||||
<a href="/usersearch/{{.User.ID}}"> search statuses </a>
|
<a href="/usersearch/{{.User.ID}}"> search statuses </a>
|
||||||
|
{{if .IsCurrent}} - <a href="/filters"> filters </a> {{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-profile-decription">
|
<div class="user-profile-decription">
|
||||||
{{EmojiFilter .User.Note .User.Emojis}}
|
{{EmojiFilter .User.Note .User.Emojis}}
|
||||||
</div>
|
</div>
|
||||||
|
{{if .User.Fields}}{{range .User.Fields}}
|
||||||
|
<div>{{.Name}} - {{.Value}}</div>
|
||||||
|
{{end}}{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<div class="user-list-item">
|
<div class="user-list-item">
|
||||||
<div class="user-list-profile-img">
|
<div class="user-list-profile-img">
|
||||||
<a class="img-link" href="/user/{{.ID}}">
|
<a class="img-link" href="/user/{{.ID}}">
|
||||||
<img class="status-profile-img" src="{{.AvatarStatic}}" title="@{{.Acct}}" alt="avatar" height="48" />
|
<img class="status-profile-img" src="{{.Avatar}}" title="@{{.Acct}}" alt="avatar" height="48" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-list-name">
|
<div class="user-list-name">
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<form class="search-form" action="/usersearch/{{.User.ID}}" method="GET">
|
<form class="search-form" action="/usersearch/{{.User.ID}}" method="GET">
|
||||||
<span class="post-form-field>
|
<span class="post-form-field>
|
||||||
<label for="query"> Query </label>
|
<label for="query"> Query </label>
|
||||||
<input id="query" name="q" value="{{.Q}}">
|
<input id="query" name="q" value="{{.Q | html}}">
|
||||||
</span>
|
</span>
|
||||||
<button type="submit"> Search </button>
|
<button type="submit"> Search </button>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
Reference in New Issue
Block a user