2019-04-09 13:59:33 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2020-05-10 01:25:25 +02:00
|
|
|
"context"
|
2020-05-13 23:00:34 +02:00
|
|
|
"crypto/tls"
|
2019-04-09 13:59:33 +02:00
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
2019-10-06 21:23:42 +02:00
|
|
|
"html"
|
2019-04-09 13:59:33 +02:00
|
|
|
"io"
|
2019-08-02 16:45:42 +02:00
|
|
|
notrand "math/rand"
|
2019-04-09 13:59:33 +02:00
|
|
|
"net/http"
|
|
|
|
"os"
|
2023-01-24 20:46:55 +01:00
|
|
|
"regexp"
|
2019-04-09 13:59:33 +02:00
|
|
|
"strings"
|
|
|
|
"time"
|
2019-05-05 00:05:15 +02:00
|
|
|
|
2019-10-13 01:25:23 +02:00
|
|
|
"humungus.tedunangst.com/r/webs/cache"
|
2019-10-29 18:38:51 +01:00
|
|
|
"humungus.tedunangst.com/r/webs/gate"
|
2019-07-29 01:44:27 +02:00
|
|
|
"humungus.tedunangst.com/r/webs/httpsig"
|
2019-06-11 16:14:12 +02:00
|
|
|
"humungus.tedunangst.com/r/webs/junk"
|
2019-12-24 14:08:40 +01:00
|
|
|
"humungus.tedunangst.com/r/webs/templates"
|
2019-04-09 13:59:33 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var theonetruename = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`
|
2019-04-23 21:58:13 +02:00
|
|
|
var thefakename = `application/activity+json`
|
2019-04-09 13:59:33 +02:00
|
|
|
var falsenames = []string{
|
|
|
|
`application/ld+json`,
|
|
|
|
`application/activity+json`,
|
|
|
|
}
|
|
|
|
var itiswhatitis = "https://www.w3.org/ns/activitystreams"
|
|
|
|
var thewholeworld = "https://www.w3.org/ns/activitystreams#Public"
|
|
|
|
|
2022-05-20 18:33:48 +02:00
|
|
|
var fastTimeout time.Duration = 5
|
|
|
|
var slowTimeout time.Duration = 30
|
|
|
|
|
2019-04-09 13:59:33 +02:00
|
|
|
func friendorfoe(ct string) bool {
|
|
|
|
ct = strings.ToLower(ct)
|
|
|
|
for _, at := range falsenames {
|
|
|
|
if strings.HasPrefix(ct, at) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-03-01 02:40:23 +01:00
|
|
|
var develClient = &http.Client{
|
2020-05-13 23:00:34 +02:00
|
|
|
Transport: &http.Transport{
|
|
|
|
TLSClientConfig: &tls.Config{
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-01-19 09:44:38 +01:00
|
|
|
func PostJunk(keyname string, key httpsig.PrivateKey, url string, j junk.Junk) error {
|
2019-10-25 23:44:46 +02:00
|
|
|
return PostMsg(keyname, key, url, j.ToBytes())
|
2019-04-14 16:06:26 +02:00
|
|
|
}
|
|
|
|
|
2020-01-19 09:44:38 +01:00
|
|
|
func PostMsg(keyname string, key httpsig.PrivateKey, url string, msg []byte) error {
|
2019-04-14 16:06:26 +02:00
|
|
|
client := http.DefaultClient
|
2022-03-01 02:40:23 +01:00
|
|
|
if develMode {
|
|
|
|
client = develClient
|
2020-05-13 23:00:34 +02:00
|
|
|
}
|
2019-04-14 16:06:26 +02:00
|
|
|
req, err := http.NewRequest("POST", url, bytes.NewReader(msg))
|
2019-04-09 13:59:33 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-07-16 02:49:01 +02:00
|
|
|
req.Header.Set("User-Agent", "honksnonk/5.0; "+serverName)
|
2019-04-09 13:59:33 +02:00
|
|
|
req.Header.Set("Content-Type", theonetruename)
|
2019-07-29 01:44:27 +02:00
|
|
|
httpsig.SignRequest(keyname, key, req, msg)
|
2022-05-20 18:33:48 +02:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*slowTimeout*time.Second)
|
2020-05-10 01:25:25 +02:00
|
|
|
defer cancel()
|
|
|
|
req = req.WithContext(ctx)
|
2019-04-09 13:59:33 +02:00
|
|
|
resp, err := client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-04-18 22:09:10 +02:00
|
|
|
resp.Body.Close()
|
|
|
|
switch resp.StatusCode {
|
|
|
|
case 200:
|
|
|
|
case 201:
|
|
|
|
case 202:
|
|
|
|
default:
|
2019-04-09 13:59:33 +02:00
|
|
|
return fmt.Errorf("http post status: %d", resp.StatusCode)
|
|
|
|
}
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("successful post: %s %d", url, resp.StatusCode)
|
2019-04-09 13:59:33 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-20 21:50:33 +02:00
|
|
|
func GetJunk(userid int64, url string) (junk.Junk, error) {
|
|
|
|
return GetJunkTimeout(userid, url, slowTimeout*time.Second)
|
2019-07-11 07:20:53 +02:00
|
|
|
}
|
|
|
|
|
2022-05-20 21:50:33 +02:00
|
|
|
func GetJunkFast(userid int64, url string) (junk.Junk, error) {
|
|
|
|
return GetJunkTimeout(userid, url, fastTimeout*time.Second)
|
2019-07-11 07:20:53 +02:00
|
|
|
}
|
|
|
|
|
2022-05-20 21:50:33 +02:00
|
|
|
func GetJunkHardMode(userid int64, url string) (junk.Junk, error) {
|
|
|
|
j, err := GetJunk(userid, url)
|
2019-08-14 19:15:11 +02:00
|
|
|
if err != nil {
|
|
|
|
emsg := err.Error()
|
|
|
|
if emsg == "http get status: 502" || strings.Contains(emsg, "timeout") {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("trying again after error: %s", emsg)
|
2019-08-14 19:15:11 +02:00
|
|
|
time.Sleep(time.Duration(60+notrand.Int63n(60)) * time.Second)
|
2022-05-20 21:50:33 +02:00
|
|
|
j, err = GetJunk(userid, url)
|
2019-08-14 19:15:11 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("still couldn't get it")
|
2019-08-14 19:15:11 +02:00
|
|
|
} else {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("retry success!")
|
2019-08-14 19:15:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return j, err
|
|
|
|
}
|
|
|
|
|
2019-10-29 18:38:51 +01:00
|
|
|
var flightdeck = gate.NewSerializer()
|
2019-10-13 19:25:12 +02:00
|
|
|
|
2022-05-20 21:50:33 +02:00
|
|
|
var signGets = true
|
|
|
|
|
2023-07-30 22:49:34 +02:00
|
|
|
func GetJunkTimeout(userid int64, url string, timeout time.Duration) (junk.Junk, error) {
|
2023-08-06 02:52:55 +02:00
|
|
|
if rejectorigin(userid, url, false) {
|
|
|
|
return nil, fmt.Errorf("rejected origin: %s", url)
|
|
|
|
}
|
2022-05-20 21:50:33 +02:00
|
|
|
client := http.DefaultClient
|
2023-07-30 22:49:34 +02:00
|
|
|
sign := func(req *http.Request) error {
|
2022-05-20 21:50:33 +02:00
|
|
|
var ki *KeyInfo
|
|
|
|
ok := ziggies.Get(userid, &ki)
|
|
|
|
if ok {
|
|
|
|
httpsig.SignRequest(ki.keyname, ki.seckey, req, nil)
|
|
|
|
}
|
2023-07-30 22:49:34 +02:00
|
|
|
return nil
|
2022-05-20 21:50:33 +02:00
|
|
|
}
|
2022-03-01 02:40:23 +01:00
|
|
|
if develMode {
|
|
|
|
client = develClient
|
2023-07-30 22:49:34 +02:00
|
|
|
sign = nil
|
2022-02-09 23:11:55 +01:00
|
|
|
}
|
2019-10-29 18:38:51 +01:00
|
|
|
fn := func() (interface{}, error) {
|
2023-08-09 22:16:11 +02:00
|
|
|
at := theonetruename
|
2019-10-29 18:38:51 +01:00
|
|
|
if strings.Contains(url, ".well-known/webfinger?resource") {
|
|
|
|
at = "application/jrd+json"
|
|
|
|
}
|
2023-07-30 22:49:34 +02:00
|
|
|
j, err := junk.Get(url, junk.GetArgs{
|
2019-10-29 18:38:51 +01:00
|
|
|
Accept: at,
|
|
|
|
Agent: "honksnonk/5.0; " + serverName,
|
|
|
|
Timeout: timeout,
|
2022-02-09 23:11:55 +01:00
|
|
|
Client: client,
|
2023-07-30 22:49:34 +02:00
|
|
|
Fixup: sign,
|
2019-10-29 18:38:51 +01:00
|
|
|
})
|
|
|
|
return j, err
|
2019-04-15 16:27:36 +02:00
|
|
|
}
|
2019-10-29 18:38:51 +01:00
|
|
|
|
|
|
|
ji, err := flightdeck.Call(url, fn)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2019-10-13 19:25:12 +02:00
|
|
|
}
|
2019-10-29 18:38:51 +01:00
|
|
|
j := ji.(junk.Junk)
|
|
|
|
return j, nil
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
|
|
|
|
2019-11-26 04:00:33 +01:00
|
|
|
func fetchsome(url string) ([]byte, error) {
|
2020-05-11 06:52:17 +02:00
|
|
|
client := http.DefaultClient
|
2022-03-01 02:40:23 +01:00
|
|
|
if develMode {
|
|
|
|
client = develClient
|
2020-07-27 06:05:21 +02:00
|
|
|
}
|
2020-05-11 06:52:17 +02:00
|
|
|
req, err := http.NewRequest("GET", url, nil)
|
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error fetching %s: %s", url, err)
|
2020-05-11 06:52:17 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-27 06:05:21 +02:00
|
|
|
req.Header.Set("User-Agent", "honksnonk/5.0; "+serverName)
|
2020-05-11 06:52:17 +02:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
|
|
|
|
defer cancel()
|
|
|
|
req = req.WithContext(ctx)
|
|
|
|
resp, err := client.Do(req)
|
2019-11-26 04:00:33 +01:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error fetching %s: %s", url, err)
|
2019-11-26 04:00:33 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2020-09-27 23:59:11 +02:00
|
|
|
switch resp.StatusCode {
|
|
|
|
case 200:
|
|
|
|
case 201:
|
|
|
|
case 202:
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("http get not 200: %d %s", resp.StatusCode, url)
|
2019-11-26 04:00:33 +01:00
|
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
|
|
limiter := io.LimitReader(resp.Body, 10*1024*1024)
|
|
|
|
io.Copy(&buf, limiter)
|
|
|
|
return buf.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
2019-09-09 15:55:04 +02:00
|
|
|
func savedonk(url string, name, desc, media string, localize bool) *Donk {
|
2019-05-28 10:23:36 +02:00
|
|
|
if url == "" {
|
|
|
|
return nil
|
|
|
|
}
|
2020-04-30 17:06:26 +02:00
|
|
|
if donk := finddonk(url); donk != nil {
|
2019-10-03 05:02:01 +02:00
|
|
|
return donk
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("saving donk: %s", url)
|
2019-05-28 10:23:36 +02:00
|
|
|
data := []byte{}
|
|
|
|
if localize {
|
2019-11-26 04:00:33 +01:00
|
|
|
fn := func() (interface{}, error) {
|
|
|
|
return fetchsome(url)
|
2019-05-28 10:23:36 +02:00
|
|
|
}
|
2019-11-26 04:00:33 +01:00
|
|
|
ii, err := flightdeck.Call(url, fn)
|
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error fetching donk: %s", err)
|
2019-05-28 10:23:36 +02:00
|
|
|
localize = false
|
|
|
|
goto saveit
|
|
|
|
}
|
2019-11-26 04:00:33 +01:00
|
|
|
data = ii.([]byte)
|
2019-05-28 10:23:36 +02:00
|
|
|
|
2019-10-03 18:37:15 +02:00
|
|
|
if len(data) == 10*1024*1024 {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("truncation likely")
|
2019-10-03 07:17:43 +02:00
|
|
|
}
|
2019-05-28 10:23:36 +02:00
|
|
|
if strings.HasPrefix(media, "image") {
|
2019-11-09 08:15:15 +01:00
|
|
|
img, err := shrinkit(data)
|
2019-05-28 10:23:36 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("unable to decode image: %s", err)
|
2019-05-28 10:23:36 +02:00
|
|
|
localize = false
|
2019-07-05 00:46:15 +02:00
|
|
|
data = []byte{}
|
2019-05-28 10:23:36 +02:00
|
|
|
goto saveit
|
|
|
|
}
|
|
|
|
data = img.Data
|
2020-09-30 17:35:18 +02:00
|
|
|
media = "image/" + img.Format
|
2019-11-26 08:32:23 +01:00
|
|
|
} else if media == "application/pdf" {
|
|
|
|
if len(data) > 1000000 {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("not saving large pdf")
|
2019-11-26 08:32:23 +01:00
|
|
|
localize = false
|
|
|
|
data = []byte{}
|
|
|
|
}
|
2019-07-05 00:47:45 +02:00
|
|
|
} else if len(data) > 100000 {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("not saving large attachment")
|
2019-07-05 00:47:45 +02:00
|
|
|
localize = false
|
|
|
|
data = []byte{}
|
2019-04-26 23:01:17 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 10:23:36 +02:00
|
|
|
saveit:
|
2020-09-30 17:35:18 +02:00
|
|
|
fileid, err := savefile(name, desc, url, media, localize, data)
|
2019-04-09 13:59:33 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error saving file %s: %s", url, err)
|
2019-04-09 13:59:33 +02:00
|
|
|
return nil
|
|
|
|
}
|
2020-04-30 17:06:26 +02:00
|
|
|
donk := new(Donk)
|
2019-09-30 03:40:37 +02:00
|
|
|
donk.FileID = fileid
|
2019-10-03 05:02:01 +02:00
|
|
|
return donk
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
|
|
|
|
2019-06-17 18:18:37 +02:00
|
|
|
func iszonked(userid int64, xid string) bool {
|
|
|
|
var id int64
|
2019-11-13 17:00:25 +01:00
|
|
|
row := stmtFindZonk.QueryRow(userid, xid)
|
2019-06-17 18:18:37 +02:00
|
|
|
err := row.Scan(&id)
|
|
|
|
if err == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if err != sql.ErrNoRows {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error querying zonk: %s", err)
|
2019-06-17 18:18:37 +02:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-04-14 16:15:47 +02:00
|
|
|
func needxonk(user *WhatAbout, x *Honk) bool {
|
2019-10-05 03:47:27 +02:00
|
|
|
if rejectxonk(x) {
|
2019-04-26 15:35:22 +02:00
|
|
|
return false
|
|
|
|
}
|
2019-04-25 07:18:39 +02:00
|
|
|
return needxonkid(user, x.XID)
|
|
|
|
}
|
2019-12-09 01:09:56 +01:00
|
|
|
func needbonkid(user *WhatAbout, xid string) bool {
|
|
|
|
return needxonkidX(user, xid, true)
|
|
|
|
}
|
2019-04-25 07:18:39 +02:00
|
|
|
func needxonkid(user *WhatAbout, xid string) bool {
|
2019-12-09 01:09:56 +01:00
|
|
|
return needxonkidX(user, xid, false)
|
|
|
|
}
|
|
|
|
func needxonkidX(user *WhatAbout, xid string, isannounce bool) bool {
|
2019-11-30 23:51:27 +01:00
|
|
|
if !strings.HasPrefix(xid, "https://") {
|
|
|
|
return false
|
|
|
|
}
|
2019-07-23 19:21:09 +02:00
|
|
|
if strings.HasPrefix(xid, user.URL+"/") {
|
2019-04-25 07:18:39 +02:00
|
|
|
return false
|
2019-09-06 20:44:29 +02:00
|
|
|
}
|
2019-12-09 01:09:56 +01:00
|
|
|
if rejectorigin(user.ID, xid, isannounce) {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("rejecting origin: %s", xid)
|
2019-09-06 20:44:29 +02:00
|
|
|
return false
|
2019-04-25 07:18:39 +02:00
|
|
|
}
|
2019-06-17 18:18:37 +02:00
|
|
|
if iszonked(user.ID, xid) {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("already zonked: %s", xid)
|
2019-06-17 18:18:37 +02:00
|
|
|
return false
|
|
|
|
}
|
2019-04-25 07:18:39 +02:00
|
|
|
var id int64
|
2019-11-13 17:00:25 +01:00
|
|
|
row := stmtFindXonk.QueryRow(user.ID, xid)
|
2019-04-25 07:18:39 +02:00
|
|
|
err := row.Scan(&id)
|
2019-04-09 13:59:33 +02:00
|
|
|
if err == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if err != sql.ErrNoRows {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error querying xonk: %s", err)
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-09-30 07:30:39 +02:00
|
|
|
func eradicatexonk(userid int64, xid string) {
|
|
|
|
xonk := getxonk(userid, xid)
|
|
|
|
if xonk != nil {
|
|
|
|
deletehonk(xonk.ID)
|
2023-08-01 04:54:53 +02:00
|
|
|
_, err := stmtSaveZonker.Exec(userid, xid, "zonk")
|
|
|
|
if err != nil {
|
|
|
|
elog.Printf("error eradicating: %s", err)
|
|
|
|
}
|
2019-09-30 07:30:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func savexonk(x *Honk) {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("saving xonk: %s", x.XID)
|
2019-10-29 19:18:13 +01:00
|
|
|
go handles(x.Honker)
|
|
|
|
go handles(x.Oonker)
|
2019-09-11 22:20:22 +02:00
|
|
|
savehonk(x)
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
|
|
|
|
2019-04-16 20:40:23 +02:00
|
|
|
type Box struct {
|
2019-04-16 20:47:08 +02:00
|
|
|
In string
|
|
|
|
Out string
|
2019-04-16 20:40:23 +02:00
|
|
|
Shared string
|
|
|
|
}
|
|
|
|
|
2019-10-13 01:25:23 +02:00
|
|
|
var boxofboxes = cache.New(cache.Options{Filler: func(ident string) (*Box, bool) {
|
2019-06-03 06:15:06 +02:00
|
|
|
var info string
|
|
|
|
row := stmtGetXonker.QueryRow(ident, "boxes")
|
|
|
|
err := row.Scan(&info)
|
2019-11-11 18:03:00 +01:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("need to get boxes for %s", ident)
|
2019-11-26 06:42:32 +01:00
|
|
|
var j junk.Junk
|
2022-12-26 19:27:39 +01:00
|
|
|
j, err = GetJunk(readyLuserOne, ident)
|
2019-11-11 18:03:00 +01:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("error getting boxes: %s", err)
|
2019-11-11 18:03:00 +01:00
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
allinjest(originate(ident), j)
|
|
|
|
row = stmtGetXonker.QueryRow(ident, "boxes")
|
|
|
|
err = row.Scan(&info)
|
|
|
|
}
|
2019-10-07 20:45:02 +02:00
|
|
|
if err == nil {
|
|
|
|
m := strings.Split(info, " ")
|
|
|
|
b := &Box{In: m[0], Out: m[1], Shared: m[2]}
|
|
|
|
return b, true
|
|
|
|
}
|
2019-11-11 18:03:00 +01:00
|
|
|
return nil, false
|
2019-10-07 20:45:02 +02:00
|
|
|
}})
|
2019-04-09 13:59:33 +02:00
|
|
|
|
2019-06-17 04:36:52 +02:00
|
|
|
func gimmexonks(user *WhatAbout, outbox string) {
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("getting outbox: %s", outbox)
|
2022-05-20 21:50:33 +02:00
|
|
|
j, err := GetJunk(user.ID, outbox)
|
2019-06-17 04:36:52 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error getting outbox: %s", err)
|
2019-06-17 04:36:52 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
t, _ := j.GetString("type")
|
|
|
|
origin := originate(outbox)
|
|
|
|
if t == "OrderedCollection" {
|
|
|
|
items, _ := j.GetArray("orderedItems")
|
2019-10-11 00:04:42 +02:00
|
|
|
if items == nil {
|
|
|
|
items, _ = j.GetArray("items")
|
|
|
|
}
|
2019-06-17 04:36:52 +02:00
|
|
|
if items == nil {
|
|
|
|
obj, ok := j.GetMap("first")
|
|
|
|
if ok {
|
|
|
|
items, _ = obj.GetArray("orderedItems")
|
|
|
|
} else {
|
2019-10-11 00:04:42 +02:00
|
|
|
page1, ok := j.GetString("first")
|
|
|
|
if ok {
|
2022-05-20 21:50:33 +02:00
|
|
|
j, err = GetJunk(user.ID, page1)
|
2019-10-11 00:04:42 +02:00
|
|
|
if err != nil {
|
2022-11-14 20:21:49 +01:00
|
|
|
ilog.Printf("error getting page1: %s", err)
|
2019-10-11 00:04:42 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
items, _ = j.GetArray("orderedItems")
|
2019-06-17 04:36:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(items) > 20 {
|
|
|
|
items = items[0:20]
|
|
|
|
}
|
|
|
|
for i, j := 0, len(items)-1; i < j; i, j = i+1, j-1 {
|
|
|
|
items[i], items[j] = items[j], items[i]
|
|
|
|
}
|
|
|
|
for _, item := range items {
|
|
|
|
obj, ok := item.(junk.Junk)
|
2019-10-26 23:35:44 +02:00
|
|
|
if ok {
|
|
|
|
xonksaver(user, obj, origin)
|
2019-06-17 04:36:52 +02:00
|
|
|
continue
|
|
|
|
}
|
2019-10-26 23:35:44 +02:00
|
|
|
xid, ok := item.(string)
|
|
|
|
if ok {
|
|
|
|
if !needxonkid(user, xid) {
|
|
|
|
continue
|
|
|
|
}
|
2022-05-20 21:50:33 +02:00
|
|
|
obj, err = GetJunk(user.ID, xid)
|
2019-10-26 23:35:44 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error getting item: %s", err)
|
2019-10-26 23:35:44 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
xonksaver(user, obj, originate(xid))
|
|
|
|
}
|
2019-06-17 04:36:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 16:14:12 +02:00
|
|
|
func newphone(a []string, obj junk.Junk) []string {
|
2019-04-09 13:59:33 +02:00
|
|
|
for _, addr := range []string{"to", "cc", "attributedTo"} {
|
2019-06-11 16:14:12 +02:00
|
|
|
who, _ := obj.GetString(addr)
|
2019-04-09 13:59:33 +02:00
|
|
|
if who != "" {
|
|
|
|
a = append(a, who)
|
|
|
|
}
|
2019-06-11 16:14:12 +02:00
|
|
|
whos, _ := obj.GetArray(addr)
|
2019-04-09 13:59:33 +02:00
|
|
|
for _, w := range whos {
|
|
|
|
who, _ := w.(string)
|
|
|
|
if who != "" {
|
|
|
|
a = append(a, who)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2019-07-01 16:43:38 +02:00
|
|
|
func extractattrto(obj junk.Junk) string {
|
2023-07-30 19:08:53 +02:00
|
|
|
arr := oneforall(obj, "attributedTo")
|
|
|
|
for _, a := range arr {
|
|
|
|
s, ok := a.(string)
|
2019-07-21 04:45:43 +02:00
|
|
|
if ok {
|
2023-07-30 19:08:53 +02:00
|
|
|
return s
|
2019-07-21 04:45:43 +02:00
|
|
|
}
|
2019-07-01 16:43:38 +02:00
|
|
|
o, ok := a.(junk.Junk)
|
|
|
|
if ok {
|
|
|
|
t, _ := o.GetString("type")
|
|
|
|
id, _ := o.GetString("id")
|
|
|
|
if t == "Person" || t == "" {
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2023-07-30 19:08:53 +02:00
|
|
|
func oneforall(obj junk.Junk, key string) []interface{} {
|
|
|
|
if val, ok := obj.GetMap(key); ok {
|
|
|
|
return []interface{}{val}
|
|
|
|
}
|
|
|
|
if str, ok := obj.GetString(key); ok {
|
|
|
|
return []interface{}{str}
|
|
|
|
}
|
|
|
|
arr, _ := obj.GetArray(key)
|
|
|
|
return arr
|
|
|
|
}
|
|
|
|
|
2021-05-25 00:28:37 +02:00
|
|
|
func firstofmany(obj junk.Junk, key string) string {
|
|
|
|
if val, _ := obj.GetString(key); val != "" {
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
if arr, _ := obj.GetArray(key); len(arr) > 0 {
|
|
|
|
val, ok := arr[0].(string)
|
|
|
|
if ok {
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2023-01-24 20:46:55 +01:00
|
|
|
var re_mast0link = regexp.MustCompile(`https://[[:alnum:].]+/users/[[:alnum:]]+/statuses/[[:digit:]]+`)
|
2023-07-02 20:44:52 +02:00
|
|
|
var re_masto1ink = regexp.MustCompile(`https://([[:alnum:].]+)/@([[:alnum:]]+)/([[:digit:]]+)`)
|
2023-01-24 20:46:55 +01:00
|
|
|
var re_misslink = regexp.MustCompile(`https://[[:alnum:].]+/notes/[[:alnum:]]+`)
|
|
|
|
var re_honklink = regexp.MustCompile(`https://[[:alnum:].]+/u/[[:alnum:]]+/h/[[:alnum:]]+`)
|
2023-03-09 06:54:59 +01:00
|
|
|
var re_r0malink = regexp.MustCompile(`https://[[:alnum:].]+/objects/[[:alnum:]-]+`)
|
|
|
|
var re_roma1ink = regexp.MustCompile(`https://[[:alnum:].]+/notice/[[:alnum:]]+`)
|
2023-01-24 20:46:55 +01:00
|
|
|
var re_qtlinks = regexp.MustCompile(`>https://[^\s<]+<`)
|
|
|
|
|
2019-10-01 05:32:10 +02:00
|
|
|
func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
|
2019-04-25 19:23:18 +02:00
|
|
|
depth := 0
|
2019-07-29 20:24:45 +02:00
|
|
|
maxdepth := 10
|
2019-06-07 17:15:46 +02:00
|
|
|
currenttid := ""
|
2019-10-01 06:01:45 +02:00
|
|
|
goingup := 0
|
2023-08-06 09:04:37 +02:00
|
|
|
var xonkxonkfn func(junk.Junk, string, bool, string) *Honk
|
2019-04-25 19:23:18 +02:00
|
|
|
|
2023-07-02 20:44:52 +02:00
|
|
|
qutify := func(user *WhatAbout, content string) string {
|
|
|
|
if depth >= maxdepth {
|
|
|
|
ilog.Printf("in too deep")
|
|
|
|
return content
|
|
|
|
}
|
|
|
|
// well this is gross
|
|
|
|
malcontent := strings.ReplaceAll(content, `</span><span class="ellipsis">`, "")
|
|
|
|
malcontent = strings.ReplaceAll(malcontent, `</span><span class="invisible">`, "")
|
|
|
|
mlinks := re_qtlinks.FindAllString(malcontent, -1)
|
|
|
|
for _, m := range mlinks {
|
|
|
|
tryit := false
|
|
|
|
m = m[1 : len(m)-1]
|
|
|
|
if re_mast0link.MatchString(m) || re_misslink.MatchString(m) ||
|
|
|
|
re_honklink.MatchString(m) || re_r0malink.MatchString(m) ||
|
|
|
|
re_roma1ink.MatchString(m) {
|
|
|
|
tryit = true
|
|
|
|
} else if re_masto1ink.MatchString(m) {
|
|
|
|
m = re_masto1ink.ReplaceAllString(m, "https://$1/users/$2/statuses/$3")
|
|
|
|
tryit = true
|
|
|
|
}
|
|
|
|
if tryit {
|
|
|
|
if x := getxonk(user.ID, m); x != nil {
|
|
|
|
content = fmt.Sprintf("%s<blockquote>%s</blockquote>", content, x.Noise)
|
|
|
|
} else if j, err := GetJunk(user.ID, m); err == nil {
|
|
|
|
q, ok := j.GetString("content")
|
|
|
|
if ok {
|
|
|
|
content = fmt.Sprintf("%s<blockquote>%s</blockquote>", content, q)
|
|
|
|
}
|
|
|
|
prevdepth := depth
|
|
|
|
depth = maxdepth
|
2023-08-06 09:04:37 +02:00
|
|
|
xonkxonkfn(j, originate(m), false, "")
|
2023-07-02 20:44:52 +02:00
|
|
|
depth = prevdepth
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return content
|
|
|
|
}
|
|
|
|
|
2019-10-01 05:32:10 +02:00
|
|
|
saveonemore := func(xid string) {
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("getting onemore: %s", xid)
|
2019-04-25 19:23:18 +02:00
|
|
|
if depth >= maxdepth {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("in too deep")
|
2019-04-25 19:23:18 +02:00
|
|
|
return
|
|
|
|
}
|
2022-05-20 21:50:33 +02:00
|
|
|
obj, err := GetJunkHardMode(user.ID, xid)
|
2019-04-25 19:23:18 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error getting onemore: %s: %s", xid, err)
|
2019-04-25 19:23:18 +02:00
|
|
|
return
|
|
|
|
}
|
2023-08-06 09:04:37 +02:00
|
|
|
xonkxonkfn(obj, originate(xid), false, "")
|
2019-04-25 19:23:18 +02:00
|
|
|
}
|
|
|
|
|
2023-08-06 09:04:37 +02:00
|
|
|
xonkxonkfn = func(item junk.Junk, origin string, isUpdate bool, bonker string) *Honk {
|
2020-05-13 20:36:16 +02:00
|
|
|
id, _ := item.GetString("id")
|
2021-05-25 00:28:37 +02:00
|
|
|
what := firstofmany(item, "type")
|
2019-12-24 14:08:40 +01:00
|
|
|
dt, ok := item.GetString("published")
|
|
|
|
if !ok {
|
|
|
|
dt = time.Now().Format(time.RFC3339)
|
|
|
|
}
|
2023-08-01 22:17:45 +02:00
|
|
|
if depth >= maxdepth+5 {
|
|
|
|
ilog.Printf("went too deep in xonkxonk")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
depth++
|
|
|
|
defer func() { depth-- }()
|
2019-04-25 19:23:18 +02:00
|
|
|
|
|
|
|
var err error
|
2020-05-22 06:15:48 +02:00
|
|
|
var xid, rid, url, convoy string
|
2019-10-01 05:16:54 +02:00
|
|
|
var replies []string
|
2019-06-11 16:14:12 +02:00
|
|
|
var obj junk.Junk
|
2023-01-04 17:29:40 +01:00
|
|
|
waspage := false
|
2023-03-25 20:09:53 +01:00
|
|
|
preferorig := false
|
2019-04-25 19:23:18 +02:00
|
|
|
switch what {
|
2019-09-30 07:30:39 +02:00
|
|
|
case "Delete":
|
|
|
|
obj, ok = item.GetMap("object")
|
|
|
|
if ok {
|
|
|
|
xid, _ = obj.GetString("id")
|
|
|
|
} else {
|
|
|
|
xid, _ = item.GetString("object")
|
|
|
|
}
|
|
|
|
if xid == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if originate(xid) != origin {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("forged delete: %s", xid)
|
2019-09-30 07:30:39 +02:00
|
|
|
return nil
|
|
|
|
}
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("eradicating %s", xid)
|
2019-09-30 07:30:39 +02:00
|
|
|
eradicatexonk(user.ID, xid)
|
|
|
|
return nil
|
2021-10-19 21:26:17 +02:00
|
|
|
case "Remove":
|
|
|
|
xid, _ = item.GetString("object")
|
|
|
|
targ, _ := obj.GetString("target")
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("remove %s from %s", obj, targ)
|
2021-10-19 21:26:17 +02:00
|
|
|
return nil
|
2019-09-30 20:28:57 +02:00
|
|
|
case "Tombstone":
|
|
|
|
xid, _ = item.GetString("id")
|
|
|
|
if xid == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if originate(xid) != origin {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("forged delete: %s", xid)
|
2019-09-30 20:28:57 +02:00
|
|
|
return nil
|
|
|
|
}
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("eradicating %s", xid)
|
2019-09-30 20:28:57 +02:00
|
|
|
eradicatexonk(user.ID, xid)
|
|
|
|
return nil
|
2019-04-25 19:23:18 +02:00
|
|
|
case "Announce":
|
2019-06-11 16:14:12 +02:00
|
|
|
obj, ok = item.GetMap("object")
|
2019-04-25 19:23:18 +02:00
|
|
|
if ok {
|
2023-08-01 22:17:45 +02:00
|
|
|
// peek ahead some
|
2023-06-11 07:40:34 +02:00
|
|
|
what, ok := obj.GetString("type")
|
2023-07-29 22:13:19 +02:00
|
|
|
if ok && (what == "Create" || what == "Update") {
|
|
|
|
if what == "Update" {
|
|
|
|
isUpdate = true
|
|
|
|
}
|
2023-08-01 22:17:45 +02:00
|
|
|
inner, ok := obj.GetMap("object")
|
|
|
|
if ok {
|
|
|
|
obj = inner
|
|
|
|
} else {
|
|
|
|
xid, _ = obj.GetString("object")
|
|
|
|
}
|
2023-07-20 00:09:12 +02:00
|
|
|
}
|
2023-08-01 22:17:45 +02:00
|
|
|
if xid == "" {
|
|
|
|
xid, _ = obj.GetString("id")
|
2023-06-11 07:40:34 +02:00
|
|
|
}
|
2019-04-25 19:23:18 +02:00
|
|
|
} else {
|
2019-06-11 16:14:12 +02:00
|
|
|
xid, _ = item.GetString("object")
|
2019-05-20 16:51:15 +02:00
|
|
|
}
|
2023-08-01 22:17:45 +02:00
|
|
|
if !isUpdate && !needbonkid(user, xid) {
|
2019-05-20 16:51:15 +02:00
|
|
|
return nil
|
|
|
|
}
|
2023-08-06 09:04:37 +02:00
|
|
|
bonker, _ = item.GetString("actor")
|
2019-05-21 19:56:15 +02:00
|
|
|
origin = originate(xid)
|
2023-06-11 07:40:34 +02:00
|
|
|
if ok && originate(id) == origin {
|
|
|
|
dlog.Printf("using object in announce for %s", xid)
|
|
|
|
} else {
|
|
|
|
dlog.Printf("getting bonk: %s", xid)
|
|
|
|
obj, err = GetJunkHardMode(user.ID, xid)
|
|
|
|
if err != nil {
|
|
|
|
ilog.Printf("error getting bonk: %s: %s", xid, err)
|
2023-08-06 02:59:58 +02:00
|
|
|
return nil
|
2023-06-11 07:40:34 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-06 09:04:37 +02:00
|
|
|
return xonkxonkfn(obj, origin, isUpdate, bonker)
|
2019-09-17 00:00:13 +02:00
|
|
|
case "Update":
|
|
|
|
isUpdate = true
|
|
|
|
fallthrough
|
2019-04-25 19:23:18 +02:00
|
|
|
case "Create":
|
2019-07-21 05:01:04 +02:00
|
|
|
obj, ok = item.GetMap("object")
|
|
|
|
if !ok {
|
2019-09-17 00:05:46 +02:00
|
|
|
xid, _ = item.GetString("object")
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("getting created honk: %s", xid)
|
2020-05-13 20:36:16 +02:00
|
|
|
if originate(xid) != origin {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("out of bounds %s not from %s", xid, origin)
|
2020-05-13 20:36:16 +02:00
|
|
|
return nil
|
|
|
|
}
|
2022-05-20 21:50:33 +02:00
|
|
|
obj, err = GetJunkHardMode(user.ID, xid)
|
2019-07-21 05:01:04 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error getting creation: %s", err)
|
2019-07-21 05:01:04 +02:00
|
|
|
}
|
2019-10-11 02:19:18 +02:00
|
|
|
}
|
2020-05-13 20:36:16 +02:00
|
|
|
if obj == nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("no object for creation %s", id)
|
2020-05-13 20:36:16 +02:00
|
|
|
return nil
|
2019-07-21 05:01:04 +02:00
|
|
|
}
|
2023-08-06 09:04:37 +02:00
|
|
|
return xonkxonkfn(obj, origin, isUpdate, bonker)
|
2019-08-21 07:23:00 +02:00
|
|
|
case "Read":
|
|
|
|
xid, ok = item.GetString("object")
|
|
|
|
if ok {
|
|
|
|
if !needxonkid(user, xid) {
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("don't need read obj: %s", xid)
|
2019-08-21 07:23:00 +02:00
|
|
|
return nil
|
|
|
|
}
|
2022-05-20 21:50:33 +02:00
|
|
|
obj, err = GetJunkHardMode(user.ID, xid)
|
2019-08-21 07:23:00 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error getting read: %s", err)
|
2019-08-21 07:23:00 +02:00
|
|
|
return nil
|
|
|
|
}
|
2023-08-06 09:04:37 +02:00
|
|
|
return xonkxonkfn(obj, originate(xid), false, "")
|
2019-08-21 07:23:00 +02:00
|
|
|
}
|
|
|
|
return nil
|
2019-10-27 06:22:43 +01:00
|
|
|
case "Add":
|
|
|
|
xid, ok = item.GetString("object")
|
|
|
|
if ok {
|
2019-10-28 20:40:13 +01:00
|
|
|
// check target...
|
2019-10-27 06:22:43 +01:00
|
|
|
if !needxonkid(user, xid) {
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("don't need added obj: %s", xid)
|
2019-10-27 06:22:43 +01:00
|
|
|
return nil
|
|
|
|
}
|
2022-05-20 21:50:33 +02:00
|
|
|
obj, err = GetJunkHardMode(user.ID, xid)
|
2019-10-27 06:22:43 +01:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error getting add: %s", err)
|
2019-10-27 06:22:43 +01:00
|
|
|
return nil
|
|
|
|
}
|
2023-08-06 09:04:37 +02:00
|
|
|
return xonkxonkfn(obj, originate(xid), false, "")
|
2019-10-27 06:22:43 +01:00
|
|
|
}
|
|
|
|
return nil
|
2019-12-24 14:08:40 +01:00
|
|
|
case "Move":
|
|
|
|
obj = item
|
|
|
|
what = "move"
|
2023-01-04 17:33:42 +01:00
|
|
|
case "Page":
|
|
|
|
waspage = true
|
|
|
|
fallthrough
|
2019-10-09 16:55:54 +02:00
|
|
|
case "Audio":
|
|
|
|
fallthrough
|
2020-01-12 07:15:20 +01:00
|
|
|
case "Image":
|
2023-06-11 05:19:31 +02:00
|
|
|
if what == "Image" {
|
|
|
|
preferorig = true
|
|
|
|
}
|
2020-01-12 07:15:20 +01:00
|
|
|
fallthrough
|
2019-07-01 16:43:38 +02:00
|
|
|
case "Video":
|
|
|
|
fallthrough
|
2019-06-12 05:03:53 +02:00
|
|
|
case "Question":
|
|
|
|
fallthrough
|
2019-05-13 15:36:28 +02:00
|
|
|
case "Note":
|
|
|
|
fallthrough
|
|
|
|
case "Article":
|
2019-06-11 16:14:12 +02:00
|
|
|
obj = item
|
2019-05-13 15:36:28 +02:00
|
|
|
what = "honk"
|
2019-10-03 00:20:14 +02:00
|
|
|
case "Event":
|
|
|
|
obj = item
|
|
|
|
what = "event"
|
2020-05-13 23:15:29 +02:00
|
|
|
case "ChatMessage":
|
2023-08-06 09:04:37 +02:00
|
|
|
bonker = ""
|
2020-05-13 23:15:29 +02:00
|
|
|
obj = item
|
|
|
|
what = "chonk"
|
2019-04-25 19:23:18 +02:00
|
|
|
default:
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("unknown activity: %s", what)
|
2020-02-18 18:50:19 +01:00
|
|
|
dumpactivity(item)
|
2019-04-25 19:23:18 +02:00
|
|
|
return nil
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
2023-08-06 09:04:37 +02:00
|
|
|
if bonker != "" {
|
2023-08-01 22:17:45 +02:00
|
|
|
what = "bonk"
|
|
|
|
}
|
2019-04-25 19:23:18 +02:00
|
|
|
|
2019-10-05 08:46:01 +02:00
|
|
|
if obj != nil {
|
2020-01-24 04:32:52 +01:00
|
|
|
xid, _ = obj.GetString("id")
|
2019-10-05 08:46:01 +02:00
|
|
|
}
|
2019-10-07 04:07:39 +02:00
|
|
|
|
2020-01-24 02:41:30 +01:00
|
|
|
if xid == "" {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("don't know what xid is")
|
|
|
|
item.Write(ilog.Writer())
|
2020-01-24 02:41:30 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if originate(xid) != origin {
|
2023-01-24 20:46:55 +01:00
|
|
|
if !develMode && origin != "" {
|
|
|
|
ilog.Printf("original sin: %s not from %s", xid, origin)
|
|
|
|
item.Write(ilog.Writer())
|
|
|
|
return nil
|
|
|
|
}
|
2020-01-24 02:41:30 +01:00
|
|
|
}
|
|
|
|
|
2019-04-25 19:23:18 +02:00
|
|
|
var xonk Honk
|
2019-09-28 23:03:05 +02:00
|
|
|
// early init
|
2020-01-24 02:41:30 +01:00
|
|
|
xonk.XID = xid
|
2019-09-28 23:40:24 +02:00
|
|
|
xonk.UserID = user.ID
|
2019-09-28 23:03:05 +02:00
|
|
|
xonk.Honker, _ = item.GetString("actor")
|
2019-10-05 08:46:01 +02:00
|
|
|
if xonk.Honker == "" {
|
|
|
|
xonk.Honker, _ = item.GetString("attributedTo")
|
|
|
|
}
|
2019-04-25 19:23:18 +02:00
|
|
|
if obj != nil {
|
2019-09-28 23:03:05 +02:00
|
|
|
if xonk.Honker == "" {
|
|
|
|
xonk.Honker = extractattrto(obj)
|
2019-04-22 21:05:44 +02:00
|
|
|
}
|
2023-08-06 09:04:37 +02:00
|
|
|
if bonker != "" {
|
|
|
|
xonk.Honker, xonk.Oonker = bonker, xonk.Honker
|
|
|
|
}
|
2019-09-28 23:03:05 +02:00
|
|
|
if xonk.Oonker == xonk.Honker {
|
|
|
|
xonk.Oonker = ""
|
|
|
|
}
|
|
|
|
xonk.Audience = newphone(nil, obj)
|
|
|
|
}
|
|
|
|
xonk.Audience = append(xonk.Audience, xonk.Honker)
|
|
|
|
xonk.Audience = oneofakind(xonk.Audience)
|
2022-04-07 21:03:37 +02:00
|
|
|
xonk.Public = loudandproud(xonk.Audience)
|
2019-09-28 23:03:05 +02:00
|
|
|
|
2019-11-27 20:36:29 +01:00
|
|
|
var mentions []Mention
|
2019-09-28 23:03:05 +02:00
|
|
|
if obj != nil {
|
2019-06-11 16:14:12 +02:00
|
|
|
ot, _ := obj.GetString("type")
|
|
|
|
url, _ = obj.GetString("url")
|
2019-12-24 14:28:25 +01:00
|
|
|
if dt2, ok := obj.GetString("published"); ok {
|
2019-09-22 00:28:57 +02:00
|
|
|
dt = dt2
|
|
|
|
}
|
2020-05-22 06:15:48 +02:00
|
|
|
content, _ := obj.GetString("content")
|
2020-01-12 07:43:31 +01:00
|
|
|
if !strings.HasPrefix(content, "<p>") {
|
|
|
|
content = "<p>" + content
|
|
|
|
}
|
2020-05-22 06:15:48 +02:00
|
|
|
precis, _ := obj.GetString("summary")
|
2019-12-24 14:17:06 +01:00
|
|
|
if name, ok := obj.GetString("name"); ok {
|
|
|
|
if precis != "" {
|
2020-01-12 07:43:31 +01:00
|
|
|
content = precis + "<p>" + content
|
2019-12-24 14:17:06 +01:00
|
|
|
}
|
2020-01-12 17:26:52 +01:00
|
|
|
precis = html.EscapeString(name)
|
2019-09-30 07:30:39 +02:00
|
|
|
}
|
2019-12-24 14:28:25 +01:00
|
|
|
if sens, _ := obj["sensitive"].(bool); sens && precis == "" {
|
2019-09-30 07:30:39 +02:00
|
|
|
precis = "unspecified horror"
|
|
|
|
}
|
2023-01-04 17:29:40 +01:00
|
|
|
if waspage {
|
|
|
|
content += fmt.Sprintf(`<p><a href="%s">%s</a>`, url, url)
|
|
|
|
url = xid
|
|
|
|
}
|
2023-01-26 22:38:52 +01:00
|
|
|
if user.Options.InlineQuotes {
|
|
|
|
content = qutify(user, content)
|
|
|
|
}
|
2019-09-30 07:30:39 +02:00
|
|
|
rid, ok = obj.GetString("inReplyTo")
|
|
|
|
if !ok {
|
2019-12-24 14:28:25 +01:00
|
|
|
if robj, ok := obj.GetMap("inReplyTo"); ok {
|
2019-09-30 07:30:39 +02:00
|
|
|
rid, _ = robj.GetString("id")
|
2019-04-25 19:23:18 +02:00
|
|
|
}
|
2019-09-30 07:30:39 +02:00
|
|
|
}
|
|
|
|
convoy, _ = obj.GetString("context")
|
|
|
|
if convoy == "" {
|
|
|
|
convoy, _ = obj.GetString("conversation")
|
|
|
|
}
|
|
|
|
if ot == "Question" {
|
|
|
|
if what == "honk" {
|
|
|
|
what = "qonk"
|
2019-07-10 20:46:43 +02:00
|
|
|
}
|
2019-09-30 07:30:39 +02:00
|
|
|
content += "<ul>"
|
|
|
|
ans, _ := obj.GetArray("oneOf")
|
|
|
|
for _, ai := range ans {
|
|
|
|
a, ok := ai.(junk.Junk)
|
|
|
|
if !ok {
|
|
|
|
continue
|
2019-07-22 06:09:16 +02:00
|
|
|
}
|
2019-09-30 07:30:39 +02:00
|
|
|
as, _ := a.GetString("name")
|
|
|
|
content += "<li>" + as
|
2019-07-22 06:09:16 +02:00
|
|
|
}
|
2019-09-30 07:30:39 +02:00
|
|
|
ans, _ = obj.GetArray("anyOf")
|
|
|
|
for _, ai := range ans {
|
|
|
|
a, ok := ai.(junk.Junk)
|
|
|
|
if !ok {
|
|
|
|
continue
|
2019-06-12 05:03:53 +02:00
|
|
|
}
|
2019-09-30 07:30:39 +02:00
|
|
|
as, _ := a.GetString("name")
|
|
|
|
content += "<li>" + as
|
2019-04-25 19:23:18 +02:00
|
|
|
}
|
2019-09-30 07:30:39 +02:00
|
|
|
content += "</ul>"
|
|
|
|
}
|
2019-12-24 14:08:40 +01:00
|
|
|
if ot == "Move" {
|
|
|
|
targ, _ := obj.GetString("target")
|
|
|
|
content += string(templates.Sprintf(`<p>Moved to <a href="%s">%s</a>`, targ, targ))
|
|
|
|
}
|
2020-05-22 06:15:48 +02:00
|
|
|
if len(content) > 90001 {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("content too long. truncating")
|
2020-05-22 06:15:48 +02:00
|
|
|
content = content[:90001]
|
|
|
|
}
|
|
|
|
|
|
|
|
xonk.Noise = content
|
|
|
|
xonk.Precis = precis
|
|
|
|
if rejectxonk(&xonk) {
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("fast reject: %s", xid)
|
2020-05-22 06:15:48 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-14 23:42:57 +02:00
|
|
|
numatts := 0
|
|
|
|
procatt := func(att junk.Junk) {
|
2019-06-11 16:14:12 +02:00
|
|
|
at, _ := att.GetString("type")
|
|
|
|
mt, _ := att.GetString("mediaType")
|
2023-06-11 05:19:31 +02:00
|
|
|
if mt == "" {
|
|
|
|
mt = "image"
|
|
|
|
}
|
2020-05-14 23:45:11 +02:00
|
|
|
u, ok := att.GetString("url")
|
2023-03-25 20:09:53 +01:00
|
|
|
if !ok {
|
|
|
|
u, ok = att.GetString("href")
|
|
|
|
}
|
2020-05-14 23:45:11 +02:00
|
|
|
if !ok {
|
2020-05-15 06:18:40 +02:00
|
|
|
if ua, ok := att.GetArray("url"); ok && len(ua) > 0 {
|
|
|
|
u, ok = ua[0].(string)
|
|
|
|
if !ok {
|
|
|
|
if uu, ok := ua[0].(junk.Junk); ok {
|
|
|
|
u, _ = uu.GetString("href")
|
2020-05-19 00:09:18 +02:00
|
|
|
if mt == "" {
|
|
|
|
mt, _ = uu.GetString("mediaType")
|
|
|
|
}
|
2020-05-15 06:18:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if uu, ok := att.GetMap("url"); ok {
|
2020-05-14 23:45:11 +02:00
|
|
|
u, _ = uu.GetString("href")
|
2020-05-19 00:09:18 +02:00
|
|
|
if mt == "" {
|
|
|
|
mt, _ = uu.GetString("mediaType")
|
|
|
|
}
|
2020-05-14 23:45:11 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-11 16:14:12 +02:00
|
|
|
name, _ := att.GetString("name")
|
2019-09-09 15:55:04 +02:00
|
|
|
desc, _ := att.GetString("summary")
|
2021-04-05 20:09:11 +02:00
|
|
|
desc = html.UnescapeString(desc)
|
2019-09-09 15:55:04 +02:00
|
|
|
if desc == "" {
|
|
|
|
desc = name
|
|
|
|
}
|
2019-05-28 10:23:36 +02:00
|
|
|
localize := false
|
2023-06-11 05:23:11 +02:00
|
|
|
if at == "Document" || at == "Image" {
|
2019-04-25 19:23:18 +02:00
|
|
|
mt = strings.ToLower(mt)
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("attachment: %s %s", mt, u)
|
2019-11-26 08:32:23 +01:00
|
|
|
if mt == "text/plain" || mt == "application/pdf" ||
|
|
|
|
strings.HasPrefix(mt, "image") {
|
2023-06-11 05:23:11 +02:00
|
|
|
if numatts > 4 {
|
|
|
|
ilog.Printf("excessive attachment: %s", at)
|
|
|
|
} else {
|
|
|
|
localize = true
|
|
|
|
}
|
2019-04-25 19:23:18 +02:00
|
|
|
}
|
2023-06-11 05:33:27 +02:00
|
|
|
} else if at == "Link" {
|
|
|
|
if waspage {
|
|
|
|
xonk.Noise += fmt.Sprintf(`<p><a href="%s">%s</a>`, u, u)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if name == "" {
|
|
|
|
name = u
|
|
|
|
}
|
2019-04-29 04:28:59 +02:00
|
|
|
} else {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("unknown attachment: %s", at)
|
2019-04-25 19:23:18 +02:00
|
|
|
}
|
2019-09-28 23:40:24 +02:00
|
|
|
if skipMedia(&xonk) {
|
|
|
|
localize = false
|
|
|
|
}
|
2023-03-25 20:09:53 +01:00
|
|
|
if preferorig && !localize {
|
|
|
|
return
|
|
|
|
}
|
2019-09-09 15:55:04 +02:00
|
|
|
donk := savedonk(u, name, desc, mt, localize)
|
2019-05-28 10:23:36 +02:00
|
|
|
if donk != nil {
|
|
|
|
xonk.Donks = append(xonk.Donks, donk)
|
|
|
|
}
|
2020-05-14 23:42:57 +02:00
|
|
|
numatts++
|
|
|
|
}
|
2023-06-11 05:19:31 +02:00
|
|
|
if img, ok := obj.GetMap("image"); ok {
|
|
|
|
procatt(img)
|
|
|
|
}
|
2023-03-25 20:09:53 +01:00
|
|
|
if preferorig {
|
|
|
|
atts, _ := obj.GetArray("url")
|
|
|
|
for _, atti := range atts {
|
|
|
|
att, ok := atti.(junk.Junk)
|
|
|
|
if !ok {
|
|
|
|
ilog.Printf("attachment that wasn't map?")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
procatt(att)
|
|
|
|
}
|
|
|
|
if numatts == 0 {
|
|
|
|
preferorig = false
|
2020-05-14 23:42:57 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-25 20:09:53 +01:00
|
|
|
if !preferorig {
|
2023-07-30 19:08:53 +02:00
|
|
|
atts := oneforall(obj, "attachment")
|
2023-03-25 20:09:53 +01:00
|
|
|
for _, atti := range atts {
|
|
|
|
att, ok := atti.(junk.Junk)
|
|
|
|
if !ok {
|
|
|
|
ilog.Printf("attachment that wasn't map?")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
procatt(att)
|
|
|
|
}
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
2023-07-29 21:04:11 +02:00
|
|
|
proctag := func(tag junk.Junk) {
|
2019-06-11 16:14:12 +02:00
|
|
|
tt, _ := tag.GetString("type")
|
|
|
|
name, _ := tag.GetString("name")
|
2019-09-09 15:55:04 +02:00
|
|
|
desc, _ := tag.GetString("summary")
|
2021-04-05 20:09:11 +02:00
|
|
|
desc = html.UnescapeString(desc)
|
2019-09-09 15:55:04 +02:00
|
|
|
if desc == "" {
|
|
|
|
desc = name
|
|
|
|
}
|
2019-04-25 19:23:18 +02:00
|
|
|
if tt == "Emoji" {
|
2019-06-11 16:14:12 +02:00
|
|
|
icon, _ := tag.GetMap("icon")
|
|
|
|
mt, _ := icon.GetString("mediaType")
|
2019-04-25 20:18:33 +02:00
|
|
|
if mt == "" {
|
|
|
|
mt = "image/png"
|
|
|
|
}
|
2019-06-11 16:14:12 +02:00
|
|
|
u, _ := icon.GetString("url")
|
2019-09-09 15:55:04 +02:00
|
|
|
donk := savedonk(u, name, desc, mt, true)
|
2019-04-09 13:59:33 +02:00
|
|
|
if donk != nil {
|
|
|
|
xonk.Donks = append(xonk.Donks, donk)
|
|
|
|
}
|
|
|
|
}
|
2019-08-25 05:18:19 +02:00
|
|
|
if tt == "Hashtag" {
|
2019-10-10 23:57:00 +02:00
|
|
|
if name == "" || name == "#" {
|
|
|
|
// skip it
|
2019-09-17 15:53:01 +02:00
|
|
|
} else {
|
2019-10-10 23:57:00 +02:00
|
|
|
if name[0] != '#' {
|
|
|
|
name = "#" + name
|
|
|
|
}
|
|
|
|
xonk.Onts = append(xonk.Onts, name)
|
2019-09-17 15:53:01 +02:00
|
|
|
}
|
2019-08-25 05:18:19 +02:00
|
|
|
}
|
2019-09-28 06:28:26 +02:00
|
|
|
if tt == "Place" {
|
|
|
|
p := new(Place)
|
|
|
|
p.Name = name
|
2020-09-10 21:04:29 +02:00
|
|
|
p.Latitude, _ = tag.GetNumber("latitude")
|
|
|
|
p.Longitude, _ = tag.GetNumber("longitude")
|
2019-09-29 22:07:35 +02:00
|
|
|
p.Url, _ = tag.GetString("url")
|
2019-09-28 06:28:26 +02:00
|
|
|
xonk.Place = p
|
|
|
|
}
|
2019-10-17 00:23:25 +02:00
|
|
|
if tt == "Mention" {
|
2019-11-27 20:36:29 +01:00
|
|
|
var m Mention
|
|
|
|
m.Who, _ = tag.GetString("name")
|
|
|
|
m.Where, _ = tag.GetString("href")
|
2019-10-17 00:23:25 +02:00
|
|
|
mentions = append(mentions, m)
|
|
|
|
}
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
2023-07-30 19:08:53 +02:00
|
|
|
tags := oneforall(obj, "tag")
|
2023-07-29 21:04:11 +02:00
|
|
|
for _, tagi := range tags {
|
|
|
|
tag, ok := tagi.(junk.Junk)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
proctag(tag)
|
|
|
|
}
|
2019-12-24 14:28:25 +01:00
|
|
|
if starttime, ok := obj.GetString("startTime"); ok {
|
|
|
|
if start, err := time.Parse(time.RFC3339, starttime); err == nil {
|
2019-10-03 00:20:14 +02:00
|
|
|
t := new(Time)
|
|
|
|
t.StartTime = start
|
2019-10-05 22:49:56 +02:00
|
|
|
endtime, _ := obj.GetString("endTime")
|
|
|
|
t.EndTime, _ = time.Parse(time.RFC3339, endtime)
|
2019-10-03 06:11:02 +02:00
|
|
|
dura, _ := obj.GetString("duration")
|
|
|
|
if strings.HasPrefix(dura, "PT") {
|
|
|
|
dura = strings.ToLower(dura[2:])
|
|
|
|
d, _ := time.ParseDuration(dura)
|
|
|
|
t.Duration = Duration(d)
|
|
|
|
}
|
2019-10-03 00:20:14 +02:00
|
|
|
xonk.Time = t
|
|
|
|
}
|
|
|
|
}
|
2019-12-24 14:28:25 +01:00
|
|
|
if loca, ok := obj.GetMap("location"); ok {
|
|
|
|
if tt, _ := loca.GetString("type"); tt == "Place" {
|
2019-10-03 03:24:40 +02:00
|
|
|
p := new(Place)
|
2019-12-24 14:28:25 +01:00
|
|
|
p.Name, _ = loca.GetString("name")
|
2020-09-10 21:04:29 +02:00
|
|
|
p.Latitude, _ = loca.GetNumber("latitude")
|
|
|
|
p.Longitude, _ = loca.GetNumber("longitude")
|
2019-10-03 03:24:40 +02:00
|
|
|
p.Url, _ = loca.GetString("url")
|
|
|
|
xonk.Place = p
|
|
|
|
}
|
|
|
|
}
|
2019-10-03 00:20:14 +02:00
|
|
|
|
2019-08-28 18:07:46 +02:00
|
|
|
xonk.Onts = oneofakind(xonk.Onts)
|
2019-10-01 05:16:54 +02:00
|
|
|
replyobj, ok := obj.GetMap("replies")
|
|
|
|
if ok {
|
2019-10-01 06:01:45 +02:00
|
|
|
items, ok := replyobj.GetArray("items")
|
|
|
|
if !ok {
|
|
|
|
first, ok := replyobj.GetMap("first")
|
|
|
|
if ok {
|
|
|
|
items, _ = first.GetArray("items")
|
|
|
|
}
|
|
|
|
}
|
2019-10-01 05:16:54 +02:00
|
|
|
for _, repl := range items {
|
|
|
|
s, ok := repl.(string)
|
|
|
|
if ok {
|
|
|
|
replies = append(replies, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
|
|
|
|
2019-06-07 17:15:46 +02:00
|
|
|
if currenttid == "" {
|
|
|
|
currenttid = convoy
|
|
|
|
}
|
|
|
|
|
2019-09-11 22:20:22 +02:00
|
|
|
// init xonk
|
2019-04-25 19:23:18 +02:00
|
|
|
xonk.What = what
|
|
|
|
xonk.RID = rid
|
|
|
|
xonk.Date, _ = time.Parse(time.RFC3339, dt)
|
|
|
|
xonk.URL = url
|
2019-09-11 22:20:22 +02:00
|
|
|
xonk.Format = "html"
|
2019-10-01 05:32:10 +02:00
|
|
|
xonk.Convoy = convoy
|
2019-11-27 20:36:29 +01:00
|
|
|
xonk.Mentions = mentions
|
2019-10-17 00:23:25 +02:00
|
|
|
for _, m := range mentions {
|
2019-11-27 20:36:29 +01:00
|
|
|
if m.Where == user.URL {
|
2019-10-17 00:23:25 +02:00
|
|
|
xonk.Whofore = 1
|
|
|
|
}
|
|
|
|
}
|
2019-10-22 06:19:31 +02:00
|
|
|
imaginate(&xonk)
|
2019-04-25 19:23:18 +02:00
|
|
|
|
2020-05-13 23:15:29 +02:00
|
|
|
if what == "chonk" {
|
2023-08-01 22:17:45 +02:00
|
|
|
target, _ := obj.GetString("to")
|
|
|
|
if target == user.URL {
|
|
|
|
target = xonk.Honker
|
|
|
|
}
|
2020-05-13 23:15:29 +02:00
|
|
|
ch := Chonk{
|
|
|
|
UserID: xonk.UserID,
|
|
|
|
XID: xid,
|
|
|
|
Who: xonk.Honker,
|
2023-08-01 22:17:45 +02:00
|
|
|
Target: target,
|
2020-05-13 23:15:29 +02:00
|
|
|
Date: xonk.Date,
|
|
|
|
Noise: xonk.Noise,
|
|
|
|
Format: xonk.Format,
|
2020-05-15 05:51:42 +02:00
|
|
|
Donks: xonk.Donks,
|
2020-05-13 23:15:29 +02:00
|
|
|
}
|
|
|
|
savechonk(&ch)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-09-17 00:00:13 +02:00
|
|
|
if isUpdate {
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("something has changed! %s", xonk.XID)
|
2019-09-17 00:00:13 +02:00
|
|
|
prev := getxonk(user.ID, xonk.XID)
|
|
|
|
if prev == nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("didn't find old version for update: %s", xonk.XID)
|
2019-10-11 01:12:34 +02:00
|
|
|
isUpdate = false
|
|
|
|
} else {
|
2019-11-27 20:44:16 +01:00
|
|
|
xonk.ID = prev.ID
|
|
|
|
updatehonk(&xonk)
|
2019-09-17 00:00:13 +02:00
|
|
|
}
|
2019-10-11 01:12:34 +02:00
|
|
|
}
|
|
|
|
if !isUpdate && needxonk(user, &xonk) {
|
2022-04-07 21:03:37 +02:00
|
|
|
if rid != "" && xonk.Public {
|
2019-04-29 20:06:34 +02:00
|
|
|
if needxonkid(user, rid) {
|
2019-10-01 06:01:45 +02:00
|
|
|
goingup++
|
2019-10-01 05:32:10 +02:00
|
|
|
saveonemore(rid)
|
2019-10-01 06:01:45 +02:00
|
|
|
goingup--
|
2019-04-29 20:06:34 +02:00
|
|
|
}
|
2019-09-25 18:27:02 +02:00
|
|
|
if convoy == "" {
|
|
|
|
xx := getxonk(user.ID, rid)
|
|
|
|
if xx != nil {
|
|
|
|
convoy = xx.Convoy
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 20:06:34 +02:00
|
|
|
}
|
2019-07-06 19:31:11 +02:00
|
|
|
if convoy == "" {
|
|
|
|
convoy = currenttid
|
|
|
|
}
|
2019-10-03 18:35:17 +02:00
|
|
|
if convoy == "" {
|
2019-11-27 20:48:18 +01:00
|
|
|
convoy = "data:,missing-" + xfiltrate()
|
2019-10-03 18:37:15 +02:00
|
|
|
currenttid = convoy
|
2019-10-03 18:35:17 +02:00
|
|
|
}
|
2019-10-03 18:33:19 +02:00
|
|
|
xonk.Convoy = convoy
|
2019-10-01 05:32:10 +02:00
|
|
|
savexonk(&xonk)
|
|
|
|
}
|
2019-10-01 06:01:45 +02:00
|
|
|
if goingup == 0 {
|
|
|
|
for _, replid := range replies {
|
|
|
|
if needxonkid(user, replid) {
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("missing a reply: %s", replid)
|
2019-10-01 06:01:45 +02:00
|
|
|
saveonemore(replid)
|
|
|
|
}
|
2019-10-01 05:16:54 +02:00
|
|
|
}
|
2019-04-29 20:06:34 +02:00
|
|
|
}
|
2019-10-01 05:32:10 +02:00
|
|
|
return &xonk
|
2019-04-25 19:23:18 +02:00
|
|
|
}
|
2019-04-09 13:59:33 +02:00
|
|
|
|
2023-08-06 09:04:37 +02:00
|
|
|
return xonkxonkfn(item, origin, false, "")
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 18:50:19 +01:00
|
|
|
func dumpactivity(item junk.Junk) {
|
|
|
|
fd, err := os.OpenFile("savedinbox.json", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error opening inbox! %s", err)
|
2020-02-18 18:50:19 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
defer fd.Close()
|
|
|
|
item.Write(fd)
|
|
|
|
io.WriteString(fd, "\n")
|
|
|
|
}
|
|
|
|
|
2019-06-11 16:14:12 +02:00
|
|
|
func rubadubdub(user *WhatAbout, req junk.Junk) {
|
|
|
|
actor, _ := req.GetString("actor")
|
|
|
|
j := junk.New()
|
2019-04-09 13:59:33 +02:00
|
|
|
j["@context"] = itiswhatitis
|
2020-08-10 21:16:42 +02:00
|
|
|
j["id"] = user.URL + "/dub/" + xfiltrate()
|
2019-04-09 13:59:33 +02:00
|
|
|
j["type"] = "Accept"
|
|
|
|
j["actor"] = user.URL
|
2019-06-11 05:57:03 +02:00
|
|
|
j["to"] = actor
|
2019-04-09 13:59:33 +02:00
|
|
|
j["published"] = time.Now().UTC().Format(time.RFC3339)
|
|
|
|
j["object"] = req
|
|
|
|
|
2023-06-12 21:01:03 +02:00
|
|
|
deliverate(user.ID, actor, j.ToBytes())
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
|
|
|
|
2020-09-10 20:52:24 +02:00
|
|
|
func itakeitallback(user *WhatAbout, xid string, owner string, folxid string) {
|
2019-06-11 16:14:12 +02:00
|
|
|
j := junk.New()
|
2019-04-26 21:31:42 +02:00
|
|
|
j["@context"] = itiswhatitis
|
2020-09-10 20:52:24 +02:00
|
|
|
j["id"] = user.URL + "/unsub/" + folxid
|
2019-04-26 21:31:42 +02:00
|
|
|
j["type"] = "Undo"
|
|
|
|
j["actor"] = user.URL
|
2020-09-10 20:52:24 +02:00
|
|
|
j["to"] = owner
|
2019-06-11 16:14:12 +02:00
|
|
|
f := junk.New()
|
2020-09-10 20:52:24 +02:00
|
|
|
f["id"] = user.URL + "/sub/" + folxid
|
2019-04-26 21:31:42 +02:00
|
|
|
f["type"] = "Follow"
|
|
|
|
f["actor"] = user.URL
|
2020-09-10 20:52:24 +02:00
|
|
|
f["to"] = owner
|
2019-06-21 05:47:05 +02:00
|
|
|
f["object"] = xid
|
2019-04-26 21:31:42 +02:00
|
|
|
j["object"] = f
|
|
|
|
j["published"] = time.Now().UTC().Format(time.RFC3339)
|
|
|
|
|
2023-06-12 21:01:03 +02:00
|
|
|
deliverate(user.ID, owner, j.ToBytes())
|
2019-04-26 21:31:42 +02:00
|
|
|
}
|
|
|
|
|
2020-09-10 20:52:24 +02:00
|
|
|
func subsub(user *WhatAbout, xid string, owner string, folxid string) {
|
2019-10-07 03:33:10 +02:00
|
|
|
if xid == "" {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("can't subscribe to empty")
|
2019-10-07 03:33:10 +02:00
|
|
|
return
|
|
|
|
}
|
2019-06-11 16:14:12 +02:00
|
|
|
j := junk.New()
|
2019-04-09 13:59:33 +02:00
|
|
|
j["@context"] = itiswhatitis
|
2020-09-10 20:52:24 +02:00
|
|
|
j["id"] = user.URL + "/sub/" + folxid
|
2019-04-09 13:59:33 +02:00
|
|
|
j["type"] = "Follow"
|
|
|
|
j["actor"] = user.URL
|
2019-10-27 00:31:42 +02:00
|
|
|
j["to"] = owner
|
2019-04-09 13:59:33 +02:00
|
|
|
j["object"] = xid
|
|
|
|
j["published"] = time.Now().UTC().Format(time.RFC3339)
|
|
|
|
|
2023-06-12 21:01:03 +02:00
|
|
|
deliverate(user.ID, owner, j.ToBytes())
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 03:09:54 +02:00
|
|
|
func activatedonks(donks []*Donk) []junk.Junk {
|
|
|
|
var atts []junk.Junk
|
|
|
|
for _, d := range donks {
|
|
|
|
if re_emus.MatchString(d.Name) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
jd := junk.New()
|
|
|
|
jd["mediaType"] = d.Media
|
2023-03-09 18:32:53 +01:00
|
|
|
jd["name"] = d.Name
|
|
|
|
jd["summary"] = html.EscapeString(d.Desc)
|
2020-05-18 03:09:54 +02:00
|
|
|
jd["type"] = "Document"
|
|
|
|
jd["url"] = d.URL
|
|
|
|
atts = append(atts, jd)
|
|
|
|
}
|
|
|
|
return atts
|
|
|
|
}
|
|
|
|
|
2019-09-23 02:29:10 +02:00
|
|
|
// returns activity, object
|
2019-06-11 16:14:12 +02:00
|
|
|
func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
|
2019-04-09 13:59:33 +02:00
|
|
|
dt := h.Date.Format(time.RFC3339)
|
2019-06-11 16:14:12 +02:00
|
|
|
var jo junk.Junk
|
|
|
|
j := junk.New()
|
2019-05-20 16:48:02 +02:00
|
|
|
j["id"] = user.URL + "/" + h.What + "/" + shortxid(h.XID)
|
2019-04-09 13:59:33 +02:00
|
|
|
j["actor"] = user.URL
|
|
|
|
j["published"] = dt
|
2020-09-26 00:49:47 +02:00
|
|
|
j["to"] = h.Audience[0]
|
2019-04-09 13:59:33 +02:00
|
|
|
if len(h.Audience) > 1 {
|
|
|
|
j["cc"] = h.Audience[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
switch h.What {
|
2019-09-17 00:00:13 +02:00
|
|
|
case "update":
|
|
|
|
fallthrough
|
2019-10-03 00:20:14 +02:00
|
|
|
case "event":
|
|
|
|
fallthrough
|
2019-04-09 13:59:33 +02:00
|
|
|
case "honk":
|
2019-10-03 00:20:14 +02:00
|
|
|
j["type"] = "Create"
|
2019-06-11 16:14:12 +02:00
|
|
|
jo = junk.New()
|
2019-05-20 16:48:02 +02:00
|
|
|
jo["id"] = h.XID
|
2019-04-09 13:59:33 +02:00
|
|
|
jo["type"] = "Note"
|
2019-10-03 00:20:14 +02:00
|
|
|
if h.What == "event" {
|
|
|
|
jo["type"] = "Event"
|
|
|
|
}
|
2022-05-27 19:43:48 +02:00
|
|
|
if h.What == "update" {
|
|
|
|
j["type"] = "Update"
|
|
|
|
jo["updated"] = dt
|
|
|
|
}
|
2019-04-09 13:59:33 +02:00
|
|
|
jo["published"] = dt
|
2019-05-20 16:48:02 +02:00
|
|
|
jo["url"] = h.XID
|
2019-04-09 13:59:33 +02:00
|
|
|
jo["attributedTo"] = user.URL
|
|
|
|
if h.RID != "" {
|
|
|
|
jo["inReplyTo"] = h.RID
|
|
|
|
}
|
2019-04-19 17:50:35 +02:00
|
|
|
if h.Convoy != "" {
|
2019-04-19 18:48:44 +02:00
|
|
|
jo["context"] = h.Convoy
|
2019-04-19 17:50:35 +02:00
|
|
|
jo["conversation"] = h.Convoy
|
|
|
|
}
|
2019-04-09 13:59:33 +02:00
|
|
|
jo["to"] = h.Audience[0]
|
|
|
|
if len(h.Audience) > 1 {
|
|
|
|
jo["cc"] = h.Audience[1:]
|
|
|
|
}
|
2019-05-28 09:54:03 +02:00
|
|
|
if !h.Public {
|
|
|
|
jo["directMessage"] = true
|
|
|
|
}
|
2023-07-31 02:31:00 +02:00
|
|
|
h.Noise = re_retag.ReplaceAllString(h.Noise, "")
|
2019-12-04 08:30:07 +01:00
|
|
|
translate(h)
|
|
|
|
redoimages(h)
|
2019-11-26 04:14:27 +01:00
|
|
|
if h.Precis != "" {
|
2019-06-24 01:07:28 +02:00
|
|
|
jo["sensitive"] = true
|
2019-05-04 18:28:00 +02:00
|
|
|
}
|
2019-06-24 01:07:28 +02:00
|
|
|
|
2019-08-19 05:25:11 +02:00
|
|
|
var replies []string
|
|
|
|
for _, reply := range h.Replies {
|
|
|
|
replies = append(replies, reply.XID)
|
|
|
|
}
|
|
|
|
if len(replies) > 0 {
|
|
|
|
jr := junk.New()
|
|
|
|
jr["type"] = "Collection"
|
|
|
|
jr["totalItems"] = len(replies)
|
|
|
|
jr["items"] = replies
|
|
|
|
jo["replies"] = jr
|
|
|
|
}
|
|
|
|
|
2019-07-29 02:01:12 +02:00
|
|
|
var tags []junk.Junk
|
2020-07-21 05:28:42 +02:00
|
|
|
for _, m := range h.Mentions {
|
2019-06-11 16:14:12 +02:00
|
|
|
t := junk.New()
|
2019-04-12 21:02:56 +02:00
|
|
|
t["type"] = "Mention"
|
2019-11-27 20:36:29 +01:00
|
|
|
t["name"] = m.Who
|
|
|
|
t["href"] = m.Where
|
2019-04-12 21:02:56 +02:00
|
|
|
tags = append(tags, t)
|
|
|
|
}
|
2019-08-28 18:07:46 +02:00
|
|
|
for _, o := range h.Onts {
|
2019-06-16 00:24:18 +02:00
|
|
|
t := junk.New()
|
|
|
|
t["type"] = "Hashtag"
|
2019-08-25 05:03:05 +02:00
|
|
|
o = strings.ToLower(o)
|
|
|
|
t["href"] = fmt.Sprintf("https://%s/o/%s", serverName, o[1:])
|
2019-06-16 00:24:18 +02:00
|
|
|
t["name"] = o
|
|
|
|
tags = append(tags, t)
|
|
|
|
}
|
2019-10-19 21:26:36 +02:00
|
|
|
for _, e := range herdofemus(h.Noise) {
|
2019-06-11 16:14:12 +02:00
|
|
|
t := junk.New()
|
2019-04-12 21:02:56 +02:00
|
|
|
t["id"] = e.ID
|
|
|
|
t["type"] = "Emoji"
|
|
|
|
t["name"] = e.Name
|
2019-06-11 16:14:12 +02:00
|
|
|
i := junk.New()
|
2019-04-12 21:02:56 +02:00
|
|
|
i["type"] = "Image"
|
2022-05-11 22:15:40 +02:00
|
|
|
i["mediaType"] = e.Type
|
2019-04-12 21:02:56 +02:00
|
|
|
i["url"] = e.ID
|
|
|
|
t["icon"] = i
|
|
|
|
tags = append(tags, t)
|
|
|
|
}
|
2020-07-08 02:34:59 +02:00
|
|
|
for _, e := range fixupflags(h) {
|
2020-05-11 22:24:18 +02:00
|
|
|
t := junk.New()
|
|
|
|
t["id"] = e.ID
|
|
|
|
t["type"] = "Emoji"
|
|
|
|
t["name"] = e.Name
|
|
|
|
i := junk.New()
|
|
|
|
i["type"] = "Image"
|
|
|
|
i["mediaType"] = "image/png"
|
|
|
|
i["url"] = e.ID
|
|
|
|
t["icon"] = i
|
|
|
|
tags = append(tags, t)
|
|
|
|
}
|
2019-11-06 21:17:53 +01:00
|
|
|
if len(tags) > 0 {
|
|
|
|
jo["tag"] = tags
|
|
|
|
}
|
2019-09-28 06:12:50 +02:00
|
|
|
if p := h.Place; p != nil {
|
|
|
|
t := junk.New()
|
|
|
|
t["type"] = "Place"
|
2019-11-06 21:17:53 +01:00
|
|
|
if p.Name != "" {
|
|
|
|
t["name"] = p.Name
|
2019-10-05 22:49:56 +02:00
|
|
|
}
|
2019-11-06 21:17:53 +01:00
|
|
|
if p.Latitude != 0 {
|
|
|
|
t["latitude"] = p.Latitude
|
|
|
|
}
|
|
|
|
if p.Longitude != 0 {
|
|
|
|
t["longitude"] = p.Longitude
|
|
|
|
}
|
|
|
|
if p.Url != "" {
|
|
|
|
t["url"] = p.Url
|
|
|
|
}
|
|
|
|
jo["location"] = t
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
2019-10-03 00:20:14 +02:00
|
|
|
if t := h.Time; t != nil {
|
|
|
|
jo["startTime"] = t.StartTime.Format(time.RFC3339)
|
2019-10-03 06:11:02 +02:00
|
|
|
if t.Duration != 0 {
|
|
|
|
jo["duration"] = "PT" + strings.ToUpper(t.Duration.String())
|
|
|
|
}
|
2019-10-03 00:20:14 +02:00
|
|
|
}
|
2020-05-18 03:09:54 +02:00
|
|
|
atts := activatedonks(h.Donks)
|
2019-04-09 13:59:33 +02:00
|
|
|
if len(atts) > 0 {
|
|
|
|
jo["attachment"] = atts
|
|
|
|
}
|
2023-02-24 00:19:37 +01:00
|
|
|
jo["summary"] = h.Precis
|
2020-05-11 22:24:18 +02:00
|
|
|
jo["content"] = h.Noise
|
2019-04-09 13:59:33 +02:00
|
|
|
j["object"] = jo
|
|
|
|
case "bonk":
|
|
|
|
j["type"] = "Announce"
|
2019-06-26 23:19:45 +02:00
|
|
|
if h.Convoy != "" {
|
|
|
|
j["context"] = h.Convoy
|
|
|
|
}
|
2019-04-09 13:59:33 +02:00
|
|
|
j["object"] = h.XID
|
2019-08-28 03:22:59 +02:00
|
|
|
case "unbonk":
|
|
|
|
b := junk.New()
|
|
|
|
b["id"] = user.URL + "/" + "bonk" + "/" + shortxid(h.XID)
|
|
|
|
b["type"] = "Announce"
|
2019-09-23 02:29:10 +02:00
|
|
|
b["actor"] = user.URL
|
2019-08-28 03:22:59 +02:00
|
|
|
if h.Convoy != "" {
|
|
|
|
b["context"] = h.Convoy
|
|
|
|
}
|
|
|
|
b["object"] = h.XID
|
|
|
|
j["type"] = "Undo"
|
|
|
|
j["object"] = b
|
2019-05-03 19:42:39 +02:00
|
|
|
case "zonk":
|
|
|
|
j["type"] = "Delete"
|
2019-05-20 16:48:02 +02:00
|
|
|
j["object"] = h.XID
|
2019-08-21 07:23:00 +02:00
|
|
|
case "ack":
|
|
|
|
j["type"] = "Read"
|
|
|
|
j["object"] = h.XID
|
2019-10-30 00:50:45 +01:00
|
|
|
if h.Convoy != "" {
|
|
|
|
j["context"] = h.Convoy
|
|
|
|
}
|
2020-01-24 00:08:15 +01:00
|
|
|
case "react":
|
2020-02-07 17:57:00 +01:00
|
|
|
j["type"] = "EmojiReact"
|
2020-01-24 00:08:15 +01:00
|
|
|
j["object"] = h.XID
|
|
|
|
if h.Convoy != "" {
|
|
|
|
j["context"] = h.Convoy
|
|
|
|
}
|
2020-04-26 20:36:11 +02:00
|
|
|
j["content"] = h.Noise
|
2019-08-21 07:23:00 +02:00
|
|
|
case "deack":
|
2019-09-23 02:29:10 +02:00
|
|
|
b := junk.New()
|
|
|
|
b["id"] = user.URL + "/" + "ack" + "/" + shortxid(h.XID)
|
|
|
|
b["type"] = "Read"
|
|
|
|
b["actor"] = user.URL
|
|
|
|
b["object"] = h.XID
|
2019-10-30 00:50:45 +01:00
|
|
|
if h.Convoy != "" {
|
|
|
|
b["context"] = h.Convoy
|
|
|
|
}
|
2019-09-23 02:29:10 +02:00
|
|
|
j["type"] = "Undo"
|
|
|
|
j["object"] = b
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return j, jo
|
|
|
|
}
|
|
|
|
|
2019-10-13 01:25:23 +02:00
|
|
|
var oldjonks = cache.New(cache.Options{Filler: func(xid string) ([]byte, bool) {
|
2019-10-07 21:22:10 +02:00
|
|
|
row := stmtAnyXonk.QueryRow(xid)
|
|
|
|
honk := scanhonk(row)
|
|
|
|
if honk == nil || !honk.Public {
|
|
|
|
return nil, true
|
|
|
|
}
|
|
|
|
user, _ := butwhatabout(honk.Username)
|
2019-10-20 20:36:55 +02:00
|
|
|
rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy, 0)
|
2019-10-08 06:58:42 +02:00
|
|
|
reversehonks(rawhonks)
|
2019-10-07 21:22:10 +02:00
|
|
|
for _, h := range rawhonks {
|
|
|
|
if h.RID == honk.XID && h.Public && (h.Whofore == 2 || h.IsAcked()) {
|
|
|
|
honk.Replies = append(honk.Replies, h)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
donksforhonks([]*Honk{honk})
|
|
|
|
_, j := jonkjonk(user, honk)
|
2022-11-10 20:08:25 +01:00
|
|
|
if j == nil {
|
|
|
|
elog.Fatalf("what just happened? %v", honk)
|
|
|
|
}
|
2019-10-07 21:22:10 +02:00
|
|
|
j["@context"] = itiswhatitis
|
2019-10-25 23:44:46 +02:00
|
|
|
|
|
|
|
return j.ToBytes(), true
|
2019-11-12 00:30:40 +01:00
|
|
|
}, Limit: 128})
|
2019-10-07 21:22:10 +02:00
|
|
|
|
|
|
|
func gimmejonk(xid string) ([]byte, bool) {
|
|
|
|
var j []byte
|
|
|
|
ok := oldjonks.Get(xid, &j)
|
|
|
|
return j, ok
|
|
|
|
}
|
|
|
|
|
2019-11-26 20:57:23 +01:00
|
|
|
func boxuprcpts(user *WhatAbout, addresses []string, useshared bool) map[string]bool {
|
2019-04-17 02:14:24 +02:00
|
|
|
rcpts := make(map[string]bool)
|
2019-11-26 20:57:23 +01:00
|
|
|
for _, a := range addresses {
|
|
|
|
if a == "" || a == thewholeworld || a == user.URL || strings.HasSuffix(a, "/followers") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if a[0] == '%' {
|
|
|
|
rcpts[a] = true
|
2019-09-28 23:13:57 +02:00
|
|
|
continue
|
|
|
|
}
|
2019-10-07 20:45:02 +02:00
|
|
|
var box *Box
|
|
|
|
ok := boxofboxes.Get(a, &box)
|
2019-11-26 20:57:23 +01:00
|
|
|
if ok && useshared && box.Shared != "" {
|
2019-09-28 23:13:57 +02:00
|
|
|
rcpts["%"+box.Shared] = true
|
|
|
|
} else {
|
|
|
|
rcpts[a] = true
|
2019-04-17 02:14:24 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-26 20:57:23 +01:00
|
|
|
return rcpts
|
|
|
|
}
|
|
|
|
|
2020-05-18 03:26:59 +02:00
|
|
|
func chonkifymsg(user *WhatAbout, ch *Chonk) []byte {
|
2020-05-13 23:15:29 +02:00
|
|
|
dt := ch.Date.Format(time.RFC3339)
|
|
|
|
aud := []string{ch.Target}
|
|
|
|
|
|
|
|
jo := junk.New()
|
|
|
|
jo["id"] = ch.XID
|
|
|
|
jo["type"] = "ChatMessage"
|
|
|
|
jo["published"] = dt
|
|
|
|
jo["attributedTo"] = user.URL
|
|
|
|
jo["to"] = aud
|
2020-05-15 05:06:23 +02:00
|
|
|
jo["content"] = ch.HTML
|
2020-05-18 03:09:54 +02:00
|
|
|
atts := activatedonks(ch.Donks)
|
|
|
|
if len(atts) > 0 {
|
|
|
|
jo["attachment"] = atts
|
|
|
|
}
|
2020-07-27 06:30:01 +02:00
|
|
|
var tags []junk.Junk
|
|
|
|
for _, e := range herdofemus(ch.Noise) {
|
|
|
|
t := junk.New()
|
|
|
|
t["id"] = e.ID
|
|
|
|
t["type"] = "Emoji"
|
|
|
|
t["name"] = e.Name
|
|
|
|
i := junk.New()
|
|
|
|
i["type"] = "Image"
|
2022-05-11 22:15:40 +02:00
|
|
|
i["mediaType"] = e.Type
|
2020-07-27 06:30:01 +02:00
|
|
|
i["url"] = e.ID
|
|
|
|
t["icon"] = i
|
|
|
|
tags = append(tags, t)
|
|
|
|
}
|
|
|
|
if len(tags) > 0 {
|
|
|
|
jo["tag"] = tags
|
|
|
|
}
|
2020-05-13 23:15:29 +02:00
|
|
|
|
|
|
|
j := junk.New()
|
|
|
|
j["@context"] = itiswhatitis
|
|
|
|
j["id"] = user.URL + "/" + "honk" + "/" + shortxid(ch.XID)
|
|
|
|
j["type"] = "Create"
|
|
|
|
j["actor"] = user.URL
|
|
|
|
j["published"] = dt
|
|
|
|
j["to"] = aud
|
|
|
|
j["object"] = jo
|
|
|
|
|
2020-05-18 03:26:59 +02:00
|
|
|
return j.ToBytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
func sendchonk(user *WhatAbout, ch *Chonk) {
|
|
|
|
msg := chonkifymsg(user, ch)
|
|
|
|
|
2020-05-13 23:15:29 +02:00
|
|
|
rcpts := make(map[string]bool)
|
|
|
|
rcpts[ch.Target] = true
|
|
|
|
for a := range rcpts {
|
2023-06-12 21:01:03 +02:00
|
|
|
go deliverate(user.ID, a, msg)
|
2020-05-13 23:15:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 20:57:23 +01:00
|
|
|
func honkworldwide(user *WhatAbout, honk *Honk) {
|
|
|
|
jonk, _ := jonkjonk(user, honk)
|
|
|
|
jonk["@context"] = itiswhatitis
|
|
|
|
msg := jonk.ToBytes()
|
|
|
|
|
|
|
|
rcpts := boxuprcpts(user, honk.Audience, honk.Public)
|
|
|
|
|
2019-05-28 08:36:47 +02:00
|
|
|
if honk.Public {
|
2019-10-21 07:29:39 +02:00
|
|
|
for _, h := range getdubs(user.ID) {
|
|
|
|
if h.XID == user.URL {
|
2019-09-28 23:13:57 +02:00
|
|
|
continue
|
|
|
|
}
|
2019-10-07 20:45:02 +02:00
|
|
|
var box *Box
|
2019-10-21 07:29:39 +02:00
|
|
|
ok := boxofboxes.Get(h.XID, &box)
|
2019-10-07 20:45:02 +02:00
|
|
|
if ok && box.Shared != "" {
|
2019-05-28 08:36:47 +02:00
|
|
|
rcpts["%"+box.Shared] = true
|
|
|
|
} else {
|
2019-10-21 07:29:39 +02:00
|
|
|
rcpts[h.XID] = true
|
2019-05-28 08:36:47 +02:00
|
|
|
}
|
2019-04-16 20:40:23 +02:00
|
|
|
}
|
2019-11-26 06:29:31 +01:00
|
|
|
for _, f := range getbacktracks(honk.XID) {
|
2022-02-04 18:45:44 +01:00
|
|
|
if f[0] == '%' {
|
2020-07-29 08:42:11 +02:00
|
|
|
rcpts[f] = true
|
2022-02-04 18:45:44 +01:00
|
|
|
} else {
|
|
|
|
var box *Box
|
|
|
|
ok := boxofboxes.Get(f, &box)
|
|
|
|
if ok && box.Shared != "" {
|
|
|
|
rcpts["%"+box.Shared] = true
|
|
|
|
} else {
|
|
|
|
rcpts[f] = true
|
|
|
|
}
|
2020-07-29 08:42:11 +02:00
|
|
|
}
|
2019-11-26 06:29:31 +01:00
|
|
|
}
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
2019-04-14 16:06:26 +02:00
|
|
|
for a := range rcpts {
|
2023-06-12 21:01:03 +02:00
|
|
|
go deliverate(user.ID, a, msg)
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
2019-10-26 02:31:07 +02:00
|
|
|
if honk.Public && len(honk.Onts) > 0 {
|
|
|
|
collectiveaction(honk)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func collectiveaction(honk *Honk) {
|
|
|
|
user := getserveruser()
|
|
|
|
for _, ont := range honk.Onts {
|
2022-12-26 19:27:39 +01:00
|
|
|
dubs := getnameddubs(readyLuserOne, ont)
|
2019-10-26 02:31:07 +02:00
|
|
|
if len(dubs) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
j := junk.New()
|
|
|
|
j["@context"] = itiswhatitis
|
|
|
|
j["type"] = "Add"
|
|
|
|
j["id"] = user.URL + "/add/" + shortxid(ont+honk.XID)
|
|
|
|
j["actor"] = user.URL
|
|
|
|
j["object"] = honk.XID
|
2019-10-28 21:03:32 +01:00
|
|
|
j["target"] = fmt.Sprintf("https://%s/o/%s", serverName, ont[1:])
|
2019-10-26 02:31:07 +02:00
|
|
|
rcpts := make(map[string]bool)
|
|
|
|
for _, dub := range dubs {
|
|
|
|
var box *Box
|
|
|
|
ok := boxofboxes.Get(dub.XID, &box)
|
|
|
|
if ok && box.Shared != "" {
|
|
|
|
rcpts["%"+box.Shared] = true
|
|
|
|
} else {
|
|
|
|
rcpts[dub.XID] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msg := j.ToBytes()
|
|
|
|
for a := range rcpts {
|
2023-06-12 21:01:03 +02:00
|
|
|
go deliverate(user.ID, a, msg)
|
2019-10-26 02:31:07 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
|
|
|
|
2020-05-01 07:34:08 +02:00
|
|
|
func junkuser(user *WhatAbout) junk.Junk {
|
2019-06-11 16:14:12 +02:00
|
|
|
j := junk.New()
|
2019-04-09 13:59:33 +02:00
|
|
|
j["@context"] = itiswhatitis
|
|
|
|
j["id"] = user.URL
|
|
|
|
j["inbox"] = user.URL + "/inbox"
|
|
|
|
j["outbox"] = user.URL + "/outbox"
|
|
|
|
j["name"] = user.Display
|
|
|
|
j["preferredUsername"] = user.Name
|
2020-09-26 01:02:26 +02:00
|
|
|
j["summary"] = user.HTAbout
|
2020-09-26 01:09:01 +02:00
|
|
|
var tags []junk.Junk
|
|
|
|
for _, o := range user.Onts {
|
|
|
|
t := junk.New()
|
|
|
|
t["type"] = "Hashtag"
|
|
|
|
o = strings.ToLower(o)
|
|
|
|
t["href"] = fmt.Sprintf("https://%s/o/%s", serverName, o[1:])
|
|
|
|
t["name"] = o
|
|
|
|
tags = append(tags, t)
|
|
|
|
}
|
|
|
|
if len(tags) > 0 {
|
|
|
|
j["tag"] = tags
|
|
|
|
}
|
|
|
|
|
2019-10-25 23:31:48 +02:00
|
|
|
if user.ID > 0 {
|
|
|
|
j["type"] = "Person"
|
|
|
|
j["url"] = user.URL
|
|
|
|
j["followers"] = user.URL + "/followers"
|
|
|
|
j["following"] = user.URL + "/following"
|
|
|
|
a := junk.New()
|
|
|
|
a["type"] = "Image"
|
|
|
|
a["mediaType"] = "image/png"
|
2023-06-13 20:58:35 +02:00
|
|
|
a["url"] = avatarURL(user)
|
2019-10-25 23:31:48 +02:00
|
|
|
j["icon"] = a
|
2022-05-31 07:31:11 +02:00
|
|
|
if ban := user.Options.Banner; ban != "" {
|
|
|
|
a := junk.New()
|
|
|
|
a["type"] = "Image"
|
|
|
|
a["mediaType"] = "image/jpg"
|
|
|
|
a["url"] = ban
|
|
|
|
j["image"] = a
|
|
|
|
}
|
2019-10-25 23:31:48 +02:00
|
|
|
} else {
|
|
|
|
j["type"] = "Service"
|
|
|
|
}
|
2019-06-11 16:14:12 +02:00
|
|
|
k := junk.New()
|
2019-04-09 13:59:33 +02:00
|
|
|
k["id"] = user.URL + "#key"
|
|
|
|
k["owner"] = user.URL
|
|
|
|
k["publicKeyPem"] = user.Key
|
|
|
|
j["publicKey"] = k
|
|
|
|
|
2020-05-01 07:34:08 +02:00
|
|
|
return j
|
2019-10-25 23:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var oldjonkers = cache.New(cache.Options{Filler: func(name string) ([]byte, bool) {
|
|
|
|
user, err := butwhatabout(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, false
|
|
|
|
}
|
2020-05-01 07:34:08 +02:00
|
|
|
j := junkuser(user)
|
2023-06-19 03:48:45 +02:00
|
|
|
return j.ToBytes(), true
|
2019-10-07 21:47:37 +02:00
|
|
|
}, Duration: 1 * time.Minute})
|
|
|
|
|
|
|
|
func asjonker(name string) ([]byte, bool) {
|
|
|
|
var j []byte
|
|
|
|
ok := oldjonkers.Get(name, &j)
|
|
|
|
return j, ok
|
2019-04-09 13:59:33 +02:00
|
|
|
}
|
2019-05-11 00:18:32 +02:00
|
|
|
|
2019-10-13 01:25:23 +02:00
|
|
|
var handfull = cache.New(cache.Options{Filler: func(name string) (string, bool) {
|
2019-05-11 00:18:32 +02:00
|
|
|
m := strings.Split(name, "@")
|
|
|
|
if len(m) != 2 {
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("bad fish name: %s", name)
|
2019-10-07 20:45:02 +02:00
|
|
|
return "", true
|
2019-05-11 00:18:32 +02:00
|
|
|
}
|
|
|
|
var href string
|
2019-11-13 17:00:25 +01:00
|
|
|
row := stmtGetXonker.QueryRow(name, "fishname")
|
2019-05-11 00:18:32 +02:00
|
|
|
err := row.Scan(&href)
|
|
|
|
if err == nil {
|
2019-10-07 20:45:02 +02:00
|
|
|
return href, true
|
2019-05-11 00:18:32 +02:00
|
|
|
}
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("fishing for %s", name)
|
2022-12-26 19:27:39 +01:00
|
|
|
j, err := GetJunkFast(readyLuserOne, fmt.Sprintf("https://%s/.well-known/webfinger?resource=acct:%s", m[1], name))
|
2019-05-11 00:18:32 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("failed to go fish %s: %s", name, err)
|
2019-10-07 20:45:02 +02:00
|
|
|
return "", true
|
2019-05-11 00:18:32 +02:00
|
|
|
}
|
2019-06-11 16:14:12 +02:00
|
|
|
links, _ := j.GetArray("links")
|
|
|
|
for _, li := range links {
|
|
|
|
l, ok := li.(junk.Junk)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
href, _ := l.GetString("href")
|
|
|
|
rel, _ := l.GetString("rel")
|
|
|
|
t, _ := l.GetString("type")
|
2019-05-11 00:18:32 +02:00
|
|
|
if rel == "self" && friendorfoe(t) {
|
2019-11-25 21:50:17 +01:00
|
|
|
when := time.Now().UTC().Format(dbtimeformat)
|
|
|
|
_, err := stmtSaveXonker.Exec(name, href, "fishname", when)
|
2019-08-16 06:15:55 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error saving fishname: %s", err)
|
2019-08-16 06:15:55 +02:00
|
|
|
}
|
2019-10-07 20:45:02 +02:00
|
|
|
return href, true
|
2019-05-11 00:18:32 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-07 20:45:02 +02:00
|
|
|
return href, true
|
2020-04-23 00:37:26 +02:00
|
|
|
}, Duration: 1 * time.Minute})
|
2019-10-07 20:45:02 +02:00
|
|
|
|
|
|
|
func gofish(name string) string {
|
|
|
|
if name[0] == '@' {
|
|
|
|
name = name[1:]
|
|
|
|
}
|
|
|
|
var href string
|
|
|
|
handfull.Get(name, &href)
|
|
|
|
return href
|
2019-05-11 00:18:32 +02:00
|
|
|
}
|
2019-06-03 09:20:03 +02:00
|
|
|
|
2019-10-27 00:31:42 +02:00
|
|
|
func investigate(name string) (*SomeThing, error) {
|
2019-06-03 09:20:03 +02:00
|
|
|
if name == "" {
|
2019-08-30 16:16:59 +02:00
|
|
|
return nil, fmt.Errorf("no name")
|
2019-06-03 09:20:03 +02:00
|
|
|
}
|
|
|
|
if name[0] == '@' {
|
|
|
|
name = gofish(name)
|
|
|
|
}
|
|
|
|
if name == "" {
|
2019-08-30 16:16:59 +02:00
|
|
|
return nil, fmt.Errorf("no name")
|
2019-06-03 09:20:03 +02:00
|
|
|
}
|
2022-12-26 19:27:39 +01:00
|
|
|
obj, err := GetJunkFast(readyLuserOne, name)
|
2019-06-03 09:20:03 +02:00
|
|
|
if err != nil {
|
2019-08-30 16:16:59 +02:00
|
|
|
return nil, err
|
2019-06-03 09:20:03 +02:00
|
|
|
}
|
2019-11-11 18:03:00 +01:00
|
|
|
allinjest(originate(name), obj)
|
2019-10-27 00:31:42 +02:00
|
|
|
return somethingabout(obj)
|
|
|
|
}
|
|
|
|
|
|
|
|
func somethingabout(obj junk.Junk) (*SomeThing, error) {
|
|
|
|
info := new(SomeThing)
|
2019-06-11 16:14:12 +02:00
|
|
|
t, _ := obj.GetString("type")
|
2023-06-11 06:02:05 +02:00
|
|
|
isowned := false
|
2019-10-27 00:31:42 +02:00
|
|
|
switch t {
|
|
|
|
case "Person":
|
|
|
|
fallthrough
|
2023-06-11 05:42:07 +02:00
|
|
|
case "Group":
|
|
|
|
fallthrough
|
2019-10-27 00:31:42 +02:00
|
|
|
case "Organization":
|
|
|
|
fallthrough
|
|
|
|
case "Application":
|
|
|
|
fallthrough
|
|
|
|
case "Service":
|
|
|
|
info.What = SomeActor
|
|
|
|
case "OrderedCollection":
|
2023-06-11 06:02:05 +02:00
|
|
|
isowned = true
|
2019-10-27 00:31:42 +02:00
|
|
|
fallthrough
|
|
|
|
case "Collection":
|
|
|
|
info.What = SomeCollection
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unknown object type")
|
|
|
|
}
|
|
|
|
info.XID, _ = obj.GetString("id")
|
|
|
|
info.Name, _ = obj.GetString("preferredUsername")
|
|
|
|
if info.Name == "" {
|
|
|
|
info.Name, _ = obj.GetString("name")
|
|
|
|
}
|
2023-06-11 06:02:05 +02:00
|
|
|
if isowned {
|
2023-06-11 05:51:31 +02:00
|
|
|
info.Owner, _ = obj.GetString("attributedTo")
|
|
|
|
}
|
2019-10-27 00:31:42 +02:00
|
|
|
if info.Owner == "" {
|
|
|
|
info.Owner = info.XID
|
2019-06-03 09:20:03 +02:00
|
|
|
}
|
2019-10-27 00:31:42 +02:00
|
|
|
return info, nil
|
2019-06-03 09:20:03 +02:00
|
|
|
}
|
2019-11-11 18:03:00 +01:00
|
|
|
|
|
|
|
func allinjest(origin string, obj junk.Junk) {
|
|
|
|
keyobj, ok := obj.GetMap("publicKey")
|
|
|
|
if ok {
|
|
|
|
ingestpubkey(origin, keyobj)
|
|
|
|
}
|
|
|
|
ingestboxes(origin, obj)
|
2019-11-11 18:52:08 +01:00
|
|
|
ingesthandle(origin, obj)
|
2019-11-11 18:03:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func ingestpubkey(origin string, obj junk.Junk) {
|
|
|
|
keyobj, ok := obj.GetMap("publicKey")
|
|
|
|
if ok {
|
|
|
|
obj = keyobj
|
|
|
|
}
|
|
|
|
keyname, ok := obj.GetString("id")
|
|
|
|
var data string
|
2019-11-13 17:00:25 +01:00
|
|
|
row := stmtGetXonker.QueryRow(keyname, "pubkey")
|
2019-11-11 18:03:00 +01:00
|
|
|
err := row.Scan(&data)
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !ok || origin != originate(keyname) {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("bad key origin %s <> %s", origin, keyname)
|
2019-11-11 18:03:00 +01:00
|
|
|
return
|
|
|
|
}
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("ingesting a needed pubkey: %s", keyname)
|
2019-11-11 18:03:00 +01:00
|
|
|
owner, ok := obj.GetString("owner")
|
|
|
|
if !ok {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error finding %s pubkey owner", keyname)
|
2019-11-11 18:03:00 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
data, ok = obj.GetString("publicKeyPem")
|
|
|
|
if !ok {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error finding %s pubkey", keyname)
|
2019-11-11 18:03:00 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if originate(owner) != origin {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("bad key owner: %s <> %s", owner, origin)
|
2019-11-11 18:03:00 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
_, _, err = httpsig.DecodeKey(data)
|
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("error decoding %s pubkey: %s", keyname, err)
|
2019-11-11 18:03:00 +01:00
|
|
|
return
|
|
|
|
}
|
2019-11-25 21:50:17 +01:00
|
|
|
when := time.Now().UTC().Format(dbtimeformat)
|
|
|
|
_, err = stmtSaveXonker.Exec(keyname, data, "pubkey", when)
|
2019-11-11 18:03:00 +01:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error saving key: %s", err)
|
2019-11-11 18:03:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ingestboxes(origin string, obj junk.Junk) {
|
|
|
|
ident, _ := obj.GetString("id")
|
|
|
|
if ident == "" {
|
|
|
|
return
|
|
|
|
}
|
2019-11-11 18:52:08 +01:00
|
|
|
if originate(ident) != origin {
|
|
|
|
return
|
|
|
|
}
|
2019-11-11 18:03:00 +01:00
|
|
|
var info string
|
|
|
|
row := stmtGetXonker.QueryRow(ident, "boxes")
|
|
|
|
err := row.Scan(&info)
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
2022-02-06 06:42:13 +01:00
|
|
|
dlog.Printf("ingesting boxes: %s", ident)
|
2019-11-11 18:03:00 +01:00
|
|
|
inbox, _ := obj.GetString("inbox")
|
|
|
|
outbox, _ := obj.GetString("outbox")
|
|
|
|
sbox, _ := obj.GetString("endpoints", "sharedInbox")
|
|
|
|
if inbox != "" {
|
2019-11-25 21:50:17 +01:00
|
|
|
when := time.Now().UTC().Format(dbtimeformat)
|
2019-11-11 18:03:00 +01:00
|
|
|
m := strings.Join([]string{inbox, outbox, sbox}, " ")
|
2019-11-25 21:50:17 +01:00
|
|
|
_, err = stmtSaveXonker.Exec(ident, m, "boxes", when)
|
2019-11-11 18:03:00 +01:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error saving boxes: %s", err)
|
2019-11-11 18:03:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-11 18:52:08 +01:00
|
|
|
|
|
|
|
func ingesthandle(origin string, obj junk.Junk) {
|
|
|
|
xid, _ := obj.GetString("id")
|
|
|
|
if xid == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if originate(xid) != origin {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var handle string
|
|
|
|
row := stmtGetXonker.QueryRow(xid, "handle")
|
|
|
|
err := row.Scan(&handle)
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
handle, _ = obj.GetString("preferredUsername")
|
|
|
|
if handle != "" {
|
2019-11-25 21:50:17 +01:00
|
|
|
when := time.Now().UTC().Format(dbtimeformat)
|
|
|
|
_, err = stmtSaveXonker.Exec(xid, handle, "handle", when)
|
2019-11-11 18:52:08 +01:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error saving handle: %s", err)
|
2019-11-11 18:52:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-01 05:50:47 +02:00
|
|
|
|
|
|
|
func updateMe(username string) {
|
|
|
|
var user *WhatAbout
|
|
|
|
somenamedusers.Get(username, &user)
|
|
|
|
dt := time.Now().UTC().Format(time.RFC3339)
|
|
|
|
j := junk.New()
|
|
|
|
j["@context"] = itiswhatitis
|
|
|
|
j["id"] = fmt.Sprintf("%s/upme/%s/%d", user.URL, user.Name, time.Now().Unix())
|
|
|
|
j["actor"] = user.URL
|
|
|
|
j["published"] = dt
|
2020-09-26 00:49:47 +02:00
|
|
|
j["to"] = thewholeworld
|
2020-04-01 05:50:47 +02:00
|
|
|
j["type"] = "Update"
|
2020-05-01 07:34:08 +02:00
|
|
|
j["object"] = junkuser(user)
|
2020-04-01 05:50:47 +02:00
|
|
|
|
|
|
|
msg := j.ToBytes()
|
|
|
|
|
|
|
|
rcpts := make(map[string]bool)
|
|
|
|
for _, f := range getdubs(user.ID) {
|
|
|
|
if f.XID == user.URL {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var box *Box
|
|
|
|
boxofboxes.Get(f.XID, &box)
|
|
|
|
if box != nil && box.Shared != "" {
|
|
|
|
rcpts["%"+box.Shared] = true
|
|
|
|
} else {
|
|
|
|
rcpts[f.XID] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for a := range rcpts {
|
2023-06-12 21:01:03 +02:00
|
|
|
go deliverate(user.ID, a, msg)
|
2020-04-01 05:50:47 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-09 19:58:48 +02:00
|
|
|
|
|
|
|
func followme(user *WhatAbout, who string, name string, j junk.Junk) {
|
2020-09-14 20:59:45 +02:00
|
|
|
folxid, _ := j.GetString("id")
|
|
|
|
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("updating honker follow: %s %s", who, folxid)
|
2020-09-09 19:58:48 +02:00
|
|
|
|
|
|
|
var x string
|
|
|
|
db := opendatabase()
|
|
|
|
row := db.QueryRow("select xid from honkers where name = ? and xid = ? and userid = ? and flavor in ('dub', 'undub')", name, who, user.ID)
|
|
|
|
err := row.Scan(&x)
|
|
|
|
if err != sql.ErrNoRows {
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("duplicate follow request: %s", who)
|
2020-09-14 20:59:45 +02:00
|
|
|
_, err = stmtUpdateFlavor.Exec("dub", folxid, user.ID, name, who, "undub")
|
2020-09-09 19:58:48 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error updating honker: %s", err)
|
2020-09-09 19:58:48 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-09-14 20:59:45 +02:00
|
|
|
stmtSaveDub.Exec(user.ID, name, who, "dub", folxid)
|
2020-09-09 19:58:48 +02:00
|
|
|
}
|
|
|
|
go rubadubdub(user, j)
|
|
|
|
}
|
|
|
|
|
|
|
|
func unfollowme(user *WhatAbout, who string, name string, j junk.Junk) {
|
2020-09-14 21:44:21 +02:00
|
|
|
var folxid string
|
|
|
|
if who == "" {
|
|
|
|
folxid, _ = j.GetString("object")
|
|
|
|
|
|
|
|
db := opendatabase()
|
|
|
|
row := db.QueryRow("select xid, name from honkers where userid = ? and folxid = ? and flavor in ('dub', 'undub')", user.ID, folxid)
|
|
|
|
err := row.Scan(&who, &name)
|
|
|
|
if err != nil {
|
|
|
|
if err != sql.ErrNoRows {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error scanning honker: %s", err)
|
2020-09-14 21:44:21 +02:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-09-14 20:59:45 +02:00
|
|
|
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("updating honker undo: %s %s", who, folxid)
|
2020-09-14 20:59:45 +02:00
|
|
|
_, err := stmtUpdateFlavor.Exec("undub", folxid, user.ID, name, who, "dub")
|
2020-09-09 19:58:48 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error updating honker: %s", err)
|
2020-09-09 19:58:48 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-01 20:48:50 +01:00
|
|
|
func followyou(user *WhatAbout, honkerid int64, sync bool) {
|
2020-09-09 20:33:12 +02:00
|
|
|
var url, owner string
|
|
|
|
db := opendatabase()
|
|
|
|
row := db.QueryRow("select xid, owner from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep', 'presub', 'sub')",
|
|
|
|
honkerid, user.ID)
|
|
|
|
err := row.Scan(&url, &owner)
|
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("can't get honker xid: %s", err)
|
2020-09-09 20:33:12 +02:00
|
|
|
return
|
|
|
|
}
|
2020-09-10 20:52:24 +02:00
|
|
|
folxid := xfiltrate()
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("subscribing to %s", url)
|
2020-09-10 20:52:24 +02:00
|
|
|
_, err = db.Exec("update honkers set flavor = ?, folxid = ? where honkerid = ?", "presub", folxid, honkerid)
|
2020-09-09 20:33:12 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error updating honker: %s", err)
|
2020-09-09 20:33:12 +02:00
|
|
|
return
|
|
|
|
}
|
2023-03-01 20:48:50 +01:00
|
|
|
if sync {
|
|
|
|
subsub(user, url, owner, folxid)
|
|
|
|
} else {
|
|
|
|
go subsub(user, url, owner, folxid)
|
|
|
|
}
|
2020-09-09 20:33:12 +02:00
|
|
|
|
|
|
|
}
|
2023-03-01 20:48:50 +01:00
|
|
|
func unfollowyou(user *WhatAbout, honkerid int64, sync bool) {
|
2020-09-09 20:33:12 +02:00
|
|
|
db := opendatabase()
|
2023-03-17 19:28:29 +01:00
|
|
|
row := db.QueryRow("select xid, owner, folxid, flavor from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep', 'presub', 'sub')",
|
2020-09-09 20:33:12 +02:00
|
|
|
honkerid, user.ID)
|
2023-03-17 19:28:29 +01:00
|
|
|
var url, owner, folxid, flavor string
|
|
|
|
err := row.Scan(&url, &owner, &folxid, &flavor)
|
2020-09-09 20:33:12 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("can't get honker xid: %s", err)
|
2020-09-09 20:33:12 +02:00
|
|
|
return
|
|
|
|
}
|
2023-03-17 19:28:29 +01:00
|
|
|
if flavor == "peep" {
|
|
|
|
return
|
|
|
|
}
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("unsubscribing from %s", url)
|
2020-09-09 20:33:12 +02:00
|
|
|
_, err = db.Exec("update honkers set flavor = ? where honkerid = ?", "unsub", honkerid)
|
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error updating honker: %s", err)
|
2020-09-09 20:33:12 +02:00
|
|
|
return
|
|
|
|
}
|
2023-03-01 20:48:50 +01:00
|
|
|
if sync {
|
|
|
|
itakeitallback(user, url, owner, folxid)
|
|
|
|
} else {
|
|
|
|
go itakeitallback(user, url, owner, folxid)
|
|
|
|
}
|
2020-09-09 20:33:12 +02:00
|
|
|
}
|
|
|
|
|
2020-09-09 19:58:48 +02:00
|
|
|
func followyou2(user *WhatAbout, j junk.Junk) {
|
|
|
|
who, _ := j.GetString("actor")
|
|
|
|
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("updating honker accept: %s", who)
|
2020-09-09 19:58:48 +02:00
|
|
|
db := opendatabase()
|
2023-01-25 01:10:17 +01:00
|
|
|
row := db.QueryRow("select name, folxid from honkers where userid = ? and xid = ? and flavor in ('presub', 'sub')",
|
2020-09-09 19:58:48 +02:00
|
|
|
user.ID, who)
|
2020-09-14 20:59:45 +02:00
|
|
|
var name, folxid string
|
|
|
|
err := row.Scan(&name, &folxid)
|
2020-09-09 19:58:48 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("can't get honker name: %s", err)
|
2020-09-09 19:58:48 +02:00
|
|
|
return
|
|
|
|
}
|
2020-09-14 20:59:45 +02:00
|
|
|
_, err = stmtUpdateFlavor.Exec("sub", folxid, user.ID, name, who, "presub")
|
2020-09-09 19:58:48 +02:00
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error updating honker: %s", err)
|
2020-09-09 19:58:48 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-10-13 21:12:56 +02:00
|
|
|
|
|
|
|
func nofollowyou2(user *WhatAbout, j junk.Junk) {
|
|
|
|
who, _ := j.GetString("actor")
|
|
|
|
|
2022-02-06 06:42:13 +01:00
|
|
|
ilog.Printf("updating honker reject: %s", who)
|
2020-10-13 21:12:56 +02:00
|
|
|
db := opendatabase()
|
|
|
|
row := db.QueryRow("select name, folxid from honkers where userid = ? and xid = ? and flavor in ('presub', 'sub')",
|
|
|
|
user.ID, who)
|
|
|
|
var name, folxid string
|
|
|
|
err := row.Scan(&name, &folxid)
|
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("can't get honker name: %s", err)
|
2020-10-13 21:12:56 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
_, err = stmtUpdateFlavor.Exec("unsub", folxid, user.ID, name, who, "presub")
|
|
|
|
_, err = stmtUpdateFlavor.Exec("unsub", folxid, user.ID, name, who, "sub")
|
|
|
|
if err != nil {
|
2022-02-06 06:42:13 +01:00
|
|
|
elog.Printf("error updating honker: %s", err)
|
2020-10-13 21:12:56 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|