diff options
author | 2021-10-10 12:39:25 +0200 | |
---|---|---|
committer | 2021-10-10 12:39:25 +0200 | |
commit | 367bdca25093ee76b36506d8a5e6733b0aa2e2bb (patch) | |
tree | 37b1b82ae6e9fad7e6d95b8abbb58bdb42049707 /internal/federation/federatingdb/util.go | |
parent | Derive visibility fixes (#271) (diff) | |
download | gotosocial-367bdca25093ee76b36506d8a5e6733b0aa2e2bb.tar.xz |
Handle forwarded messages (#273)
* correct path of foss_satan
* add APIri and notes
* test create forward note
* rename target => receiving account
* split up create into separate funcs
* update extractFromCtx
* tidy up from federator processing
* foss satan => http not https
* check if status in db
* mock dereference of status from IRI
* add forward message deref test
* update test with activities
* add remote_account_2 to test rig
Diffstat (limited to 'internal/federation/federatingdb/util.go')
-rw-r--r-- | internal/federation/federatingdb/util.go | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go index dfc998abb..49a95a449 100644 --- a/internal/federation/federatingdb/util.go +++ b/internal/federation/federatingdb/util.go @@ -289,29 +289,26 @@ func (f *federatingDB) collectIRIs(ctx context.Context, iris []*url.URL) (vocab. // extractFromCtx extracts some useful values from a context passed into the federatingDB via the API: // - The target account that owns the inbox or URI being interacted with. +// - The requesting account that posted to the inbox. // - A channel that messages for the processor can be placed into. -func extractFromCtx(ctx context.Context) (*gtsmodel.Account, chan messages.FromFederator, error) { - var targetAcct *gtsmodel.Account - targetAcctI := ctx.Value(util.APAccount) - if targetAcctI != nil { - var ok bool - targetAcct, ok = targetAcctI.(*gtsmodel.Account) - if !ok { - return nil, nil, errors.New("extractFromCtx: account value in context not parseable") - } +// If a value is not present, nil will be returned for it. It's up to the caller to check this and respond appropriately. +func extractFromCtx(ctx context.Context) (receivingAccount, requestingAccount *gtsmodel.Account, fromFederatorChan chan messages.FromFederator) { + receivingAccountI := ctx.Value(util.APReceivingAccount) + if receivingAccountI != nil { + receivingAccount = receivingAccountI.(*gtsmodel.Account) + } + + requestingAcctI := ctx.Value(util.APRequestingAccount) + if requestingAcctI != nil { + requestingAccount = requestingAcctI.(*gtsmodel.Account) } - var fromFederatorChan chan messages.FromFederator fromFederatorChanI := ctx.Value(util.APFromFederatorChanKey) if fromFederatorChanI != nil { - var ok bool - fromFederatorChan, ok = fromFederatorChanI.(chan messages.FromFederator) - if !ok { - return nil, nil, errors.New("extractFromCtx: fromFederatorChan value in context not parseable") - } + fromFederatorChan = fromFederatorChanI.(chan messages.FromFederator) } - return targetAcct, fromFederatorChan, nil + return } func marshalItem(item vocab.Type) (string, error) { |