2018-02-13 06:17:59 +00:00
|
|
|
<template>
|
2022-06-20 04:20:28 +00:00
|
|
|
<div
|
|
|
|
ref="rootEl"
|
|
|
|
class="_section"
|
2018-02-26 19:36:16 +00:00
|
|
|
@dragover.prevent.stop="onDragover"
|
|
|
|
@drop.prevent.stop="onDrop"
|
|
|
|
>
|
2020-10-17 11:12:00 +00:00
|
|
|
<div class="_content mk-messaging-room">
|
|
|
|
<div class="body">
|
2022-06-20 04:20:28 +00:00
|
|
|
<MkPagination v-if="pagination" ref="pagingComponent" :key="userAcct || groupId" :pagination="pagination">
|
|
|
|
<template #empty>
|
|
|
|
<div class="_fullinfo">
|
|
|
|
<img src="https://xn--931a.moe/assets/info.jpg" class="_ghost"/>
|
|
|
|
<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 11:12:00 +00:00
|
|
|
</div>
|
|
|
|
<footer>
|
2021-11-19 10:36:12 +00:00
|
|
|
<div v-if="typers.length > 0" class="typers">
|
2022-06-20 04:20:28 +00:00
|
|
|
<I18n :src="i18n.ts.typingUsers" text-tag="span" class="users">
|
2021-02-21 03:26:49 +00:00
|
|
|
<template #users>
|
2022-06-20 04:20:28 +00:00
|
|
|
<b v-for="typer in typers" :key="typer.id" class="user">{{ typer.username }}</b>
|
2021-02-21 03:26:49 +00:00
|
|
|
</template>
|
|
|
|
</I18n>
|
|
|
|
<MkEllipsis/>
|
|
|
|
</div>
|
2022-06-20 04:20:28 +00:00
|
|
|
<transition :name="animation ? 'fade' : ''">
|
2021-11-19 10:36:12 +00:00
|
|
|
<div v-show="showIndicator" class="new-message">
|
2022-06-20 04:20:28 +00:00
|
|
|
<button class="_buttonPrimary" @click="onIndicatorClick"><i class="fas fa-fw fa-arrow-circle-down"></i>{{ i18n.ts.newMessageExists }}</button>
|
2020-10-17 11:12:00 +00:00
|
|
|
</div>
|
|
|
|
</transition>
|
2022-06-20 04:20:28 +00:00
|
|
|
<XForm v-if="!fetching" ref="formEl" :user="user" :group="group" class="form"/>
|
2020-10-17 11:12:00 +00:00
|
|
|
</footer>
|
2018-02-13 06:17:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-06-20 04:20:28 +00: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-20 16:39:51 +00:00
|
|
|
import XMessage from './messaging-room.message.vue';
|
|
|
|
import XForm from './messaging-room.form.vue';
|
2022-08-30 15:24:33 +00:00
|
|
|
import XList from '@/components/MkDateSeparatedList.vue';
|
2022-09-06 09:21:49 +00:00
|
|
|
import MkPagination, { Paging } from '@/components/MkPagination.vue';
|
2022-06-20 04:20:28 +00:00
|
|
|
import { isBottomVisible, onScrollBottom, scrollToBottom } from '@/scripts/scroll';
|
2021-11-11 17:02:25 +00:00
|
|
|
import * as os from '@/os';
|
2021-12-29 13:13:09 +00:00
|
|
|
import { stream } from '@/stream';
|
2021-11-11 17:02:25 +00:00
|
|
|
import * as sound from '@/scripts/sound';
|
2022-06-20 04:20:28 +00:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { $i } from '@/account';
|
|
|
|
import { defaultStore } from '@/store';
|
2022-06-20 08:38:49 +00:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2022-06-20 04:20:28 +00: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 06:17:59 +00:00
|
|
|
|
2022-06-20 04:20:28 +00: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;
|
|
|
|
|
|
|
|
pagination = {
|
|
|
|
endpoint: 'messaging/messages',
|
|
|
|
limit: 20,
|
|
|
|
params: {
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
reversed: true,
|
|
|
|
pageEl: $$(rootEl).value,
|
2018-02-13 06:17:59 +00:00
|
|
|
};
|
2022-06-20 04:20:28 +00: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-26 19:36:16 +00:00
|
|
|
|
2022-06-20 04:20:28 +00: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(() => {
|
|
|
|
thisScrollToBottom();
|
|
|
|
window.setTimeout(() => {
|
|
|
|
fetching = false;
|
|
|
|
}, 300);
|
|
|
|
});
|
|
|
|
}
|
2018-02-13 06:17:59 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
function onDragover(ev: DragEvent) {
|
|
|
|
if (!ev.dataTransfer) return;
|
2020-05-31 03:53:06 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
const isFile = ev.dataTransfer.items[0].kind === 'file';
|
|
|
|
const isDriveFile = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FILE_;
|
2018-02-26 19:36:16 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
if (isFile || isDriveFile) {
|
2022-10-12 23:34:23 +00:00
|
|
|
switch (ev.dataTransfer.effectAllowed) {
|
|
|
|
case 'all':
|
|
|
|
case 'uninitialized':
|
|
|
|
case 'copy':
|
|
|
|
case 'copyLink':
|
|
|
|
case 'copyMove':
|
|
|
|
ev.dataTransfer.dropEffect = 'copy';
|
|
|
|
break;
|
|
|
|
case 'linkMove':
|
|
|
|
case 'move':
|
|
|
|
ev.dataTransfer.dropEffect = 'move';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
|
|
|
break;
|
|
|
|
}
|
2022-06-20 04:20:28 +00:00
|
|
|
} else {
|
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-06-20 04:20:28 +00: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-29 19:37:25 +00:00
|
|
|
|
2022-06-20 04:20:28 +00: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-29 19:37:25 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
function onMessage(message) {
|
|
|
|
sound.play('chat');
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
const _isBottom = isBottomVisible(rootEl, 64);
|
2020-05-31 03:53:06 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
pagingComponent.prepend(message);
|
|
|
|
if (message.userId !== $i?.id && !document.hidden) {
|
|
|
|
connection?.send('read', {
|
|
|
|
id: message.id,
|
|
|
|
});
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
if (_isBottom) {
|
|
|
|
// Scroll to bottom
|
|
|
|
nextTick(() => {
|
|
|
|
thisScrollToBottom();
|
|
|
|
});
|
|
|
|
} else if (message.userId !== $i?.id) {
|
|
|
|
// Notify
|
|
|
|
notifyNewMessage();
|
|
|
|
}
|
|
|
|
}
|
2018-02-26 21:25:17 +00:00
|
|
|
|
2022-06-20 04:20:28 +00: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-26 19:36:16 +00:00
|
|
|
}
|
2022-06-20 04:20:28 +00: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-26 19:36:16 +00:00
|
|
|
}
|
2022-06-20 04:20:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-13 06:17:59 +00:00
|
|
|
|
2022-06-20 04:20:28 +00: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 06:17:59 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
function thisScrollToBottom() {
|
|
|
|
scrollToBottom($$(rootEl).value, { behavior: 'smooth' });
|
|
|
|
}
|
2018-02-26 19:36:16 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
function onIndicatorClick() {
|
|
|
|
showIndicator = false;
|
|
|
|
thisScrollToBottom();
|
|
|
|
}
|
2018-12-26 16:24:57 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
let scrollRemove: (() => void) | null = $ref(null);
|
2018-02-26 19:36:16 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
function notifyNewMessage() {
|
|
|
|
showIndicator = true;
|
2018-05-23 19:55:29 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
scrollRemove = onScrollBottom(rootEl, () => {
|
|
|
|
showIndicator = false;
|
|
|
|
scrollRemove = null;
|
|
|
|
});
|
|
|
|
}
|
2018-05-23 19:55:29 +00:00
|
|
|
|
2022-06-20 04:20:28 +00: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 03:26:05 +00:00
|
|
|
});
|
2018-02-13 06:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-20 04:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
fetch();
|
2018-02-13 06:17:59 +00:00
|
|
|
});
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
onBeforeUnmount(() => {
|
|
|
|
connection?.dispose();
|
|
|
|
document.removeEventListener('visibilitychange', onVisibilitychange);
|
|
|
|
if (scrollRemove) scrollRemove();
|
|
|
|
});
|
|
|
|
|
2022-06-20 08:38:49 +00:00
|
|
|
definePageMetadata(computed(() => !fetching ? user ? {
|
|
|
|
userName: user,
|
|
|
|
avatar: user,
|
|
|
|
} : {
|
|
|
|
title: group?.name,
|
|
|
|
icon: 'fas fa-users',
|
|
|
|
} : null));
|
2018-02-13 06:17:59 +00:00
|
|
|
</script>
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-messaging-room {
|
2022-06-20 04:20:28 +00:00
|
|
|
position: relative;
|
2022-07-22 15:46:52 +00:00
|
|
|
overflow: auto;
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
> .body {
|
|
|
|
.more {
|
2020-01-29 19:37:25 +00: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 14:22:59 +00:00
|
|
|
> i {
|
2020-01-29 19:37:25 +00:00
|
|
|
margin-right: 4px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 04:20:28 +00:00
|
|
|
.messages {
|
|
|
|
padding: 8px 0;
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
> ::v-deep(*) {
|
2020-01-29 19:37:25 +00:00
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> footer {
|
|
|
|
width: 100%;
|
2022-06-20 04:20:28 +00:00
|
|
|
position: sticky;
|
|
|
|
z-index: 2;
|
|
|
|
bottom: 0;
|
|
|
|
padding-top: 8px;
|
2022-07-22 15:46:52 +00:00
|
|
|
bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
|
2020-01-29 19:37:25 +00:00
|
|
|
|
|
|
|
> .new-message {
|
|
|
|
width: 100%;
|
2022-06-20 04:20:28 +00:00
|
|
|
padding-bottom: 8px;
|
2020-01-29 19:37:25 +00:00
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
> button {
|
|
|
|
display: inline-block;
|
|
|
|
margin: 0;
|
2022-06-20 04:20:28 +00:00
|
|
|
padding: 0 12px;
|
2020-01-29 19:37:25 +00:00
|
|
|
line-height: 32px;
|
|
|
|
font-size: 12px;
|
|
|
|
border-radius: 16px;
|
|
|
|
|
|
|
|
> i {
|
2022-06-20 04:20:28 +00:00
|
|
|
display: inline-block;
|
|
|
|
margin-right: 8px;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-21 03:26:49 +00: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 07:12:42 +00:00
|
|
|
|
|
|
|
> .form {
|
2022-06-20 04:20:28 +00:00
|
|
|
max-height: 12em;
|
|
|
|
overflow-y: scroll;
|
2021-08-07 07:12:42 +00:00
|
|
|
border-top: solid 0.5px var(--divider);
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.fade-enter-active, .fade-leave-active {
|
|
|
|
transition: opacity 0.1s;
|
|
|
|
}
|
2018-05-23 19:55:29 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
.fade-enter-from, .fade-leave-to {
|
2020-01-29 19:37:25 +00:00
|
|
|
transition: opacity 0.5s;
|
|
|
|
opacity: 0;
|
|
|
|
}
|
2018-02-13 06:17:59 +00:00
|
|
|
</style>
|