blob: 6f65ac6ee85c9b3609bf286545a25f0df291d822 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
export default {
props: ['messageID', 'parent'],
methods: {
likeObjects(objects, messageID=this.messageID) {
return objects.filter(o=>
'like' in o &&
'timestamp' in o &&
o.like == messageID &&
typeof o.timestamp == 'number')
},
toggleLike(objects) {
const myLikes = this.likeObjects(objects).mine
if (myLikes.length) {
myLikes.removeMine()
} else {
this.$graffitiUpdate({
like: this.messageID,
timestamp: Date.now(),
_tags: [this.messageID, this.parent]
})
}
}
},
template: `
<graffiti-objects :tags="[messageID]" v-slot="{objects}">
<button @click="toggleLike(objects)" :class="likeObjects(objects).mine.length?'button-primary':''">
👍 {{ likeObjects(objects).length }}
</button>
</graffiti-objects>`
}
|