2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2022-06-20 10:38:49 +02:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
2022-11-06 22:32:25 +01:00
|
|
|
<div>
|
|
|
|
<MkSpacer :content-max="800">
|
|
|
|
<swiper
|
|
|
|
:modules="[Virtual]"
|
|
|
|
:space-between="20"
|
|
|
|
:virtual="true"
|
|
|
|
:allow-touch-move="!(deviceKind === 'desktop' && !defaultStore.state.swipeOnDesktop)"
|
|
|
|
@swiper="setSwiperRef"
|
|
|
|
@slide-change="onSlideChange"
|
|
|
|
>
|
2022-11-06 22:49:51 +01:00
|
|
|
<swiper-slide>
|
2022-11-06 22:32:25 +01:00
|
|
|
<div class="_content yweeujhr dms">
|
|
|
|
<MkButton primary class="start" @click="startUser"><i class="fas fa-plus"></i> {{ i18n.ts.startMessaging }}</MkButton>
|
|
|
|
<MkPagination v-slot="{items}" :pagination="dmsPagination">
|
|
|
|
<MkChatPreview v-for="message in items" :key="message.id" class="yweeujhr message _block" :message="message"/>
|
|
|
|
</MkPagination>
|
2022-11-06 23:04:18 +01:00
|
|
|
<!-- <div v-if="messages.length == 0" class="_fullinfo">
|
2022-11-06 22:32:25 +01:00
|
|
|
<img src="/static-assets/badges/info.png" class="_ghost" alt="Info"/>
|
|
|
|
<div>{{ i18n.ts.noHistory }}</div>
|
2022-11-06 23:04:18 +01:00
|
|
|
</div> -->
|
2022-11-06 22:13:34 +01:00
|
|
|
</div>
|
2022-11-06 22:49:51 +01:00
|
|
|
</swiper-slide>
|
2022-11-06 22:32:25 +01:00
|
|
|
<swiper-slide>
|
|
|
|
<div class="_content yweeujhr groups">
|
2022-11-06 22:49:51 +01:00
|
|
|
<div class="start">
|
|
|
|
<MkButton primary @click="startGroup"><i class="fas fa-plus"></i> {{ i18n.ts.startMessaging }}</MkButton>
|
|
|
|
<MkButton primary :link="true" to="/my/groups"><i class="fas fa-people-roof"></i> {{ i18n.ts.manageGroups }}</MkButton>
|
|
|
|
</div>
|
2022-11-06 22:32:25 +01:00
|
|
|
<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>
|
2022-06-20 10:38:49 +02:00
|
|
|
</MkStickyContainer>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
<script lang="ts" setup>
|
2022-11-06 23:00:34 +01:00
|
|
|
import { markRaw, onMounted, onUnmounted, watch } from 'vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as Acct from 'misskey-js/built/acct';
|
2022-11-06 21:49:37 +01:00
|
|
|
import { Virtual } from 'swiper';
|
|
|
|
import { Swiper, SwiperSlide } from 'swiper/vue';
|
2022-11-06 22:37:26 +01:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2022-11-06 21:49:37 +01:00
|
|
|
import MkChatPreview from '@/components/MkChatPreview.vue';
|
|
|
|
import MkPagination from '@/components/MkPagination.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
2021-12-29 14:13:09 +01:00
|
|
|
import { stream } from '@/stream';
|
2022-06-20 10:38:49 +02:00
|
|
|
import { useRouter } from '@/router';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
|
|
|
import { $i } from '@/account';
|
2022-11-06 21:49:37 +01:00
|
|
|
import { deviceKind } from '@/scripts/device-kind';
|
|
|
|
import { defaultStore } from '@/store';
|
|
|
|
import 'swiper/scss';
|
|
|
|
import 'swiper/scss/virtual';
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
2022-11-06 23:04:18 +01:00
|
|
|
// let messages = $ref([]);
|
|
|
|
// let connection = $ref(null);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2022-11-06 22:20:28 +01:00
|
|
|
const tabs = ['dms', 'groups'];
|
|
|
|
let tab = $ref(tabs[0]);
|
|
|
|
watch($$(tab), () => (syncSlide(tabs.indexOf(tab))));
|
|
|
|
|
2022-11-06 23:00:34 +01:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => [{
|
|
|
|
key: 'dms',
|
|
|
|
title: i18n.ts._messaging.dms,
|
|
|
|
icon: 'fas fa-user',
|
|
|
|
}, {
|
|
|
|
key: 'groups',
|
|
|
|
title: i18n.ts._messaging.groups,
|
|
|
|
icon: 'fas fa-users',
|
|
|
|
}]);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.messaging,
|
|
|
|
icon: 'fas fa-comments',
|
|
|
|
});
|
|
|
|
|
2022-11-06 22:02:17 +01:00
|
|
|
const dmsPagination = {
|
|
|
|
endpoint: 'messaging/history' as const,
|
2022-11-06 22:08:43 +01:00
|
|
|
limit: 15,
|
2022-11-06 22:02:17 +01:00
|
|
|
params: {
|
|
|
|
group: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const groupsPagination = {
|
|
|
|
endpoint: 'messaging/history' as const,
|
2022-11-06 22:08:43 +01:00
|
|
|
limit: 5,
|
2022-11-06 22:02:17 +01:00
|
|
|
params: {
|
|
|
|
group: true,
|
|
|
|
},
|
|
|
|
};
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2022-11-06 23:04:18 +01:00
|
|
|
// function onMessage(message): void {
|
|
|
|
// if (message.recipientId) {
|
|
|
|
// messages = messages.filter(m => !(
|
|
|
|
// (m.recipientId === message.recipientId && m.userId === message.userId) ||
|
|
|
|
// (m.recipientId === message.userId && m.userId === message.recipientId)));
|
|
|
|
|
|
|
|
// messages.unshift(message);
|
|
|
|
// } else if (message.groupId) {
|
|
|
|
// messages = messages.filter(m => m.groupId !== message.groupId);
|
|
|
|
// messages.unshift(message);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// function onRead(ids): void {
|
|
|
|
// for (const id of ids) {
|
|
|
|
// const found = messages.find(m => m.id === id);
|
|
|
|
// if (found) {
|
|
|
|
// if (found.recipientId) {
|
|
|
|
// found.isRead = true;
|
|
|
|
// } else if (found.groupId) {
|
|
|
|
// found.reads.push($i.id);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2022-11-06 23:00:34 +01:00
|
|
|
async function startUser(): void {
|
2022-06-20 10:38:49 +02:00
|
|
|
os.selectUser().then(user => {
|
|
|
|
router.push(`/my/messaging/${Acct.toString(user)}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-06 23:00:34 +01:00
|
|
|
async function startGroup(): void {
|
2022-06-20 10:38:49 +02:00
|
|
|
const groups1 = await os.api('users/groups/owned');
|
|
|
|
const groups2 = await os.api('users/groups/joined');
|
|
|
|
if (groups1.length === 0 && groups2.length === 0) {
|
|
|
|
os.alert({
|
|
|
|
type: 'warning',
|
|
|
|
title: i18n.ts.youHaveNoGroups,
|
|
|
|
text: i18n.ts.joinOrCreateGroup,
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
2022-06-20 10:38:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { canceled, result: group } = await os.select({
|
|
|
|
title: i18n.ts.group,
|
|
|
|
items: groups1.concat(groups2).map(group => ({
|
|
|
|
value: group, text: group.name,
|
|
|
|
})),
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
router.push(`/my/messaging/group/${group.id}`);
|
|
|
|
}
|
|
|
|
|
2022-11-06 23:00:34 +01:00
|
|
|
let swiperRef = null;
|
|
|
|
|
|
|
|
function setSwiperRef(swiper) {
|
|
|
|
swiperRef = swiper;
|
|
|
|
syncSlide(tabs.indexOf(tab));
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSlideChange() {
|
|
|
|
tab = tabs[swiperRef.activeIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
function syncSlide(index) {
|
|
|
|
swiperRef.slideTo(index);
|
|
|
|
}
|
|
|
|
|
2022-11-06 23:04:18 +01:00
|
|
|
// onMounted(() => {
|
|
|
|
// connection = markRaw(stream.useChannel('messagingIndex'));
|
|
|
|
|
|
|
|
// connection.on('message', onMessage);
|
|
|
|
// connection.on('read', onRead);
|
|
|
|
|
|
|
|
// os.api('messaging/history', { group: false, limit: 5 }).then(userMessages => {
|
|
|
|
// os.api('messaging/history', { group: true, limit: 5 }).then(groupMessages => {
|
|
|
|
// const _messages = userMessages.concat(groupMessages);
|
|
|
|
// _messages.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
|
|
// messages = _messages;
|
|
|
|
// fetching = false;
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
// onUnmounted(() => {
|
|
|
|
// if (connection) connection.dispose();
|
|
|
|
// });
|
2020-01-29 20:37:25 +01:00
|
|
|
</script>
|
|
|
|
|
2022-11-04 23:20:15 +01:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.yweeujhr {
|
|
|
|
> .start {
|
|
|
|
margin: 0 auto var(--margin) auto;
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2022-11-04 23:20:15 +01:00
|
|
|
</style>
|