mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:18:52 +00:00
support deleting queued http requests by target ID
This commit is contained in:
parent
8fdd5b18aa
commit
d7e14d5dbb
4 changed files with 36 additions and 5 deletions
|
@ -79,6 +79,7 @@ func (f *federate) DeleteAccount(ctx context.Context, account *gtsmodel.Account)
|
|||
// (this stops any queued likes, boosts, creates etc).
|
||||
f.state.Queues.APRequests.Delete("ActorID", account.URI)
|
||||
f.state.Queues.APRequests.Delete("ObjectID", account.URI)
|
||||
f.state.Queues.APRequests.Delete("TargetID", account.URI)
|
||||
|
||||
// Parse relevant URI(s).
|
||||
outboxIRI, err := parseURI(account.OutboxURI)
|
||||
|
@ -230,6 +231,7 @@ func (f *federate) DeleteStatus(ctx context.Context, status *gtsmodel.Status) er
|
|||
// Drop any queued outgoing http requests for status,
|
||||
// (this stops any queued likes, boosts, creates etc).
|
||||
f.state.Queues.APRequests.Delete("ObjectID", status.URI)
|
||||
f.state.Queues.APRequests.Delete("TargetID", status.URI)
|
||||
|
||||
// Ensure the status model is fully populated.
|
||||
if err := f.state.DB.PopulateStatus(ctx, status); err != nil {
|
||||
|
|
|
@ -63,6 +63,9 @@ type APRequest struct {
|
|||
// ObjectID ...
|
||||
ObjectID string
|
||||
|
||||
// TargetID ...
|
||||
TargetID string
|
||||
|
||||
// Request ...
|
||||
Request *http.Request
|
||||
}
|
||||
|
|
|
@ -39,7 +39,9 @@ func (q *Queues) Init() {
|
|||
func (q *Queues) initHTTPRequest() {
|
||||
q.APRequests.Init(structr.QueueConfig[*APRequest]{
|
||||
Indices: []structr.IndexConfig{
|
||||
{Fields: "ActorID", Multiple: true},
|
||||
{Fields: "ObjectID", Multiple: true},
|
||||
{Fields: "TargetID", Multiple: true},
|
||||
{Fields: "Request.URL.Host", Multiple: true},
|
||||
},
|
||||
})
|
||||
|
|
|
@ -51,8 +51,9 @@ func (t *transport) BatchDeliver(ctx context.Context, obj map[string]interface{}
|
|||
}
|
||||
|
||||
// Extract object IDs.
|
||||
objID := getObjectID(obj)
|
||||
actID := getActorID(obj)
|
||||
objID := getObjectID(obj)
|
||||
tgtID := getTargetID(obj)
|
||||
|
||||
for _, to := range recipients {
|
||||
// Skip delivery to recipient if it is "us".
|
||||
|
@ -60,8 +61,14 @@ func (t *transport) BatchDeliver(ctx context.Context, obj map[string]interface{}
|
|||
continue
|
||||
}
|
||||
|
||||
// Prepare new outgoing http client request.
|
||||
req, err := t.prepare(ctx, objID, actID, b, to)
|
||||
// Prepare http client request.
|
||||
req, err := t.prepare(ctx,
|
||||
actID,
|
||||
objID,
|
||||
tgtID,
|
||||
b,
|
||||
to,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(err)
|
||||
continue
|
||||
|
@ -92,8 +99,9 @@ func (t *transport) Deliver(ctx context.Context, obj map[string]interface{}, to
|
|||
|
||||
// Prepare http client request.
|
||||
req, err := t.prepare(ctx,
|
||||
getObjectID(obj),
|
||||
getActorID(obj),
|
||||
getObjectID(obj),
|
||||
getTargetID(obj),
|
||||
b,
|
||||
to,
|
||||
)
|
||||
|
@ -112,8 +120,9 @@ func (t *transport) Deliver(ctx context.Context, obj map[string]interface{}, to
|
|||
// request object with signing function.
|
||||
func (t *transport) prepare(
|
||||
ctx context.Context,
|
||||
objectID string,
|
||||
actorID string,
|
||||
objectID string,
|
||||
targetID string,
|
||||
data []byte,
|
||||
to *url.URL,
|
||||
) (
|
||||
|
@ -142,7 +151,9 @@ func (t *transport) prepare(
|
|||
req.Header.Add("Accept-Charset", "utf-8")
|
||||
|
||||
return &queue.APRequest{
|
||||
ActorID: actorID,
|
||||
ObjectID: objectID,
|
||||
TargetID: targetID,
|
||||
Request: req,
|
||||
}, nil
|
||||
}
|
||||
|
@ -172,3 +183,16 @@ func getActorID(obj map[string]interface{}) string {
|
|||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// getTargetID extracts a target ID from 'serialized' ActivityPub object map.
|
||||
func getTargetID(obj map[string]interface{}) string {
|
||||
switch t := obj["target"].(type) {
|
||||
case string:
|
||||
return t
|
||||
case map[string]interface{}:
|
||||
id, _ := t["id"].(string)
|
||||
return id
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue