2018-04-25 23:01:41 -06:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<mk-friends-maker v-if="src == 'home' && alone" style="margin-bottom:8px"/>
|
|
|
|
|
|
|
|
<mk-notes ref="timeline" :more="existMore ? more : null">
|
|
|
|
<div slot="empty">
|
|
|
|
%fa:R comments%
|
|
|
|
%i18n:@empty%
|
|
|
|
</div>
|
|
|
|
</mk-notes>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-09-16 18:00:20 -06:00
|
|
|
import { HashtagStream } from '../../../common/scripts/streaming/hashtag';
|
2018-04-25 23:01:41 -06:00
|
|
|
|
|
|
|
const fetchLimit = 10;
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
props: {
|
|
|
|
src: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2018-09-16 18:00:20 -06:00
|
|
|
},
|
|
|
|
tagTl: {
|
|
|
|
required: false
|
2018-04-25 23:01:41 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
|
|
|
moreFetching: false,
|
|
|
|
existMore: false,
|
2018-09-16 18:00:20 -06:00
|
|
|
streamManager: null,
|
2018-04-25 23:01:41 -06:00
|
|
|
connection: null,
|
|
|
|
connectionId: null,
|
|
|
|
unreadCount: 0,
|
2018-09-17 11:14:12 -06:00
|
|
|
date: null,
|
|
|
|
baseQuery: {
|
|
|
|
includeMyRenotes: this.$store.state.settings.showMyRenotes,
|
|
|
|
includeRenotedMyNotes: this.$store.state.settings.showRenotedMyNotes,
|
|
|
|
includeLocalRenotes: this.$store.state.settings.showLocalRenotes
|
|
|
|
},
|
|
|
|
query: {},
|
|
|
|
endpoint: null
|
2018-04-25 23:01:41 -06:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
alone(): boolean {
|
2018-05-26 22:49:09 -06:00
|
|
|
return this.$store.state.i.followingCount == 0;
|
2018-04-25 23:01:41 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
canFetchMore(): boolean {
|
|
|
|
return !this.moreFetching && !this.fetching && this.existMore;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2018-09-17 11:14:12 -06:00
|
|
|
const prepend = note => {
|
|
|
|
(this.$refs.timeline as any).prepend(note);
|
|
|
|
};
|
|
|
|
|
2018-09-16 18:00:20 -06:00
|
|
|
if (this.src == 'tag') {
|
2018-09-17 11:14:12 -06:00
|
|
|
this.endpoint = 'notes/search_by_tag';
|
|
|
|
this.query = {
|
|
|
|
query: this.tagTl.query
|
|
|
|
};
|
2018-09-16 18:00:20 -06:00
|
|
|
this.connection = new HashtagStream((this as any).os, this.$store.state.i, this.tagTl.query);
|
2018-09-17 11:14:12 -06:00
|
|
|
this.connection.on('note', prepend);
|
|
|
|
this.$once('beforeDestroy', () => {
|
|
|
|
this.connection.off('note', prepend);
|
|
|
|
this.connection.close();
|
|
|
|
});
|
2018-09-16 18:00:20 -06:00
|
|
|
} else if (this.src == 'home') {
|
2018-09-17 11:14:12 -06:00
|
|
|
this.endpoint = 'notes/timeline';
|
|
|
|
const onChangeFollowing = () => {
|
|
|
|
this.fetch();
|
|
|
|
};
|
2018-09-16 18:00:20 -06:00
|
|
|
this.streamManager = (this as any).os.stream;
|
|
|
|
this.connection = this.streamManager.getConnection();
|
|
|
|
this.connectionId = this.streamManager.use();
|
2018-09-17 11:14:12 -06:00
|
|
|
this.connection.on('note', prepend);
|
|
|
|
this.connection.on('follow', onChangeFollowing);
|
|
|
|
this.connection.on('unfollow', onChangeFollowing);
|
|
|
|
this.$once('beforeDestroy', () => {
|
|
|
|
this.connection.off('note', prepend);
|
|
|
|
this.connection.off('follow', onChangeFollowing);
|
|
|
|
this.connection.off('unfollow', onChangeFollowing);
|
|
|
|
this.streamManager.dispose(this.connectionId);
|
|
|
|
});
|
2018-09-16 18:00:20 -06:00
|
|
|
} else if (this.src == 'local') {
|
2018-09-17 11:14:12 -06:00
|
|
|
this.endpoint = 'notes/local-timeline';
|
2018-09-16 18:00:20 -06:00
|
|
|
this.streamManager = (this as any).os.streams.localTimelineStream;
|
|
|
|
this.connection = this.streamManager.getConnection();
|
|
|
|
this.connectionId = this.streamManager.use();
|
2018-09-17 11:14:12 -06:00
|
|
|
this.connection.on('note', prepend);
|
|
|
|
this.$once('beforeDestroy', () => {
|
|
|
|
this.connection.off('note', prepend);
|
|
|
|
this.streamManager.dispose(this.connectionId);
|
|
|
|
});
|
2018-09-16 18:00:20 -06:00
|
|
|
} else if (this.src == 'hybrid') {
|
2018-09-17 11:14:12 -06:00
|
|
|
this.endpoint = 'notes/hybrid-timeline';
|
2018-09-16 18:00:20 -06:00
|
|
|
this.streamManager = (this as any).os.streams.hybridTimelineStream;
|
|
|
|
this.connection = this.streamManager.getConnection();
|
|
|
|
this.connectionId = this.streamManager.use();
|
2018-09-17 11:14:12 -06:00
|
|
|
this.connection.on('note', prepend);
|
|
|
|
this.$once('beforeDestroy', () => {
|
|
|
|
this.connection.off('note', prepend);
|
|
|
|
this.streamManager.dispose(this.connectionId);
|
|
|
|
});
|
2018-09-16 18:00:20 -06:00
|
|
|
} else if (this.src == 'global') {
|
2018-09-17 11:14:12 -06:00
|
|
|
this.endpoint = 'notes/global-timeline';
|
2018-09-16 18:00:20 -06:00
|
|
|
this.streamManager = (this as any).os.streams.globalTimelineStream;
|
|
|
|
this.connection = this.streamManager.getConnection();
|
|
|
|
this.connectionId = this.streamManager.use();
|
2018-09-17 11:14:12 -06:00
|
|
|
this.connection.on('note', prepend);
|
|
|
|
this.$once('beforeDestroy', () => {
|
|
|
|
this.connection.off('note', prepend);
|
|
|
|
this.streamManager.dispose(this.connectionId);
|
|
|
|
});
|
2018-09-16 18:00:20 -06:00
|
|
|
} else if (this.src == 'mentions') {
|
2018-09-17 11:14:12 -06:00
|
|
|
this.endpoint = 'notes/mentions';
|
|
|
|
this.streamManager = (this as any).os.stream;
|
|
|
|
this.connection = this.streamManager.getConnection();
|
|
|
|
this.connectionId = this.streamManager.use();
|
|
|
|
this.connection.on('mention', prepend);
|
|
|
|
this.$once('beforeDestroy', () => {
|
|
|
|
this.connection.off('mention', prepend);
|
|
|
|
this.streamManager.dispose(this.connectionId);
|
|
|
|
});
|
|
|
|
} else if (this.src == 'messages') {
|
|
|
|
this.endpoint = 'notes/mentions';
|
|
|
|
this.query = {
|
|
|
|
visibility: 'specified'
|
|
|
|
};
|
|
|
|
const onNote = note => {
|
|
|
|
if (note.visibility == 'specified') {
|
|
|
|
prepend(note);
|
|
|
|
}
|
|
|
|
};
|
2018-09-16 18:00:20 -06:00
|
|
|
this.streamManager = (this as any).os.stream;
|
|
|
|
this.connection = this.streamManager.getConnection();
|
|
|
|
this.connectionId = this.streamManager.use();
|
2018-09-17 11:14:12 -06:00
|
|
|
this.connection.on('mention', onNote);
|
|
|
|
this.$once('beforeDestroy', () => {
|
|
|
|
this.connection.off('mention', onNote);
|
|
|
|
this.streamManager.dispose(this.connectionId);
|
|
|
|
});
|
2018-04-25 23:01:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
this.fetch();
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeDestroy() {
|
2018-09-17 11:14:12 -06:00
|
|
|
this.$emit('beforeDestroy');
|
2018-04-25 23:01:41 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
fetch() {
|
|
|
|
this.fetching = true;
|
|
|
|
|
|
|
|
(this.$refs.timeline as any).init(() => new Promise((res, rej) => {
|
2018-09-17 11:14:12 -06:00
|
|
|
(this as any).api(this.endpoint, Object.assign({
|
2018-04-25 23:01:41 -06:00
|
|
|
limit: fetchLimit + 1,
|
2018-09-17 11:14:12 -06:00
|
|
|
untilDate: this.date ? this.date.getTime() : undefined
|
|
|
|
}, this.baseQuery, this.query)).then(notes => {
|
2018-04-25 23:01:41 -06:00
|
|
|
if (notes.length == fetchLimit + 1) {
|
|
|
|
notes.pop();
|
|
|
|
this.existMore = true;
|
|
|
|
}
|
|
|
|
res(notes);
|
|
|
|
this.fetching = false;
|
|
|
|
this.$emit('loaded');
|
|
|
|
}, rej);
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
more() {
|
|
|
|
if (!this.canFetchMore) return;
|
|
|
|
|
|
|
|
this.moreFetching = true;
|
|
|
|
|
2018-09-17 11:14:12 -06:00
|
|
|
const promise = (this as any).api(this.endpoint, Object.assign({
|
2018-04-25 23:01:41 -06:00
|
|
|
limit: fetchLimit + 1,
|
2018-09-17 11:14:12 -06:00
|
|
|
untilId: (this.$refs.timeline as any).tail().id
|
|
|
|
}, this.baseQuery, this.query));
|
2018-05-26 08:53:22 -06:00
|
|
|
|
|
|
|
promise.then(notes => {
|
2018-04-25 23:01:41 -06:00
|
|
|
if (notes.length == fetchLimit + 1) {
|
|
|
|
notes.pop();
|
|
|
|
} else {
|
|
|
|
this.existMore = false;
|
|
|
|
}
|
|
|
|
notes.forEach(n => (this.$refs.timeline as any).append(n));
|
|
|
|
this.moreFetching = false;
|
|
|
|
});
|
2018-05-26 08:53:22 -06:00
|
|
|
|
|
|
|
return promise;
|
2018-04-25 23:01:41 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
focus() {
|
|
|
|
(this.$refs.timeline as any).focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
warp(date) {
|
|
|
|
this.date = date;
|
|
|
|
this.fetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|