2019-04-09 11:59:33 +00: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 (
|
|
|
|
"html/template"
|
2019-10-21 06:28:35 +00:00
|
|
|
"strconv"
|
2019-10-03 04:11:02 +00:00
|
|
|
"strings"
|
2019-04-09 11:59:33 +00:00
|
|
|
"time"
|
2020-01-19 08:44:38 +00:00
|
|
|
|
|
|
|
"humungus.tedunangst.com/r/webs/httpsig"
|
2019-04-09 11:59:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type WhatAbout struct {
|
2019-10-29 05:00:38 +00:00
|
|
|
ID int64
|
|
|
|
Name string
|
|
|
|
Display string
|
|
|
|
About string
|
2020-09-25 23:02:26 +00:00
|
|
|
HTAbout template.HTML
|
2020-09-25 23:09:01 +00:00
|
|
|
Onts []string
|
2019-10-29 05:00:38 +00:00
|
|
|
Key string
|
|
|
|
URL string
|
|
|
|
Options UserOptions
|
2020-01-19 08:44:38 +00:00
|
|
|
SecKey httpsig.PrivateKey
|
2019-10-29 05:00:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type UserOptions struct {
|
2023-01-26 21:38:52 +00:00
|
|
|
SkinnyCSS bool `json:",omitempty"`
|
|
|
|
OmitImages bool `json:",omitempty"`
|
|
|
|
MentionAll bool `json:",omitempty"`
|
|
|
|
InlineQuotes bool `json:",omitempty"`
|
|
|
|
Avatar string `json:",omitempty"`
|
|
|
|
Banner string `json:",omitempty"`
|
|
|
|
MapLink string `json:",omitempty"`
|
|
|
|
Reaction string `json:",omitempty"`
|
|
|
|
MeCount int64
|
|
|
|
ChatCount int64
|
2019-04-09 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 22:46:27 +00:00
|
|
|
type KeyInfo struct {
|
|
|
|
keyname string
|
2020-01-19 08:44:38 +00:00
|
|
|
seckey httpsig.PrivateKey
|
2019-10-25 22:46:27 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 21:31:48 +00:00
|
|
|
const serverUID int64 = -2
|
2022-12-26 18:27:39 +00:00
|
|
|
const readyLuserOne int64 = 1
|
2019-10-25 21:31:48 +00:00
|
|
|
|
2019-04-13 17:58:42 +00:00
|
|
|
type Honk struct {
|
|
|
|
ID int64
|
|
|
|
UserID int64
|
|
|
|
Username string
|
|
|
|
What string
|
|
|
|
Honker string
|
2019-06-03 04:22:00 +00:00
|
|
|
Handle string
|
2020-08-05 19:33:27 +00:00
|
|
|
Handles string
|
2019-05-15 20:27:50 +00:00
|
|
|
Oonker string
|
2019-07-05 17:07:59 +00:00
|
|
|
Oondle string
|
2019-04-13 17:58:42 +00:00
|
|
|
XID string
|
|
|
|
RID string
|
|
|
|
Date time.Time
|
|
|
|
URL string
|
|
|
|
Noise string
|
2019-05-15 20:27:50 +00:00
|
|
|
Precis string
|
2019-09-11 20:20:22 +00:00
|
|
|
Format string
|
2019-04-19 15:08:22 +00:00
|
|
|
Convoy string
|
2019-04-13 17:58:42 +00:00
|
|
|
Audience []string
|
2019-05-28 06:36:47 +00:00
|
|
|
Public bool
|
2019-05-20 14:48:02 +00:00
|
|
|
Whofore int64
|
2019-08-19 03:25:11 +00:00
|
|
|
Replies []*Honk
|
2019-08-16 19:13:33 +00:00
|
|
|
Flags int64
|
2019-09-18 19:08:50 +00:00
|
|
|
HTPrecis template.HTML
|
2019-04-13 17:58:42 +00:00
|
|
|
HTML template.HTML
|
2019-07-08 00:24:54 +00:00
|
|
|
Style string
|
2019-07-10 18:36:14 +00:00
|
|
|
Open string
|
2019-04-13 17:58:42 +00:00
|
|
|
Donks []*Donk
|
2019-08-25 03:11:53 +00:00
|
|
|
Onts []string
|
2019-09-28 04:12:50 +00:00
|
|
|
Place *Place
|
2019-10-02 21:27:29 +00:00
|
|
|
Time *Time
|
2019-11-27 19:36:29 +00:00
|
|
|
Mentions []Mention
|
2021-02-09 13:18:22 +00:00
|
|
|
Badonks []Badonk
|
|
|
|
}
|
|
|
|
|
|
|
|
type Badonk struct {
|
|
|
|
Who string
|
|
|
|
What string
|
2019-11-27 19:36:29 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 21:15:29 +00:00
|
|
|
type Chonk struct {
|
|
|
|
ID int64
|
|
|
|
UserID int64
|
|
|
|
XID string
|
|
|
|
Who string
|
|
|
|
Target string
|
|
|
|
Date time.Time
|
|
|
|
Noise string
|
|
|
|
Format string
|
2020-05-15 03:51:42 +00:00
|
|
|
Donks []*Donk
|
2020-05-13 21:15:29 +00:00
|
|
|
Handle string
|
|
|
|
HTML template.HTML
|
|
|
|
}
|
|
|
|
|
2020-05-23 23:17:30 +00:00
|
|
|
type Chatter struct {
|
|
|
|
Target string
|
|
|
|
Chonks []*Chonk
|
|
|
|
}
|
|
|
|
|
2019-11-27 19:36:29 +00:00
|
|
|
type Mention struct {
|
|
|
|
Who string
|
|
|
|
Where string
|
2019-04-09 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 05:07:27 +00:00
|
|
|
func (mention *Mention) IsPresent(noise string) bool {
|
|
|
|
nick := strings.TrimLeft(mention.Who, "@")
|
|
|
|
idx := strings.IndexByte(nick, '@')
|
|
|
|
if idx != -1 {
|
|
|
|
nick = nick[:idx]
|
2022-05-31 04:24:02 +00:00
|
|
|
}
|
2022-05-31 05:07:27 +00:00
|
|
|
return strings.Contains(noise, ">@"+nick) || strings.Contains(noise, "@<span>"+nick)
|
2022-05-31 04:24:02 +00:00
|
|
|
}
|
|
|
|
|
2023-07-31 00:31:00 +00:00
|
|
|
func OntIsPresent(ont, noise string) bool {
|
2023-07-31 01:31:53 +00:00
|
|
|
ont = strings.ToLower(ont[1:])
|
2023-07-31 01:01:45 +00:00
|
|
|
idx := strings.IndexByte(noise, '#')
|
|
|
|
for idx >= 0 {
|
|
|
|
if strings.HasPrefix(noise[idx:], "#<span>") {
|
2023-07-31 01:31:53 +00:00
|
|
|
idx += 6
|
2023-07-31 01:01:45 +00:00
|
|
|
}
|
2023-07-31 01:31:53 +00:00
|
|
|
idx += 1
|
2023-07-31 23:46:55 +00:00
|
|
|
if idx+len(ont) >= len(noise) {
|
2023-07-31 01:01:45 +00:00
|
|
|
return false
|
|
|
|
}
|
2023-07-31 23:46:55 +00:00
|
|
|
test := noise[idx : idx+len(ont)]
|
2023-07-31 01:01:45 +00:00
|
|
|
test = strings.ToLower(test)
|
|
|
|
if test == ont {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
newidx := strings.IndexByte(noise[idx:], '#')
|
|
|
|
if newidx == -1 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
idx += newidx
|
|
|
|
}
|
|
|
|
return false
|
2023-07-31 00:31:00 +00:00
|
|
|
}
|
|
|
|
|
2019-10-02 21:10:01 +00:00
|
|
|
type OldRevision struct {
|
|
|
|
Precis string
|
|
|
|
Noise string
|
|
|
|
}
|
|
|
|
|
2019-08-16 19:35:12 +00:00
|
|
|
const (
|
2019-10-29 23:14:41 +00:00
|
|
|
flagIsAcked = 1
|
|
|
|
flagIsBonked = 2
|
|
|
|
flagIsSaved = 4
|
|
|
|
flagIsUntagged = 8
|
2020-01-23 23:08:15 +00:00
|
|
|
flagIsReacted = 16
|
2019-08-16 19:35:12 +00:00
|
|
|
)
|
|
|
|
|
2019-08-19 04:01:00 +00:00
|
|
|
func (honk *Honk) IsAcked() bool {
|
|
|
|
return honk.Flags&flagIsAcked != 0
|
2019-08-16 19:35:12 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 00:43:30 +00:00
|
|
|
func (honk *Honk) IsBonked() bool {
|
|
|
|
return honk.Flags&flagIsBonked != 0
|
|
|
|
}
|
|
|
|
|
2019-10-11 20:03:17 +00:00
|
|
|
func (honk *Honk) IsSaved() bool {
|
|
|
|
return honk.Flags&flagIsSaved != 0
|
|
|
|
}
|
|
|
|
|
2019-10-29 23:14:41 +00:00
|
|
|
func (honk *Honk) IsUntagged() bool {
|
|
|
|
return honk.Flags&flagIsUntagged != 0
|
|
|
|
}
|
|
|
|
|
2020-01-23 23:08:15 +00:00
|
|
|
func (honk *Honk) IsReacted() bool {
|
|
|
|
return honk.Flags&flagIsReacted != 0
|
|
|
|
}
|
|
|
|
|
2019-04-13 17:58:42 +00:00
|
|
|
type Donk struct {
|
2020-10-01 17:18:05 +00:00
|
|
|
FileID int64
|
|
|
|
XID string
|
|
|
|
Name string
|
|
|
|
Desc string
|
|
|
|
URL string
|
|
|
|
Media string
|
|
|
|
Local bool
|
|
|
|
External bool
|
2019-04-09 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 04:12:50 +00:00
|
|
|
type Place struct {
|
|
|
|
Name string
|
|
|
|
Latitude float64
|
|
|
|
Longitude float64
|
2019-09-29 20:07:35 +00:00
|
|
|
Url string
|
2019-09-28 04:12:50 +00:00
|
|
|
}
|
|
|
|
|
2019-10-03 04:11:02 +00:00
|
|
|
type Duration int64
|
|
|
|
|
|
|
|
func (d Duration) String() string {
|
|
|
|
s := time.Duration(d).String()
|
|
|
|
if strings.HasSuffix(s, "m0s") {
|
|
|
|
s = s[:len(s)-2]
|
|
|
|
}
|
|
|
|
if strings.HasSuffix(s, "h0m") {
|
|
|
|
s = s[:len(s)-2]
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2019-10-21 06:28:35 +00:00
|
|
|
func parseDuration(s string) time.Duration {
|
|
|
|
didx := strings.IndexByte(s, 'd')
|
|
|
|
if didx != -1 {
|
|
|
|
days, _ := strconv.ParseInt(s[:didx], 10, 0)
|
|
|
|
dur, _ := time.ParseDuration(s[didx:])
|
|
|
|
return dur + 24*time.Hour*time.Duration(days)
|
|
|
|
}
|
|
|
|
dur, _ := time.ParseDuration(s)
|
|
|
|
return dur
|
|
|
|
}
|
|
|
|
|
2019-10-02 21:27:29 +00:00
|
|
|
type Time struct {
|
|
|
|
StartTime time.Time
|
|
|
|
EndTime time.Time
|
2019-10-03 04:11:02 +00:00
|
|
|
Duration Duration
|
2019-10-02 21:27:29 +00:00
|
|
|
}
|
|
|
|
|
2019-04-13 17:58:42 +00:00
|
|
|
type Honker struct {
|
|
|
|
ID int64
|
|
|
|
UserID int64
|
|
|
|
Name string
|
|
|
|
XID string
|
2019-08-16 03:27:55 +00:00
|
|
|
Handle string
|
2019-04-13 17:58:42 +00:00
|
|
|
Flavor string
|
2019-04-22 21:03:55 +00:00
|
|
|
Combos []string
|
2019-12-04 05:44:45 +00:00
|
|
|
Meta HonkerMeta
|
2019-12-02 23:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type HonkerMeta struct {
|
|
|
|
Notes string
|
2019-04-09 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
2019-10-26 22:31:42 +00:00
|
|
|
type SomeThing struct {
|
|
|
|
What int
|
|
|
|
XID string
|
|
|
|
Owner string
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
SomeNothing int = iota
|
|
|
|
SomeActor
|
|
|
|
SomeCollection
|
|
|
|
)
|