PostCard - resolve and display actor info

This commit is contained in:
Will Murphy 2019-10-12 14:20:19 -05:00
parent dbd8da4bfc
commit fe97162490

View file

@ -1,7 +1,13 @@
<template> <template>
<div class="w3-card"> <div class="w3-card">
<label>{{ post.actor }}</label> <div class="actor">
<p>{{ post.content }}</p> <img crossorigin="anonymous" :src="actorIconUrl">
<label>
{{ actor.preferredUsername }}
<span class="muted">@{{ actorHost }}</span>
</label>
</div>
<p v-html="post.content"></p>
</div> </div>
</template> </template>
@ -15,26 +21,63 @@ export default {
}, },
data () { data () {
return { return {
post: {} post: {},
actor: {},
isError: false,
} }
}, },
created () { computed: {
if (typeof this.activity.object === 'string') { actorIconUrl() {
window.fetch(`/o/${encodeURIComponent(this.activity.object)}`, { 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', method: 'get',
headers: { headers: {
accept: 'application/activity+json' accept: 'application/activity+json'
} }
}).then(res => res.json()) })
.then(post => { .then(res => res.json())
this.post = post
})
.catch(err => { .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 })
} }
} }
</script> </script>
<style scoped>
.actor img {
width: 32px;
height: 32px;
}
.actor label {
font-weight: bold;
}
.actor label .muted {
font-weight: normal;
color: gray;
}
</style>