summaryrefslogtreecommitdiff
path: root/src/client/app/common/views/deck/deck.direct.vue
blob: 29db5cb7f32a2cb92f7c01e5d120e85bbe217c02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<template>
<x-notes ref="timeline" :make-promise="makePromise" @inited="() => $emit('loaded')"/>
</template>

<script lang="ts">
import Vue from 'vue';
import XNotes from './deck.notes.vue';

const fetchLimit = 10;

export default Vue.extend({
	components: {
		XNotes
	},

	data() {
		return {
			connection: null,
			makePromise: cursor => this.$root.api('notes/mentions', {
				limit: fetchLimit + 1,
				untilId: cursor ? cursor : undefined,
				includeMyRenotes: this.$store.state.settings.showMyRenotes,
				includeRenotedMyNotes: this.$store.state.settings.showRenotedMyNotes,
				includeLocalRenotes: this.$store.state.settings.showLocalRenotes,
				visibility: 'specified'
			}).then(notes => {
				if (notes.length == fetchLimit + 1) {
					notes.pop();
					return {
						notes: notes,
						more: true
					};
				} else {
					return {
						notes: notes,
						more: false
					};
				}
			})
		};
	},

	mounted() {
		this.connection = this.$root.stream.useSharedConnection('main');
		this.connection.on('mention', this.onNote);
	},

	beforeDestroy() {
		this.connection.dispose();
	},

	methods: {
		onNote(note) {
			// Prepend a note
			if (note.visibility == 'specified') {
				(this.$refs.timeline as any).prepend(note);
			}
		},

		focus() {
			this.$refs.timeline.focus();
		}
	}
});
</script>