Whalebird-desktop-client-ma.../src/renderer/components/TimelineSpace/Cards/Toot.vue

250 lines
5.6 KiB
Vue
Raw Normal View History

<template>
<div class="toot" tabIndex="0">
<div class="icon">
<img :src="originalMessage(message).account.avatar" />
</div>
<div class="detail">
<div class="toot-header">
2018-03-12 11:36:13 +01:00
<div class="user">
{{ username(originalMessage(message).account) }}
</div>
<div class="timestamp">
2018-03-12 12:04:30 +01:00
{{ parseDatetime(message.created_at) }}
</div>
</div>
<div class="content" v-html="message.content" @click.capture.prevent="tootClick"></div>
<div class="attachments">
<div class="media" v-for="media in originalMessage(message).media_attachments">
<img :src="media.preview_url" />
</div>
</div>
2018-03-14 15:09:04 +01:00
<div class="reblogger" v-if="message.reblog !== null">
<icon name="retweet"></icon>
<span class="reblogger-icon">
<img :src="message.account.avatar" />
</span>
<span class="reblogger-name">
{{ username(message.account) }}
2018-03-14 15:09:04 +01:00
</span>
</div>
<div class="tool-box">
<el-button type="text" @click="openReply(message)" class="reply">
2018-03-14 14:38:42 +01:00
<icon name="reply" scale="0.9"></icon>
</el-button>
<el-button type="text" @click="changeReblog(originalMessage(message))" :class="originalMessage(message).reblogged ? 'reblogged' : 'reblog'">
2018-03-14 14:38:42 +01:00
<icon name="retweet" scale="0.9"></icon>
</el-button>
<el-button type="text" @click="changeFavourite(originalMessage(message))" :class="originalMessage(message).favourited ? 'favourited' : 'favourite'">
2018-03-14 14:38:42 +01:00
<icon name="star" scale="0.9"></icon>
</el-button>
</div>
</div>
2018-03-12 11:36:13 +01:00
<div class="clearfix"></div>
<div class="fill-line"></div>
</div>
</template>
<script>
2018-03-12 12:04:30 +01:00
import moment from 'moment'
import { shell } from 'electron'
2018-03-12 12:04:30 +01:00
export default {
name: 'toot',
2018-03-12 12:04:30 +01:00
props: ['message'],
methods: {
originalMessage (message) {
2018-03-14 15:09:04 +01:00
if (message.reblog !== null) {
return message.reblog
2018-03-14 15:09:04 +01:00
} else {
return message
2018-03-14 15:09:04 +01:00
}
},
username (account) {
if (account.display_name !== '') {
return account.display_name
} else {
return account.username
}
},
2018-03-12 12:04:30 +01:00
parseDatetime (datetime) {
return moment(datetime).format('YYYY-MM-DD HH:mm:ss')
},
tootClick (e) {
const link = findLink(e.target)
if (link !== null) {
shell.openExternal(link)
}
2018-03-14 08:59:39 +01:00
},
openReply (message) {
this.$store.dispatch('TimelineSpace/NewTootModal/openReply', message)
},
2018-03-14 14:38:42 +01:00
changeReblog (message) {
if (message.reblogged) {
this.$store.dispatch('TimelineSpace/Cards/Toot/unreblog', message)
.then((data) => {
this.$emit('update', data)
})
.catch(() => {
this.$message({
message: 'Faild to unreblog',
type: 'error'
})
})
} else {
this.$store.dispatch('TimelineSpace/Cards/Toot/reblog', message)
.then((data) => {
this.$emit('update', data)
})
.catch(() => {
this.$message({
message: 'Faild to reblog',
type: 'error'
})
})
}
},
2018-03-14 09:35:44 +01:00
changeFavourite (message) {
if (message.favourited) {
this.$store.dispatch('TimelineSpace/Cards/Toot/removeFavourite', message)
.then((data) => {
this.$emit('update', data)
})
2018-03-14 09:35:44 +01:00
.catch(() => {
this.$message({
message: 'Failed to unfavourite',
type: 'error'
})
2018-03-14 08:59:39 +01:00
})
2018-03-14 09:35:44 +01:00
} else {
this.$store.dispatch('TimelineSpace/Cards/Toot/addFavourite', message)
.then((data) => {
this.$emit('update', data)
})
2018-03-14 09:35:44 +01:00
.catch(() => {
this.$message({
message: 'Failed to favourite',
type: 'error'
})
})
}
2018-03-12 12:04:30 +01:00
}
}
}
function findLink (target) {
if (target.localName === 'a') {
return target.href
}
if (target.parentNode === undefined || target.parentNode === null) {
return null
}
if (target.parentNode.getAttribute('class') === 'toot') {
return null
}
return findLink(target.parentNode)
}
</script>
2018-03-12 11:36:13 +01:00
<style lang="scss" scoped>
.fill-line {
height: 1px;
background-color: #ebeef5;
margin: 4px 0 0;
2018-03-12 11:36:13 +01:00
}
.toot {
padding: 4px 0 0 16px;
2018-03-22 10:09:58 +01:00
background-color: #ffffff;
2018-03-12 11:36:13 +01:00
.icon {
float: left;
img {
width: 36px;
height: 36px;
border-radius: 4px;
}
}
.detail {
margin: 0 8px 0 42px;
2018-03-12 11:36:13 +01:00
.toot-header {
.user {
float: left;
font-weight: 800;
color: #303133;
font-size: 14px;
}
.timestamp {
font-size: 14px;
text-align: right;
width: 100%;
color: #909399;
}
}
.content {
font-size: 14px;
color: #303133;
margin: 4px 0 8px;
2018-03-24 02:00:35 +01:00
word-wrap: break-word;
2018-03-12 11:36:13 +01:00
}
.attachments {
.media {
img {
width: 200px;
max-width: 100%;
border-radius: 8px;
}
}
}
2018-03-14 15:09:04 +01:00
.reblogger {
color: #909399;
.reblogger-icon {
img {
width: 16px;
height: 16px;
border-radius: 2px;
}
}
.reblogger-name {
font-size: 12px;
}
}
2018-03-12 11:36:13 +01:00
.tool-box {
button {
margin: 0 8px;
padding: 0;
color: #909399;
}
.reblogged {
color: #409eff;
}
.favourited {
color: #e6a23c;
}
2018-03-12 11:36:13 +01:00
}
.reply:hover,
.reblog:hover,
.favourite:hover {
color: #409eff;
}
2018-03-12 11:36:13 +01:00
}
}
.toot:focus {
background-color: #f2f6fc;
outline: 0;
}
2018-03-12 11:36:13 +01:00
</style>