From 1ce854358def5f04b7c3b73418ab56bb58512634 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:42:19 +0200 Subject: [feature] Show info for pending replies, allow implicit accept of pending replies (#3322) * [feature] Allow implicit accept of pending replies * update wording --- internal/typeutils/util.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'internal/typeutils/util.go') 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(`
`) + note.WriteString(`

ℹ️ 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(``) + note.WriteString(settingsURL) + note.WriteString(`.`) + note.WriteString(`

`) + + return text.SanitizeToHTML(note.String()), nil +} + // ContentToContentLanguage tries to // extract a content string and language // tag string from the given intermediary -- cgit v1.2.3