misskey-awawa/src/client/components/timeline.vue

137 lines
3.3 KiB
Vue
Raw Normal View History

<template>
2020-02-18 19:08:35 +00:00
<x-notes ref="tl" :pagination="pagination" @before="$emit('before')" @after="e => $emit('after', e)" @queue="$emit('queue', $event)"/>
</template>
<script lang="ts">
import Vue from 'vue';
import XNotes from './notes.vue';
export default Vue.extend({
components: {
XNotes
},
props: {
src: {
type: String,
required: true
},
list: {
required: false
},
antenna: {
required: false
2020-02-19 17:40:53 +00:00
},
sound: {
type: Boolean,
required: false,
default: false,
}
},
data() {
return {
connection: null,
2020-02-09 13:00:38 +00:00
connection2: null,
pagination: null,
baseQuery: {
includeMyRenotes: this.$store.state.settings.showMyRenotes,
includeRenotedMyNotes: this.$store.state.settings.showRenotedMyNotes,
includeLocalRenotes: this.$store.state.settings.showLocalRenotes
},
query: {},
};
},
created() {
this.$once('hook:beforeDestroy', () => {
this.connection.dispose();
2020-02-09 13:00:38 +00:00
if (this.connection2) this.connection2.dispose();
});
const prepend = note => {
(this.$refs.tl as any).prepend(note);
2020-02-19 17:40:53 +00:00
if (this.sound) {
const audio = new Audio(`/assets/sounds/${this.$store.state.device.sfxNote}.mp3`);
audio.volume = this.$store.state.device.sfxVolume;
audio.play();
}
};
const onUserAdded = () => {
(this.$refs.tl as any).reload();
};
const onUserRemoved = () => {
(this.$refs.tl as any).reload();
};
2020-02-09 13:00:38 +00:00
const onChangeFollowing = () => {
if (!this.$refs.tl.backed) {
this.$refs.tl.reload();
}
};
let endpoint;
if (this.src == 'antenna') {
endpoint = 'antennas/notes';
this.query = {
antennaId: this.antenna.id
};
this.connection = this.$root.stream.connectToChannel('antenna', {
antennaId: this.antenna.id
});
this.connection.on('note', prepend);
} else if (this.src == 'home') {
endpoint = 'notes/timeline';
this.connection = this.$root.stream.useSharedConnection('homeTimeline');
this.connection.on('note', prepend);
2020-02-09 13:00:38 +00:00
this.connection2 = this.$root.stream.useSharedConnection('main');
this.connection2.on('follow', onChangeFollowing);
this.connection2.on('unfollow', onChangeFollowing);
} else if (this.src == 'local') {
endpoint = 'notes/local-timeline';
this.connection = this.$root.stream.useSharedConnection('localTimeline');
this.connection.on('note', prepend);
} else if (this.src == 'social') {
endpoint = 'notes/hybrid-timeline';
this.connection = this.$root.stream.useSharedConnection('hybridTimeline');
this.connection.on('note', prepend);
} else if (this.src == 'global') {
endpoint = 'notes/global-timeline';
this.connection = this.$root.stream.useSharedConnection('globalTimeline');
this.connection.on('note', prepend);
} else if (this.src == 'list') {
endpoint = 'notes/user-list-timeline';
this.query = {
listId: this.list.id
};
this.connection = this.$root.stream.connectToChannel('userList', {
listId: this.list.id
});
this.connection.on('note', prepend);
this.connection.on('userAdded', onUserAdded);
this.connection.on('userRemoved', onUserRemoved);
}
this.pagination = {
endpoint: endpoint,
limit: 10,
params: init => ({
untilDate: init ? undefined : (this.date ? this.date.getTime() : undefined),
...this.baseQuery, ...this.query
})
};
},
methods: {
focus() {
this.$refs.tl.focus();
}
}
});
</script>