Custom Emoji: Fix size in message media caption (#2179)
This commit is contained in:
parent
af49c11dd4
commit
dc2d7984a1
@ -57,7 +57,7 @@ import { buildPeer } from '../gramjsBuilders';
|
|||||||
import { addPhotoToLocalDb, resolveMessageApiChatId, serializeBytes } from '../helpers';
|
import { addPhotoToLocalDb, resolveMessageApiChatId, serializeBytes } from '../helpers';
|
||||||
import { buildApiPeerId, getApiChatIdFromMtpPeer, isPeerUser } from './peers';
|
import { buildApiPeerId, getApiChatIdFromMtpPeer, isPeerUser } from './peers';
|
||||||
import { buildApiCallDiscardReason } from './calls';
|
import { buildApiCallDiscardReason } from './calls';
|
||||||
import parseEmojiOnlyString from '../../../util/parseEmojiOnlyString';
|
import { getEmojiOnlyCountForMessage } from '../../../global/helpers/getEmojiOnlyCountForMessage';
|
||||||
|
|
||||||
const LOCAL_MEDIA_UPLOADING_TEMP_ID = 'temp';
|
const LOCAL_MEDIA_UPLOADING_TEMP_ID = 'temp';
|
||||||
const INPUT_WAVEFORM_LENGTH = 63;
|
const INPUT_WAVEFORM_LENGTH = 63;
|
||||||
@ -177,7 +177,7 @@ export function buildApiMessageWithChatId(chatId: string, mtpMessage: UniversalM
|
|||||||
const shouldHideKeyboardButtons = mtpMessage.replyMarkup instanceof GramJs.ReplyKeyboardHide;
|
const shouldHideKeyboardButtons = mtpMessage.replyMarkup instanceof GramJs.ReplyKeyboardHide;
|
||||||
const isProtected = mtpMessage.noforwards || isInvoiceMedia;
|
const isProtected = mtpMessage.noforwards || isInvoiceMedia;
|
||||||
const isForwardingAllowed = !mtpMessage.noforwards;
|
const isForwardingAllowed = !mtpMessage.noforwards;
|
||||||
const emojiOnlyCount = content.text && !groupedId && parseEmojiOnlyString(content.text.text);
|
const emojiOnlyCount = getEmojiOnlyCountForMessage(content, groupedId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: mtpMessage.id,
|
id: mtpMessage.id,
|
||||||
@ -1219,9 +1219,8 @@ export function buildLocalMessage(
|
|||||||
const localId = getNextLocalMessageId();
|
const localId = getNextLocalMessageId();
|
||||||
const media = attachment && buildUploadingMedia(attachment);
|
const media = attachment && buildUploadingMedia(attachment);
|
||||||
const isChannel = chat.type === 'chatTypeChannel';
|
const isChannel = chat.type === 'chatTypeChannel';
|
||||||
const emojiOnlyCount = text && !groupedId && parseEmojiOnlyString(text);
|
|
||||||
|
|
||||||
return {
|
const message = {
|
||||||
id: localId,
|
id: localId,
|
||||||
chatId: chat.id,
|
chatId: chat.id,
|
||||||
content: {
|
content: {
|
||||||
@ -1240,7 +1239,6 @@ export function buildLocalMessage(
|
|||||||
date: scheduledAt || Math.round(Date.now() / 1000) + serverTimeOffset,
|
date: scheduledAt || Math.round(Date.now() / 1000) + serverTimeOffset,
|
||||||
isOutgoing: !isChannel,
|
isOutgoing: !isChannel,
|
||||||
senderId: sendAs?.id || currentUserId,
|
senderId: sendAs?.id || currentUserId,
|
||||||
...(emojiOnlyCount && { emojiOnlyCount }),
|
|
||||||
...(replyingTo && { replyToMessageId: replyingTo }),
|
...(replyingTo && { replyToMessageId: replyingTo }),
|
||||||
...(replyingToTopId && { replyToTopMessageId: replyingToTopId }),
|
...(replyingToTopId && { replyToTopMessageId: replyingToTopId }),
|
||||||
...(groupedId && {
|
...(groupedId && {
|
||||||
@ -1250,6 +1248,13 @@ export function buildLocalMessage(
|
|||||||
...(scheduledAt && { isScheduled: true }),
|
...(scheduledAt && { isScheduled: true }),
|
||||||
isForwardingAllowed: true,
|
isForwardingAllowed: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const emojiOnlyCount = getEmojiOnlyCountForMessage(message.content, message.groupedId);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...message,
|
||||||
|
...(emojiOnlyCount && { emojiOnlyCount }),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildLocalForwardedMessage(
|
export function buildLocalForwardedMessage(
|
||||||
@ -1281,7 +1286,7 @@ export function buildLocalForwardedMessage(
|
|||||||
text: content.text.text,
|
text: content.text.text,
|
||||||
entities: content.text.entities.filter((entity) => entity.type !== ApiMessageEntityTypes.CustomEmoji),
|
entities: content.text.entities.filter((entity) => entity.type !== ApiMessageEntityTypes.CustomEmoji),
|
||||||
} : content.text;
|
} : content.text;
|
||||||
const emojiOnlyCount = content.text && !groupedId && parseEmojiOnlyString(content.text.text);
|
const emojiOnlyCount = getEmojiOnlyCountForMessage(content, groupedId);
|
||||||
|
|
||||||
const updatedContent = {
|
const updatedContent = {
|
||||||
...content,
|
...content,
|
||||||
|
|||||||
@ -63,7 +63,7 @@ import {
|
|||||||
} from '../helpers';
|
} from '../helpers';
|
||||||
import { interpolateArray } from '../../../util/waveform';
|
import { interpolateArray } from '../../../util/waveform';
|
||||||
import { requestChatUpdate } from './chats';
|
import { requestChatUpdate } from './chats';
|
||||||
import parseEmojiOnlyString from '../../../util/parseEmojiOnlyString';
|
import { getEmojiOnlyCountForMessage } from '../../../global/helpers/getEmojiOnlyCountForMessage';
|
||||||
|
|
||||||
const FAST_SEND_TIMEOUT = 1000;
|
const FAST_SEND_TIMEOUT = 1000;
|
||||||
const INPUT_WAVEFORM_LENGTH = 63;
|
const INPUT_WAVEFORM_LENGTH = 63;
|
||||||
@ -492,8 +492,7 @@ export async function editMessage({
|
|||||||
serverTimeOffset: number;
|
serverTimeOffset: number;
|
||||||
}) {
|
}) {
|
||||||
const isScheduled = message.date * 1000 > Date.now() + serverTimeOffset * 1000;
|
const isScheduled = message.date * 1000 > Date.now() + serverTimeOffset * 1000;
|
||||||
const emojiOnlyCount = text && !message.groupedId ? parseEmojiOnlyString(text) : undefined;
|
let messageUpdate: Partial<ApiMessage> = {
|
||||||
const messageUpdate: Partial<ApiMessage> = {
|
|
||||||
content: {
|
content: {
|
||||||
...message.content,
|
...message.content,
|
||||||
...(text && {
|
...(text && {
|
||||||
@ -503,7 +502,12 @@ export async function editMessage({
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
emojiOnlyCount: emojiOnlyCount || undefined,
|
};
|
||||||
|
|
||||||
|
const emojiOnlyCount = getEmojiOnlyCountForMessage(messageUpdate.content!, messageUpdate.groupedId);
|
||||||
|
messageUpdate = {
|
||||||
|
...messageUpdate,
|
||||||
|
emojiOnlyCount,
|
||||||
};
|
};
|
||||||
|
|
||||||
onUpdate({
|
onUpdate({
|
||||||
|
|||||||
13
src/global/helpers/getEmojiOnlyCountForMessage.ts
Normal file
13
src/global/helpers/getEmojiOnlyCountForMessage.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import type { ApiMessage } from '../../api/types';
|
||||||
|
import { ApiMessageEntityTypes } from '../../api/types';
|
||||||
|
import parseEmojiOnlyString from '../../util/parseEmojiOnlyString';
|
||||||
|
|
||||||
|
export function getEmojiOnlyCountForMessage(content: ApiMessage['content'], groupedId?: string): number | undefined {
|
||||||
|
if (!content.text) return undefined;
|
||||||
|
return (
|
||||||
|
!groupedId
|
||||||
|
&& Object.keys(content).length === 1 // Only text is present
|
||||||
|
&& !content.text.entities?.some((entity) => entity.type !== ApiMessageEntityTypes.CustomEmoji)
|
||||||
|
&& parseEmojiOnlyString(content.text.text)
|
||||||
|
) || undefined;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user