2018-02-14 03:24:49 +00:00
|
|
|
<template>
|
|
|
|
<div class="mk-timeline">
|
2018-02-14 04:35:51 +00:00
|
|
|
<mk-friends-maker v-if="alone"/>
|
2018-02-22 08:51:08 +00:00
|
|
|
<mk-posts :posts="posts">
|
2018-02-14 03:24:49 +00:00
|
|
|
<div class="init" v-if="fetching">
|
|
|
|
%fa:spinner .pulse%%i18n:common.loading%
|
|
|
|
</div>
|
|
|
|
<div class="empty" v-if="!fetching && posts.length == 0">
|
|
|
|
%fa:R comments%
|
|
|
|
%i18n:mobile.tags.mk-home-timeline.empty-timeline%
|
|
|
|
</div>
|
2018-02-22 23:07:30 +00:00
|
|
|
<button v-if="!fetching && existMore" @click="more" :disabled="moreFetching" slot="tail">
|
|
|
|
<span v-if="!moreFetching">%i18n:mobile.tags.mk-timeline.load-more%</span>
|
|
|
|
<span v-if="moreFetching">%i18n:common.loading%<mk-ellipsis/></span>
|
2018-02-14 03:24:49 +00:00
|
|
|
</button>
|
|
|
|
</mk-posts>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-02-22 23:07:30 +00:00
|
|
|
|
|
|
|
const limit = 10;
|
|
|
|
|
2018-02-14 03:24:49 +00:00
|
|
|
export default Vue.extend({
|
|
|
|
props: {
|
|
|
|
date: {
|
|
|
|
type: Date,
|
|
|
|
required: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
|
|
|
moreFetching: false,
|
|
|
|
posts: [],
|
2018-02-22 23:07:30 +00:00
|
|
|
existMore: false,
|
2018-02-14 03:24:49 +00:00
|
|
|
connection: null,
|
|
|
|
connectionId: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
alone(): boolean {
|
2018-03-29 05:48:47 +00:00
|
|
|
return (this as any).os.i.followingCount == 0;
|
2018-02-14 03:24:49 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2018-02-18 03:35:18 +00:00
|
|
|
this.connection = (this as any).os.stream.getConnection();
|
|
|
|
this.connectionId = (this as any).os.stream.use();
|
2018-02-14 03:24:49 +00:00
|
|
|
|
|
|
|
this.connection.on('post', this.onPost);
|
|
|
|
this.connection.on('follow', this.onChangeFollowing);
|
|
|
|
this.connection.on('unfollow', this.onChangeFollowing);
|
|
|
|
|
|
|
|
this.fetch();
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.connection.off('post', this.onPost);
|
|
|
|
this.connection.off('follow', this.onChangeFollowing);
|
|
|
|
this.connection.off('unfollow', this.onChangeFollowing);
|
2018-02-18 03:35:18 +00:00
|
|
|
(this as any).os.stream.dispose(this.connectionId);
|
2018-02-14 03:24:49 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
fetch(cb?) {
|
|
|
|
this.fetching = true;
|
2018-02-18 03:35:18 +00:00
|
|
|
(this as any).api('posts/timeline', {
|
2018-02-22 23:07:30 +00:00
|
|
|
limit: limit + 1,
|
2018-03-29 05:48:47 +00:00
|
|
|
untilDate: this.date ? (this.date as any).getTime() : undefined
|
2018-02-14 03:24:49 +00:00
|
|
|
}).then(posts => {
|
2018-02-22 23:07:30 +00:00
|
|
|
if (posts.length == limit + 1) {
|
|
|
|
posts.pop();
|
|
|
|
this.existMore = true;
|
|
|
|
}
|
2018-02-14 03:24:49 +00:00
|
|
|
this.posts = posts;
|
2018-02-19 14:37:09 +00:00
|
|
|
this.fetching = false;
|
2018-02-22 08:38:48 +00:00
|
|
|
this.$emit('loaded');
|
2018-02-14 03:24:49 +00:00
|
|
|
if (cb) cb();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
more() {
|
|
|
|
this.moreFetching = true;
|
2018-02-18 03:35:18 +00:00
|
|
|
(this as any).api('posts/timeline', {
|
2018-02-22 23:07:30 +00:00
|
|
|
limit: limit + 1,
|
2018-03-29 05:48:47 +00:00
|
|
|
untilId: this.posts[this.posts.length - 1].id
|
2018-02-14 03:24:49 +00:00
|
|
|
}).then(posts => {
|
2018-02-22 23:07:30 +00:00
|
|
|
if (posts.length == limit + 1) {
|
|
|
|
posts.pop();
|
|
|
|
this.existMore = true;
|
|
|
|
} else {
|
|
|
|
this.existMore = false;
|
|
|
|
}
|
2018-02-22 08:37:40 +00:00
|
|
|
this.posts = this.posts.concat(posts);
|
2018-02-14 03:24:49 +00:00
|
|
|
this.moreFetching = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onPost(post) {
|
|
|
|
this.posts.unshift(post);
|
|
|
|
},
|
|
|
|
onChangeFollowing() {
|
|
|
|
this.fetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2018-02-22 08:51:08 +00:00
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
.mk-friends-maker
|
|
|
|
margin-bottom 8px
|
|
|
|
</style>
|