Added prototype send pleroma emoji reactions via reactions page

This commit is contained in:
localhost_frssoft 2022-10-19 19:15:52 +03:00
parent 80170099f8
commit 9cdac3e623
14 changed files with 5128 additions and 2 deletions

View File

@ -139,7 +139,9 @@ type LikedByData struct {
//For Pleroma reactions
type ReactedByData struct {
*CommonData
Reactions []*mastodon.ReactionsPleroma
Reactions []*mastodon.ReactionsPleroma
ReactionEmojis map[string]string
ID string
}
type RetweetedByData struct {

View File

@ -11,6 +11,8 @@ import (
"bloat/model"
"bloat/renderer"
"bloat/util"
"github.com/enescakir/emoji"
)
var (
@ -513,7 +515,9 @@ func (s *service) ReactedByPage(c *client, id string) (err error) {
cdata := s.cdata(c, "reactions", 0, 0, "")
data := &renderer.ReactedByData{
CommonData: cdata,
ID: id,
Reactions: reactions,
ReactionEmojis: emoji.Map(),
}
return s.renderer.Render(c.rctx, c.w, renderer.ReactedByPage, data)
}

View File

@ -1,8 +1,20 @@
{{with .Data}}
{{template "header.tmpl" (WithContext .CommonData $.Ctx)}}
{{$st_id := .ID}}
<div class="scrollable-emoji" style="overflow-y: scroll; height:400px;">
<div class="pleroma-reactions">
{{range $shortcode, $code := .ReactionEmojis}}
<form action="/react-with/{{$st_id}}?emoji={{$code}}" method="post" target="_self" title="{{$shortcode}}">
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
<input type="submit" value="{{$code}}" class="pleroma-emoji">
</form>
{{end}}
</div>
</div>
{{range .Reactions}}
<div class="page-title">{{.Name}}</div>
{{template "userlist.tmpl" (WithContext .Accounts $.Ctx)}}
</div>
{{end}}
{{end}}

15
vendor/github.com/enescakir/emoji/.gitignore generated vendored Normal file
View File

@ -0,0 +1,15 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/

21
vendor/github.com/enescakir/emoji/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Enes Çakır
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

99
vendor/github.com/enescakir/emoji/README.md generated vendored Normal file
View File

@ -0,0 +1,99 @@
# emoji :rocket: :school_satchel: :tada:
[![Build Status](https://github.com/enescakir/emoji/workflows/build/badge.svg?branch=master)](https://github.com/enescakir/emoji/actions)
[![godoc](https://godoc.org/github.com/enescakir/emoji?status.svg)](https://godoc.org/github.com/enescakir/emoji)
[![Go Report Card](https://goreportcard.com/badge/github.com/enescakir/emoji)](https://goreportcard.com/report/github.com/enescakir/emoji)
[![Codecov](https://img.shields.io/codecov/c/github/enescakir/emoji)](https://codecov.io/gh/enescakir/emoji)
[![MIT License](https://img.shields.io/github/license/enescakir/emoji)](https://github.com/enescakir/emoji/blob/master/LICENSE)
`emoji` is a minimalistic emoji library for Go. It lets you use emoji characters in strings.
Inspired by [spatie/emoji](https://github.com/spatie/emoji)
## Install :floppy_disk:
``` bash
go get github.com/enescakir/emoji
```
## Usage :surfer:
```go
package main
import (
"fmt"
"github.com/enescakir/emoji"
)
func main() {
fmt.Printf("Hello %v\n", emoji.WavingHand)
fmt.Printf("I am %v from %v\n",
emoji.ManTechnologist,
emoji.FlagForTurkey,
)
fmt.Printf("Different skin tones.\n default: %v light: %v dark: %v\n",
emoji.ThumbsUp,
emoji.OkHand.Tone(emoji.Light),
emoji.CallMeHand.Tone(emoji.Dark),
)
fmt.Printf("Emojis with multiple skin tones.\n both medium: %v light and dark: %v\n",
emoji.PeopleHoldingHands.Tone(emoji.Medium),
emoji.PeopleHoldingHands.Tone(emoji.Light, emoji.Dark),
)
fmt.Println(emoji.Parse("Emoji aliases are :sunglasses:"))
emoji.Println("Use fmt wrappers :+1: with emoji support :tada:")
}
/* OUTPUT
Hello 👋
I am 👨‍💻 from 🇹🇷
Different skin tones.
default: 👍 light: 👌🏻 dark: 🤙🏿
Emojis with multiple skin tones.
both medium: 🧑🏽‍🤝‍🧑🏽 light and dark: 🧑🏻‍🤝‍🧑🏿
Emoji aliases are 😎
Use fmt wrappers 👍 with emoji support 🎉
*/
```
This package contains emojis constants based on [Full Emoji List v13.0](https://unicode.org/Public/emoji/13.0/emoji-test.txt).
```go
emoji.CallMeHand // 🤙
emoji.CallMeHand.Tone(emoji.Dark) // 🤙🏿
```
Also, it has additional emoji aliases from [github/gemoji](https://github.com/github/gemoji).
```go
emoji.Parse(":+1:") // 👍
emoji.Parse(":100:") // 💯
```
You can generate country flag emoji with [ISO 3166 Alpha2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) codes:
```go
emoji.CountryFlag("tr") // 🇹🇷
emoji.CountryFlag("US") // 🇺🇸
emoji.Parse("country flag alias :flag-gb:") // country flag alias 🇬🇧
```
All constants are generated by `internal/generator`.
## Testing :hammer:
``` bash
go test
```
## Todo :pushpin:
* Add examples to `godoc`
## Contributing :man_technologist:
I am accepting PRs that add aliases to the package.
You have to add it to `customEmojis` list at `internal/generator/main`.
If you think an emoji constant is not correct, open an issue.
Please use [this list](http://unicode.org/emoji/charts/full-emoji-list.html)
to look up the correct unicode value and the name of the character.
## Credits :star:
- [Enes Çakır](https://github.com/enescakir)
## License :scroll:
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

1944
vendor/github.com/enescakir/emoji/constants.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

4
vendor/github.com/enescakir/emoji/doc.go generated vendored Normal file
View File

@ -0,0 +1,4 @@
/*
Package emoji makes working with emojis easier.
*/
package emoji

124
vendor/github.com/enescakir/emoji/emoji.go generated vendored Normal file
View File

@ -0,0 +1,124 @@
package emoji
import (
"fmt"
"strings"
)
// Base attributes
const (
TonePlaceholder = "@"
flagBaseIndex = '\U0001F1E6' - 'a'
)
// Skin tone colors
const (
Default Tone = ""
Light Tone = "\U0001F3FB"
MediumLight Tone = "\U0001F3FC"
Medium Tone = "\U0001F3FD"
MediumDark Tone = "\U0001F3FE"
Dark Tone = "\U0001F3FF"
)
// Emoji defines an emoji object with no skin variations.
type Emoji string
// String returns string representation of the simple emoji.
func (e Emoji) String() string {
return string(e)
}
// EmojiWithTone defines an emoji object that has skin tone options.
type EmojiWithTone struct {
oneTonedCode string
twoTonedCode string
defaultTone Tone
}
// newEmojiWithTone constructs a new emoji object that has skin tone options.
func newEmojiWithTone(codes ...string) EmojiWithTone {
if len(codes) == 0 {
return EmojiWithTone{}
}
one := codes[0]
two := codes[0]
if len(codes) > 1 {
two = codes[1]
}
return EmojiWithTone{
oneTonedCode: one,
twoTonedCode: two,
}
}
// withDefaultTone sets default tone for an emoji and returns it.
func (e EmojiWithTone) withDefaultTone(tone string) EmojiWithTone {
e.defaultTone = Tone(tone)
return e
}
// String returns string representation of the emoji with default skin tone.
func (e EmojiWithTone) String() string {
return strings.ReplaceAll(e.oneTonedCode, TonePlaceholder, e.defaultTone.String())
}
// Tone returns string representation of the emoji with given skin tone.
func (e EmojiWithTone) Tone(tones ...Tone) string {
// if no tone given, return with default skin tone
if len(tones) == 0 {
return e.String()
}
str := e.twoTonedCode
replaceCount := 1
// if one tone given or emoji doesn't have twoTonedCode, use oneTonedCode
// Also, replace all with one tone
if len(tones) == 1 {
str = e.oneTonedCode
replaceCount = -1
}
// replace tone one by one
for _, t := range tones {
// use emoji's default tone
if t == Default {
t = e.defaultTone
}
str = strings.Replace(str, TonePlaceholder, t.String(), replaceCount)
}
return str
}
// Tone defines skin tone options for emojis.
type Tone string
// String returns string representation of the skin tone.
func (t Tone) String() string {
return string(t)
}
// CountryFlag returns a country flag emoji from given country code.
// Full list of country codes: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
func CountryFlag(code string) (Emoji, error) {
if len(code) != 2 {
return "", fmt.Errorf("not valid country code: %q", code)
}
code = strings.ToLower(code)
flag := countryCodeLetter(code[0]) + countryCodeLetter(code[1])
return Emoji(flag), nil
}
// countryCodeLetter shifts given letter byte as flagBaseIndex.
func countryCodeLetter(l byte) string {
return string(rune(l) + flagBaseIndex)
}

56
vendor/github.com/enescakir/emoji/fmt.go generated vendored Normal file
View File

@ -0,0 +1,56 @@
package emoji
import (
"fmt"
"io"
)
// Sprint wraps fmt.Sprint with emoji support
func Sprint(a ...interface{}) string {
return Parse(fmt.Sprint(a...))
}
// Sprintf wraps fmt.Sprintf with emoji support
func Sprintf(format string, a ...interface{}) string {
return Parse(fmt.Sprintf(format, a...))
}
// Sprintln wraps fmt.Sprintln with emoji support
func Sprintln(a ...interface{}) string {
return Parse(fmt.Sprintln(a...))
}
// Print wraps fmt.Print with emoji support
func Print(a ...interface{}) (n int, err error) {
return fmt.Print(Sprint(a...))
}
// Println wraps fmt.Println with emoji support
func Println(a ...interface{}) (n int, err error) {
return fmt.Println(Sprint(a...))
}
// Printf wraps fmt.Printf with emoji support
func Printf(format string, a ...interface{}) (n int, err error) {
return fmt.Print(Sprintf(format, a...))
}
// Fprint wraps fmt.Fprint with emoji support
func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
return fmt.Fprint(w, Sprint(a...))
}
// Fprintf wraps fmt.Fprintf with emoji support
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
return fmt.Fprint(w, Sprintf(format, a...))
}
// Fprintln wraps fmt.Fprintln with emoji support
func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
return fmt.Fprintln(w, Sprint(a...))
}
// Errorf wraps fmt.Errorf with emoji support
func Errorf(format string, a ...interface{}) error {
return fmt.Errorf(Sprintf(format, a...))
}

3
vendor/github.com/enescakir/emoji/go.mod generated vendored Normal file
View File

@ -0,0 +1,3 @@
module github.com/enescakir/emoji
go 1.13

0
vendor/github.com/enescakir/emoji/go.sum generated vendored Normal file
View File

2715
vendor/github.com/enescakir/emoji/map.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

127
vendor/github.com/enescakir/emoji/parser.go generated vendored Normal file
View File

@ -0,0 +1,127 @@
package emoji
import (
"fmt"
"regexp"
"strings"
"unicode"
)
var (
flagRegex = regexp.MustCompile(`^:flag-([a-zA-Z]{2}):$`)
)
// Parse replaces emoji aliases (:pizza:) with unicode representation.
func Parse(input string) string {
var matched strings.Builder
var output strings.Builder
for _, r := range input {
// when it's not `:`, it might be inner or outer of the emoji alias
if r != ':' {
// if matched is empty, it's the outer of the emoji alias
if matched.Len() == 0 {
output.WriteRune(r)
continue
}
matched.WriteRune(r)
// if it's space, the alias's not valid.
// reset matched for breaking the emoji alias
if unicode.IsSpace(r) {
output.WriteString(matched.String())
matched.Reset()
}
continue
}
// r is `:` now
// if matched is empty, it's the beginning of the emoji alias
if matched.Len() == 0 {
matched.WriteRune(r)
continue
}
// it's the end of the emoji alias
match := matched.String()
alias := match + ":"
// check for emoji alias
if code, ok := Find(alias); ok {
output.WriteString(code)
matched.Reset()
continue
}
// not found any emoji
output.WriteString(match)
// it might be the beginning of the another emoji alias
matched.Reset()
matched.WriteRune(r)
}
// if matched not empty, add it to output
if matched.Len() != 0 {
output.WriteString(matched.String())
matched.Reset()
}
return output.String()
}
// Map returns the emojis map.
// Key is the alias of the emoji.
// Value is the code of the emoji.
func Map() map[string]string {
return emojiMap
}
// AppendAlias adds new emoji pair to the emojis map.
func AppendAlias(alias, code string) error {
if c, ok := emojiMap[alias]; ok {
return fmt.Errorf("emoji already exist: %q => %+q", alias, c)
}
for _, r := range alias {
if unicode.IsSpace(r) {
return fmt.Errorf("emoji alias is not valid: %q", alias)
}
}
emojiMap[alias] = code
return nil
}
// Exist checks existence of the emoji by alias.
func Exist(alias string) bool {
_, ok := Find(alias)
return ok
}
// Find returns the emoji code by alias.
func Find(alias string) (string, bool) {
if code, ok := emojiMap[alias]; ok {
return code, true
}
if flag := checkFlag(alias); len(flag) > 0 {
return flag, true
}
return "", false
}
// checkFlag finds flag emoji for `flag-[CODE]` pattern
func checkFlag(alias string) string {
if matches := flagRegex.FindStringSubmatch(alias); len(matches) == 2 {
flag, _ := CountryFlag(matches[1])
return flag.String()
}
return ""
}