mirror of
https://git.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-22 03:51:28 +00:00
update README and hardcode poll options to 20
This commit is contained in:
parent
8dcd6cfdd7
commit
4c0c1c40a8
4
README
4
README
|
@ -12,6 +12,10 @@ Changes (localhost_custom fork):
|
|||
- visible edited post time
|
||||
- visible quoted post (status in status)
|
||||
- visible profile banner in spoiler
|
||||
- add schedule status
|
||||
- add language input form
|
||||
- add expiry status
|
||||
- add support for send poll (hardcoded to 20 options)
|
||||
- hide boosts in spoiler
|
||||
- hide NSFW content and attachments in spoiler
|
||||
- some micro visual changes
|
||||
|
|
|
@ -213,6 +213,15 @@ type Toot struct {
|
|||
Language string `json:"language"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
ScheduledAt string `json:"scheduled_at"`
|
||||
Poll TootPoll `json:"poll"`
|
||||
}
|
||||
|
||||
// TootPoll is struct to poll in post status.
|
||||
type TootPoll struct {
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
HideTotals bool `json:"hide_totals"`
|
||||
Multiple bool `json:"multiple"`
|
||||
Options []string `json:"options"`
|
||||
}
|
||||
|
||||
// Mention hold information for mention.
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"encoding/json"
|
||||
"path"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type StatusPleroma struct {
|
||||
|
@ -367,7 +368,19 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
|
|||
if toot.ScheduledAt != "" {
|
||||
params.Set("scheduled_at", toot.ScheduledAt)
|
||||
}
|
||||
if len(toot.Poll.Options) > 2 {
|
||||
for _, option := range toot.Poll.Options {
|
||||
params.Add("poll[options][]", string(option))
|
||||
}
|
||||
params.Set("poll[expires_in]", strconv.Itoa(toot.Poll.ExpiresIn))
|
||||
if toot.Poll.Multiple {
|
||||
params.Set("poll[multiple]", "true")
|
||||
}
|
||||
if toot.Poll.HideTotals {
|
||||
params.Set("poll[hide_totals]", "true")
|
||||
}
|
||||
|
||||
}
|
||||
var status Status
|
||||
if toot.Edit != "" {
|
||||
err := c.doAPI(ctx, http.MethodPut, fmt.Sprintf("/api/v1/statuses/%s", toot.Edit), params, &status, nil)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"fmt"
|
||||
|
||||
"bloat/mastodon"
|
||||
)
|
||||
|
@ -67,6 +68,14 @@ func emojiFilter(content string, emojis []mastodon.Emoji) string {
|
|||
return strings.NewReplacer(replacements...).Replace(content)
|
||||
}
|
||||
|
||||
func generatePollOptions() string {
|
||||
var pollbuilder string
|
||||
for i := 0; i < 20; i++ {
|
||||
pollbuilder = pollbuilder + `<div><input id="` + fmt.Sprintf("poll-option-%d", i) + `" name="` + fmt.Sprintf("poll-option-%d", i) + `"></div>`
|
||||
}
|
||||
return pollbuilder
|
||||
}
|
||||
|
||||
var quoteRE = regexp.MustCompile("(?mU)(^|> *|\n)(>.*)(<br|$)")
|
||||
|
||||
func statusContentFilter(content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
|
||||
|
@ -158,6 +167,7 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) {
|
|||
t, err = t.Funcs(template.FuncMap{
|
||||
"EmojiFilter": emojiFilter,
|
||||
"Allowed_emoji_page": allowed_emoji_page,
|
||||
"GeneratePollOptions": generatePollOptions,
|
||||
"StatusContentFilter": statusContentFilter,
|
||||
"DisplayInteractionCount": displayInteractionCount,
|
||||
"TimeSince": timeSince,
|
||||
|
|
|
@ -978,7 +978,8 @@ func (s *service) Signout(c *client) (err error) {
|
|||
|
||||
func (s *service) Post(c *client, content string, replyToID string,
|
||||
format string, visibility string, isNSFW bool, spoilerText string,
|
||||
files []*multipart.FileHeader, edit string, language string, expiresIn int, scheduledAt string) (id string, err error) {
|
||||
files []*multipart.FileHeader, edit string, language string, expiresIn int, scheduledAt string,
|
||||
pollOptions []string, pollExpiresIn int, pollHideTotals bool, pollMultiple bool) (id string, err error) {
|
||||
|
||||
var mediaIDs []string
|
||||
for _, f := range files {
|
||||
|
@ -991,6 +992,13 @@ func (s *service) Post(c *client, content string, replyToID string,
|
|||
|
||||
expiresIn = expiresIn * 3600
|
||||
|
||||
pollTweet := mastodon.TootPoll{
|
||||
ExpiresIn: pollExpiresIn,
|
||||
Options: pollOptions,
|
||||
Multiple: pollMultiple,
|
||||
HideTotals: pollHideTotals,
|
||||
}
|
||||
|
||||
tweet := &mastodon.Toot{
|
||||
SpoilerText: spoilerText,
|
||||
Status: content,
|
||||
|
@ -1003,6 +1011,7 @@ func (s *service) Post(c *client, content string, replyToID string,
|
|||
Language: language,
|
||||
ExpiresIn: expiresIn, // pleroma compatible
|
||||
ScheduledAt: scheduledAt,
|
||||
Poll: pollTweet,
|
||||
}
|
||||
|
||||
st, err := c.PostStatus(c.ctx, tweet)
|
||||
|
|
|
@ -327,8 +327,22 @@ func NewHandler(s *service, verbose bool, staticDir string) http.Handler {
|
|||
}
|
||||
scheduledAt = string(scheduled.UTC().Format(time.RFC3339))
|
||||
}
|
||||
var pollOptions []string
|
||||
for i := 0; i < 16; i++ {
|
||||
v := c.r.FormValue(fmt.Sprintf("poll-option-%d", i))
|
||||
if len(v) == 0 {
|
||||
continue
|
||||
}
|
||||
pollOptions = append(pollOptions, v)
|
||||
}
|
||||
pollExpiresIn, err := strconv.Atoi(c.r.FormValue("poll-expires-in"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pollHideTotals := c.r.FormValue("poll-hide-totals") == "true"
|
||||
pollMultiple := c.r.FormValue("poll-is-multiple") == "true"
|
||||
|
||||
id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit, language, expiresIn, scheduledAt)
|
||||
id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit, language, expiresIn, scheduledAt, pollOptions, pollExpiresIn, pollHideTotals, pollMultiple)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -51,6 +51,21 @@
|
|||
<input id="lang-code" name="lang-code" placeholder="lang" title="Post language (ISO 639) [en, ru, etc..] Default: none" size="4" value="{{if .ReplyContext}}{{.ReplyContext.ReplyLanguage}}{{end}}">
|
||||
<input type="number" id="expires-in" name="expires-in" title="Post autodeleted after hour(s)" min="0" value="0" size="4">
|
||||
<input type="datetime-local" id="scheduled" name="scheduled" step=300 title="Schedule your status (timezone UTC+0)">
|
||||
<details><summary>Poll</summary>
|
||||
<div>
|
||||
<input type="number" id="poll-expires-in" name="poll-expires-in" min="1" value="300">
|
||||
<label for="poll-expires-in"> Expires in (secs) </label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="checkbox" id="poll-hide-totals" name="poll-hide-totals" value="true">
|
||||
<label for="poll-hide-totals"> Hide vote counts? </label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="checkbox" id="poll-is-multiple" name="poll-is-multiple" value="true">
|
||||
<label for="poll-is_multiple "> Allow multiple choice? </label>
|
||||
</div>
|
||||
<div>{{GeneratePollOptions | Raw}}</div>
|
||||
</details>
|
||||
</form>
|
||||
{{end}}
|
||||
|
||||
|
|
Loading…
Reference in a new issue