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