Merge pull request #753 from amyspark/improve-toot-handling

Keep timestamp up-to-date and accessible
This commit is contained in:
AkiraFukushima 2018-11-30 08:14:37 +09:00 committed by GitHub
commit dd74867930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 4 deletions

View File

@ -27,7 +27,9 @@
<span class="acct">{{ accountName(originalMessage(message).account) }}</span> <span class="acct">{{ accountName(originalMessage(message).account) }}</span>
</div> </div>
<div class="timestamp"> <div class="timestamp">
{{ parseDatetime(originalMessage(message).created_at) }} <time :datetime="originalMessage(message).created_at" :title="readableTimestamp">
{{ timestamp }}
</time>
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
@ -144,6 +146,7 @@ import DisplayStyle from '~/src/constants/displayStyle'
import TimeFormat from '~/src/constants/timeFormat' import TimeFormat from '~/src/constants/timeFormat'
import emojify from '~/src/renderer/utils/emojify' import emojify from '~/src/renderer/utils/emojify'
import FailoverImg from '~/src/renderer/components/atoms/FailoverImg' import FailoverImg from '~/src/renderer/components/atoms/FailoverImg'
import { setInterval, clearInterval } from 'timers'
export default { export default {
name: 'toot', name: 'toot',
@ -153,7 +156,8 @@ export default {
data () { data () {
return { return {
showContent: false, showContent: false,
showAttachments: false showAttachments: false,
now: Date.now()
} }
}, },
props: { props: {
@ -186,12 +190,25 @@ export default {
}), }),
shortcutEnabled: function () { shortcutEnabled: function () {
return this.focused && !this.overlaid return this.focused && !this.overlaid
},
timestamp: function () {
return this.parseDatetime(this.originalMessage(this.message).created_at, this.now)
},
readableTimestamp: function () {
moment.locale(this.language)
return moment(this.originalMessage(this.message).created_at).format('LLLL')
} }
}, },
mounted () { mounted () {
if (this.focused) { if (this.focused) {
this.$refs.status.focus() this.$refs.status.focus()
} }
this.updateInterval = setInterval(() => {
this.$data.now = Date.now()
}, 60000)
},
beforeDestroy () {
clearInterval(this.updateInterval)
}, },
watch: { watch: {
focused: function (newState, oldState) { focused: function (newState, oldState) {
@ -241,13 +258,13 @@ export default {
return '' return ''
} }
}, },
parseDatetime (datetime) { parseDatetime (datetime, epoch) {
switch (this.timeFormat) { switch (this.timeFormat) {
case TimeFormat.Absolute.value: case TimeFormat.Absolute.value:
return moment(datetime).format('YYYY-MM-DD HH:mm:ss') return moment(datetime).format('YYYY-MM-DD HH:mm:ss')
case TimeFormat.Relative.value: case TimeFormat.Relative.value:
moment.locale(this.language) moment.locale(this.language)
return moment(datetime).fromNow() return moment(datetime).from(epoch)
} }
}, },
tootClick (e) { tootClick (e) {