feat: Observe notification read and fix #6406 (#6407)

* Resolve https://github.com/syuilo/misskey/pull/6406#issuecomment-633203670

* Improve typing

* Observe notification read

* capture readAllNotifications

* fix

* fix

* Refactor

* Update src/client/components/notification.vue

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>

* Update src/client/components/notification.vue

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>

* missing ;

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
syuilo
2020-06-04 22:07:39 +09:00
committed by GitHub
10 changed files with 55 additions and 14 deletions

View File

@@ -90,9 +90,36 @@ export default Vue.extend({
getNoteSummary: (text: string) => noteSummary(text, this.$root.i18n.messages[this.$root.i18n.locale]),
followRequestDone: false,
groupInviteDone: false,
connection: null,
readObserver: null,
faIdCardAlt, faPlus, faQuoteLeft, faQuoteRight, faRetweet, faReply, faAt, faClock, faCheck, faPollH
};
},
mounted() {
if (!this.notification.isRead) {
this.readObserver = new IntersectionObserver((entries, observer) => {
if (!entries.some(entry => entry.isIntersecting)) return;
this.$root.stream.send('readNotification', {
id: this.notification.id
});
entries.map(({ target }) => observer.unobserve(target));
});
this.readObserver.observe(this.$el);
this.connection = this.$root.stream.useSharedConnection('main');
this.connection.on('readAllNotifications', () => this.readObserver.unobserve(this.$el));
}
},
beforeDestroy() {
if (!this.notification.isRead) {
this.readObserver.unobserve(this.$el);
this.connection.dispose();
}
},
methods: {
acceptFollowRequest() {
this.followRequestDone = true;

View File

@@ -71,10 +71,13 @@ export default Vue.extend({
methods: {
onNotification(notification) {
// TODO: ユーザーが画面を見てないと思われるとき(ブラウザやタブがアクティブじゃないなど)は送信しない
this.$root.stream.send('readNotification', {
id: notification.id
});
if (document.visibilityState === 'visible') {
this.$root.stream.send('readNotification', {
id: notification.id
});
notification.isRead = true;
}
this.prepend(notification);
},

View File

@@ -67,6 +67,7 @@ import extractMentions from '../../misc/extract-mentions';
import getAcct from '../../misc/acct/render';
import { formatTimeString } from '../../misc/format-time-string';
import { selectDriveFile } from '../scripts/select-drive-file';
import { noteVisibilities } from '../../types';
export default Vue.extend({
components: {
@@ -407,7 +408,7 @@ export default Vue.extend({
},
applyVisibility(v: string) {
this.visibility = ['public', 'home', 'followers', 'specified'].includes(v) ? v : 'public'; // v11互換性のため
this.visibility = (noteVisibilities as unknown as string[]).includes(v) ? v : 'public'; // v11互換性のため
},
addVisibleUser() {