summaryrefslogtreecommitdiff
path: root/internal/typeutils/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/typeutils/util.go')
-rw-r--r--internal/typeutils/util.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/typeutils/util.go b/internal/typeutils/util.go
index 3a867ba35..1747dbdcd 100644
--- a/internal/typeutils/util.go
+++ b/internal/typeutils/util.go
@@ -19,6 +19,7 @@ package typeutils
import (
"context"
+ "errors"
"fmt"
"math"
"net/url"
@@ -30,6 +31,8 @@ import (
"github.com/k3a/html2text"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/language"
"github.com/superseriousbusiness/gotosocial/internal/log"
@@ -187,6 +190,47 @@ func placeholderAttachments(arr []*apimodel.Attachment) (string, []*apimodel.Att
return text.SanitizeToHTML(note.String()), arr
}
+func (c *Converter) pendingReplyNote(
+ ctx context.Context,
+ s *gtsmodel.Status,
+) (string, error) {
+ intReq, err := c.state.DB.GetInteractionRequestByInteractionURI(ctx, s.URI)
+ if err != nil && !errors.Is(err, db.ErrNoEntries) {
+ // Something's gone wrong.
+ err := gtserror.Newf("db error getting interaction request for %s: %w", s.URI, err)
+ return "", err
+ }
+
+ // No interaction request present
+ // for this status. Race condition?
+ if intReq == nil {
+ return "", nil
+ }
+
+ var (
+ proto = config.GetProtocol()
+ host = config.GetHost()
+
+ // Build the settings panel URL at which the user
+ // can view + approve/reject the interaction request.
+ //
+ // Eg., https://example.org/settings/user/interaction_requests/01J5QVXCCEATJYSXM9H6MZT4JR
+ settingsURL = proto + "://" + host + "/settings/user/interaction_requests/" + intReq.ID
+ )
+
+ var note strings.Builder
+ note.WriteString(`<hr>`)
+ note.WriteString(`<p><i lang="en">ℹ️ Note from ` + host + `: `)
+ note.WriteString(`This reply is pending your approval. You can quickly accept it by liking, boosting or replying to it. You can also accept or reject it at the following link: `)
+ note.WriteString(`<a href="` + settingsURL + `" `)
+ note.WriteString(`rel="noreferrer noopener" target="_blank">`)
+ note.WriteString(settingsURL)
+ note.WriteString(`</a>.`)
+ note.WriteString(`</i></p>`)
+
+ return text.SanitizeToHTML(note.String()), nil
+}
+
// ContentToContentLanguage tries to
// extract a content string and language
// tag string from the given intermediary