Skip to content

Commit c3ed10b

Browse files
committed
chore: improve dMsg frontend
1 parent 188f447 commit c3ed10b

File tree

13 files changed

+171
-200
lines changed

13 files changed

+171
-200
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ opt-level = 's'
2525

2626
[workspace.package]
2727
edition = "2021"
28-
version = "2.9.2"
28+
version = "2.9.3"
2929
repository = "https://github.com/ldclabs/ic-panda"
3030
keywords = ["canister", "icp", "panda"]
3131
categories = ["web-programming"]

src/ic_message_frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@
8484
"test": "vitest run"
8585
},
8686
"type": "module",
87-
"version": "2.9.7"
87+
"version": "2.9.8"
8888
}

src/ic_message_frontend/src/lib/canisters/message.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ export class MessageCanisterAPI {
194194
return unwrapResult(res, 'call update_my_name failed')
195195
}
196196

197+
async update_my_username(username: string): Promise<UserInfo> {
198+
const res = await this.actor.update_my_username(username)
199+
return unwrapResult(res, 'call update_my_username failed')
200+
}
201+
197202
async update_my_ecdh(
198203
ecdhPub: Uint8Array,
199204
encryptedECDH: Uint8Array

src/ic_message_frontend/src/lib/components/messages/ChannelDetail.svelte

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import type { Principal } from '@dfinity/principal'
1313
import { Avatar, getToastStore } from '@skeletonlabs/skeleton'
1414
import { getContext, onMount } from 'svelte'
15-
import { readable, type Readable } from 'svelte/store'
15+
import { type Readable } from 'svelte/store'
1616
import ChannelMessages from './ChannelMessages.svelte'
1717
import ChannelSetting from './ChannelSetting.svelte'
1818
@@ -28,20 +28,14 @@
2828
const { canister, id } = channelId
2929
const onChatBack = getContext('onChatBack') as () => void
3030
31-
let channelInfo: Readable<ChannelInfoEx | null> = $state(readable(null))
31+
let channelInfo: ChannelInfoEx | null = $state(null)
3232
let isLoading = $state(true)
3333
let openMessages = $state(true)
3434
let switching = $state(false)
3535
async function onClickChannelSetting() {
3636
if (!canister) return
3737
switching = true
38-
await Promise.all([
39-
async () => {
40-
// load latest channel info
41-
channelInfo = await myState.loadChannelInfo(canister, id)
42-
},
43-
sleep(100)
44-
])
38+
await sleep(100)
4539
openMessages = !openMessages
4640
switching = false
4741
}
@@ -51,25 +45,25 @@
5145
async (signal: AbortSignal) => {
5246
if (canister) {
5347
channelInfo = await myState.loadChannelInfo(canister, id)
54-
openMessages = !!$channelInfo?._kek
48+
openMessages = !!channelInfo._kek
5549
if (openMessages) {
5650
try {
5751
// try to decrypt channel DEK
58-
await myState.decryptChannelDEK($channelInfo!)
52+
await myState.decryptChannelDEK(channelInfo)
5953
} catch (_e) {
6054
openMessages = false
6155
}
6256
}
6357
isLoading = false
64-
return channelInfo
58+
return true
6559
}
66-
return null
60+
return false
6761
},
6862
toastStore
6963
)
7064
71-
onfinally((channel) => {
72-
if (!channel) {
65+
onfinally((hasChannel) => {
66+
if (!hasChannel) {
7367
goto('/_/messages')
7468
}
7569
})
@@ -89,18 +83,18 @@
8983
>
9084
</div>
9185
<div class="flex flex-row items-center gap-2">
92-
{#if $channelInfo}
86+
{#if channelInfo}
9387
<Avatar
94-
initials={$channelInfo.name}
95-
src={$channelInfo.image}
96-
background={$channelInfo.image ? '' : 'bg-panda'}
88+
initials={channelInfo.name}
89+
src={channelInfo.image}
90+
background={channelInfo.image ? '' : 'bg-panda'}
9791
fill="fill-white"
9892
width="w-10"
9993
/>
10094
<span class="flex-1 text-start">
101-
{$channelInfo.name +
95+
{channelInfo.name +
10296
' (' +
103-
($channelInfo.managers.length + $channelInfo.members.length) +
97+
(channelInfo.managers.length + channelInfo.members.length) +
10498
')'}
10599
</span>
106100
{:else}
@@ -119,7 +113,7 @@
119113
disabled={switching}
120114
onclick={onClickChannelSetting}
121115
>
122-
{#if channelInfo && openMessages && ($channelInfo?.ecdh_request || []).length > 0}
116+
{#if channelInfo && openMessages && (channelInfo?.ecdh_request || []).length > 0}
123117
<span class="badge-icon z-10 size-2 bg-error-500"></span>
124118
{/if}
125119
<span>
@@ -133,14 +127,14 @@
133127
</header>
134128
{#if isLoading}
135129
<Loading />
136-
{:else if $channelInfo}
130+
{:else if channelInfo}
137131
{#if openMessages}
138-
<ChannelMessages {myState} {myInfo} channelInfo={$channelInfo} />
132+
<ChannelMessages {myState} {myInfo} bind:channelInfo />
139133
{:else}
140134
<ChannelSetting
141135
{myState}
142136
{myInfo}
143-
channelInfo={$channelInfo}
137+
bind:channelInfo
144138
close={() => (openMessages = true)}
145139
/>
146140
{/if}

src/ic_message_frontend/src/lib/components/messages/ChannelMessages.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,14 @@
442442
async (signal: AbortSignal, abortingQue: (() => void)[]) => {
443443
abortingQue.push(popupDestroy)
444444
445-
if (
446-
!channelInfo._kek ||
447-
channelInfo._sync_at < Date.now() - 5 * 60 * 1000
448-
) {
445+
if (!channelInfo._kek) {
449446
channelInfo = await myState.refreshChannel(channelInfo)
447+
} else if (channelInfo._sync_at < Date.now() - 60 * 1000) {
448+
myState.loadChannelInfo(canister, id).then((info) => {
449+
channelInfo = info
450+
})
450451
}
452+
451453
hasKEK = !!channelInfo._kek
452454
if (!hasKEK) {
453455
return

src/ic_message_frontend/src/lib/components/messages/ChannelSetting.svelte

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@
4444
close: () => void
4545
}
4646
47-
let props: Props = $props()
48-
let { myState, myInfo, close } = props
47+
let { myState, myInfo, close, channelInfo = $bindable() }: Props = $props()
4948
50-
let channelInfo = $state(props.channelInfo)
5149
const toastStore = getToastStore()
5250
const modalStore = getModalStore()
5351
const members: Writable<DisplayUserInfoEx[]> = writable([])
@@ -315,7 +313,7 @@
315313
316314
onMount(() => {
317315
const { abort } = toastRun(async (signal: AbortSignal) => {
318-
channelInfo = await myState.refreshChannel(channelInfo, true)
316+
channelInfo = await myState.refreshChannel(channelInfo)
319317
try {
320318
await myState.decryptChannelDEK(channelInfo)
321319
validKEK = true
@@ -340,7 +338,7 @@
340338
onclick={onClickMyECDH}
341339
disabled={myECDHSubmitting}
342340
>
343-
<span>Accept encryption key and start chat</span>
341+
<span>Accept and start chat</span>
344342
{#if myECDHSubmitting}
345343
<span class=" text-panda *:size-4">
346344
<IconCircleSpin />
@@ -464,30 +462,24 @@
464462
</span>
465463
</div>
466464
<div class="flex flex-row items-center gap-4">
467-
<p>Request encryption key:</p>
465+
<p>Encryption key:</p>
468466
{#if channelInfo.my_setting.ecdh_remote.length > 0}
469467
<button
470468
type="button"
471469
class="variant-filled-success btn btn-sm"
472470
onclick={onClickMyECDH}
473-
disabled={myECDHSubmitting}
474-
><span>Key received, accept it</span></button
471+
disabled={myECDHSubmitting}><span>Accept</span></button
475472
>
476473
{:else if channelInfo.my_setting.ecdh_pub.length > 0}
477-
<span class="text-sm opacity-50"
478-
>Request sent, waiting for a manager share key</span
479-
>
474+
<span class="text-sm opacity-50">Waiting for the grant</span>
480475
{:else if validKEK}
481-
<span class="text-sm opacity-50"
482-
>Key already exists, no action needed</span
483-
>
476+
<span class="text-sm opacity-50">Existed</span>
484477
{:else}
485478
<button
486479
type="button"
487480
class="variant-filled-error btn btn-sm"
488481
onclick={onClickMyECDH}
489-
disabled={myECDHSubmitting}
490-
><span>No key to decrypt messages, make a request</span></button
482+
disabled={myECDHSubmitting}><span>Request key</span></button
491483
>
492484
{/if}
493485
<span class="text-panda *:size-4 {myECDHSubmitting ? '' : 'invisible'}">
@@ -503,6 +495,7 @@
503495
type="text"
504496
class="border-gray/10 h-8 truncate py-1 leading-8 invalid:input-warning"
505497
bind:value={leavingWord}
498+
onfocus={() => (leavingWord = channelInfo.name)}
506499
placeholder="channel name"
507500
/>
508501
<button
@@ -564,7 +557,7 @@
564557
!hasExchangeKeys}
565558
>
566559
<span class="*:size-4"><IconExchange2Line /></span>
567-
<span>Exchange keys</span>
560+
<span>Grant requests</span>
568561
<span
569562
class="text-panda *:size-4 {adminExchangeKeysSubmitting
570563
? ''

0 commit comments

Comments
 (0)