2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2021-08-07 10:55:16 +02:00
|
|
|
<div class="shaynizk">
|
|
|
|
<div class="form">
|
2021-10-12 14:46:18 +02:00
|
|
|
<MkInput v-model="name" class="_formBlock">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.name }}</template>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkInput>
|
2021-10-12 14:46:18 +02:00
|
|
|
<MkSelect v-model="src" class="_formBlock">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.antennaSource }}</template>
|
|
|
|
<option value="all">{{ i18n.ts._antennaSources.all }}</option>
|
|
|
|
<!--<option value="home">{{ i18n.ts._antennaSources.homeTimeline }}</option>-->
|
|
|
|
<option value="users">{{ i18n.ts._antennaSources.users }}</option>
|
|
|
|
<!--<option value="list">{{ i18n.ts._antennaSources.userList }}</option>-->
|
|
|
|
<!--<option value="group">{{ i18n.ts._antennaSources.userGroup }}</option>-->
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkSelect>
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkSelect v-if="src === 'list'" v-model="userListId" class="_formBlock">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.userList }}</template>
|
2021-11-19 11:36:12 +01:00
|
|
|
<option v-for="list in userLists" :key="list.id" :value="list.id">{{ list.name }}</option>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkSelect>
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkSelect v-else-if="src === 'group'" v-model="userGroupId" class="_formBlock">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.userGroup }}</template>
|
2021-11-19 11:36:12 +01:00
|
|
|
<option v-for="group in userGroups" :key="group.id" :value="group.id">{{ group.name }}</option>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkSelect>
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkTextarea v-else-if="src === 'users'" v-model="users" class="_formBlock">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.users }}</template>
|
|
|
|
<template #caption>{{ i18n.ts.antennaUsersDescription }} <button class="_textButton" @click="addUser">{{ i18n.ts.addUser }}</button></template>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkTextarea>
|
2022-07-20 15:24:26 +02:00
|
|
|
<MkSwitch v-model="withReplies" class="_formBlock">{{ i18n.ts.withReplies }}</MkSwitch>
|
2021-10-12 14:46:18 +02:00
|
|
|
<MkTextarea v-model="keywords" class="_formBlock">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.antennaKeywords }}</template>
|
|
|
|
<template #caption>{{ i18n.ts.antennaKeywordsDescription }}</template>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkTextarea>
|
2021-10-12 14:46:18 +02:00
|
|
|
<MkTextarea v-model="excludeKeywords" class="_formBlock">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.antennaExcludeKeywords }}</template>
|
|
|
|
<template #caption>{{ i18n.ts.antennaKeywordsDescription }}</template>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkTextarea>
|
2022-07-20 15:24:26 +02:00
|
|
|
<MkSwitch v-model="caseSensitive" class="_formBlock">{{ i18n.ts.caseSensitive }}</MkSwitch>
|
|
|
|
<MkSwitch v-model="withFile" class="_formBlock">{{ i18n.ts.withFileAntenna }}</MkSwitch>
|
|
|
|
<MkSwitch v-model="notify" class="_formBlock">{{ i18n.ts.notifyAntenna }}</MkSwitch>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
2021-08-07 10:55:16 +02:00
|
|
|
<div class="actions">
|
2022-07-20 15:24:26 +02:00
|
|
|
<MkButton inline primary @click="saveAntenna()"><i class="fas fa-save"></i> {{ i18n.ts.save }}</MkButton>
|
|
|
|
<MkButton v-if="antenna.id != null" inline danger @click="deleteAntenna()"><i class="fas fa-trash"></i> {{ i18n.ts.delete }}</MkButton>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { watch } from 'vue';
|
2022-07-04 16:33:55 +02:00
|
|
|
import * as Acct from 'misskey-js/built/acct';
|
2021-11-11 18:02:25 +01:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkInput from '@/components/form/input.vue';
|
|
|
|
import MkTextarea from '@/components/form/textarea.vue';
|
|
|
|
import MkSelect from '@/components/form/select.vue';
|
|
|
|
import MkSwitch from '@/components/form/switch.vue';
|
|
|
|
import * as os from '@/os';
|
2022-05-25 09:37:15 +02:00
|
|
|
import { i18n } from '@/i18n';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
antenna: any
|
|
|
|
}>();
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'created'): void,
|
|
|
|
(ev: 'updated'): void,
|
|
|
|
(ev: 'deleted'): void,
|
|
|
|
}>();
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
let name: string = $ref(props.antenna.name);
|
|
|
|
let src: string = $ref(props.antenna.src);
|
|
|
|
let userListId: any = $ref(props.antenna.userListId);
|
|
|
|
let userGroupId: any = $ref(props.antenna.userGroupId);
|
|
|
|
let users: string = $ref(props.antenna.users.join('\n'));
|
|
|
|
let keywords: string = $ref(props.antenna.keywords.map(x => x.join(' ')).join('\n'));
|
|
|
|
let excludeKeywords: string = $ref(props.antenna.excludeKeywords.map(x => x.join(' ')).join('\n'));
|
|
|
|
let caseSensitive: boolean = $ref(props.antenna.caseSensitive);
|
|
|
|
let withReplies: boolean = $ref(props.antenna.withReplies);
|
|
|
|
let withFile: boolean = $ref(props.antenna.withFile);
|
|
|
|
let notify: boolean = $ref(props.antenna.notify);
|
|
|
|
let userLists: any = $ref(null);
|
|
|
|
let userGroups: any = $ref(null);
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
watch(() => src, async () => {
|
|
|
|
if (src === 'list' && userLists === null) {
|
|
|
|
userLists = await os.api('users/lists/list');
|
|
|
|
}
|
2020-02-14 17:03:59 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
if (src === 'group' && userGroups === null) {
|
|
|
|
const groups1 = await os.api('users/groups/owned');
|
|
|
|
const groups2 = await os.api('users/groups/joined');
|
2020-02-14 17:03:59 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
userGroups = [...groups1, ...groups2];
|
|
|
|
}
|
|
|
|
});
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
async function saveAntenna() {
|
|
|
|
const antennaData = {
|
|
|
|
name,
|
|
|
|
src,
|
|
|
|
userListId,
|
|
|
|
userGroupId,
|
|
|
|
withReplies,
|
|
|
|
withFile,
|
|
|
|
notify,
|
|
|
|
caseSensitive,
|
|
|
|
users: users.trim().split('\n').map(x => x.trim()),
|
|
|
|
keywords: keywords.trim().split('\n').map(x => x.trim().split(' ')),
|
|
|
|
excludeKeywords: excludeKeywords.trim().split('\n').map(x => x.trim().split(' ')),
|
|
|
|
};
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
if (props.antenna.id == null) {
|
|
|
|
await os.apiWithDialog('antennas/create', antennaData);
|
|
|
|
emit('created');
|
|
|
|
} else {
|
|
|
|
antennaData['antennaId'] = props.antenna.id;
|
|
|
|
await os.apiWithDialog('antennas/update', antennaData);
|
|
|
|
emit('updated');
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
async function deleteAntenna() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('removeAreYouSure', { x: props.antenna.name }),
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
await os.api('antennas/delete', {
|
|
|
|
antennaId: props.antenna.id,
|
|
|
|
});
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
os.success();
|
|
|
|
emit('deleted');
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-25 09:37:15 +02:00
|
|
|
function addUser() {
|
|
|
|
os.selectUser().then(user => {
|
|
|
|
users = users.trim();
|
|
|
|
users += '\n@' + Acct.toString(user as any);
|
|
|
|
users = users.trim();
|
|
|
|
});
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.shaynizk {
|
2021-08-07 10:55:16 +02:00
|
|
|
> .form {
|
|
|
|
padding: 32px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .actions {
|
|
|
|
padding: 24px 32px;
|
|
|
|
border-top: solid 0.5px var(--divider);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|