feat: ユーザーをcontextmenuからアンテナに追加できるようになど (#11206)

* feat: ユーザーをcontextmenuからアンテナに追加できるように close #11115

* MkAvatars.vue変更

* nanka iroiro

* fix MkAvatars

* ix

* fix

---------

Co-authored-by: tamaina <tamaina@hotmail.co.jp>
This commit is contained in:
yupix
2023-07-10 15:55:10 +09:00
committed by GitHub
parent 239ea39d6f
commit f4d1fcaf67
11 changed files with 144 additions and 77 deletions

View File

@@ -1,7 +1,8 @@
import { ref } from "vue";
export class Cache<T> {
private cachedAt: number | null = null;
private value: T | undefined;
public value = ref<T | undefined>();
private lifetime: number;
constructor(lifetime: Cache<never>['lifetime']) {
@@ -10,21 +11,20 @@ export class Cache<T> {
public set(value: T): void {
this.cachedAt = Date.now();
this.value = value;
this.value.value = value;
}
public get(): T | undefined {
private get(): T | undefined {
if (this.cachedAt == null) return undefined;
if ((Date.now() - this.cachedAt) > this.lifetime) {
this.value = undefined;
this.value.value = undefined;
this.cachedAt = null;
return undefined;
}
return this.value;
return this.value.value;
}
public delete() {
this.value = undefined;
this.cachedAt = null;
}

View File

@@ -1,3 +1,4 @@
import { toUnicode } from 'punycode';
import { defineAsyncComponent } from 'vue';
import * as misskey from 'misskey-js';
import { i18n } from '@/i18n';
@@ -8,8 +9,7 @@ import { defaultStore, userActions } from '@/store';
import { $i, iAmModerator } from '@/account';
import { mainRouter } from '@/router';
import { Router } from '@/nirax';
import { rolesCache, userListsCache } from '@/cache';
import { toUnicode } from 'punycode';
import { antennasCache, rolesCache, userListsCache } from '@/cache';
export function getUserMenu(user: misskey.entities.UserDetailed, router: Router = mainRouter) {
const meId = $i ? $i.id : null;
@@ -166,11 +166,39 @@ export function getUserMenu(user: misskey.entities.UserDetailed, router: Router
return lists.map(list => ({
text: list.name,
action: () => {
os.apiWithDialog('users/lists/push', {
action: async () => {
await os.apiWithDialog('users/lists/push', {
listId: list.id,
userId: user.id,
});
userListsCache.delete();
},
}));
},
}, {
type: 'parent',
icon: 'ti ti-antenna',
text: i18n.ts.addToAntenna,
children: async () => {
const antennas = await antennasCache.fetch(() => os.api('antennas/list'));
const canonical = user.host === null ? `@${user.username}` : `@${user.username}@${toUnicode(user.host)}`;
return antennas.filter((a) => a.src === 'users').map(antenna => ({
text: antenna.name,
action: async () => {
await os.apiWithDialog('antennas/update', {
antennaId: antenna.id,
name: antenna.name,
keywords: antenna.keywords,
excludeKeywords: antenna.excludeKeywords,
src: antenna.src,
userListId: antenna.userListId,
users: [...antenna.users, canonical],
caseSensitive: antenna.caseSensitive,
withReplies: antenna.withReplies,
withFile: antenna.withFile,
notify: antenna.notify,
});
antennasCache.delete();
},
}));
},