From fe97162490a3d93cadc94fd8f8ef010ab597b078 Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Sat, 12 Oct 2019 14:20:19 -0500 Subject: [PATCH] PostCard - resolve and display actor info --- web/src/components/PostCard.vue | 71 ++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/web/src/components/PostCard.vue b/web/src/components/PostCard.vue index 1fd95bd..93eca52 100644 --- a/web/src/components/PostCard.vue +++ b/web/src/components/PostCard.vue @@ -1,7 +1,13 @@ @@ -15,26 +21,63 @@ export default { }, data () { return { - post: {} + post: {}, + actor: {}, + isError: false, } }, - created () { - if (typeof this.activity.object === 'string') { - window.fetch(`/o/${encodeURIComponent(this.activity.object)}`, { + computed: { + actorIconUrl() { + return this.actor.icon && this.actor.icon.url + }, + actorHost() { + try { + const id = new URL(this.actor.id) + return id.host + } catch (ignore) { + return '' + } + } + }, + methods: { + resolveObject(idOrObject) { + if (typeof idOrObject !== 'string') { + return new Promise((resolve) => resolve(idOrObject)) + } + return window.fetch(`/o/${encodeURIComponent(idOrObject)}`, { method: 'get', headers: { accept: 'application/activity+json' } - }).then(res => res.json()) - .then(post => { - this.post = post - }) + }) + .then(res => res.json()) .catch(err => { - this.post.content = err.message + this.isError = true + console.log(err.message) }) - } else { - this.post = this.activity.object } + }, + created () { + this.resolveObject(this.activity.object) + .then(object => { + this.post = object + return this.resolveObject(this.post.attributedTo) + }) + .then(actor => { this.actor = actor }) } } - \ No newline at end of file + + + \ No newline at end of file