forked from misskey-dev/dolphin
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<template> | ||
<x-notes ref="timeline" :pagination="pagination" @before="$emit('before')" @after="e => $emit('after', e)"/> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Vue from 'vue'; | ||
import XNotes from '../components/notes.vue'; | ||
export default Vue.extend({ | ||
components: { | ||
XNotes | ||
}, | ||
data() { | ||
return { | ||
connection: null, | ||
pagination: null, | ||
}; | ||
}, | ||
created() { | ||
this.$once('hook:beforeDestroy', () => { | ||
this.connection.dispose(); | ||
}); | ||
const prepend = note => { | ||
(this.$refs.timeline as any).prepend(note); | ||
}; | ||
const onChangeFollowing = () => { | ||
this.fetch(); | ||
}; | ||
this.connection = this.$root.stream.useSharedConnection('globalTimeline'); | ||
this.connection.on('note', prepend); | ||
this.connection.on('follow', onChangeFollowing); | ||
this.connection.on('unfollow', onChangeFollowing); | ||
this.pagination = { | ||
endpoint: 'notes/global-timeline', | ||
limit: 10, | ||
params: {} | ||
}; | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<template> | ||
<div class="dp-global"> | ||
<x-global-timeline @before="before()" @after="after()"/> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Vue from 'vue'; | ||
import Progress from '../scripts/loading'; | ||
import XGlobalTimeline from './index.global.timeline.vue'; | ||
export default Vue.extend({ | ||
metaInfo() { | ||
return { | ||
title: this.$t('globalTimeline') | ||
}; | ||
}, | ||
components: { | ||
XGlobalTimeline | ||
}, | ||
methods: { | ||
before() { | ||
Progress.start(); | ||
}, | ||
after() { | ||
Progress.done(); | ||
} | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import $ from 'cafy'; | ||
import { ID } from '../../../../misc/cafy-id'; | ||
import define from '../../define'; | ||
import { makePaginationQuery } from '../../common/make-pagination-query'; | ||
import { Notes } from '../../../../models'; | ||
import { generateMuteQuery } from '../../common/generate-mute-query'; | ||
|
||
export const meta = { | ||
desc: { | ||
'ja-JP': 'グローバルタイムラインを取得します。' | ||
}, | ||
|
||
tags: ['notes'], | ||
|
||
params: { | ||
withFiles: { | ||
validator: $.optional.bool, | ||
desc: { | ||
'ja-JP': 'ファイルが添付された投稿に限定するか否か' | ||
} | ||
}, | ||
|
||
limit: { | ||
validator: $.optional.num.range(1, 100), | ||
default: 10 | ||
}, | ||
|
||
sinceId: { | ||
validator: $.optional.type(ID), | ||
}, | ||
|
||
untilId: { | ||
validator: $.optional.type(ID), | ||
}, | ||
|
||
sinceDate: { | ||
validator: $.optional.num | ||
}, | ||
|
||
untilDate: { | ||
validator: $.optional.num | ||
}, | ||
}, | ||
|
||
res: { | ||
type: 'array' as const, | ||
optional: false as const, nullable: false as const, | ||
items: { | ||
type: 'object' as const, | ||
optional: false as const, nullable: false as const, | ||
ref: 'Note', | ||
} | ||
}, | ||
}; | ||
|
||
export default define(meta, async (ps, user) => { | ||
//#region Construct query | ||
const query = makePaginationQuery(Notes.createQueryBuilder('note'), | ||
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate) | ||
.andWhere('note.visibility = \'public\'') | ||
.andWhere('note.replyId IS NULL') | ||
.leftJoinAndSelect('note.user', 'user'); | ||
|
||
if (user) generateMuteQuery(query, user); | ||
|
||
if (ps.withFiles) { | ||
query.andWhere('note.fileIds != \'{}\''); | ||
} | ||
//#endregion | ||
|
||
const timeline = await query.take(ps.limit!).getMany(); | ||
|
||
return await Notes.packMany(timeline, user); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import autobind from 'autobind-decorator'; | ||
import shouldMuteThisNote from '../../../../misc/should-mute-this-note'; | ||
import Channel from '../channel'; | ||
import { Notes } from '../../../../models'; | ||
import { PackedNote } from '../../../../models/repositories/note'; | ||
|
||
export default class extends Channel { | ||
public readonly chName = 'globalTimeline'; | ||
public static shouldShare = true; | ||
public static requireCredential = false; | ||
|
||
@autobind | ||
public async init(params: any) { | ||
// Subscribe events | ||
this.subscriber.on('notesStream', this.onNote); | ||
} | ||
|
||
@autobind | ||
private async onNote(note: PackedNote) { | ||
if (note.visibility !== 'public') return; | ||
|
||
// リプライなら再pack | ||
if (note.replyId != null) { | ||
note.reply = await Notes.pack(note.replyId, this.user, { | ||
detail: true | ||
}); | ||
} | ||
// Renoteなら再pack | ||
if (note.renoteId != null) { | ||
note.renote = await Notes.pack(note.renoteId, this.user, { | ||
detail: true | ||
}); | ||
} | ||
|
||
// 返信は除外 | ||
if (note.reply) { | ||
return; | ||
} | ||
|
||
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する | ||
if (shouldMuteThisNote(note, this.muting)) return; | ||
|
||
this.send('note', note); | ||
} | ||
|
||
@autobind | ||
public dispose() { | ||
// Unsubscribe events | ||
this.subscriber.off('notesStream', this.onNote); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters