summaryrefslogtreecommitdiff
path: root/internal/typeutils/internal.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-08-24 11:49:37 +0200
committerLibravatar GitHub <noreply@github.com>2024-08-24 11:49:37 +0200
commitf23f04e0b1d117be714bf91d5266dab219ed741e (patch)
tree0b3ddd60d51c8729949c3669993910a7f8f32a7b /internal/typeutils/internal.go
parent[performance] ffmpeg ffprobe wrapper improvements (#3225) (diff)
downloadgotosocial-f23f04e0b1d117be714bf91d5266dab219ed741e.tar.xz
[feature] Interaction requests client api + settings panel (#3215)
* [feature] Interaction requests client api + settings panel * test accept / reject * fmt * don't pin rejected interaction * use single db model for interaction accept, reject, and request * swaggor * env sharting * append errors * remove ErrNoEntries checks * change intReqID to reqID * rename "pend" to "request" * markIntsPending -> mark interactionsPending * use log instead of returning error when rejecting interaction * empty migration * jolly renaming * make interactionURI unique again * swag grr * remove unnecessary locks * invalidate as last step
Diffstat (limited to 'internal/typeutils/internal.go')
-rw-r--r--internal/typeutils/internal.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/internal/typeutils/internal.go b/internal/typeutils/internal.go
index 75da4b27e..ed4ed4dd9 100644
--- a/internal/typeutils/internal.go
+++ b/internal/typeutils/internal.go
@@ -20,6 +20,7 @@ package typeutils
import (
"context"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/uris"
@@ -97,3 +98,80 @@ func (c *Converter) StatusToBoost(
return boost, nil
}
+
+func StatusToInteractionRequest(
+ ctx context.Context,
+ status *gtsmodel.Status,
+) (*gtsmodel.InteractionRequest, error) {
+ reqID, err := id.NewULIDFromTime(status.CreatedAt)
+ if err != nil {
+ return nil, gtserror.Newf("error generating ID: %w", err)
+ }
+
+ var (
+ targetID string
+ target *gtsmodel.Status
+ targetAccountID string
+ targetAccount *gtsmodel.Account
+ interactionType gtsmodel.InteractionType
+ reply *gtsmodel.Status
+ announce *gtsmodel.Status
+ )
+
+ if status.InReplyToID != "" {
+ // It's a reply.
+ targetID = status.InReplyToID
+ target = status.InReplyTo
+ targetAccountID = status.InReplyToAccountID
+ targetAccount = status.InReplyToAccount
+ interactionType = gtsmodel.InteractionReply
+ reply = status
+ } else {
+ // It's a boost.
+ targetID = status.BoostOfID
+ target = status.BoostOf
+ targetAccountID = status.BoostOfAccountID
+ targetAccount = status.BoostOfAccount
+ interactionType = gtsmodel.InteractionAnnounce
+ announce = status
+ }
+
+ return &gtsmodel.InteractionRequest{
+ ID: reqID,
+ CreatedAt: status.CreatedAt,
+ StatusID: targetID,
+ Status: target,
+ TargetAccountID: targetAccountID,
+ TargetAccount: targetAccount,
+ InteractingAccountID: status.AccountID,
+ InteractingAccount: status.Account,
+ InteractionURI: status.URI,
+ InteractionType: interactionType,
+ Reply: reply,
+ Announce: announce,
+ }, nil
+}
+
+func StatusFaveToInteractionRequest(
+ ctx context.Context,
+ fave *gtsmodel.StatusFave,
+) (*gtsmodel.InteractionRequest, error) {
+ reqID, err := id.NewULIDFromTime(fave.CreatedAt)
+ if err != nil {
+ return nil, gtserror.Newf("error generating ID: %w", err)
+ }
+
+ return &gtsmodel.InteractionRequest{
+ ID: reqID,
+ CreatedAt: fave.CreatedAt,
+ StatusID: fave.StatusID,
+ Status: fave.Status,
+ TargetAccountID: fave.TargetAccountID,
+ TargetAccount: fave.TargetAccount,
+ InteractingAccountID: fave.AccountID,
+ InteractingAccount: fave.Account,
+ InteractionURI: fave.URI,
+ InteractionType: gtsmodel.InteractionLike,
+ Like: fave,
+ }, nil
+}