feat: better support both Person and Note data

This commit is contained in:
Yarmo Mackenbach 2023-09-14 15:37:26 +02:00
parent 75ec28b618
commit 3df1bc7106
No known key found for this signature in database
GPG key ID: 3C57D093219103A3
2 changed files with 19 additions and 3 deletions

View file

@ -270,7 +270,7 @@ export class Claim {
const def = _data[claimData.about.id] const def = _data[claimData.about.id]
if (def.functions?.postprocess) { if (def.functions?.postprocess) {
try { try {
({ claimData, proofData } = def.functions.postprocess(claimData, proofData)) ({ claimData, proofData } = await def.functions.postprocess(claimData, proofData, opts))
} catch (_) {} } catch (_) {}
} }
} else { } else {

View file

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import * as E from '../enums.js' import * as E from '../enums.js'
import { activitypub } from '../fetcher/index.js'
import { ServiceProvider } from '../serviceProvider.js' import { ServiceProvider } from '../serviceProvider.js'
export const reURI = /^https:\/\/(.*)\/?/ export const reURI = /^https:\/\/(.*)\/?/
@ -76,8 +77,23 @@ export function processURI (uri) {
} }
export const functions = { export const functions = {
postprocess: (claimData, proofData) => { postprocess: async (/** @type {ServiceProvider} */ claimData, proofData, opts) => {
claimData.profile.display = `@${proofData.result.preferredUsername}@${new URL(proofData.result.url).hostname}` switch (proofData.result.type) {
case 'Note': {
claimData.profile.uri = proofData.result.attributedTo
const personData = await activitypub.fn({ url: proofData.result.attributedTo }, opts)
claimData.profile.display = `@${personData.preferredUsername}@${new URL(proofData.result.url).hostname}`
break
}
case 'Person':
claimData.profile.display = `@${proofData.result.preferredUsername}@${new URL(proofData.result.url).hostname}`
break
default:
break
}
return { claimData, proofData } return { claimData, proofData }
} }
} }