feat: ✨ introduce local user select dialog
Used for selecting group members and proxy account. Closes #7987, API change: users/search-by-username-and-host now takes `maxDaysSinceLastActive` parameter and doesn't have any active threshold anymore by default.
This commit is contained in:
parent
7df442b48e
commit
24cc6a925d
|
@ -32,6 +32,12 @@ export const paramDef = {
|
|||
username: { type: "string", nullable: true },
|
||||
host: { type: "string", nullable: true },
|
||||
limit: { type: "integer", minimum: 1, maximum: 100, default: 10 },
|
||||
maxDaysSinceLastActive: {
|
||||
type: "integer",
|
||||
minimum: 1,
|
||||
maximum: 1000,
|
||||
default: 30,
|
||||
},
|
||||
detail: { type: "boolean", default: true },
|
||||
},
|
||||
anyOf: [{ required: ["username"] }, { required: ["host"] }],
|
||||
|
@ -40,7 +46,9 @@ export const paramDef = {
|
|||
// TODO: avatar,bannerをJOINしたいけどエラーになる
|
||||
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const activeThreshold = new Date(Date.now() - 1000 * 60 * 60 * 24 * 30); // 30日
|
||||
const activeThreshold = ps.maxDaysSinceLastActive
|
||||
? new Date(Date.now() - 1000 * 60 * 60 * 24 * ps.maxDaysSinceLastActive)
|
||||
: null;
|
||||
|
||||
if (ps.host) {
|
||||
const q = Users.createQueryBuilder("user")
|
||||
|
@ -75,8 +83,10 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
.andWhere("user.isSuspended = FALSE")
|
||||
.andWhere("user.usernameLower LIKE :username", {
|
||||
username: `${sqlLikeEscape(ps.username.toLowerCase())}%`,
|
||||
})
|
||||
.andWhere(
|
||||
});
|
||||
|
||||
if (activeThreshold) {
|
||||
query.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where("user.updatedAt IS NULL").orWhere(
|
||||
"user.updatedAt > :activeThreshold",
|
||||
|
@ -84,6 +94,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
query.setParameters(followingQuery.getParameters());
|
||||
|
||||
|
|
|
@ -0,0 +1,223 @@
|
|||
<template>
|
||||
<XModalWindow
|
||||
ref="dialogEl"
|
||||
:with-ok-button="true"
|
||||
:ok-button-disabled="selected == null"
|
||||
@click="cancel()"
|
||||
@close="cancel()"
|
||||
@ok="ok()"
|
||||
@closed="$emit('closed')"
|
||||
>
|
||||
<template #header>{{ i18n.ts.selectUser }}</template>
|
||||
<div class="tbhwbxdg">
|
||||
<div class="form">
|
||||
<FormSplit :min-width="170">
|
||||
<MkInput
|
||||
v-model="username"
|
||||
:autofocus="true"
|
||||
@update:modelValue="search"
|
||||
>
|
||||
<template #label>{{ i18n.ts.username }}</template>
|
||||
<template #prefix>@</template>
|
||||
</MkInput>
|
||||
</FormSplit>
|
||||
</div>
|
||||
<div
|
||||
v-if="username != '' || host != ''"
|
||||
class="result"
|
||||
:class="{ hit: users.length > 0 }"
|
||||
>
|
||||
<div v-if="users.length > 0" class="users">
|
||||
<div
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
class="user"
|
||||
:class="{
|
||||
selected: selected && selected.id === user.id,
|
||||
}"
|
||||
@click="selected = user"
|
||||
@dblclick="ok()"
|
||||
>
|
||||
<MkAvatar
|
||||
:user="user"
|
||||
class="avatar"
|
||||
:show-indicator="true"
|
||||
disableLink
|
||||
/>
|
||||
<div class="body">
|
||||
<MkUserName :user="user" class="name" />
|
||||
<MkAcct :user="user" class="acct" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty">
|
||||
<span>{{ i18n.ts.noUsers }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="username == '' && host == ''" class="recent">
|
||||
<div class="users">
|
||||
<div
|
||||
v-for="user in recentUsers"
|
||||
:key="user.id"
|
||||
class="user"
|
||||
:class="{
|
||||
selected: selected && selected.id === user.id,
|
||||
}"
|
||||
@click="selected = user"
|
||||
@dblclick="ok()"
|
||||
>
|
||||
<MkAvatar
|
||||
:user="user"
|
||||
class="avatar"
|
||||
:show-indicator="true"
|
||||
disableLink
|
||||
/>
|
||||
<div class="body">
|
||||
<MkUserName :user="user" class="name" />
|
||||
<MkAcct :user="user" class="acct" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</XModalWindow>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { nextTick, onMounted } from "vue";
|
||||
import * as misskey from "calckey-js";
|
||||
import MkInput from "@/components/form/input.vue";
|
||||
import FormSplit from "@/components/form/split.vue";
|
||||
import XModalWindow from "@/components/MkModalWindow.vue";
|
||||
import * as os from "@/os";
|
||||
import { defaultStore } from "@/store";
|
||||
import { i18n } from "@/i18n";
|
||||
|
||||
const emit = defineEmits<{
|
||||
(ev: "ok", selected: misskey.entities.UserDetailed): void;
|
||||
(ev: "cancel"): void;
|
||||
(ev: "closed"): void;
|
||||
}>();
|
||||
|
||||
let username = $ref("");
|
||||
let host = $ref("");
|
||||
let users: misskey.entities.UserDetailed[] = $ref([]);
|
||||
let recentUsers: misskey.entities.UserDetailed[] = $ref([]);
|
||||
let selected: misskey.entities.UserDetailed | null = $ref(null);
|
||||
let dialogEl = $ref();
|
||||
|
||||
const search = () => {
|
||||
if (username === "" && host === "") {
|
||||
users = [];
|
||||
return;
|
||||
}
|
||||
os.api("users/search-by-username-and-host", {
|
||||
username: username,
|
||||
host: null,
|
||||
limit: 10,
|
||||
detail: false,
|
||||
}).then((_users) => {
|
||||
users = _users;
|
||||
});
|
||||
};
|
||||
|
||||
const ok = () => {
|
||||
if (selected == null) return;
|
||||
emit("ok", selected);
|
||||
dialogEl.close();
|
||||
|
||||
// 最近使ったユーザー更新
|
||||
let recents = defaultStore.state.recentlyUsedUsers;
|
||||
recents = recents.filter((x) => x !== selected.id);
|
||||
recents.unshift(selected.id);
|
||||
defaultStore.set("recentlyUsedUsers", recents.splice(0, 16));
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
emit("cancel");
|
||||
dialogEl.close();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
os.api("users/show", {
|
||||
userIds: defaultStore.state.recentlyUsedUsers,
|
||||
}).then((users) => {
|
||||
recentUsers = users;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.tbhwbxdg {
|
||||
> .form {
|
||||
padding: 0 var(--root-margin);
|
||||
}
|
||||
|
||||
> .result,
|
||||
> .recent {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: auto;
|
||||
height: 100%;
|
||||
|
||||
&.result.hit {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&.recent {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
> .users {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
padding: 8px 0;
|
||||
|
||||
> .user {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8px var(--root-margin);
|
||||
font-size: 14px;
|
||||
|
||||
&:hover {
|
||||
background: var(--X7);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
> * {
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
> .avatar {
|
||||
width: 45px;
|
||||
height: 45px;
|
||||
}
|
||||
|
||||
> .body {
|
||||
padding: 0 8px;
|
||||
min-width: 0;
|
||||
|
||||
> .name {
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
> .acct {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> .empty {
|
||||
opacity: 0.7;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
|
@ -631,6 +631,25 @@ export async function selectUser() {
|
|||
});
|
||||
}
|
||||
|
||||
export async function selectLocalUser() {
|
||||
return new Promise((resolve, reject) => {
|
||||
popup(
|
||||
defineAsyncComponent({
|
||||
loader: () => import("@/components/MkUserSelectLocalDialog.vue"),
|
||||
loadingComponent: MkWaitingDialog,
|
||||
delay: 1000,
|
||||
}),
|
||||
{},
|
||||
{
|
||||
ok: (user) => {
|
||||
resolve(user);
|
||||
},
|
||||
},
|
||||
"closed",
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function selectInstance(): Promise<Misskey.entities.Instance> {
|
||||
return new Promise((resolve, reject) => {
|
||||
popup(
|
||||
|
|
|
@ -20,12 +20,15 @@
|
|||
}}</template>
|
||||
</MkKeyValue>
|
||||
|
||||
<FormButton
|
||||
<MkButton
|
||||
primary
|
||||
class="_formBlock"
|
||||
@click="chooseProxyAccount"
|
||||
>{{ i18n.ts.selectAccount }}</FormButton
|
||||
>{{ i18n.ts.selectAccount }}</MkButton
|
||||
>
|
||||
<MkButton danger class="_formBlock" @click="del">{{
|
||||
i18n.ts.remove
|
||||
}}</MkButton>
|
||||
</FormSuspense>
|
||||
</MkSpacer>
|
||||
</MkStickyContainer>
|
||||
|
@ -34,7 +37,7 @@
|
|||
<script lang="ts" setup>
|
||||
import {} from "vue";
|
||||
import MkKeyValue from "@/components/MkKeyValue.vue";
|
||||
import FormButton from "@/components/MkButton.vue";
|
||||
import MkButton from "@/components/MkButton.vue";
|
||||
import MkInfo from "@/components/MkInfo.vue";
|
||||
import FormSuspense from "@/components/form/suspense.vue";
|
||||
import * as os from "@/os";
|
||||
|
@ -54,7 +57,7 @@ async function init() {
|
|||
}
|
||||
|
||||
function chooseProxyAccount() {
|
||||
os.selectUser().then((user) => {
|
||||
os.selectLocalUser().then((user) => {
|
||||
proxyAccount = user;
|
||||
proxyAccountId = user.id;
|
||||
save();
|
||||
|
@ -69,6 +72,14 @@ function save() {
|
|||
});
|
||||
}
|
||||
|
||||
function del() {
|
||||
os.apiWithDialog("admin/update-meta", {
|
||||
proxyAccountId: null,
|
||||
}).then(() => {
|
||||
fetchInstance();
|
||||
});
|
||||
}
|
||||
|
||||
const headerActions = $computed(() => []);
|
||||
|
||||
const headerTabs = $computed(() => []);
|
||||
|
|
|
@ -77,7 +77,7 @@ async function fetch() {
|
|||
fetch();
|
||||
|
||||
function invite() {
|
||||
os.selectUser().then((user) => {
|
||||
os.selectLocalUser().then((user) => {
|
||||
os.apiWithDialog("users/groups/invite", {
|
||||
groupId: group.value.id,
|
||||
userId: user.id,
|
||||
|
@ -110,7 +110,7 @@ async function renameGroup() {
|
|||
}
|
||||
|
||||
function transfer() {
|
||||
os.selectUser().then((user) => {
|
||||
os.selectLocalUser().then((user) => {
|
||||
os.apiWithDialog("users/groups/transfer", {
|
||||
groupId: group.value.id,
|
||||
userId: user.id,
|
||||
|
|
Loading…
Reference in New Issue