Merge branch 'develop' of https://codeberg.org/calckey/calckey into note-improvements
This commit is contained in:
commit
ca971f1116
5 changed files with 366 additions and 408 deletions
10
README.md
10
README.md
|
@ -64,6 +64,9 @@ If you have access to a server that supports one of the sources below, I recomme
|
||||||
|
|
||||||
[![Install on Ubuntu](https://pool.jortage.com/voringme/misskey/3b62a443-1b44-45cf-8f9e-f1c588f803ed.png)](https://codeberg.org/calckey/ubuntu-bash-install) [![Install on the Arch User Repository](https://pool.jortage.com/voringme/misskey/ba2a5c07-f078-43f1-8483-2e01acca9c40.png)](https://aur.archlinux.org/packages/calckey) [![Install Calckey with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=calckey)
|
[![Install on Ubuntu](https://pool.jortage.com/voringme/misskey/3b62a443-1b44-45cf-8f9e-f1c588f803ed.png)](https://codeberg.org/calckey/ubuntu-bash-install) [![Install on the Arch User Repository](https://pool.jortage.com/voringme/misskey/ba2a5c07-f078-43f1-8483-2e01acca9c40.png)](https://aur.archlinux.org/packages/calckey) [![Install Calckey with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=calckey)
|
||||||
|
|
||||||
|
### 🐋 Docker
|
||||||
|
|
||||||
|
[How to run Calckey with Docker](./docker-README.md).
|
||||||
|
|
||||||
## 🧑💻 Dependencies
|
## 🧑💻 Dependencies
|
||||||
|
|
||||||
|
@ -103,7 +106,8 @@ cd calckey/
|
||||||
# nvm install 19 && nvm use 19
|
# nvm install 19 && nvm use 19
|
||||||
corepack enable
|
corepack enable
|
||||||
corepack prepare pnpm@latest --activate
|
corepack prepare pnpm@latest --activate
|
||||||
pnpm i
|
# To build without TensorFlow, append --no-optional
|
||||||
|
pnpm i # --no-optional
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🐘 Create database
|
## 🐘 Create database
|
||||||
|
@ -157,10 +161,6 @@ NODE_ENV=production pnpm install && pnpm run build && pnpm run migrate
|
||||||
pm2 start "NODE_ENV=production pnpm run start" --name Calckey
|
pm2 start "NODE_ENV=production pnpm run start" --name Calckey
|
||||||
```
|
```
|
||||||
|
|
||||||
### 🐋 Docker
|
|
||||||
|
|
||||||
[How to run Calckey with Docker](./docker-README.md).
|
|
||||||
|
|
||||||
## 😉 Tips & Tricks
|
## 😉 Tips & Tricks
|
||||||
|
|
||||||
- When editing the config file, please don't fill out the settings at the bottom. They're designed *only* for managed hosting, not self hosting. Those settings are much better off being set in Calckey's control panel.
|
- When editing the config file, please don't fill out the settings at the bottom. They're designed *only* for managed hosting, not self hosting. Those settings are much better off being set in Calckey's control panel.
|
||||||
|
|
|
@ -68,7 +68,7 @@ export async function toDbReaction(
|
||||||
const match = emojiRegex.exec(reaction);
|
const match = emojiRegex.exec(reaction);
|
||||||
if (match) {
|
if (match) {
|
||||||
const unicode = match[0];
|
const unicode = match[0];
|
||||||
return unicode.match('\u200d') ? unicode : unicode.replace(/\ufe0f/g, '');
|
return unicode.match("\u200d") ? unicode : unicode.replace(/\ufe0f/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
const custom = reaction.match(/^:([\w+-]+)(?:@\.)?:$/);
|
const custom = reaction.match(/^:([\w+-]+)(?:@\.)?:$/);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<MkPagination ref="pagingComponent" :pagination="pagination" disableReload="true">
|
<MkPagination ref="pagingComponent" :pagination="pagination">
|
||||||
<template #empty>
|
<template #empty>
|
||||||
<div class="_fullinfo">
|
<div class="_fullinfo">
|
||||||
<img src="/static-assets/badges/info.png" class="_ghost" alt="Info"/>
|
<img src="/static-assets/badges/info.png" class="_ghost" alt="Info"/>
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<template>
|
<template>
|
||||||
<transition :name="$store.state.animation ? 'fade' : ''" mode="out-in">
|
<transition :name="$store.state.animation ? 'fade' : ''" mode="out-in">
|
||||||
<MkLoading v-if="fetching" />
|
<MkLoading v-if="fetching"/>
|
||||||
|
|
||||||
<MkError v-else-if="error" @retry="init()" />
|
<MkError v-else-if="error" @retry="init()"/>
|
||||||
|
|
||||||
<div v-else-if="empty" key="_empty_" class="empty">
|
<div v-else-if="empty" key="_empty_" class="empty">
|
||||||
<slot name="empty">
|
<slot name="empty">
|
||||||
<div class="_fullinfo">
|
<div class="_fullinfo">
|
||||||
<img src="/static-assets/badges/info.png" class="_ghost" alt="Error" />
|
<img src="/static-assets/badges/info.png" class="_ghost" alt="Error"/>
|
||||||
<div>{{ i18n.ts.nothing }}</div>
|
<div>{{ i18n.ts.nothing }}</div>
|
||||||
</div>
|
</div>
|
||||||
</slot>
|
</slot>
|
||||||
|
@ -15,375 +15,343 @@
|
||||||
|
|
||||||
<div v-else ref="rootEl">
|
<div v-else ref="rootEl">
|
||||||
<div v-show="pagination.reversed && more" key="_more_" class="cxiknjgy _gap">
|
<div v-show="pagination.reversed && more" key="_more_" class="cxiknjgy _gap">
|
||||||
<MkButton v-if="!moreFetching" class="button" :disabled="moreFetching"
|
<MkButton v-if="!moreFetching" class="button" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMoreAhead">
|
||||||
:style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMoreAhead">
|
|
||||||
{{ i18n.ts.loadMore }}
|
{{ i18n.ts.loadMore }}
|
||||||
</MkButton>
|
</MkButton>
|
||||||
<MkLoading v-else class="loading" />
|
<MkLoading v-else class="loading"/>
|
||||||
</div>
|
</div>
|
||||||
<slot :items="items"></slot>
|
<slot :items="items"></slot>
|
||||||
<div v-show="!pagination.reversed && more" key="_more_" class="cxiknjgy _gap">
|
<div v-show="!pagination.reversed && more" key="_more_" class="cxiknjgy _gap">
|
||||||
<MkButton v-if="!moreFetching"
|
<MkButton v-if="!moreFetching" v-appear="($store.state.enableInfiniteScroll && !disableAutoLoad) ? fetchMore : null" class="button" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMore">
|
||||||
v-appear="($store.state.enableInfiniteScroll && !disableAutoLoad) ? fetchMore : null" class="button"
|
|
||||||
:disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMore">
|
|
||||||
{{ i18n.ts.loadMore }}
|
{{ i18n.ts.loadMore }}
|
||||||
</MkButton>
|
</MkButton>
|
||||||
<MkLoading v-else class="loading" />
|
<MkLoading v-else class="loading"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ComputedRef, isRef, markRaw, onActivated, onDeactivated, Ref, ref, watch } from 'vue';
|
import { computed, ComputedRef, isRef, markRaw, onActivated, onDeactivated, Ref, ref, watch } from 'vue';
|
||||||
import * as calckey from 'calckey-js';
|
import * as misskey from 'calckey-js';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import { onScrollTop, isTopVisible, getScrollPosition, getScrollContainer } from '@/scripts/scroll';
|
import { onScrollTop, isTopVisible, getScrollPosition, getScrollContainer } from '@/scripts/scroll';
|
||||||
import MkButton from '@/components/MkButton.vue';
|
import MkButton from '@/components/MkButton.vue';
|
||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
import { ItemHolder } from 'photoswipe';
|
|
||||||
|
|
||||||
export type Paging<E extends keyof calckey.Endpoints = keyof calckey.Endpoints> = {
|
export type Paging<E extends keyof misskey.Endpoints = keyof misskey.Endpoints> = {
|
||||||
endpoint: E;
|
endpoint: E;
|
||||||
limit: number;
|
limit: number;
|
||||||
params?: calckey.Endpoints[E]['req'] | ComputedRef<calckey.Endpoints[E]['req']>;
|
params?: misskey.Endpoints[E]['req'] | ComputedRef<misskey.Endpoints[E]['req']>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When using non-pageable endpoints, such as the search API
|
* 検索APIのような、ページング不可なエンドポイントを利用する場合
|
||||||
* (though it is somewhat inconsistent to use such an API with this function)
|
* (そのようなAPIをこの関数で使うのは若干矛盾してるけど)
|
||||||
*/
|
*/
|
||||||
noPaging?: boolean;
|
noPaging?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array items in reverse order (newest first)
|
* items 配列の中身を逆順にする(新しい方が最後)
|
||||||
*/
|
*/
|
||||||
reversed?: boolean;
|
reversed?: boolean;
|
||||||
|
|
||||||
offsetMode?: boolean;
|
offsetMode?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SECOND_FETCH_LIMIT = 30;
|
const SECOND_FETCH_LIMIT = 30;
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
pagination: Paging;
|
pagination: Paging;
|
||||||
disableAutoLoad?: boolean;
|
disableAutoLoad?: boolean;
|
||||||
displayLimit?: number;
|
displayLimit?: number;
|
||||||
externalItemArray?: Ref<Array<any>>;
|
}>(), {
|
||||||
disableReload?: boolean;
|
displayLimit: 30,
|
||||||
}>(), {
|
});
|
||||||
displayLimit: 30,
|
|
||||||
});
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(ev: 'queue', count: number): void;
|
(ev: 'queue', count: number): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
type Item = { id: string;[another: string]: unknown; };
|
type Item = { id: string; [another: string]: unknown; };
|
||||||
|
|
||||||
const rootEl = ref<HTMLElement>();
|
const rootEl = ref<HTMLElement>();
|
||||||
const items = ref<Item[]>([]);
|
const items = ref<Item[]>([]);
|
||||||
const queue = ref<Item[]>([]);
|
const queue = ref<Item[]>([]);
|
||||||
const offset = ref(0);
|
const offset = ref(0);
|
||||||
const fetching = ref(true);
|
const fetching = ref(true);
|
||||||
const moreFetching = ref(false);
|
const moreFetching = ref(false);
|
||||||
const more = ref(false);
|
const more = ref(false);
|
||||||
const backed = ref(false); // 遡り中か否か
|
const backed = ref(false); // 遡り中か否か
|
||||||
const isBackTop = ref(false);
|
const isBackTop = ref(false);
|
||||||
const empty = computed(() => items.value.length === 0);
|
const empty = computed(() => items.value.length === 0);
|
||||||
const error = ref(false);
|
const error = ref(false);
|
||||||
const alreadyInitedOnce = ref(false);
|
|
||||||
|
|
||||||
const init = async (): Promise<void> => {
|
const init = async (): Promise<void> => {
|
||||||
queue.value = [];
|
queue.value = [];
|
||||||
fetching.value = true;
|
fetching.value = true;
|
||||||
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
||||||
await os.api(props.pagination.endpoint, {
|
await os.api(props.pagination.endpoint, {
|
||||||
...(params as object),
|
...params,
|
||||||
limit: props.pagination.noPaging ? (props.pagination.limit || 10) : (props.pagination.limit || 10) + 1,
|
limit: props.pagination.noPaging ? (props.pagination.limit || 10) : (props.pagination.limit || 10) + 1,
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
for (let i = 0; i < res.length; i++) {
|
for (let i = 0; i < res.length; i++) {
|
||||||
const item = res[i];
|
const item = res[i];
|
||||||
if (props.pagination.reversed) {
|
if (props.pagination.reversed) {
|
||||||
if (i === res.length - 2) item._shouldInsertAd_ = true;
|
if (i === res.length - 2) item._shouldInsertAd_ = true;
|
||||||
|
} else {
|
||||||
|
if (i === 3) item._shouldInsertAd_ = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!props.pagination.noPaging && (res.length > (props.pagination.limit || 10))) {
|
||||||
|
res.pop();
|
||||||
|
items.value = props.pagination.reversed ? [...res].reverse() : res;
|
||||||
|
more.value = true;
|
||||||
} else {
|
} else {
|
||||||
if (i === 3) item._shouldInsertAd_ = true;
|
items.value = props.pagination.reversed ? [...res].reverse() : res;
|
||||||
|
more.value = false;
|
||||||
}
|
}
|
||||||
}
|
offset.value = res.length;
|
||||||
if (!props.pagination.noPaging && (res.length > (props.pagination.limit || 10))) {
|
error.value = false;
|
||||||
res.pop();
|
fetching.value = false;
|
||||||
items.value = props.pagination.reversed ? [...res].reverse() : res;
|
}, err => {
|
||||||
if (props.externalItemArray) {
|
error.value = true;
|
||||||
props.externalItemArray.value = items.value;
|
fetching.value = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const reload = (): void => {
|
||||||
|
items.value = [];
|
||||||
|
init();
|
||||||
|
};
|
||||||
|
|
||||||
|
const refresh = async (): void => {
|
||||||
|
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
||||||
|
await os.api(props.pagination.endpoint, {
|
||||||
|
...params,
|
||||||
|
limit: items.value.length + 1,
|
||||||
|
offset: 0,
|
||||||
|
}).then(res => {
|
||||||
|
let ids = items.value.reduce((a, b) => {
|
||||||
|
a[b.id] = true;
|
||||||
|
return a;
|
||||||
|
}, {} as { [id: string]: boolean; });
|
||||||
|
|
||||||
|
for (let i = 0; i < res.length; i++) {
|
||||||
|
const item = res[i];
|
||||||
|
if (!updateItem(item.id, old => item)) {
|
||||||
|
append(item);
|
||||||
|
}
|
||||||
|
delete ids[item.id];
|
||||||
}
|
}
|
||||||
more.value = true;
|
|
||||||
} else {
|
for (const id in ids) {
|
||||||
items.value = props.pagination.reversed ? [...res].reverse() : res;
|
removeItem(i => i.id === id);
|
||||||
if (props.externalItemArray) {
|
|
||||||
props.externalItemArray.value = items.value;
|
|
||||||
}
|
}
|
||||||
more.value = false;
|
}, err => {
|
||||||
}
|
error.value = true;
|
||||||
offset.value = res.length;
|
fetching.value = false;
|
||||||
error.value = false;
|
});
|
||||||
fetching.value = false;
|
};
|
||||||
}, err => {
|
|
||||||
error.value = true;
|
|
||||||
fetching.value = false;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const reload = (): void => {
|
const fetchMore = async (): Promise<void> => {
|
||||||
items.value = [];
|
if (!more.value || fetching.value || moreFetching.value || items.value.length === 0) return;
|
||||||
if (props.externalItemArray) {
|
moreFetching.value = true;
|
||||||
props.externalItemArray.value = [];
|
backed.value = true;
|
||||||
}
|
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
||||||
init();
|
await os.api(props.pagination.endpoint, {
|
||||||
};
|
...params,
|
||||||
|
limit: SECOND_FETCH_LIMIT + 1,
|
||||||
const refresh = async (): Promise<void> => {
|
...(props.pagination.offsetMode ? {
|
||||||
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
offset: offset.value,
|
||||||
await os.api(props.pagination.endpoint, {
|
} : props.pagination.reversed ? {
|
||||||
...(params as object),
|
sinceId: items.value[0].id,
|
||||||
limit: items.value.length + 1,
|
} : {
|
||||||
offset: 0,
|
untilId: items.value[items.value.length - 1].id,
|
||||||
}).then(res => {
|
}),
|
||||||
let ids = items.value.reduce((a, b) => {
|
}).then(res => {
|
||||||
a[b.id] = true;
|
for (let i = 0; i < res.length; i++) {
|
||||||
return a;
|
const item = res[i];
|
||||||
}, {} as { [id: string]: boolean; });
|
if (props.pagination.reversed) {
|
||||||
|
if (i === res.length - 9) item._shouldInsertAd_ = true;
|
||||||
for (let i = 0; i < res.length; i++) {
|
} else {
|
||||||
const item = res[i];
|
if (i === 10) item._shouldInsertAd_ = true;
|
||||||
if (!updateItem(item.id, old => item)) {
|
}
|
||||||
append(item);
|
|
||||||
}
|
}
|
||||||
delete ids[item.id];
|
if (res.length > SECOND_FETCH_LIMIT) {
|
||||||
}
|
res.pop();
|
||||||
|
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
|
||||||
for (const id in ids) {
|
more.value = true;
|
||||||
removeItem(i => i.id === id);
|
|
||||||
}
|
|
||||||
}, err => {
|
|
||||||
error.value = true;
|
|
||||||
fetching.value = false;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchMore = async (): Promise<void> => {
|
|
||||||
if (!more.value || fetching.value || moreFetching.value || items.value.length === 0) return;
|
|
||||||
moreFetching.value = true;
|
|
||||||
backed.value = true;
|
|
||||||
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
|
||||||
await os.api(props.pagination.endpoint, {
|
|
||||||
...(params as object),
|
|
||||||
limit: SECOND_FETCH_LIMIT + 1,
|
|
||||||
...(props.pagination.offsetMode ? {
|
|
||||||
offset: offset.value,
|
|
||||||
} : props.pagination.reversed ? {
|
|
||||||
sinceId: items.value[0].id,
|
|
||||||
} : {
|
|
||||||
untilId: items.value[items.value.length - 1].id,
|
|
||||||
}),
|
|
||||||
}).then(res => {
|
|
||||||
for (let i = 0; i < res.length; i++) {
|
|
||||||
const item = res[i];
|
|
||||||
if (props.pagination.reversed) {
|
|
||||||
if (i === res.length - 9) item._shouldInsertAd_ = true;
|
|
||||||
} else {
|
} else {
|
||||||
if (i === 10) item._shouldInsertAd_ = true;
|
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
|
||||||
|
more.value = false;
|
||||||
}
|
}
|
||||||
}
|
offset.value += res.length;
|
||||||
if (res.length > SECOND_FETCH_LIMIT) {
|
moreFetching.value = false;
|
||||||
res.pop();
|
}, err => {
|
||||||
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
|
moreFetching.value = false;
|
||||||
if (props.externalItemArray) {
|
});
|
||||||
props.externalItemArray.value = items.value;
|
};
|
||||||
}
|
|
||||||
more.value = true;
|
|
||||||
} else {
|
|
||||||
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
|
|
||||||
if (props.externalItemArray) {
|
|
||||||
props.externalItemArray.value = items.value;
|
|
||||||
}
|
|
||||||
more.value = false;
|
|
||||||
}
|
|
||||||
offset.value += res.length;
|
|
||||||
moreFetching.value = false;
|
|
||||||
}, err => {
|
|
||||||
moreFetching.value = false;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchMoreAhead = async (): Promise<void> => {
|
const fetchMoreAhead = async (): Promise<void> => {
|
||||||
if (!more.value || fetching.value || moreFetching.value || items.value.length === 0) return;
|
if (!more.value || fetching.value || moreFetching.value || items.value.length === 0) return;
|
||||||
moreFetching.value = true;
|
moreFetching.value = true;
|
||||||
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
||||||
await os.api(props.pagination.endpoint, {
|
await os.api(props.pagination.endpoint, {
|
||||||
...(params as object),
|
...params,
|
||||||
limit: SECOND_FETCH_LIMIT + 1,
|
limit: SECOND_FETCH_LIMIT + 1,
|
||||||
...(props.pagination.offsetMode ? {
|
...(props.pagination.offsetMode ? {
|
||||||
offset: offset.value,
|
offset: offset.value,
|
||||||
} : props.pagination.reversed ? {
|
} : props.pagination.reversed ? {
|
||||||
untilId: items.value[0].id,
|
untilId: items.value[0].id,
|
||||||
} : {
|
} : {
|
||||||
sinceId: items.value[items.value.length - 1].id,
|
sinceId: items.value[items.value.length - 1].id,
|
||||||
}),
|
}),
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.length > SECOND_FETCH_LIMIT) {
|
if (res.length > SECOND_FETCH_LIMIT) {
|
||||||
res.pop();
|
res.pop();
|
||||||
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
|
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
|
||||||
if (props.externalItemArray) {
|
more.value = true;
|
||||||
props.externalItemArray.value = items.value;
|
|
||||||
}
|
|
||||||
more.value = true;
|
|
||||||
} else {
|
|
||||||
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
|
|
||||||
if (props.externalItemArray) {
|
|
||||||
props.externalItemArray.value = items.value;
|
|
||||||
}
|
|
||||||
more.value = false;
|
|
||||||
}
|
|
||||||
offset.value += res.length;
|
|
||||||
moreFetching.value = false;
|
|
||||||
}, err => {
|
|
||||||
moreFetching.value = false;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const prepend = (item: Item): void => {
|
|
||||||
if (props.pagination.reversed) {
|
|
||||||
if (rootEl.value) {
|
|
||||||
const container = getScrollContainer(rootEl.value);
|
|
||||||
if (container == null) {
|
|
||||||
// TODO?
|
|
||||||
} else {
|
} else {
|
||||||
const pos = getScrollPosition(rootEl.value);
|
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
|
||||||
const viewHeight = container.clientHeight;
|
more.value = false;
|
||||||
const height = container.scrollHeight;
|
}
|
||||||
const isBottom = (pos + viewHeight > height - 32);
|
offset.value += res.length;
|
||||||
if (isBottom) {
|
moreFetching.value = false;
|
||||||
// オーバーフローしたら古いアイテムは捨てる
|
}, err => {
|
||||||
if (items.value.length >= props.displayLimit) {
|
moreFetching.value = false;
|
||||||
// このやり方だとVue 3.2以降アニメーションが動かなくなる
|
});
|
||||||
//items.value = items.value.slice(-props.displayLimit);
|
};
|
||||||
while (items.value.length >= props.displayLimit) {
|
|
||||||
items.value.shift();
|
const prepend = (item: Item): void => {
|
||||||
if (props.externalItemArray) props.externalItemArray.value.shift();
|
if (props.pagination.reversed) {
|
||||||
|
if (rootEl.value) {
|
||||||
|
const container = getScrollContainer(rootEl.value);
|
||||||
|
if (container == null) {
|
||||||
|
// TODO?
|
||||||
|
} else {
|
||||||
|
const pos = getScrollPosition(rootEl.value);
|
||||||
|
const viewHeight = container.clientHeight;
|
||||||
|
const height = container.scrollHeight;
|
||||||
|
const isBottom = (pos + viewHeight > height - 32);
|
||||||
|
if (isBottom) {
|
||||||
|
// オーバーフローしたら古いアイテムは捨てる
|
||||||
|
if (items.value.length >= props.displayLimit) {
|
||||||
|
// このやり方だとVue 3.2以降アニメーションが動かなくなる
|
||||||
|
//items.value = items.value.slice(-props.displayLimit);
|
||||||
|
while (items.value.length >= props.displayLimit) {
|
||||||
|
items.value.shift();
|
||||||
|
}
|
||||||
|
more.value = true;
|
||||||
}
|
}
|
||||||
more.value = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
items.value.push(item);
|
||||||
items.value.push(item);
|
// TODO
|
||||||
if (props.externalItemArray) props.externalItemArray.value.push(item);
|
|
||||||
// TODO
|
|
||||||
} else {
|
|
||||||
// 初回表示時はunshiftだけでOK
|
|
||||||
if (!rootEl.value) {
|
|
||||||
items.value.unshift(item);
|
|
||||||
if (props.externalItemArray) props.externalItemArray.value.unshift(item);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isTop = isBackTop.value || (document.body.contains(rootEl.value) && isTopVisible(rootEl.value));
|
|
||||||
|
|
||||||
if (isTop) {
|
|
||||||
// Prepend the item
|
|
||||||
items.value.unshift(item);
|
|
||||||
if (props.externalItemArray) props.externalItemArray.value.unshift(item);
|
|
||||||
} else {
|
} else {
|
||||||
queue.value.push(item);
|
// 初回表示時はunshiftだけでOK
|
||||||
onScrollTop(rootEl.value, () => {
|
if (!rootEl.value) {
|
||||||
for (const queueItem of queue.value) {
|
items.value.unshift(item);
|
||||||
prepend(queueItem);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isTop = isBackTop.value || (document.body.contains(rootEl.value) && isTopVisible(rootEl.value));
|
||||||
|
|
||||||
|
if (isTop) {
|
||||||
|
// Prepend the item
|
||||||
|
items.value.unshift(item);
|
||||||
|
|
||||||
|
// オーバーフローしたら古いアイテムは捨てる
|
||||||
|
if (items.value.length >= props.displayLimit) {
|
||||||
|
// このやり方だとVue 3.2以降アニメーションが動かなくなる
|
||||||
|
//this.items = items.value.slice(0, props.displayLimit);
|
||||||
|
while (items.value.length >= props.displayLimit) {
|
||||||
|
items.value.pop();
|
||||||
|
}
|
||||||
|
more.value = true;
|
||||||
}
|
}
|
||||||
queue.value = [];
|
} else {
|
||||||
});
|
queue.value.push(item);
|
||||||
|
onScrollTop(rootEl.value, () => {
|
||||||
|
for (const queueItem of queue.value) {
|
||||||
|
prepend(queueItem);
|
||||||
|
}
|
||||||
|
queue.value = [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const append = (item: Item): void => {
|
||||||
|
items.value.push(item);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeItem = (finder: (item: Item) => boolean): boolean => {
|
||||||
|
const i = items.value.findIndex(finder);
|
||||||
|
if (i === -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
items.value.splice(i, 1);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateItem = (id: Item['id'], replacer: (old: Item) => Item): boolean => {
|
||||||
|
const i = items.value.findIndex(item => item.id === id);
|
||||||
|
if (i === -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
items.value[i] = replacer(items.value[i]);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (props.pagination.params && isRef(props.pagination.params)) {
|
||||||
|
watch(props.pagination.params, init, { deep: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(queue, (a, b) => {
|
||||||
|
if (a.length === 0 && b.length === 0) return;
|
||||||
|
emit('queue', queue.value.length);
|
||||||
|
}, { deep: true });
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
onActivated(() => {
|
||||||
|
isBackTop.value = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
onDeactivated(() => {
|
||||||
|
isBackTop.value = window.scrollY === 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
items,
|
||||||
|
queue,
|
||||||
|
backed,
|
||||||
|
reload,
|
||||||
|
refresh,
|
||||||
|
prepend,
|
||||||
|
append,
|
||||||
|
removeItem,
|
||||||
|
updateItem,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.fade-enter-active,
|
||||||
|
.fade-leave-active {
|
||||||
|
transition: opacity 0.125s ease;
|
||||||
|
}
|
||||||
|
.fade-enter-from,
|
||||||
|
.fade-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cxiknjgy {
|
||||||
|
> .button {
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
</style>
|
||||||
|
|
||||||
const append = (item: Item): void => {
|
|
||||||
items.value.push(item);
|
|
||||||
if (props.externalItemArray) props.externalItemArray.value.push(item);
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeItem = (finder: (item: Item) => boolean): boolean => {
|
|
||||||
const i = items.value.findIndex(finder);
|
|
||||||
const j = props.externalItemArray?.findIndex(finder);
|
|
||||||
if (i === -1 && j === -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
items.value.splice(i, 1);
|
|
||||||
if (props.externalItemArray) props.externalItemArray.value.splice(i, 1);
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateItem = (id: Item['id'], replacer: (old: Item) => Item): boolean => {
|
|
||||||
const i = items.value.findIndex(item => item.id === id);
|
|
||||||
const j = props.externalItemArray?.findIndex(item => item.id === id);
|
|
||||||
if (i === -1 && j === -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
items.value[i] = replacer(items.value[i]);
|
|
||||||
if (props.externalItemArray) props.externalItemArray.value[i] = items.value[i];
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (props.pagination.params && isRef(props.pagination.params)) {
|
|
||||||
watch(props.pagination.params, init, { deep: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(queue, (a, b) => {
|
|
||||||
if (a.length === 0 && b.length === 0) return;
|
|
||||||
emit('queue', queue.value.length);
|
|
||||||
}, { deep: true });
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
onActivated(() => {
|
|
||||||
isBackTop.value = false;
|
|
||||||
if(alreadyInitedOnce.value && (!props.disableReload || !props.disableReload.value)) {
|
|
||||||
reload();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
onDeactivated(() => {
|
|
||||||
isBackTop.value = window.scrollY === 0;
|
|
||||||
alreadyInitedOnce.value = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
defineExpose({
|
|
||||||
items,
|
|
||||||
queue,
|
|
||||||
backed,
|
|
||||||
reload,
|
|
||||||
refresh,
|
|
||||||
prepend,
|
|
||||||
append,
|
|
||||||
removeItem,
|
|
||||||
updateItem,
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.fade-enter-active,
|
|
||||||
.fade-leave-active {
|
|
||||||
transition: opacity 0.15s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.fade-enter-from,
|
|
||||||
.fade-leave-to {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cxiknjgy {
|
|
||||||
>.button {
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -1,47 +1,43 @@
|
||||||
<template>
|
<template>
|
||||||
<MkStickyContainer>
|
<MkStickyContainer>
|
||||||
<template #header>
|
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
|
||||||
<MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs" />
|
<div>
|
||||||
</template>
|
<MkSpacer :content-max="800">
|
||||||
<div>
|
<swiper
|
||||||
<MkSpacer :content-max="800">
|
:modules="[Virtual]"
|
||||||
<swiper :modules="[Virtual]" :space-between="20" :virtual="true"
|
:space-between="20"
|
||||||
:allow-touch-move="!(deviceKind === 'desktop' && !defaultStore.state.swipeOnDesktop)" @swiper="setSwiperRef"
|
:virtual="true"
|
||||||
@slide-change="onSlideChange">
|
:allow-touch-move="!(deviceKind === 'desktop' && !defaultStore.state.swipeOnDesktop)"
|
||||||
<swiper-slide>
|
@swiper="setSwiperRef"
|
||||||
<div class="_content yweeujhr dms">
|
@slide-change="onSlideChange"
|
||||||
<MkButton primary class="start" @click="startUser"><i class="ph-plus-bold ph-lg"></i> {{
|
>
|
||||||
i18n.ts.startMessaging
|
<swiper-slide>
|
||||||
}}</MkButton>
|
<div class="_content yweeujhr dms">
|
||||||
<MkPagination v-slot="{ items }" :pagination="dmsPagination">
|
<MkButton primary class="start" @click="startUser"><i class="ph-plus-bold ph-lg"></i> {{ i18n.ts.startMessaging }}</MkButton>
|
||||||
<MkChatPreview v-for="message in items" :key="message.id" class="yweeujhr message _block"
|
<MkPagination v-slot="{items}" :pagination="dmsPagination">
|
||||||
:message="message" />
|
<MkChatPreview v-for="message in items" :key="message.id" class="yweeujhr message _block" :message="message"/>
|
||||||
</MkPagination>
|
</MkPagination>
|
||||||
|
</div>
|
||||||
|
</swiper-slide>
|
||||||
|
<swiper-slide>
|
||||||
|
<div class="_content yweeujhr groups">
|
||||||
|
<div class="groupsbuttons">
|
||||||
|
<MkButton primary class="start" :link="true" to="/my/groups"><i class="ph-user-circle-gear-bold ph-lg"></i> {{ i18n.ts.manageGroups }}</MkButton>
|
||||||
|
<MkButton primary class="start" @click="startGroup"><i class="ph-plus-bold ph-lg"></i> {{ i18n.ts.startMessaging }}</MkButton>
|
||||||
</div>
|
</div>
|
||||||
</swiper-slide>
|
<MkPagination v-slot="{items}" :pagination="groupsPagination">
|
||||||
<swiper-slide>
|
<MkChatPreview v-for="message in items" :key="message.id" class="yweeujhr message _block" :message="message"/>
|
||||||
<div class="_content yweeujhr groups">
|
</MkPagination>
|
||||||
<div class="groupsbuttons">
|
</div>
|
||||||
<MkButton primary class="start" :link="true" to="/my/groups"><i
|
</swiper-slide>
|
||||||
class="ph-user-circle-gear-bold ph-lg"></i> {{ i18n.ts.manageGroups }}</MkButton>
|
</swiper>
|
||||||
<MkButton primary class="start" @click="startGroup"><i class="ph-plus-bold ph-lg"></i> {{
|
</MkSpacer>
|
||||||
i18n.ts.startMessaging
|
</div>
|
||||||
}}</MkButton>
|
</MkStickyContainer>
|
||||||
</div>
|
|
||||||
<MkPagination v-slot="{ items }" :pagination="groupsPagination">
|
|
||||||
<MkChatPreview v-for="message in items" :key="message.id" class="yweeujhr message _block"
|
|
||||||
:message="message" />
|
|
||||||
</MkPagination>
|
|
||||||
</div>
|
|
||||||
</swiper-slide>
|
|
||||||
</swiper>
|
|
||||||
</MkSpacer>
|
|
||||||
</div>
|
|
||||||
</MkStickyContainer>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { markRaw, onMounted, onUnmounted, watch, computed } from 'vue';
|
import { markRaw, onMounted, onUnmounted, watch } from 'vue';
|
||||||
import * as Acct from 'calckey-js/built/acct';
|
import * as Acct from 'calckey-js/built/acct';
|
||||||
import { Virtual } from 'swiper';
|
import { Virtual } from 'swiper';
|
||||||
import { Swiper, SwiperSlide } from 'swiper/vue';
|
import { Swiper, SwiperSlide } from 'swiper/vue';
|
||||||
|
@ -63,8 +59,6 @@ const router = useRouter();
|
||||||
|
|
||||||
let messages = $ref([]);
|
let messages = $ref([]);
|
||||||
let connection = $ref(null);
|
let connection = $ref(null);
|
||||||
let paginationComponentUser = $ref<InstanceType<typeof MkPagination>>();
|
|
||||||
let paginationComponentGroup = $ref<InstanceType<typeof MkPagination>>();
|
|
||||||
|
|
||||||
const tabs = ['dms', 'groups'];
|
const tabs = ['dms', 'groups'];
|
||||||
let tab = $ref(tabs[0]);
|
let tab = $ref(tabs[0]);
|
||||||
|
@ -94,33 +88,30 @@ definePageMetadata({
|
||||||
|
|
||||||
const dmsPagination = {
|
const dmsPagination = {
|
||||||
endpoint: 'messaging/history' as const,
|
endpoint: 'messaging/history' as const,
|
||||||
limit: 20,
|
limit: 15,
|
||||||
params: computed(() => ({
|
params: {
|
||||||
group: false,
|
group: false,
|
||||||
})),
|
},
|
||||||
offsetMode: true,
|
|
||||||
};
|
};
|
||||||
const groupsPagination = {
|
const groupsPagination = {
|
||||||
endpoint: 'messaging/history' as const,
|
endpoint: 'messaging/history' as const,
|
||||||
limit: 10,
|
limit: 5,
|
||||||
params: computed(() => ({
|
params: {
|
||||||
group: true,
|
group: true,
|
||||||
})),
|
},
|
||||||
offsetMode: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function onMessage(message): void {
|
function onMessage(message): void {
|
||||||
if (message.recipientId) {
|
if (message.recipientId) {
|
||||||
messages = messages.filter(m => !(
|
messages = messages.filter(m => !(
|
||||||
(m.recipientId === message.recipientId && m.userId === message.userId) ||
|
(m.recipientId === message.recipientId && m.userId === message.userId) ||
|
||||||
(m.recipientId === message.userId && m.userId === message.recipientId)));
|
(m.recipientId === message.userId && m.userId === message.recipientId)));
|
||||||
|
|
||||||
messages.unshift(message);
|
messages.unshift(message);
|
||||||
} else if (message.groupId) {
|
} else if (message.groupId) {
|
||||||
messages = messages.filter(m => m.groupId !== message.groupId);
|
messages = messages.filter(m => m.groupId !== message.groupId);
|
||||||
messages.unshift(message);
|
messages.unshift(message);
|
||||||
}
|
}
|
||||||
forceRerender();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onRead(ids): void {
|
function onRead(ids): void {
|
||||||
|
@ -192,12 +183,11 @@ function syncSlide(index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
syncSlide(tabs.indexOf(swiperRef?.activeIndex));
|
syncSlide(tabs.indexOf(swiperRef.activeIndex));
|
||||||
|
|
||||||
connection = markRaw(stream.useChannel('messagingIndex'));
|
connection = markRaw(stream.useChannel('messagingIndex'));
|
||||||
|
|
||||||
connection.on('message', onMessage);
|
connection.on('message', onMessage);
|
||||||
connection.on('messagingMessage', onMessage);
|
|
||||||
connection.on('read', onRead);
|
connection.on('read', onRead);
|
||||||
|
|
||||||
os.api('messaging/history', { group: false, limit: 5 }).then(userMessages => {
|
os.api('messaging/history', { group: false, limit: 5 }).then(userMessages => {
|
||||||
|
@ -214,17 +204,17 @@ onUnmounted(() => {
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.yweeujhr {
|
.yweeujhr {
|
||||||
>.start {
|
> .start {
|
||||||
margin: 0 auto var(--margin) auto;
|
margin: 0 auto var(--margin) auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
>.groupsbuttons {
|
> .groupsbuttons {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
</style>
|
||||||
</style>
|
|
||||||
|
|
Loading…
Reference in a new issue