misskey/src/client/app/mobile/views/components/timeline.vue

141 lines
3.3 KiB
Vue
Raw Normal View History

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