Skip to content

Commit

Permalink
fix: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danyadev committed Oct 4, 2024
1 parent d12cc1e commit ff9b3b0
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 71 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ module.exports = {
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-unsafe-unary-minus': 'error',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-nullish-coalescing': ['error', {
ignorePrimitives: {
string: true
}
}],
'@typescript-eslint/prefer-reduce-type-parameter': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/switch-exhaustiveness-check': ['error', {
Expand Down
4 changes: 2 additions & 2 deletions src/converters/AttachConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export function fromApiAttaches(apiAttaches: MessagesMessageAttachment[]): Attac
const link: Attach.Link = {
kind: 'Link',
url: apiAttach.link.url,
title: apiAttach.link.title ?? '',
caption: apiAttach.link.caption ?? apiAttach.link.url,
title: apiAttach.link.title || apiAttach.link.description || '',
caption: apiAttach.link.caption || apiAttach.link.url,
imageSizes: apiAttach.link.photo?.sizes
? fromApiImageSizes(apiAttach.link.photo.sizes)
: undefined
Expand Down
2 changes: 1 addition & 1 deletion src/converters/ConvoConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function fromApiConvo(
}

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

Expand Down
15 changes: 5 additions & 10 deletions src/converters/MessageConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function fromApiMessage(message: MessagesMessage): Message.Message {
cmid: Message.resolveCmid(message.conversation_message_id),
authorId: Peer.resolveOwnerId(message.from_id),
isOut: message.out === 1,
sentAt: message.date * 1000
sentAt: message.date * 1000,
updatedAt: message.update_time
? message.update_time * 1000
: undefined
} satisfies Partial<Message.Message>

if (message.action) {
Expand All @@ -25,13 +28,8 @@ export function fromApiMessage(message: MessagesMessage): Message.Message {
}

if (message.is_expired) {
if (!message.update_time) {
throw new Error('[fromApiMessage Expired] No message.update_time')
}

return {
kind: 'Expired',
updatedAt: message.update_time * 1000,
...baseMessage
}
}
Expand All @@ -50,9 +48,6 @@ export function fromApiMessage(message: MessagesMessage): Message.Message {
baseMessage.peerId,
baseMessage.cmid
),
updatedAt: message.update_time
? message.update_time * 1000
: undefined,
...baseMessage
}
}
Expand Down Expand Up @@ -146,7 +141,7 @@ function fromApiMessageAction(action: MessagesMessageAction): Message.ServiceAct

default:
typeguard(action.type)
console.warn(action)
console.warn('Unknown service action type', action)
return { type: 'unknown' }
}
}
Expand Down
1 change: 1 addition & 0 deletions src/model/api-types/objects/MessagesMessageAttachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ type MessagesMessageAttachmentsSticker = {
type MessagesMessageAttachmentLink = {
url: string
title?: string
description?: string
caption?: string
photo?: PhotosPhoto
}
Expand Down
8 changes: 4 additions & 4 deletions src/ui/messenger/ConvoComposer/ConvoComposer.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.ConvoComposer {
flex: none;
display: flex;
justify-content: center;
padding: 0 var(--convoHistoryIndent) var(--convoHistoryIndent) var(--convoHistoryIndent);
margin: 0 auto;
width: 100%;
max-width: var(--convoHistoryMaxWidth);
background: var(--vkd--color_background_convo_history);
}

Expand All @@ -12,6 +10,8 @@
align-items: center;
background: var(--vkd--color_background_composer);
padding: 4px 6px;
width: 100%;
max-width: calc(var(--convoHistoryMaxWidth) - 2 * var(--convoHistoryIndent));
min-height: 42px;
border-radius: 12px;
box-shadow: var(--vkui--elevation3);
Expand Down
105 changes: 51 additions & 54 deletions src/ui/messenger/ConvoComposer/ConvoComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,73 +13,70 @@ export const ConvoComposer = defineComponent<Props>((props) => {
const { lang, api } = useEnv()
const loading = ref(false)

return () => {
const isChannel = Convo.isChannel(props.convo)
const peer = Convo.safeGet(props.convo.id)

const toggleNotifications = async () => {
try {
loading.value = true
const toggleNotifications = async () => {
try {
loading.value = true

await api.fetch('account.setSilenceMode', {
peer_id: peer.id,
sound: props.convo.notifications.enabled ? 0 : 1,
time: props.convo.notifications.enabled ? -1 : 0
})
await api.fetch('account.setSilenceMode', {
peer_id: props.convo.id,
sound: props.convo.notifications.enabled ? 0 : 1,
time: props.convo.notifications.enabled ? -1 : 0
})

props.convo.notifications.enabled = !props.convo.notifications.enabled
} catch (error) {
console.warn(error)
} finally {
loading.value = false
}
props.convo.notifications.enabled = !props.convo.notifications.enabled
} finally {
loading.value = false
}
}

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>
)
}
const renderPanel = () => {
const isChannel = Convo.isChannel(props.convo)

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>
)
}
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 (
<div
class="ConvoComposer__input"
contenteditable
placeholder={lang.use('me_convo_composer_placeholder')}
/>
<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">
<div class="ConvoComposer__panel">{renderPanel()}</div>
</div>
<span
class="ConvoComposer__input"
contenteditable="plaintext-only"
placeholder={lang.use('me_convo_composer_placeholder')}
/>
)
}

return () => (
<div class="ConvoComposer">
<div class="ConvoComposer__panel">
{renderPanel()}
</div>
</div>
)
}, {
props: ['convo']
})

0 comments on commit ff9b3b0

Please sign in to comment.