diff --git a/.eslintrc.js b/.eslintrc.js index b7eee6ac..8ddb3f46 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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', { diff --git a/src/converters/AttachConverter.ts b/src/converters/AttachConverter.ts index 757155ad..3cc68155 100644 --- a/src/converters/AttachConverter.ts +++ b/src/converters/AttachConverter.ts @@ -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 diff --git a/src/converters/ConvoConverter.ts b/src/converters/ConvoConverter.ts index de347c5b..00e65689 100644 --- a/src/converters/ConvoConverter.ts +++ b/src/converters/ConvoConverter.ts @@ -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) } diff --git a/src/converters/MessageConverter.ts b/src/converters/MessageConverter.ts index e6c52c86..99e16517 100644 --- a/src/converters/MessageConverter.ts +++ b/src/converters/MessageConverter.ts @@ -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 if (message.action) { @@ -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 } } @@ -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 } } @@ -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' } } } diff --git a/src/model/api-types/objects/MessagesMessageAttachment.ts b/src/model/api-types/objects/MessagesMessageAttachment.ts index fdf9937d..c21ddac5 100644 --- a/src/model/api-types/objects/MessagesMessageAttachment.ts +++ b/src/model/api-types/objects/MessagesMessageAttachment.ts @@ -139,6 +139,7 @@ type MessagesMessageAttachmentsSticker = { type MessagesMessageAttachmentLink = { url: string title?: string + description?: string caption?: string photo?: PhotosPhoto } diff --git a/src/ui/messenger/ConvoComposer/ConvoComposer.css b/src/ui/messenger/ConvoComposer/ConvoComposer.css index ef7e850b..de777257 100644 --- a/src/ui/messenger/ConvoComposer/ConvoComposer.css +++ b/src/ui/messenger/ConvoComposer/ConvoComposer.css @@ -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); } @@ -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); diff --git a/src/ui/messenger/ConvoComposer/ConvoComposer.tsx b/src/ui/messenger/ConvoComposer/ConvoComposer.tsx index ca58bbd5..e170a996 100644 --- a/src/ui/messenger/ConvoComposer/ConvoComposer.tsx +++ b/src/ui/messenger/ConvoComposer/ConvoComposer.tsx @@ -13,73 +13,70 @@ export const ConvoComposer = defineComponent((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 ( -
- - {lang.use('me_chat_kicked_status')} -
- ) - } + const renderPanel = () => { + const isChannel = Convo.isChannel(props.convo) - if (isChannel) { - return ( - - ) - } + if (props.convo.kind === 'ChatConvo' && props.convo.status === 'kicked') { + return ( +
+ + {lang.use('me_chat_kicked_status')} +
+ ) + } + if (isChannel) { return ( -
+ ) } return ( -
-
{renderPanel()}
-
+ ) } + + return () => ( +
+
+ {renderPanel()} +
+
+ ) }, { props: ['convo'] })