1
0
Fork 1
mirror of https://example.com synced 2024-11-22 08:06:39 +09:00

refactor: stop importing stuff from firefish-js/built

This commit is contained in:
naskya 2024-01-23 02:19:35 +09:00
parent f1e1f9e5b0
commit c035c368c7
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
28 changed files with 101 additions and 97 deletions

View file

@ -63,12 +63,12 @@
</template>
<script lang="ts" setup>
import * as Acct from "firefish-js/built/acct";
import * as firefishJs from "firefish-js";
import { i18n } from "@/i18n";
import { acct } from "@/filters/user";
import { $i } from "@/reactiveAccount";
const getAcct = Acct.toString;
const getAcct = firefishJs.acct.toString;
const props = defineProps<{
message: Record<string, any>;

View file

@ -205,13 +205,12 @@
<script lang="ts" setup>
import { computed, onBeforeUnmount, onMounted, ref, shallowRef } from "vue";
import * as Acct from "firefish-js/built/acct";
// import { acct } from "firefish-js";
import MkModal from "@/components/MkModal.vue";
import MkButton from "@/components/MkButton.vue";
import MkInput from "@/components/form/input.vue";
import MkTextarea from "@/components/form/textarea.vue";
import MkSelect from "@/components/form/select.vue";
import * as os from "@/os";
import { i18n } from "@/i18n";
import iconClass from "@/scripts/icon";
@ -354,12 +353,12 @@ function onInputKeydown(evt: KeyboardEvent) {
}
}
function formatDateToYYYYMMDD(date) {
const year = date.getFullYear();
const month = ("0" + (date.getMonth() + 1)).slice(-2);
const day = ("0" + (date.getDate() + 1)).slice(-2);
return `${year}-${month}-${day}`;
}
// function formatDateToYYYYMMDD(date) {
// const year = date.getFullYear();
// const month = ("0" + (date.getMonth() + 1)).slice(-2);
// const day = ("0" + (date.getDate() + 1)).slice(-2);
// return `${year}-${month}-${day}`;
// }
/**
* Appends a new search parameter to the value in the input field.
@ -367,18 +366,18 @@ function formatDateToYYYYMMDD(date) {
* begin typing a new criteria.
* @param value The value to append.
*/
function appendFilter(value: string) {
return (
[
typeof inputValue.value === "string"
? inputValue.value.trim()
: inputValue.value,
value,
]
.join(" ")
.trim() + " "
);
}
// function appendFilter(value: string) {
// return (
// [
// typeof inputValue.value === "string"
// ? inputValue.value.trim()
// : inputValue.value,
// value,
// ]
// .join(" ")
// .trim() + " "
// );
// }
// async function openSearchFilters(ev) {
// await os.popupMenu(
@ -389,7 +388,7 @@ function appendFilter(value: string) {
// action: () => {
// os.selectUser().then((user) => {
// inputValue.value = appendFilter(
// "from:@" + Acct.toString(user),
// "from:@" + acct.toString(user),
// );
// });
// },

View file

@ -13,7 +13,7 @@
`${file.type}\n${bytes(file.size)}\n${new Date(
file.createdAt,
).toLocaleString()}\nby ${
file.user ? '@' + Acct.toString(file.user) : 'system'
file.user ? '@' + acct.toString(file.user) : 'system'
}`
"
:to="`/admin/file/${file.id}`"
@ -54,7 +54,7 @@
</template>
<script lang="ts" setup>
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import MkPagination from "@/components/MkPagination.vue";
import MkDriveFileThumbnail from "@/components/MkDriveFileThumbnail.vue";
import bytes from "@/filters/bytes";

View file

@ -58,21 +58,21 @@
<script lang="ts" setup>
import { ref } from "vue";
import type { Instance } from "firefish-js/built/entities";
import { entities } from "firefish-js";
import MkInput from "@/components/form/input.vue";
import XModalWindow from "@/components/MkModalWindow.vue";
import * as os from "@/os";
import { i18n } from "@/i18n";
const emit = defineEmits<{
(ev: "ok", selected: Instance): void;
(ev: "ok", selected: entities.Instance): void;
(ev: "cancel"): void;
(ev: "closed"): void;
}>();
const hostname = ref("");
const instances: Instance[] = ref([]);
const selected: Instance | null = ref(null);
const instances: entities.Instance[] = ref([]);
const selected: entities.Instance | null = ref(null);
const dialogEl = ref<InstanceType<typeof XModalWindow>>();
let searchOrderLatch = 0;
@ -97,7 +97,7 @@ const search = () => {
id: x.id,
host: x.host,
iconUrl: x.iconUrl,
}) as Instance,
}) as entities.Instance,
);
});
};

View file

@ -168,7 +168,7 @@
<script lang="ts" setup>
import { onMounted, onUnmounted, onUpdated, ref } from "vue";
import type * as firefish from "firefish-js";
import type { NoteUpdatedEvent } from "firefish-js/built/streaming.types";
import { StreamTypes } from "firefish-js";
import MkTab from "@/components/MkTab.vue";
import MkNote from "@/components/MkNote.vue";
import MkNoteSub from "@/components/MkNoteSub.vue";
@ -416,7 +416,9 @@ function loadTab() {
}
}
async function onNoteUpdated(noteData: NoteUpdatedEvent): Promise<void> {
async function onNoteUpdated(
noteData: StreamTypes.NoteUpdatedEvent,
): Promise<void> {
const { type, id, body } = noteData;
let found = -1;

View file

@ -284,7 +284,7 @@ import autosize from "autosize";
import insertTextAtCursor from "insert-text-at-cursor";
import { length } from "stringz";
import { toASCII } from "punycode/";
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import { throttle } from "throttle-debounce";
import XNoteSimple from "@/components/MkNoteSimple.vue";
import XNotePreview from "@/components/MkNotePreview.vue";
@ -1116,7 +1116,7 @@ function cancel() {
function insertMention() {
os.selectUser().then((user) => {
insertTextAtCursor(textareaEl.value, "@" + Acct.toString(user) + " ");
insertTextAtCursor(textareaEl.value, "@" + acct.toString(user) + " ");
});
}

View file

@ -11,7 +11,7 @@
<script lang="ts" setup>
import { computed } from "vue";
import type { Note } from "firefish-js/built/entities";
import { entities } from "firefish-js";
import { pleaseLogin } from "@/scripts/please-login";
import * as os from "@/os";
import { $i } from "@/reactiveAccount";
@ -20,7 +20,7 @@ import { defaultStore } from "@/store";
import icon from "@/scripts/icon";
const props = defineProps<{
note: Note;
note: entities.Note;
}>();
const canRenote = computed(

View file

@ -42,7 +42,7 @@
</template>
<script lang="ts" setup>
import type { Note } from "firefish-js/built/entities";
import { entities } from "firefish-js";
import Ripple from "@/components/MkRipple.vue";
import { pleaseLogin } from "@/scripts/please-login";
import * as os from "@/os";
@ -52,7 +52,7 @@ import { instance } from "@/instance";
import icon from "@/scripts/icon";
const props = defineProps<{
note: Note;
note: entities.Note;
}>();
function star(ev?: MouseEvent): void {

View file

@ -39,7 +39,7 @@
<script lang="ts" setup>
import { ref } from "vue";
import type { Note } from "firefish-js/built/entities";
import { entities } from "firefish-js";
import Ripple from "@/components/MkRipple.vue";
import XDetails from "@/components/MkUsersTooltip.vue";
import { pleaseLogin } from "@/scripts/please-login";
@ -50,7 +50,7 @@ import { useTooltip } from "@/scripts/use-tooltip";
import icon from "@/scripts/icon";
const props = defineProps<{
note: Note;
note: entities.Note;
count: number;
reacted: boolean;
}>();

View file

@ -29,7 +29,7 @@
<script lang="ts" setup>
import { onMounted, ref } from "vue";
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import type * as firefish from "firefish-js";
import MkUserInfo from "@/components/MkUserInfo.vue";
import * as os from "@/os";
@ -57,7 +57,7 @@ onMounted(() => {
user.value = props.q;
} else {
const query = props.q.startsWith("@")
? Acct.parse(props.q.slice(1))
? acct.parse(props.q.slice(1))
: { userId: props.q };
os.api("users/show", query).then((res) => {

View file

@ -22,7 +22,7 @@
<script lang="ts" setup>
import { computed } from "vue";
import type { CustomEmoji } from "firefish-js/built/entities";
import { entities } from "firefish-js";
import { getStaticImageUrl } from "@/scripts/get-static-image-url";
import { char2filePath } from "@/scripts/twemoji-base";
import { defaultStore } from "@/store";
@ -32,7 +32,7 @@ const props = defineProps<{
emoji: string;
normal?: boolean;
noStyle?: boolean;
customEmojis?: CustomEmoji[];
customEmojis?: entities.CustomEmoji[];
isReaction?: boolean;
}>();

View file

@ -1,9 +1,8 @@
import type * as firefish from "firefish-js";
import * as Acct from "firefish-js/built/acct";
import * as firefish from "firefish-js";
import { url } from "@/config";
export const acct = (user: firefish.Acct) => {
return Acct.toString(user);
return firefish.acct.toString(user);
};
export const userName = (user: firefish.entities.User) => {

View file

@ -3,7 +3,7 @@
</template>
<script lang="ts" setup>
import * as Acct from "firefish-js/built/acct";
import * as firefishJs from "firefish-js";
import * as os from "@/os";
import { mainRouter } from "@/router";
import { i18n } from "@/i18n";
@ -50,7 +50,7 @@ if (acct.startsWith("https://")) {
}
});
} else {
promise = os.api("users/show", Acct.parse(acct));
promise = os.api("users/show", firefishJs.acct.parse(acct));
promise.then((user) => {
follow(user);
});

View file

@ -89,7 +89,7 @@
<script lang="ts" setup>
import { computed, markRaw, onMounted, onUnmounted, ref, watch } from "vue";
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import { Virtual } from "swiper/modules";
import { Swiper, SwiperSlide } from "swiper/vue";
import MkButton from "@/components/MkButton.vue";
@ -207,7 +207,7 @@ function onRead(ids): void {
async function startUser(): void {
os.selectUser().then((user) => {
router.push(`/my/messaging/${Acct.toString(user)}`);
router.push(`/my/messaging/${acct.toString(user)}`);
});
}

View file

@ -105,8 +105,7 @@ import {
ref,
watch,
} from "vue";
import type * as firefish from "firefish-js";
import * as Acct from "firefish-js/built/acct";
import * as firefishJs from "firefish-js";
import XMessage from "./messaging-room.message.vue";
import XForm from "./messaging-room.form.vue";
import XList from "@/components/MkDateSeparatedList.vue";
@ -139,11 +138,11 @@ const formEl = ref<InstanceType<typeof XForm>>();
const pagingComponent = ref<InstanceType<typeof MkPagination>>();
const fetching = ref(true);
const user = ref<firefish.entities.UserDetailed | null>(null);
const group = ref<firefish.entities.UserGroup | null>(null);
const typers = ref<firefish.entities.User[]>([]);
const connection: firefish.ChannelConnection<
firefish.Channels["messaging"]
const user = ref<firefishJs.entities.UserDetailed | null>(null);
const group = ref<firefishJs.entities.UserGroup | null>(null);
const typers = ref<firefishJs.entities.User[]>([]);
const connection: firefishJs.ChannelConnection<
firefishJs.StreamTypes.Channels["messaging"]
> | null = ref(null);
const showIndicator = ref(false);
const { animation } = defaultStore.reactiveState;
@ -159,7 +158,7 @@ async function fetch() {
fetching.value = true;
if (props.userAcct) {
const acct = Acct.parse(props.userAcct);
const acct = firefishJs.acct.parse(props.userAcct);
user.value = await os.api("users/show", {
username: acct.username,
host: acct.host ?? undefined,

View file

@ -115,7 +115,7 @@
<script lang="ts" setup>
import { ref, watch } from "vue";
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import MkButton from "@/components/MkButton.vue";
import MkInput from "@/components/form/input.vue";
import MkTextarea from "@/components/form/textarea.vue";
@ -226,7 +226,7 @@ async function deleteAntenna() {
function addUser() {
os.selectUser().then((user) => {
users.value = users.value.trim();
users.value += `\n@${Acct.toString(user as any)}`;
users.value += `\n@${acct.toString(user as any)}`;
users.value = users.value.trim();
});
}

View file

@ -52,7 +52,7 @@
<script lang="ts" setup>
import { ref } from "vue";
import { toString } from "firefish-js/built/acct";
import { acct } from "firefish-js";
import FormSection from "@/components/form/section.vue";
import FormInput from "@/components/form/input.vue";
import FormButton from "@/components/MkButton.vue";
@ -73,7 +73,7 @@ async function init() {
const aka = await os.api("users/show", { userIds: $i.alsoKnownAs });
accountAlias.value =
aka && aka.length > 0
? aka.map((user) => `@${toString(user)}`)
? aka.map((user) => `@${acct.toString(user)}`)
: [""];
} else {
accountAlias.value = [""];

View file

@ -34,7 +34,7 @@ import { computed, ref } from "vue";
// SPECIFICATION: https://misskey-hub.net/docs/features/share-form.html
import { noteVisibilities } from "firefish-js";
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import type * as firefish from "firefish-js";
import MkButton from "@/components/MkButton.vue";
import XPostForm from "@/components/MkPostForm.vue";
@ -83,7 +83,7 @@ async function init() {
? visibleUserIds.split(",").map((userId) => ({ userId }))
: []),
...(visibleAccts
? visibleAccts.split(",").map(Acct.parse)
? visibleAccts.split(",").map(acct.parse)
: []),
]
// TypeScript

View file

@ -17,8 +17,7 @@
<script lang="ts" setup>
import { computed, ref, watch } from "vue";
import * as Acct from "firefish-js/built/acct";
import type * as firefish from "firefish-js";
import * as firefishJs from "firefish-js";
import XFollowList from "./follow-list.vue";
import * as os from "@/os";
import { definePageMetadata } from "@/scripts/page-metadata";
@ -32,13 +31,13 @@ const props = withDefaults(
{},
);
const user = ref<null | firefish.entities.UserDetailed>(null);
const user = ref<null | firefishJs.entities.UserDetailed>(null);
const error = ref(null);
function fetchUser(): void {
if (props.acct == null) return;
user.value = null;
os.api("users/show", Acct.parse(props.acct))
os.api("users/show", firefishJs.acct.parse(props.acct))
.then((u) => {
user.value = u;
})

View file

@ -17,8 +17,7 @@
<script lang="ts" setup>
import { computed, ref, watch } from "vue";
import * as Acct from "firefish-js/built/acct";
import type * as firefish from "firefish-js";
import * as firefishJs from "firefish-js";
import XFollowList from "./follow-list.vue";
import * as os from "@/os";
import { definePageMetadata } from "@/scripts/page-metadata";
@ -32,13 +31,13 @@ const props = withDefaults(
{},
);
const user = ref<null | firefish.entities.UserDetailed>(null);
const user = ref<null | firefishJs.entities.UserDetailed>(null);
const error = ref(null);
function fetchUser(): void {
if (props.acct == null) return;
user.value = null;
os.api("users/show", Acct.parse(props.acct))
os.api("users/show", firefishJs.acct.parse(props.acct))
.then((u) => {
user.value = u;
})

View file

@ -30,8 +30,7 @@
<script lang="ts" setup>
import { computed, defineAsyncComponent, ref, watch } from "vue";
import * as Acct from "firefish-js/built/acct";
import type * as firefish from "firefish-js";
import * as firefishJs from "firefish-js";
import { acct as getAcct } from "@/filters/user";
import * as os from "@/os";
import { useRouter } from "@/router";
@ -59,13 +58,13 @@ const props = withDefaults(
useRouter();
const tab = ref(props.page);
const user = ref<null | firefish.entities.UserDetailed>(null);
const user = ref<null | firefishJs.entities.UserDetailed>(null);
const error = ref(null);
function fetchUser(): void {
if (props.acct == null) return;
user.value = null;
os.api("users/show", Acct.parse(props.acct))
os.api("users/show", firefishJs.acct.parse(props.acct))
.then((u) => {
user.value = u;
})

View file

@ -1,4 +1,4 @@
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import { host as localHost } from "@/config";
export async function genSearchQuery(v: any, q: string) {
@ -17,7 +17,7 @@ export async function genSearchQuery(v: any, q: string) {
}
} else {
const user = await v.os
.api("users/show", Acct.parse(at))
.api("users/show", acct.parse(at))
.catch((x) => null);
if (user) {
userId = user.id;

View file

@ -1,4 +1,4 @@
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import { defineAsyncComponent } from "vue";
import { $i, isModerator, isSignedIn } from "@/reactiveAccount";
import { host } from "@/config";
@ -295,7 +295,7 @@ export function getUserMenu(user, router: Router = mainRouter) {
type: "link",
icon: `${icon("ph-chats-teardrop")}`,
text: i18n.ts.startMessaging,
to: `/my/messaging/${Acct.toString(user)}`,
to: `/my/messaging/${acct.toString(user)}`,
}
: undefined,
user.host != null && user.url

View file

@ -1,4 +1,4 @@
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import { i18n } from "@/i18n";
import * as os from "@/os";
@ -12,7 +12,7 @@ export async function lookupUser() {
os.pageWindow(`/user-info/${user.id}`);
};
const usernamePromise = os.api("users/show", Acct.parse(result));
const usernamePromise = os.api("users/show", acct.parse(result));
const idPromise = os.api("users/show", { userId: result });
let _notFound = false;
const notFound = () => {

View file

@ -1,4 +1,4 @@
import type { DriveFile } from "firefish-js/built/entities";
import { entities } from "firefish-js";
import { ref } from "vue";
import { i18n } from "@/i18n";
import * as os from "@/os";
@ -13,7 +13,7 @@ function select(
src: any,
label: string | null,
multiple: boolean,
): Promise<DriveFile | DriveFile[]> {
): Promise<entities.DriveFile | entities.DriveFile[]> {
return new Promise((res, rej) => {
const keepOriginal = ref(defaultStore.state.keepOriginalUploading);
@ -124,13 +124,13 @@ function select(
export function selectFile(
src: any,
label: string | null = null,
): Promise<DriveFile> {
return select(src, label, false) as Promise<DriveFile>;
): Promise<entities.DriveFile> {
return select(src, label, false) as Promise<entities.DriveFile>;
}
export function selectFiles(
src: any,
label: string | null = null,
): Promise<DriveFile[]> {
return select(src, label, true) as Promise<DriveFile[]>;
): Promise<entities.DriveFile[]> {
return select(src, label, true) as Promise<entities.DriveFile[]>;
}

View file

@ -215,7 +215,7 @@
<script lang="ts" setup>
import { computed, defineAsyncComponent, onMounted, provide, ref } from "vue";
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import type { ComputedRef } from "vue";
import XCommon from "./_common_/common.vue";
import type { PageMetadata } from "@/scripts/page-metadata";
@ -374,7 +374,7 @@ function messagingStart(ev) {
async function startUser(): void {
os.selectUser().then((user) => {
mainRouter.push(`/my/messaging/${Acct.toString(user)}`);
mainRouter.push(`/my/messaging/${acct.toString(user)}`);
});
}

View file

@ -1,10 +1,18 @@
import { Acct } from "./acct";
import * as acct from "./acct";
import type { Acct } from "./acct";
import { Endpoints } from "./api.types";
import * as consts from "./consts";
import Stream, { Connection } from "./streaming";
import { Channels } from "./streaming.types";
import * as StreamTypes from "./streaming.types";
export { Endpoints, Stream, Connection as ChannelConnection, Channels, Acct };
export {
Endpoints,
Stream,
Connection as ChannelConnection,
StreamTypes,
acct,
Acct,
};
export const permissions = consts.permissions;
export const notificationTypes = consts.notificationTypes;

View file

@ -1,5 +1,5 @@
import { get } from "idb-keyval";
import * as Acct from "firefish-js/built/acct";
import { acct } from "firefish-js";
import type { PushNotificationDataMap } from "@/types";
import {
createEmptyNotification,
@ -119,7 +119,7 @@ globalThis.addEventListener("push", (ev) => {
case "showUser":
if ("user" in data.body)
client = await swos.openUser(
Acct.toString(data.body.user),
acct.toString(data.body.user),
loginId,
);
break;
@ -178,7 +178,7 @@ globalThis.addEventListener("push", (ev) => {
client = await swos.openNote(data.body.note.id, loginId);
} else if ("user" in data.body) {
client = await swos.openUser(
Acct.toString(data.body.user),
acct.toString(data.body.user),
loginId,
);
}