2018-04-26 05:01:41 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
2019-02-17 19:45:16 +00:00
|
|
|
<ui-container v-if="src == 'home' && alone" :show-header="false" style="margin-bottom:8px;">
|
|
|
|
<div class="zrzngnxs">
|
|
|
|
<p>{{ $t('@.empty-timeline-info.follow-users-to-make-your-timeline') }}</p>
|
|
|
|
<router-link to="/explore">{{ $t('@.empty-timeline-info.explore') }}</router-link>
|
|
|
|
</div>
|
|
|
|
</ui-container>
|
2018-04-26 05:01:41 +00:00
|
|
|
|
2019-02-18 00:17:55 +00:00
|
|
|
<mk-notes ref="timeline" :make-promise="makePromise" @inited="() => $emit('loaded')">
|
2019-02-18 02:13:56 +00:00
|
|
|
<template #empty>
|
2019-02-14 20:59:07 +00:00
|
|
|
<fa :icon="['far', 'comments']"/>{{ $t('empty') }}
|
2019-02-18 00:48:00 +00:00
|
|
|
</template>
|
2018-04-26 05:01:41 +00:00
|
|
|
</mk-notes>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2019-02-14 20:59:07 +00:00
|
|
|
import i18n from '../../../i18n';
|
2018-04-26 05:01:41 +00:00
|
|
|
|
|
|
|
const fetchLimit = 10;
|
|
|
|
|
|
|
|
export default Vue.extend({
|
2019-02-14 20:59:07 +00:00
|
|
|
i18n: i18n('mobile/views/pages/home.timeline.vue'),
|
2019-02-17 19:45:16 +00:00
|
|
|
|
2018-04-26 05:01:41 +00:00
|
|
|
props: {
|
|
|
|
src: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2018-09-17 00:00:20 +00:00
|
|
|
},
|
|
|
|
tagTl: {
|
|
|
|
required: false
|
2018-04-26 05:01:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2018-09-17 00:00:20 +00:00
|
|
|
streamManager: null,
|
2018-04-26 05:01:41 +00:00
|
|
|
connection: null,
|
|
|
|
unreadCount: 0,
|
2018-09-17 17:14:12 +00:00
|
|
|
date: null,
|
|
|
|
baseQuery: {
|
|
|
|
includeMyRenotes: this.$store.state.settings.showMyRenotes,
|
|
|
|
includeRenotedMyNotes: this.$store.state.settings.showRenotedMyNotes,
|
|
|
|
includeLocalRenotes: this.$store.state.settings.showLocalRenotes
|
|
|
|
},
|
|
|
|
query: {},
|
2019-02-18 00:17:55 +00:00
|
|
|
endpoint: null,
|
|
|
|
makePromise: null
|
2018-04-26 05:01:41 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
alone(): boolean {
|
2018-05-27 04:49:09 +00:00
|
|
|
return this.$store.state.i.followingCount == 0;
|
2018-04-26 05:01:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-02-18 00:17:55 +00:00
|
|
|
created() {
|
2018-09-17 17:14:12 +00:00
|
|
|
const prepend = note => {
|
|
|
|
(this.$refs.timeline as any).prepend(note);
|
|
|
|
};
|
|
|
|
|
2018-09-17 00:00:20 +00:00
|
|
|
if (this.src == 'tag') {
|
2018-09-17 17:14:12 +00:00
|
|
|
this.endpoint = 'notes/search_by_tag';
|
|
|
|
this.query = {
|
|
|
|
query: this.tagTl.query
|
|
|
|
};
|
2018-11-08 23:13:34 +00:00
|
|
|
this.connection = this.$root.stream.connectToChannel('hashtag', { q: this.tagTl.query });
|
2018-09-17 17:14:12 +00:00
|
|
|
this.connection.on('note', prepend);
|
2018-09-17 00:00:20 +00:00
|
|
|
} else if (this.src == 'home') {
|
2018-09-17 17:14:12 +00:00
|
|
|
this.endpoint = 'notes/timeline';
|
|
|
|
const onChangeFollowing = () => {
|
|
|
|
this.fetch();
|
|
|
|
};
|
2018-11-08 23:13:34 +00:00
|
|
|
this.connection = this.$root.stream.useSharedConnection('homeTimeline');
|
2018-09-17 17:14:12 +00:00
|
|
|
this.connection.on('note', prepend);
|
|
|
|
this.connection.on('follow', onChangeFollowing);
|
|
|
|
this.connection.on('unfollow', onChangeFollowing);
|
2018-09-17 00:00:20 +00:00
|
|
|
} else if (this.src == 'local') {
|
2018-09-17 17:14:12 +00:00
|
|
|
this.endpoint = 'notes/local-timeline';
|
2018-11-08 23:13:34 +00:00
|
|
|
this.connection = this.$root.stream.useSharedConnection('localTimeline');
|
2018-09-17 17:14:12 +00:00
|
|
|
this.connection.on('note', prepend);
|
2018-09-17 00:00:20 +00:00
|
|
|
} else if (this.src == 'hybrid') {
|
2018-09-17 17:14:12 +00:00
|
|
|
this.endpoint = 'notes/hybrid-timeline';
|
2018-11-08 23:13:34 +00:00
|
|
|
this.connection = this.$root.stream.useSharedConnection('hybridTimeline');
|
2018-09-17 17:14:12 +00:00
|
|
|
this.connection.on('note', prepend);
|
2018-09-17 00:00:20 +00:00
|
|
|
} else if (this.src == 'global') {
|
2018-09-17 17:14:12 +00:00
|
|
|
this.endpoint = 'notes/global-timeline';
|
2018-11-08 23:13:34 +00:00
|
|
|
this.connection = this.$root.stream.useSharedConnection('globalTimeline');
|
2018-09-17 17:14:12 +00:00
|
|
|
this.connection.on('note', prepend);
|
2018-09-17 00:00:20 +00:00
|
|
|
} else if (this.src == 'mentions') {
|
2018-09-17 17:14:12 +00:00
|
|
|
this.endpoint = 'notes/mentions';
|
2018-11-08 23:13:34 +00:00
|
|
|
this.connection = this.$root.stream.useSharedConnection('main');
|
2018-09-17 17:14:12 +00:00
|
|
|
this.connection.on('mention', prepend);
|
|
|
|
} else if (this.src == 'messages') {
|
|
|
|
this.endpoint = 'notes/mentions';
|
|
|
|
this.query = {
|
|
|
|
visibility: 'specified'
|
|
|
|
};
|
|
|
|
const onNote = note => {
|
|
|
|
if (note.visibility == 'specified') {
|
|
|
|
prepend(note);
|
|
|
|
}
|
|
|
|
};
|
2018-11-08 23:13:34 +00:00
|
|
|
this.connection = this.$root.stream.useSharedConnection('main');
|
2018-09-17 17:14:12 +00:00
|
|
|
this.connection.on('mention', onNote);
|
2018-04-26 05:01:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 00:17:55 +00:00
|
|
|
this.makePromise = cursor => this.$root.api(this.endpoint, {
|
|
|
|
limit: fetchLimit + 1,
|
|
|
|
untilDate: cursor ? undefined : (this.date ? this.date.getTime() : undefined),
|
|
|
|
untilId: cursor ? cursor : undefined,
|
|
|
|
...this.baseQuery, ...this.query
|
|
|
|
}).then(notes => {
|
|
|
|
if (notes.length == fetchLimit + 1) {
|
|
|
|
notes.pop();
|
|
|
|
return {
|
|
|
|
notes: notes,
|
|
|
|
cursor: notes[notes.length - 1].id
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
notes: notes,
|
|
|
|
cursor: null
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
2018-04-26 05:01:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
beforeDestroy() {
|
2018-10-07 02:06:17 +00:00
|
|
|
this.connection.dispose();
|
2018-04-26 05:01:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
focus() {
|
|
|
|
(this.$refs.timeline as any).focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
warp(date) {
|
|
|
|
this.date = date;
|
2019-02-18 00:17:55 +00:00
|
|
|
(this.$refs.timeline as any).reload();
|
2018-04-26 05:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2019-02-17 19:45:16 +00:00
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
.zrzngnxs
|
|
|
|
padding 16px
|
|
|
|
text-align center
|
|
|
|
font-size 14px
|
|
|
|
|
|
|
|
> p
|
|
|
|
margin 0 0 8px 0
|
|
|
|
|
|
|
|
</style>
|