From ba64c1523183e47143d93c0ea28d05e533decb85 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Thu, 23 Mar 2023 23:51:59 -0700 Subject: [PATCH] feat: new chat button on mobile --- packages/client/src/ui/universal.vue | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/packages/client/src/ui/universal.vue b/packages/client/src/ui/universal.vue index 37296451e..8c7651231 100644 --- a/packages/client/src/ui/universal.vue +++ b/packages/client/src/ui/universal.vue @@ -47,6 +47,7 @@ +
import { defineAsyncComponent, provide, onMounted, computed, ref } from 'vue'; import XCommon from './_common_/common.vue'; +import * as Acct from 'calckey-js/built/acct'; import type { ComputedRef } from 'vue'; import type { PageMetadata } from '@/scripts/page-metadata'; import { instanceName } from '@/config'; @@ -115,6 +117,7 @@ const drawerMenuShowing = ref(false); let pageMetadata = $ref>(); const widgetsEl = $ref(); const postButton = $ref(); +const chatButton = $ref(); const widgetsShowing = $ref(false); provide('router', mainRouter); @@ -173,6 +176,46 @@ if (defaultStore.state.widgets.length === 0) { }]); } +function messagingStart(ev) { + os.popupMenu([{ + text: i18n.ts.messagingWithUser, + icon: 'ph-user ph-bold ph-lg', + action: () => { startUser(); }, + }, { + text: i18n.ts.messagingWithGroup, + icon: 'ph-users-three ph-bold ph-lg', + action: () => { startGroup(); }, + }], ev.currentTarget ?? ev.target); +} + + +async function startUser(): void { + os.selectUser().then(user => { + mainRouter.push(`/my/messaging/${Acct.toString(user)}`); + }); +} + +async function startGroup(): void { + 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, + }); + 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}`); +} + onMounted(() => { if (!isDesktop.value) { window.addEventListener('resize', () => {