mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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
This commit is contained in:
@ -2592,3 +2592,74 @@ func policyValsToAPIPolicyVals(vals gtsmodel.PolicyValues) []apimodel.PolicyValu
|
||||
|
||||
return apiVals
|
||||
}
|
||||
|
||||
// InteractionReqToAPIInteractionReq converts the given *gtsmodel.InteractionRequest
|
||||
// to an *apimodel.InteractionRequest, from the perspective of requestingAcct.
|
||||
func (c *Converter) InteractionReqToAPIInteractionReq(
|
||||
ctx context.Context,
|
||||
req *gtsmodel.InteractionRequest,
|
||||
requestingAcct *gtsmodel.Account,
|
||||
) (*apimodel.InteractionRequest, error) {
|
||||
// Ensure interaction request is populated.
|
||||
if err := c.state.DB.PopulateInteractionRequest(ctx, req); err != nil {
|
||||
err := gtserror.Newf("error populating: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
interactingAcct, err := c.AccountToAPIAccountPublic(ctx, req.InteractingAccount)
|
||||
if err != nil {
|
||||
err := gtserror.Newf("error converting interacting acct: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
interactedStatus, err := c.StatusToAPIStatus(
|
||||
ctx,
|
||||
req.Status,
|
||||
requestingAcct,
|
||||
statusfilter.FilterContextNone,
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
err := gtserror.Newf("error converting interacted status: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var reply *apimodel.Status
|
||||
if req.InteractionType == gtsmodel.InteractionReply {
|
||||
reply, err = c.StatusToAPIStatus(
|
||||
ctx,
|
||||
req.Reply,
|
||||
requestingAcct,
|
||||
statusfilter.FilterContextNone,
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
err := gtserror.Newf("error converting reply: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var acceptedAt string
|
||||
if req.IsAccepted() {
|
||||
acceptedAt = util.FormatISO8601(req.AcceptedAt)
|
||||
}
|
||||
|
||||
var rejectedAt string
|
||||
if req.IsRejected() {
|
||||
rejectedAt = util.FormatISO8601(req.RejectedAt)
|
||||
}
|
||||
|
||||
return &apimodel.InteractionRequest{
|
||||
ID: req.ID,
|
||||
Type: req.InteractionType.String(),
|
||||
CreatedAt: util.FormatISO8601(req.CreatedAt),
|
||||
Account: interactingAcct,
|
||||
Status: interactedStatus,
|
||||
Reply: reply,
|
||||
AcceptedAt: acceptedAt,
|
||||
RejectedAt: rejectedAt,
|
||||
URI: req.URI,
|
||||
}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user