wip
This commit is contained in:
parent
202ac80fa8
commit
4f2041c1d9
|
@ -70,75 +70,47 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="typescript">
|
<script lang="ts">
|
||||||
|
import Vue from 'vue';
|
||||||
import compile from '../../common/scripts/text-compiler';
|
import compile from '../../common/scripts/text-compiler';
|
||||||
import dateStringify from '../../common/scripts/date-stringify';
|
import dateStringify from '../../common/scripts/date-stringify';
|
||||||
|
|
||||||
this.mixin('i');
|
export default Vue.extend({
|
||||||
this.mixin('api');
|
props: ['post'],
|
||||||
this.mixin('user-preview');
|
data() {
|
||||||
|
return {
|
||||||
this.mixin('stream');
|
connection: null,
|
||||||
this.connection = this.stream.getConnection();
|
connectionId: null
|
||||||
this.connectionId = this.stream.use();
|
};
|
||||||
|
},
|
||||||
this.isDetailOpened = false;
|
computed: {
|
||||||
|
isRepost(): boolean {
|
||||||
this.set = post => {
|
return (this.post.repost &&
|
||||||
this.post = post;
|
this.post.text == null &&
|
||||||
this.isRepost = this.post.repost && this.post.text == null && this.post.media_ids == null && this.post.poll == null;
|
this.post.media_ids == null &&
|
||||||
this.p = this.isRepost ? this.post.repost : this.post;
|
this.post.poll == null);
|
||||||
this.p.reactions_count = this.p.reaction_counts ? Object.keys(this.p.reaction_counts).map(key => this.p.reaction_counts[key]).reduce((a, b) => a + b) : 0;
|
},
|
||||||
this.title = dateStringify(this.p.created_at);
|
p(): any {
|
||||||
this.url = `/${this.p.user.username}/${this.p.id}`;
|
return this.isRepost ? this.post.repost : this.post;
|
||||||
};
|
},
|
||||||
|
reactionsCount(): number {
|
||||||
this.set(this.opts.post);
|
return this.p.reaction_counts ? Object.keys(this.p.reaction_counts).map(key => this.p.reaction_counts[key]).reduce((a, b) => a + b) : 0;
|
||||||
|
},
|
||||||
this.refresh = post => {
|
title(): string {
|
||||||
this.set(post);
|
return dateStringify(this.p.created_at);
|
||||||
this.update();
|
},
|
||||||
if (this.$refs.reactionsViewer) this.$refs.reactionsViewer.update({
|
url(): string {
|
||||||
post
|
return `/${this.p.user.username}/${this.p.id}`;
|
||||||
});
|
|
||||||
if (this.$refs.pollViewer) this.$refs.pollViewer.init(post);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.onStreamPostUpdated = data => {
|
|
||||||
const post = data.post;
|
|
||||||
if (post.id == this.post.id) {
|
|
||||||
this.refresh(post);
|
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
created() {
|
||||||
this.onStreamConnected = () => {
|
this.connection = this.$root.$data.os.stream.getConnection();
|
||||||
this.capture();
|
this.connectionId = this.$root.$data.os.stream.use();
|
||||||
};
|
},
|
||||||
|
mounted() {
|
||||||
this.capture = withHandler => {
|
|
||||||
if (this.SIGNIN) {
|
|
||||||
this.connection.send({
|
|
||||||
type: 'capture',
|
|
||||||
id: this.post.id
|
|
||||||
});
|
|
||||||
if (withHandler) this.connection.on('post-updated', this.onStreamPostUpdated);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.decapture = withHandler => {
|
|
||||||
if (this.SIGNIN) {
|
|
||||||
this.connection.send({
|
|
||||||
type: 'decapture',
|
|
||||||
id: this.post.id
|
|
||||||
});
|
|
||||||
if (withHandler) this.connection.off('post-updated', this.onStreamPostUpdated);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.on('mount', () => {
|
|
||||||
this.capture(true);
|
this.capture(true);
|
||||||
|
|
||||||
if (this.SIGNIN) {
|
if (this.$root.$data.os.isSignedIn) {
|
||||||
this.connection.on('_connected_', this.onStreamConnected);
|
this.connection.on('_connected_', this.onStreamConnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,13 +132,48 @@ this.on('mount', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
beforeDestroy() {
|
||||||
this.on('unmount', () => {
|
|
||||||
this.decapture(true);
|
this.decapture(true);
|
||||||
this.connection.off('_connected_', this.onStreamConnected);
|
this.connection.off('_connected_', this.onStreamConnected);
|
||||||
this.stream.dispose(this.connectionId);
|
this.$root.$data.os.stream.dispose(this.connectionId);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
capture(withHandler = false) {
|
||||||
|
if (this.$root.$data.os.isSignedIn) {
|
||||||
|
this.connection.send({
|
||||||
|
type: 'capture',
|
||||||
|
id: this.post.id
|
||||||
|
});
|
||||||
|
if (withHandler) this.connection.on('post-updated', this.onStreamPostUpdated);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
decapture(withHandler = false) {
|
||||||
|
if (this.$root.$data.os.isSignedIn) {
|
||||||
|
this.connection.send({
|
||||||
|
type: 'decapture',
|
||||||
|
id: this.post.id
|
||||||
|
});
|
||||||
|
if (withHandler) this.connection.off('post-updated', this.onStreamPostUpdated);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onStreamConnected() {
|
||||||
|
this.capture();
|
||||||
|
},
|
||||||
|
onStreamPostUpdated(data) {
|
||||||
|
const post = data.post;
|
||||||
|
if (post.id == this.post.id) {
|
||||||
|
this.$emit('update:post', post);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script lang="typescript">
|
||||||
|
|
||||||
|
|
||||||
|
this.isDetailOpened = false;
|
||||||
|
|
||||||
this.reply = () => {
|
this.reply = () => {
|
||||||
riot.mount(document.body.appendChild(document.createElement('mk-post-form-window')), {
|
riot.mount(document.body.appendChild(document.createElement('mk-post-form-window')), {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="mk-timeline" ref="root">
|
<div class="mk-timeline" ref="root">
|
||||||
<template v-for="(post, i) in _posts">
|
<template v-for="(post, i) in _posts">
|
||||||
<mk-timeline-post :post="post" :key="post.id"/>
|
<mk-timeline-post :post.sync="post" :key="post.id"/>
|
||||||
<p class="date" :key="post.id + '-time'" v-if="i != _posts.length - 1 && _post._date != _posts[i + 1]._date"><span>%fa:angle-up%{{ post._datetext }}</span><span>%fa:angle-down%{{ _posts[i + 1]._datetext }}</span></p>
|
<p class="date" :key="post.id + '-time'" v-if="i != _posts.length - 1 && _post._date != _posts[i + 1]._date"><span>%fa:angle-up%{{ post._datetext }}</span><span>%fa:angle-down%{{ _posts[i + 1]._datetext }}</span></p>
|
||||||
</template>
|
</template>
|
||||||
<footer data-yield="footer">
|
<footer data-yield="footer">
|
||||||
|
|
Loading…
Reference in a new issue