-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: install invite flow #497
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<script lang="ts"> | ||
import adapters from '$lib/adapters' | ||
import routes from '$lib/routes' | ||
import type { InstallMessage, WithMeta } from '$lib/stores/chat' | ||
import { installedObjectStore } from '$lib/stores/installed-objects' | ||
import type { User } from '$lib/types' | ||
import Button from './button.svelte' | ||
import ChatMessage from './chat-message.svelte' | ||
import Container from './container.svelte' | ||
import CheckmarkFilled from './icons/checkmark-filled.svelte' | ||
import Loading from './loading.svelte' | ||
import ObjectInstallInfo from './object-install-info.svelte' | ||
|
||
import { goto } from '$app/navigation' | ||
import { hashString } from '$lib/adapters/waku/crypto' | ||
import Checkmark from './icons/checkmark.svelte' | ||
import Pending from './icons/pending.svelte' | ||
|
||
//am I the sender of this message? | ||
export let myMessage = false | ||
export let message: WithMeta<InstallMessage> | ||
export let users: User[] | ||
export let objects: string[] | undefined | ||
export let chatId: string | ||
|
||
//is this message in a group chat? | ||
export let group = false | ||
|
||
//is the sender of the current message the same as the previous message? | ||
export let sameSender = false | ||
export let senderName: string | undefined = undefined | ||
|
||
export let timestamp: string | undefined = undefined | ||
|
||
let senderNameLabel = myMessage | ||
? 'You' | ||
: users.find((user) => user.publicKey === message.senderPublicKey)?.name ?? '<unknown>' | ||
let recipientName = !group | ||
? myMessage | ||
? users.find((user) => user.publicKey !== message.senderPublicKey)?.name ?? '<unknown>' | ||
: 'you' | ||
: `chat members` | ||
|
||
$: object = $installedObjectStore.objects.get(message.objectId) | ||
$: isInstalledInChat = object && objects && objects.includes(object.objectId) | ||
|
||
async function acceptInstall(objectId: string) { | ||
await adapters.sendInstall(chatId, objectId, 'accept') | ||
} | ||
</script> | ||
|
||
<ChatMessage bubble={true} {group} {sameSender} {timestamp} {myMessage} object={true} {senderName}> | ||
{#if !object} | ||
<Loading /> | ||
{:else} | ||
<div class="wo text-normal"> | ||
<Container> | ||
{#if message.command === 'invite'} | ||
{senderNameLabel} invited {recipientName} to use "{object.name}" in this chat. | ||
{:else if message.command === 'accept'} | ||
{senderNameLabel} accepted the invite. You can now use "{object.name}" in this chat. | ||
{/if} | ||
</Container> | ||
<Container gap={12}> | ||
<ObjectInstallInfo | ||
onClick={() => object && goto(routes.SETTINGS_OBJECT(hashString(object.objectId)))} | ||
name={object.name} | ||
logoImg={object.logo} | ||
logoAlt={`${object.name} logo`} | ||
/> | ||
</Container> | ||
<Container padY={0}> | ||
{#if message.command === 'invite'} | ||
{#if isInstalledInChat} | ||
<p class="install-status"> | ||
<CheckmarkFilled />Invite accepted | ||
</p> | ||
{:else if myMessage} | ||
<p class="install-status"> | ||
<Pending />Invite pending | ||
</p> | ||
{:else} | ||
<Button variant="strong" on:click={() => acceptInstall(message.objectId)} | ||
><Checkmark /> Accept</Button | ||
> | ||
{/if} | ||
{:else if message.command === 'accept'} | ||
<p class="install-status"> | ||
{#if isInstalledInChat} | ||
<CheckmarkFilled />Invite accepted | ||
{:else} | ||
<Pending />Invite pending | ||
{/if} | ||
</p> | ||
{/if} | ||
</Container> | ||
</div> | ||
{/if} | ||
<svelte:fragment slot="avatar"> | ||
{#if $$slots.avatar} | ||
<slot name="avatar" /> | ||
{/if} | ||
</svelte:fragment> | ||
</ChatMessage> | ||
|
||
<style lang="scss"> | ||
.install-status { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
align-items: center; | ||
gap: var(--spacing-6); | ||
background-color: var(--color-step-10, var(--color-dark-step-50)); | ||
border-radius: var(--spacing-24); | ||
padding: var(--spacing-6); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script lang="ts"> | ||
export let size = 20 | ||
</script> | ||
|
||
<svg id="icon" xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 32 32"> | ||
<defs> | ||
<style> | ||
.cls-1 { | ||
fill: none; | ||
} | ||
</style> | ||
</defs> | ||
<path | ||
d="M28,30H4a2.0021,2.0021,0,0,1-2-2V4A2.0021,2.0021,0,0,1,4,2H28a2.0021,2.0021,0,0,1,2,2V28A2.0021,2.0021,0,0,1,28,30ZM4,4V28H28V4Z" | ||
transform="translate(0 0)" | ||
/> | ||
<rect x="13" y="7" width="2" height="7" /> | ||
<rect x="8" y="7" width="2" height="7" /> | ||
<path | ||
d="M22,14H20a2.0021,2.0021,0,0,1-2-2V9a2.0021,2.0021,0,0,1,2-2h2a2.0021,2.0021,0,0,1,2,2v3A2.0021,2.0021,0,0,1,22,14ZM20,9v3h2V9Z" | ||
transform="translate(0 0)" | ||
/> | ||
<rect x="22" y="18" width="2" height="7" /> | ||
<rect x="8" y="18" width="2" height="7" /> | ||
<path | ||
d="M17,25H15a2.0021,2.0021,0,0,1-2-2V20a2.0021,2.0021,0,0,1,2-2h2a2.0021,2.0021,0,0,1,2,2v3A2.0021,2.0021,0,0,1,17,25Zm-2-5v3h2V20Z" | ||
transform="translate(0 0)" | ||
/> | ||
<rect | ||
id="_Transparent_Rectangle_" | ||
data-name="<Transparent Rectangle>" | ||
class="cls-1" | ||
width="32" | ||
height="32" | ||
/> | ||
</svg> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove