2018-02-13 15:17:59 +09:00
|
|
|
<template>
|
2022-06-20 13:20:28 +09:00
|
|
|
<div
|
|
|
|
ref="rootEl"
|
|
|
|
class="_section"
|
2018-02-27 04:36:16 +09:00
|
|
|
@dragover.prevent.stop="onDragover"
|
|
|
|
@drop.prevent.stop="onDrop"
|
|
|
|
>
|
2020-10-17 20:12:00 +09:00
|
|
|
<div class="_content mk-messaging-room">
|
|
|
|
<div class="body">
|
2022-06-20 13:20:28 +09:00
|
|
|
<MkPagination v-if="pagination" ref="pagingComponent" :key="userAcct || groupId" :pagination="pagination">
|
|
|
|
<template #empty>
|
|
|
|
<div class="_fullinfo">
|
2022-08-09 06:07:09 +09:00
|
|
|
<img src="/static-assets/badges/info.png" class="_ghost" alt="Info"/>
|
2022-06-20 13:20:28 +09:00
|
|
|
<div>{{ i18n.ts.noMessagesYet }}</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #default="{ items: messages, fetching: pFetching }">
|
|
|
|
<XList
|
|
|
|
v-if="messages.length > 0"
|
|
|
|
v-slot="{ item: message }"
|
|
|
|
:class="{ messages: true, 'deny-move-transition': pFetching }"
|
|
|
|
:items="messages"
|
|
|
|
direction="up"
|
|
|
|
reversed
|
|
|
|
>
|
|
|
|
<XMessage :key="message.id" :message="message" :is-group="group != null"/>
|
|
|
|
</XList>
|
|
|
|
</template>
|
|
|
|
</MkPagination>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
|
|
|
<footer>
|
2021-11-19 19:36:12 +09:00
|
|
|
<div v-if="typers.length > 0" class="typers">
|
2022-06-20 13:20:28 +09:00
|
|
|
<I18n :src="i18n.ts.typingUsers" text-tag="span" class="users">
|
2021-02-21 12:26:49 +09:00
|
|
|
<template #users>
|
2022-06-20 13:20:28 +09:00
|
|
|
<b v-for="typer in typers" :key="typer.id" class="user">{{ typer.username }}</b>
|
2021-02-21 12:26:49 +09:00
|
|
|
</template>
|
|
|
|
</I18n>
|
|
|
|
<MkEllipsis/>
|
|
|
|
</div>
|
2022-06-20 13:20:28 +09:00
|
|
|
<transition :name="animation ? 'fade' : ''">
|
2021-11-19 19:36:12 +09:00
|
|
|
<div v-show="showIndicator" class="new-message">
|
2022-06-20 13:20:28 +09:00
|
|
|
<button class="_buttonPrimary" @click="onIndicatorClick"><i class="fas fa-fw fa-arrow-circle-down"></i>{{ i18n.ts.newMessageExists }}</button>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
|
|
|
</transition>
|
2022-06-20 13:20:28 +09:00
|
|
|
<XForm v-if="!fetching" ref="formEl" :user="user" :group="group" class="form"/>
|
2020-10-17 20:12:00 +09:00
|
|
|
</footer>
|
2018-02-13 15:17:59 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, watch, onMounted, nextTick, onBeforeUnmount } from 'vue';
|
|
|
|
import * as Misskey from 'misskey-js';
|
|
|
|
import * as Acct from 'misskey-js/built/acct';
|
2018-02-21 01:39:51 +09:00
|
|
|
import XMessage from './messaging-room.message.vue';
|
|
|
|
import XForm from './messaging-room.form.vue';
|
2022-08-31 00:24:33 +09:00
|
|
|
import XList from '@/components/MkDateSeparatedList.vue';
|
2022-09-06 18:21:49 +09:00
|
|
|
import MkPagination, { Paging } from '@/components/MkPagination.vue';
|
2022-06-20 13:20:28 +09:00
|
|
|
import { isBottomVisible, onScrollBottom, scrollToBottom } from '@/scripts/scroll';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2021-12-29 22:13:09 +09:00
|
|
|
import { stream } from '@/stream';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as sound from '@/scripts/sound';
|
2022-06-20 13:20:28 +09:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { $i } from '@/account';
|
|
|
|
import { defaultStore } from '@/store';
|
2022-06-20 17:38:49 +09:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2022-06-20 13:20:28 +09:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
userAcct?: string;
|
|
|
|
groupId?: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
let rootEl = $ref<HTMLDivElement>();
|
|
|
|
let formEl = $ref<InstanceType<typeof XForm>>();
|
|
|
|
let pagingComponent = $ref<InstanceType<typeof MkPagination>>();
|
|
|
|
|
|
|
|
let fetching = $ref(true);
|
|
|
|
let user: Misskey.entities.UserDetailed | null = $ref(null);
|
|
|
|
let group: Misskey.entities.UserGroup | null = $ref(null);
|
|
|
|
let typers: Misskey.entities.User[] = $ref([]);
|
|
|
|
let connection: Misskey.ChannelConnection<Misskey.Channels['messaging']> | null = $ref(null);
|
|
|
|
let showIndicator = $ref(false);
|
|
|
|
const {
|
|
|
|
animation,
|
|
|
|
} = defaultStore.reactiveState;
|
|
|
|
|
|
|
|
let pagination: Paging | null = $ref(null);
|
|
|
|
|
|
|
|
watch([() => props.userAcct, () => props.groupId], () => {
|
|
|
|
if (connection) connection.dispose();
|
|
|
|
fetch();
|
|
|
|
});
|
2018-02-13 15:17:59 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
async function fetch() {
|
|
|
|
fetching = true;
|
|
|
|
|
|
|
|
if (props.userAcct) {
|
|
|
|
const acct = Acct.parse(props.userAcct);
|
|
|
|
user = await os.api('users/show', { username: acct.username, host: acct.host || undefined });
|
|
|
|
group = null;
|
2022-09-14 08:57:42 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
pagination = {
|
|
|
|
endpoint: 'messaging/messages',
|
|
|
|
limit: 20,
|
|
|
|
params: {
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
reversed: true,
|
|
|
|
pageEl: $$(rootEl).value,
|
2018-02-13 15:17:59 +09:00
|
|
|
};
|
2022-06-20 13:20:28 +09:00
|
|
|
connection = stream.useChannel('messaging', {
|
|
|
|
otherparty: user.id,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
user = null;
|
|
|
|
group = await os.api('users/groups/show', { groupId: props.groupId });
|
|
|
|
|
|
|
|
pagination = {
|
|
|
|
endpoint: 'messaging/messages',
|
|
|
|
limit: 20,
|
|
|
|
params: {
|
|
|
|
groupId: group?.id,
|
|
|
|
},
|
|
|
|
reversed: true,
|
|
|
|
pageEl: $$(rootEl).value,
|
|
|
|
};
|
|
|
|
connection = stream.useChannel('messaging', {
|
|
|
|
group: group?.id,
|
|
|
|
});
|
|
|
|
}
|
2018-02-27 04:36:16 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
connection.on('message', onMessage);
|
|
|
|
connection.on('read', onRead);
|
|
|
|
connection.on('deleted', onDeleted);
|
|
|
|
connection.on('typers', _typers => {
|
|
|
|
typers = _typers.filter(u => u.id !== $i?.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
document.addEventListener('visibilitychange', onVisibilitychange);
|
|
|
|
|
|
|
|
nextTick(() => {
|
2022-09-14 11:40:20 +09:00
|
|
|
// thisScrollToBottom();
|
2022-06-20 13:20:28 +09:00
|
|
|
window.setTimeout(() => {
|
|
|
|
fetching = false;
|
|
|
|
}, 300);
|
|
|
|
});
|
|
|
|
}
|
2018-02-13 15:17:59 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
function onDragover(ev: DragEvent) {
|
|
|
|
if (!ev.dataTransfer) return;
|
2020-05-31 12:53:06 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
const isFile = ev.dataTransfer.items[0].kind === 'file';
|
|
|
|
const isDriveFile = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FILE_;
|
2018-02-27 04:36:16 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
if (isFile || isDriveFile) {
|
|
|
|
ev.dataTransfer.dropEffect = ev.dataTransfer.effectAllowed === 'all' ? 'copy' : 'move';
|
|
|
|
} else {
|
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
function onDrop(ev: DragEvent): void {
|
|
|
|
if (!ev.dataTransfer) return;
|
|
|
|
|
|
|
|
// ファイルだったら
|
|
|
|
if (ev.dataTransfer.files.length === 1) {
|
|
|
|
formEl.upload(ev.dataTransfer.files[0]);
|
|
|
|
return;
|
|
|
|
} else if (ev.dataTransfer.files.length > 1) {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
text: i18n.ts.onlyOneFileCanBeAttached,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
//#region ドライブのファイル
|
|
|
|
const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
|
|
|
|
if (driveFile != null && driveFile !== '') {
|
|
|
|
const file = JSON.parse(driveFile);
|
|
|
|
formEl.file = file;
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
function onMessage(message) {
|
|
|
|
sound.play('chat');
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
const _isBottom = isBottomVisible(rootEl, 64);
|
2020-05-31 12:53:06 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
pagingComponent.prepend(message);
|
|
|
|
if (message.userId !== $i?.id && !document.hidden) {
|
|
|
|
connection?.send('read', {
|
|
|
|
id: message.id,
|
|
|
|
});
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
if (_isBottom) {
|
|
|
|
// Scroll to bottom
|
|
|
|
nextTick(() => {
|
|
|
|
thisScrollToBottom();
|
|
|
|
});
|
|
|
|
} else if (message.userId !== $i?.id) {
|
|
|
|
// Notify
|
|
|
|
notifyNewMessage();
|
|
|
|
}
|
|
|
|
}
|
2018-02-27 06:25:17 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
function onRead(x) {
|
|
|
|
if (user) {
|
|
|
|
if (!Array.isArray(x)) x = [x];
|
|
|
|
for (const id of x) {
|
|
|
|
if (pagingComponent.items.some(y => y.id === id)) {
|
|
|
|
const exist = pagingComponent.items.map(y => y.id).indexOf(id);
|
|
|
|
pagingComponent.items[exist] = {
|
|
|
|
...pagingComponent.items[exist],
|
|
|
|
isRead: true,
|
|
|
|
};
|
2018-02-27 04:36:16 +09:00
|
|
|
}
|
2022-06-20 13:20:28 +09:00
|
|
|
}
|
|
|
|
} else if (group) {
|
|
|
|
for (const id of x.ids) {
|
|
|
|
if (pagingComponent.items.some(y => y.id === id)) {
|
|
|
|
const exist = pagingComponent.items.map(y => y.id).indexOf(id);
|
|
|
|
pagingComponent.items[exist] = {
|
|
|
|
...pagingComponent.items[exist],
|
|
|
|
reads: [...pagingComponent.items[exist].reads, x.userId],
|
|
|
|
};
|
2018-02-27 04:36:16 +09:00
|
|
|
}
|
2022-06-20 13:20:28 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-13 15:17:59 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
function onDeleted(id) {
|
|
|
|
const msg = pagingComponent.items.find(m => m.id === id);
|
|
|
|
if (msg) {
|
|
|
|
pagingComponent.items = pagingComponent.items.filter(m => m.id !== msg.id);
|
|
|
|
}
|
|
|
|
}
|
2018-02-13 15:17:59 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
function thisScrollToBottom() {
|
2022-09-14 11:37:38 +09:00
|
|
|
if (window.location.href.includes('my/messaging/')) {
|
|
|
|
scrollToBottom($$(rootEl).value, { behavior: 'smooth' });
|
|
|
|
}
|
2022-06-20 13:20:28 +09:00
|
|
|
}
|
2018-02-27 04:36:16 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
function onIndicatorClick() {
|
|
|
|
showIndicator = false;
|
|
|
|
thisScrollToBottom();
|
|
|
|
}
|
2018-12-27 01:24:57 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
let scrollRemove: (() => void) | null = $ref(null);
|
2018-02-27 04:36:16 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
function notifyNewMessage() {
|
|
|
|
showIndicator = true;
|
2018-05-24 04:55:29 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
scrollRemove = onScrollBottom(rootEl, () => {
|
|
|
|
showIndicator = false;
|
|
|
|
scrollRemove = null;
|
|
|
|
});
|
|
|
|
}
|
2018-05-24 04:55:29 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
function onVisibilitychange() {
|
|
|
|
if (document.hidden) return;
|
|
|
|
for (const message of pagingComponent.items) {
|
|
|
|
if (message.userId !== $i?.id && !message.isRead) {
|
|
|
|
connection?.send('read', {
|
|
|
|
id: message.id,
|
2020-07-19 12:26:05 +09:00
|
|
|
});
|
2018-02-13 15:17:59 +09:00
|
|
|
}
|
|
|
|
}
|
2022-06-20 13:20:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
fetch();
|
2018-02-13 15:17:59 +09:00
|
|
|
});
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
onBeforeUnmount(() => {
|
|
|
|
connection?.dispose();
|
|
|
|
document.removeEventListener('visibilitychange', onVisibilitychange);
|
|
|
|
if (scrollRemove) scrollRemove();
|
|
|
|
});
|
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
definePageMetadata(computed(() => !fetching ? user ? {
|
|
|
|
userName: user,
|
|
|
|
avatar: user,
|
|
|
|
} : {
|
|
|
|
title: group?.name,
|
|
|
|
icon: 'fas fa-users',
|
|
|
|
} : null));
|
2018-02-13 15:17:59 +09:00
|
|
|
</script>
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
<style lang="scss" scoped>
|
2022-09-14 12:07:19 +09:00
|
|
|
|
|
|
|
XMessage:last-of-type {
|
|
|
|
margin-bottom: 4rem;
|
|
|
|
}
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
.mk-messaging-room {
|
2022-06-20 13:20:28 +09:00
|
|
|
position: relative;
|
2022-07-12 05:45:00 +09:00
|
|
|
overflow: auto;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
> .body {
|
|
|
|
.more {
|
2020-01-30 04:37:25 +09:00
|
|
|
display: block;
|
|
|
|
margin: 16px auto;
|
|
|
|
padding: 0 12px;
|
|
|
|
line-height: 24px;
|
|
|
|
color: #fff;
|
|
|
|
background: rgba(#000, 0.3);
|
|
|
|
border-radius: 12px;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: rgba(#000, 0.4);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
background: rgba(#000, 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.fetching {
|
|
|
|
cursor: wait;
|
|
|
|
}
|
|
|
|
|
2021-04-20 23:22:59 +09:00
|
|
|
> i {
|
2020-01-30 04:37:25 +09:00
|
|
|
margin-right: 4px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 13:20:28 +09:00
|
|
|
.messages {
|
|
|
|
padding: 8px 0;
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> ::v-deep(*) {
|
2020-01-30 04:37:25 +09:00
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> footer {
|
|
|
|
width: 100%;
|
2022-06-20 13:20:28 +09:00
|
|
|
position: sticky;
|
|
|
|
z-index: 2;
|
|
|
|
bottom: 0;
|
|
|
|
padding-top: 8px;
|
2022-07-12 07:00:48 +09:00
|
|
|
bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
> .new-message {
|
|
|
|
width: 100%;
|
2022-06-20 13:20:28 +09:00
|
|
|
padding-bottom: 8px;
|
2020-01-30 04:37:25 +09:00
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
> button {
|
|
|
|
display: inline-block;
|
|
|
|
margin: 0;
|
2022-06-20 13:20:28 +09:00
|
|
|
padding: 0 12px;
|
2020-01-30 04:37:25 +09:00
|
|
|
line-height: 32px;
|
|
|
|
font-size: 12px;
|
|
|
|
border-radius: 16px;
|
|
|
|
|
|
|
|
> i {
|
2022-06-20 13:20:28 +09:00
|
|
|
display: inline-block;
|
|
|
|
margin-right: 8px;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-21 12:26:49 +09:00
|
|
|
|
|
|
|
> .typers {
|
|
|
|
position: absolute;
|
|
|
|
bottom: 100%;
|
|
|
|
padding: 0 8px 0 8px;
|
|
|
|
font-size: 0.9em;
|
|
|
|
color: var(--fgTransparentWeak);
|
|
|
|
|
|
|
|
> .users {
|
|
|
|
> .user + .user:before {
|
|
|
|
content: ", ";
|
|
|
|
font-weight: normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .user:last-of-type:after {
|
|
|
|
content: " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-07 16:12:42 +09:00
|
|
|
|
|
|
|
> .form {
|
2022-06-20 13:20:28 +09:00
|
|
|
max-height: 12em;
|
|
|
|
overflow-y: scroll;
|
2021-08-07 16:12:42 +09:00
|
|
|
border-top: solid 0.5px var(--divider);
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.fade-enter-active, .fade-leave-active {
|
|
|
|
transition: opacity 0.1s;
|
|
|
|
}
|
2018-05-24 04:55:29 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
.fade-enter-from, .fade-leave-to {
|
2020-01-30 04:37:25 +09:00
|
|
|
transition: opacity 0.5s;
|
|
|
|
opacity: 0;
|
|
|
|
}
|
2018-02-13 15:17:59 +09:00
|
|
|
</style>
|