mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-15 17:35:44 +01:00
Merge pull request #1380 from akihikodaki/misc
Fix ActivityStreams collection resolution
This commit is contained in:
commit
9449ed14d2
1 changed files with 19 additions and 16 deletions
|
@ -43,32 +43,35 @@ export default class Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async resolveCollection(value) {
|
private async resolveCollection(value) {
|
||||||
if (Array.isArray(value)) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const resolved = typeof value === 'string' ?
|
const resolved = typeof value === 'string' ?
|
||||||
await this.resolveUnrequestedOne(value) :
|
await this.resolveUnrequestedOne(value) :
|
||||||
value;
|
{ resolver: this, object: value };
|
||||||
|
|
||||||
switch (resolved.type) {
|
switch (resolved.object.type) {
|
||||||
case 'Collection':
|
case 'Collection':
|
||||||
return resolved.items;
|
resolved.object = resolved.object.items;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'OrderedCollection':
|
case 'OrderedCollection':
|
||||||
return resolved.orderedItems;
|
resolved.object = resolved.object.orderedItems;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return [resolved];
|
if (!Array.isArray(value)) {
|
||||||
|
resolved.object = [resolved.object];
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resolve(value): Promise<Array<Promise<IResult>>> {
|
public async resolve(value): Promise<Array<Promise<IResult>>> {
|
||||||
const collection = await this.resolveCollection(value);
|
const { resolver, object } = await this.resolveCollection(value);
|
||||||
|
|
||||||
return collection
|
return object
|
||||||
.filter(element => !this.requesting.has(element))
|
.filter(element => !resolver.requesting.has(element))
|
||||||
.map(this.resolveUnrequestedOne.bind(this));
|
.map(resolver.resolveUnrequestedOne.bind(resolver));
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveOne(value) {
|
public resolveOne(value) {
|
||||||
|
@ -80,9 +83,9 @@ export default class Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resolveRemoteUserObjects(value) {
|
public async resolveRemoteUserObjects(value) {
|
||||||
const collection = await this.resolveCollection(value);
|
const { resolver, object } = await this.resolveCollection(value);
|
||||||
|
|
||||||
return collection.filter(element => !this.requesting.has(element)).map(element => {
|
return object.filter(element => !resolver.requesting.has(element)).map(element => {
|
||||||
if (typeof element === 'string') {
|
if (typeof element === 'string') {
|
||||||
const object = RemoteUserObject.findOne({ uri: element });
|
const object = RemoteUserObject.findOne({ uri: element });
|
||||||
|
|
||||||
|
@ -91,7 +94,7 @@ export default class Resolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.resolveUnrequestedOne(element);
|
return resolver.resolveUnrequestedOne(element);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue