Skip to content

Commit

Permalink
feat: display leave status in chat header (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Binatik authored Oct 4, 2024
1 parent c2561ff commit d12cc1e
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 47 deletions.
3 changes: 3 additions & 0 deletions src/assets/icons/Icon24Info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { default as Icon24ChevronCompactLeft } from './Icon24ChevronCompactLeft.
// export { default as Icon24CopyOutline } from './Icon24CopyOutline.svg'
export { default as Icon24DoorArrowRightOutline } from './Icon24DoorArrowRightOutline.svg'
export { default as Icon24HideOutline } from './Icon24HideOutline.svg'
export { default as Icon24Info } from './Icon24Info.svg'
export { default as Icon24LinkExternalOutline } from './Icon24LinkExternalOutline.svg'
export { default as Icon24MuteOutline } from './Icon24MuteOutline.svg'
export { default as Icon24Spinner } from './Icon24Spinner.svg'
Expand Down
20 changes: 13 additions & 7 deletions src/converters/ConvoConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,30 @@ export function fromApiConvo(
throw new Error('Chat with out of range id: ' + peerId)
}

if (!apiConvo.chat_settings) {
console.warn(apiConvo)
throw new Error('Chat without chat_settings: ' + peerId)
}

return {
convo: {
kind: 'ChatConvo',
id: peerId,
isChannel: !!apiConvo.chat_settings?.is_group_channel,
isCasper: !!apiConvo.chat_settings?.is_disappearing,
pinnedMessage: apiConvo.chat_settings?.pinned_message
status: apiConvo.chat_settings.state,
isChannel: !!apiConvo.chat_settings.is_group_channel,
isCasper: !!apiConvo.chat_settings.is_disappearing,
pinnedMessage: apiConvo.chat_settings.pinned_message
? fromApiPinnedMessage(apiConvo.chat_settings.pinned_message)
: undefined,
...baseConvo
},
peer: {
kind: 'Chat',
id: peerId,
title: apiConvo.chat_settings?.title ?? '',
photo50: apiConvo.chat_settings?.photo?.photo_50,
photo100: apiConvo.chat_settings?.photo?.photo_100,
membersCount: apiConvo.chat_settings?.members_count ?? 0
title: apiConvo.chat_settings.title,
photo50: apiConvo.chat_settings.photo?.photo_50,
photo100: apiConvo.chat_settings.photo?.photo_100,
membersCount: apiConvo.chat_settings.members_count ?? 0
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/lang/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export const ru = {
me_user_was_online_a_long_time_ago: 'заходил давно',
me_attach_wall_empty: 'Пустая запись',
me_attach_wall_open_button: 'Открыть запись',
me_chat_leaved_status: 'Вы вышли из чата',
me_chat_kicked_status: 'Вы были исключены из чата',

me_chat_members_count: {
one: '{count} участник',
Expand Down
2 changes: 2 additions & 0 deletions src/model/Convo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface GroupConvo extends BaseConvo {
export interface ChatConvo extends BaseConvo {
kind: 'ChatConvo'
id: Peer.ChatId
status: 'in' | 'kicked' | 'left' | 'out'
isChannel: boolean
isCasper: boolean
pinnedMessage?: Message.Pinned
Expand Down Expand Up @@ -132,6 +133,7 @@ function mock(id: Peer.Id): Convo {
return {
kind: 'ChatConvo',
id,
status: 'in',
isCasper: false,
isChannel: false,
...base
Expand Down
26 changes: 15 additions & 11 deletions src/ui/messenger/ConvoComposer/ConvoComposer.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,14 @@

.ConvoComposer__panel {
display: flex;
align-items: flex-end;
align-items: center;
background: var(--vkd--color_background_composer);
padding: 4px 6px;
min-height: 42px;
border-radius: 12px;
box-shadow: var(--vkui--elevation3);
}

.ConvoComposer__panel--blocked {
align-items: center;
justify-content: center;
}

.ConvoComposer__actionButton {
color: var(--vkui--color_text_accent);
font-weight: 500;
}

.ConvoComposer__input {
width: 100%;
margin: 8px 6px;
Expand All @@ -40,3 +30,17 @@
pointer-events: none;
color: var(--vkui--color_text_secondary);
}

.ConvoComposer__restriction {
display: flex;
align-items: center;
margin: 0 4px;
gap: 8px;
color: var(--vkui--color_text_subhead);
}

.ConvoComposer__muteChannelButton {
color: var(--vkui--color_text_accent);
font-weight: 500;
margin: 0 auto;
}
70 changes: 41 additions & 29 deletions src/ui/messenger/ConvoComposer/ConvoComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineComponent, ref } from 'vue'
import * as Convo from 'model/Convo'
import { useEnv } from 'hooks'
import { Button } from 'ui/ui/Button/Button'
import { Icon24MuteOutline, Icon24VolumeOutline } from 'assets/icons'
import { Icon24Info, Icon24MuteOutline, Icon24VolumeOutline } from 'assets/icons'
import './ConvoComposer.css'

type Props = {
Expand Down Expand Up @@ -35,36 +35,48 @@ export const ConvoComposer = defineComponent<Props>((props) => {
}
}

const renderPanel = () => {
if (props.convo.kind === 'ChatConvo' && props.convo.status === 'kicked') {
return (
<div class="ConvoComposer__restriction">
<Icon24Info color="var(--vkui--color_accent_orange)" />
{lang.use('me_chat_kicked_status')}
</div>
)
}

if (isChannel) {
return (
<Button
class="ConvoComposer__muteChannelButton"
mode="tertiary"
loading={loading.value}
onClick={toggleNotifications}
before={
props.convo.notifications.enabled
? <Icon24MuteOutline />
: <Icon24VolumeOutline />
}
>
{props.convo.notifications.enabled
? lang.use('me_convo_disable_notifications')
: lang.use('me_convo_enable_notifications')}
</Button>
)
}

return (
<div
class="ConvoComposer__input"
contenteditable
placeholder={lang.use('me_convo_composer_placeholder')}
/>
)
}

return (
<div class="ConvoComposer">
<div class={['ConvoComposer__panel', {
'ConvoComposer__panel--blocked': isChannel
}]}
>
{!isChannel ? (
<div
class="ConvoComposer__input"
contenteditable
placeholder={lang.use('me_convo_composer_placeholder')}
/>
) : (
<Button
class="ConvoComposer__actionButton"
mode="tertiary"
loading={loading.value}
onClick={toggleNotifications}
before={
props.convo.notifications.enabled
? <Icon24MuteOutline />
: <Icon24VolumeOutline />
}
>
{props.convo.notifications.enabled
? lang.use('me_convo_disable_notifications')
: lang.use('me_convo_enable_notifications')}
</Button>
)}
</div>
<div class="ConvoComposer__panel">{renderPanel()}</div>
</div>
)
}
Expand Down
8 changes: 8 additions & 0 deletions src/ui/messenger/ConvoHeader/ConvoHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export const ConvoHeader = defineComponent<Props>(({ convo }) => {
}

case 'Chat': {
if (convo.kind === 'ChatConvo' && convo.status === 'left') {
return lang.use('me_chat_leaved_status')
}

if (convo.kind === 'ChatConvo' && convo.status === 'kicked') {
return lang.use('me_chat_kicked_status')
}

const langKey = isChannel ? 'me_group_members_count' : 'me_chat_members_count'
return lang.usePlural(langKey, peer.membersCount, {
count: shortenCount(peer.membersCount)
Expand Down

0 comments on commit d12cc1e

Please sign in to comment.