[Refactoring] Remove unnecessary types for filter (#2091)
This commit is contained in:
parent
4dbd91c026
commit
29c41a104e
@ -295,10 +295,10 @@ export function buildChatMembers(
|
|||||||
) {
|
) {
|
||||||
// Duplicate code because of TS union-type shenanigans
|
// Duplicate code because of TS union-type shenanigans
|
||||||
if (participants instanceof GramJs.ChatParticipants) {
|
if (participants instanceof GramJs.ChatParticipants) {
|
||||||
return participants.participants.map(buildChatMember).filter<ApiChatMember>(Boolean as any);
|
return participants.participants.map(buildChatMember).filter(Boolean);
|
||||||
}
|
}
|
||||||
if (participants instanceof GramJs.channels.ChannelParticipants) {
|
if (participants instanceof GramJs.channels.ChannelParticipants) {
|
||||||
return participants.participants.map(buildChatMember).filter<ApiChatMember>(Boolean as any);
|
return participants.participants.map(buildChatMember).filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -362,9 +362,9 @@ export function buildApiChatFolder(filter: GramJs.DialogFilter): ApiChatFolder {
|
|||||||
'excludeMuted', 'excludeRead', 'excludeArchived',
|
'excludeMuted', 'excludeRead', 'excludeArchived',
|
||||||
]),
|
]),
|
||||||
channels: filter.broadcasts,
|
channels: filter.broadcasts,
|
||||||
pinnedChatIds: filter.pinnedPeers.map(getApiChatIdFromMtpPeer).filter<string>(Boolean as any),
|
pinnedChatIds: filter.pinnedPeers.map(getApiChatIdFromMtpPeer).filter(Boolean),
|
||||||
includedChatIds: filter.includePeers.map(getApiChatIdFromMtpPeer).filter<string>(Boolean as any),
|
includedChatIds: filter.includePeers.map(getApiChatIdFromMtpPeer).filter(Boolean),
|
||||||
excludedChatIds: filter.excludePeers.map(getApiChatIdFromMtpPeer).filter<string>(Boolean as any),
|
excludedChatIds: filter.excludePeers.map(getApiChatIdFromMtpPeer).filter(Boolean),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -178,7 +178,7 @@ export function processStickerPackResult(packs: GramJs.StickerPack[]) {
|
|||||||
return packs.reduce((acc, { emoticon, documents }) => {
|
return packs.reduce((acc, { emoticon, documents }) => {
|
||||||
acc[emoticon] = documents.map((documentId) => buildStickerFromDocument(
|
acc[emoticon] = documents.map((documentId) => buildStickerFromDocument(
|
||||||
localDb.documents[String(documentId)],
|
localDb.documents[String(documentId)],
|
||||||
)).filter<ApiSticker>(Boolean as any);
|
)).filter(Boolean);
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, ApiSticker[]>);
|
}, {} as Record<string, ApiSticker[]>);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -237,15 +237,15 @@ export function buildFilterFromApiFolder(folder: ApiChatFolder): GramJs.DialogFi
|
|||||||
} = folder;
|
} = folder;
|
||||||
|
|
||||||
const pinnedPeers = pinnedChatIds
|
const pinnedPeers = pinnedChatIds
|
||||||
? pinnedChatIds.map(buildInputPeerFromLocalDb).filter<GramJs.TypeInputPeer>(Boolean as any)
|
? pinnedChatIds.map(buildInputPeerFromLocalDb).filter(Boolean)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const includePeers = includedChatIds
|
const includePeers = includedChatIds
|
||||||
? includedChatIds.map(buildInputPeerFromLocalDb).filter<GramJs.TypeInputPeer>(Boolean as any)
|
? includedChatIds.map(buildInputPeerFromLocalDb).filter(Boolean)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const excludePeers = excludedChatIds
|
const excludePeers = excludedChatIds
|
||||||
? excludedChatIds.map(buildInputPeerFromLocalDb).filter<GramJs.TypeInputPeer>(Boolean as any)
|
? excludedChatIds.map(buildInputPeerFromLocalDb).filter(Boolean)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
return new GramJs.DialogFilter({
|
return new GramJs.DialogFilter({
|
||||||
|
|||||||
@ -48,7 +48,7 @@ export async function fetchTopInlineBots() {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const users = topPeers.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = topPeers.users.map(buildApiUser).filter(Boolean);
|
||||||
const ids = users.map(({ id }) => id);
|
const ids = users.map(({ id }) => id);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -102,7 +102,7 @@ export async function fetchInlineBotResults({
|
|||||||
help: bot.botPlaceholder,
|
help: bot.botPlaceholder,
|
||||||
nextOffset: getInlineBotResultsNextOffset(bot.username, result.nextOffset),
|
nextOffset: getInlineBotResultsNextOffset(bot.username, result.nextOffset),
|
||||||
switchPm: buildBotSwitchPm(result.switchPm),
|
switchPm: buildBotSwitchPm(result.switchPm),
|
||||||
users: result.users.map(buildApiUser).filter<ApiUser>(Boolean as any),
|
users: result.users.map(buildApiUser).filter(Boolean),
|
||||||
results: processInlineBotResult(String(result.queryId), result.results),
|
results: processInlineBotResult(String(result.queryId), result.results),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,8 +42,8 @@ export async function getGroupCall({
|
|||||||
addEntitiesWithPhotosToLocalDb(result.users);
|
addEntitiesWithPhotosToLocalDb(result.users);
|
||||||
addEntitiesWithPhotosToLocalDb(result.chats);
|
addEntitiesWithPhotosToLocalDb(result.chats);
|
||||||
|
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
groupCall: buildApiGroupCall(result.call),
|
groupCall: buildApiGroupCall(result.call),
|
||||||
@ -129,8 +129,8 @@ export async function fetchGroupCallParticipants({
|
|||||||
addEntitiesWithPhotosToLocalDb(result.users);
|
addEntitiesWithPhotosToLocalDb(result.users);
|
||||||
addEntitiesWithPhotosToLocalDb(result.chats);
|
addEntitiesWithPhotosToLocalDb(result.chats);
|
||||||
|
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
|
|
||||||
onUpdate({
|
onUpdate({
|
||||||
'@type': 'updateGroupCallParticipants',
|
'@type': 'updateGroupCallParticipants',
|
||||||
|
|||||||
@ -104,7 +104,7 @@ export async function fetchChats({
|
|||||||
const lastMessagesByChatId = buildCollectionByKey(
|
const lastMessagesByChatId = buildCollectionByKey(
|
||||||
(resultPinned ? resultPinned.messages : []).concat(result.messages)
|
(resultPinned ? resultPinned.messages : []).concat(result.messages)
|
||||||
.map(buildApiMessage)
|
.map(buildApiMessage)
|
||||||
.filter<ApiMessage>(Boolean as any),
|
.filter(Boolean),
|
||||||
'chatId',
|
'chatId',
|
||||||
);
|
);
|
||||||
const peersByKey: Record<string, GramJs.TypeChat | GramJs.TypeUser> = {
|
const peersByKey: Record<string, GramJs.TypeChat | GramJs.TypeUser> = {
|
||||||
@ -218,7 +218,7 @@ export async function searchChats({ query }: { query: string }) {
|
|||||||
const localPeerIds = result.myResults.map(getApiChatIdFromMtpPeer);
|
const localPeerIds = result.myResults.map(getApiChatIdFromMtpPeer);
|
||||||
const allChats = result.chats.concat(result.users)
|
const allChats = result.chats.concat(result.users)
|
||||||
.map((user) => buildApiChatFromPreview(user))
|
.map((user) => buildApiChatFromPreview(user))
|
||||||
.filter<ApiChat>(Boolean as any);
|
.filter(Boolean);
|
||||||
const allUsers = result.users.map(buildApiUser).filter((user) => Boolean(user) && !user.isSelf) as ApiUser[];
|
const allUsers = result.users.map(buildApiUser).filter((user) => Boolean(user) && !user.isSelf) as ApiUser[];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -10,11 +10,9 @@ import type {
|
|||||||
ApiOnProgress,
|
ApiOnProgress,
|
||||||
ApiReportReason,
|
ApiReportReason,
|
||||||
ApiSticker,
|
ApiSticker,
|
||||||
ApiThreadInfo,
|
|
||||||
ApiUser,
|
ApiUser,
|
||||||
ApiVideo,
|
ApiVideo,
|
||||||
OnApiUpdate,
|
OnApiUpdate,
|
||||||
ApiSponsoredMessage,
|
|
||||||
ApiSendMessageAction,
|
ApiSendMessageAction,
|
||||||
ApiContact,
|
ApiContact,
|
||||||
ApiPoll,
|
ApiPoll,
|
||||||
@ -119,10 +117,10 @@ export async function fetchMessages({
|
|||||||
|
|
||||||
updateLocalDb(result);
|
updateLocalDb(result);
|
||||||
|
|
||||||
const messages = result.messages.map(buildApiMessage).filter<ApiMessage>(Boolean as any);
|
const messages = result.messages.map(buildApiMessage).filter(Boolean);
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
const threadInfos = messages.map(({ threadInfo }) => threadInfo).filter<ApiThreadInfo>(Boolean as any);
|
const threadInfos = messages.map(({ threadInfo }) => threadInfo).filter(Boolean);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
@ -188,7 +186,7 @@ export async function fetchMessage({ chat, messageId }: { chat: ApiChat; message
|
|||||||
addMessageToLocalDb(mtpMessage);
|
addMessageToLocalDb(mtpMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
|
|
||||||
return { message, users };
|
return { message, users };
|
||||||
}
|
}
|
||||||
@ -857,7 +855,7 @@ export async function requestThreadInfoUpdate({
|
|||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const chats = topMessageResult.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
const chats = topMessageResult.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
chats.forEach((newChat) => {
|
chats.forEach((newChat) => {
|
||||||
onUpdate({
|
onUpdate({
|
||||||
'@type': 'updateChat',
|
'@type': 'updateChat',
|
||||||
@ -931,9 +929,9 @@ export async function searchMessagesLocal({
|
|||||||
|
|
||||||
updateLocalDb(result);
|
updateLocalDb(result);
|
||||||
|
|
||||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const messages = result.messages.map(buildApiMessage).filter<ApiMessage>(Boolean as any);
|
const messages = result.messages.map(buildApiMessage).filter(Boolean);
|
||||||
|
|
||||||
let totalCount = messages.length;
|
let totalCount = messages.length;
|
||||||
let nextOffsetId: number | undefined;
|
let nextOffsetId: number | undefined;
|
||||||
@ -1016,9 +1014,9 @@ export async function searchMessagesGlobal({
|
|||||||
messages: result.messages,
|
messages: result.messages,
|
||||||
} as GramJs.messages.Messages);
|
} as GramJs.messages.Messages);
|
||||||
|
|
||||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const messages = result.messages.map(buildApiMessage).filter<ApiMessage>(Boolean as any);
|
const messages = result.messages.map(buildApiMessage).filter(Boolean);
|
||||||
|
|
||||||
let totalCount = messages.length;
|
let totalCount = messages.length;
|
||||||
let nextRate: number | undefined;
|
let nextRate: number | undefined;
|
||||||
@ -1109,7 +1107,7 @@ export async function loadPollOptionResults({
|
|||||||
messages: [] as GramJs.Message[],
|
messages: [] as GramJs.Message[],
|
||||||
} as GramJs.messages.Messages);
|
} as GramJs.messages.Messages);
|
||||||
|
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const votes = result.votes.map((vote) => ({
|
const votes = result.votes.map((vote) => ({
|
||||||
userId: vote.userId,
|
userId: vote.userId,
|
||||||
date: vote.date,
|
date: vote.date,
|
||||||
@ -1222,7 +1220,7 @@ export async function fetchScheduledHistory({ chat }: { chat: ApiChat }) {
|
|||||||
|
|
||||||
updateLocalDb(result);
|
updateLocalDb(result);
|
||||||
|
|
||||||
const messages = result.messages.map(buildApiMessage).filter<ApiMessage>(Boolean as any);
|
const messages = result.messages.map(buildApiMessage).filter(Boolean);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
@ -1274,9 +1272,9 @@ export async function fetchPinnedMessages({ chat }: { chat: ApiChat }) {
|
|||||||
|
|
||||||
updateLocalDb(result);
|
updateLocalDb(result);
|
||||||
|
|
||||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const messages = result.messages.map(buildApiMessage).filter<ApiMessage>(Boolean as any);
|
const messages = result.messages.map(buildApiMessage).filter(Boolean);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
@ -1342,9 +1340,9 @@ export async function fetchSponsoredMessages({ chat }: { chat: ApiChat }) {
|
|||||||
|
|
||||||
updateLocalDb(result);
|
updateLocalDb(result);
|
||||||
|
|
||||||
const messages = result.messages.map(buildApiSponsoredMessage).filter<ApiSponsoredMessage>(Boolean as any);
|
const messages = result.messages.map(buildApiSponsoredMessage).filter(Boolean);
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
@ -1405,9 +1403,9 @@ export async function fetchUnreadMentions({
|
|||||||
|
|
||||||
updateLocalDb(result);
|
updateLocalDb(result);
|
||||||
|
|
||||||
const messages = result.messages.map(buildApiMessage).filter<ApiMessage>(Boolean as any);
|
const messages = result.messages.map(buildApiMessage).filter(Boolean);
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
@ -1441,9 +1439,9 @@ export async function fetchUnreadReactions({
|
|||||||
|
|
||||||
updateLocalDb(result);
|
updateLocalDb(result);
|
||||||
|
|
||||||
const messages = result.messages.map(buildApiMessage).filter<ApiMessage>(Boolean as any);
|
const messages = result.messages.map(buildApiMessage).filter(Boolean);
|
||||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
const users = result.users.map(buildApiUser).filter(Boolean);
|
||||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
|
|||||||
@ -3,12 +3,9 @@ import { Api as GramJs } from '../../../lib/gramjs';
|
|||||||
|
|
||||||
import type {
|
import type {
|
||||||
ApiAppConfig,
|
ApiAppConfig,
|
||||||
ApiChat,
|
|
||||||
ApiLangString,
|
ApiLangString,
|
||||||
ApiLanguage,
|
ApiLanguage,
|
||||||
ApiNotifyException,
|
ApiNotifyException,
|
||||||
ApiUser,
|
|
||||||
ApiWallpaper,
|
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
import type { ApiPrivacyKey, InputPrivacyRules, LangCode } from '../../../types';
|
import type { ApiPrivacyKey, InputPrivacyRules, LangCode } from '../../../types';
|
||||||
|
|
||||||
@ -99,7 +96,7 @@ export async function fetchWallpapers() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
wallpapers: filteredWallpapers.map(buildApiWallpaper).filter<ApiWallpaper>(Boolean as any),
|
wallpapers: filteredWallpapers.map(buildApiWallpaper).filter(Boolean),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,8 +134,8 @@ export async function fetchBlockedContacts() {
|
|||||||
updateLocalDb(result);
|
updateLocalDb(result);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
users: result.users.map(buildApiUser).filter<ApiUser>(Boolean as any),
|
users: result.users.map(buildApiUser).filter(Boolean),
|
||||||
chats: result.chats.map((chat) => buildApiChatFromPreview(chat)).filter<ApiChat>(Boolean as any),
|
chats: result.chats.map((chat) => buildApiChatFromPreview(chat)).filter(Boolean),
|
||||||
blockedIds: result.blocked.map((blocked) => getApiChatIdFromMtpPeer(blocked.peerId)),
|
blockedIds: result.blocked.map((blocked) => getApiChatIdFromMtpPeer(blocked.peerId)),
|
||||||
totalCount: result instanceof GramJs.contacts.BlockedSlice ? result.count : result.blocked.length,
|
totalCount: result instanceof GramJs.contacts.BlockedSlice ? result.count : result.blocked.length,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -318,7 +318,7 @@ export async function searchGifs({ query, offset = '' }: { query: string; offset
|
|||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
})
|
})
|
||||||
.filter<GramJs.TypeDocument>(Boolean as any);
|
.filter(Boolean);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nextOffset: result.nextOffset,
|
nextOffset: result.nextOffset,
|
||||||
@ -382,5 +382,5 @@ function processGifResult(gifs: GramJs.TypeDocument[]) {
|
|||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
})
|
})
|
||||||
.filter<ApiVideo>(Boolean as any);
|
.filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import BigInt from 'big-integer';
|
import BigInt from 'big-integer';
|
||||||
import { Api as GramJs } from '../../../lib/gramjs';
|
import { Api as GramJs } from '../../../lib/gramjs';
|
||||||
import type {
|
import type {
|
||||||
OnApiUpdate, ApiUser, ApiChat, ApiPhoto,
|
OnApiUpdate, ApiUser, ApiChat,
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
|
|
||||||
import { COMMON_CHATS_LIMIT, PROFILE_PHOTOS_LIMIT } from '../../../config';
|
import { COMMON_CHATS_LIMIT, PROFILE_PHOTOS_LIMIT } from '../../../config';
|
||||||
@ -138,7 +138,7 @@ export async function fetchContactList() {
|
|||||||
return {
|
return {
|
||||||
users,
|
users,
|
||||||
userStatusesById,
|
userStatusesById,
|
||||||
chats: result.users.map((user) => buildApiChatFromPreview(user)).filter<ApiChat>(Boolean as any),
|
chats: result.users.map((user) => buildApiChatFromPreview(user)).filter(Boolean),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ export async function fetchProfilePhotos(user?: ApiUser, chat?: ApiChat) {
|
|||||||
const { messages, users } = result;
|
const { messages, users } = result;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
photos: messages.map((message) => message.content.action!.photo).filter<ApiPhoto>(Boolean as any),
|
photos: messages.map((message) => message.content.action!.photo).filter(Boolean),
|
||||||
users,
|
users,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -331,7 +331,7 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
|||||||
return message && message instanceof GramJs.MessageService && 'photo' in message.action
|
return message && message instanceof GramJs.MessageService && 'photo' in message.action
|
||||||
? String(message.action.photo.id)
|
? String(message.action.photo.id)
|
||||||
: undefined;
|
: undefined;
|
||||||
}).filter<string>(Boolean as any);
|
}).filter(Boolean);
|
||||||
|
|
||||||
if (existingIds.length) {
|
if (existingIds.length) {
|
||||||
onUpdate({
|
onUpdate({
|
||||||
|
|||||||
@ -113,7 +113,7 @@ export function renderActionMessageText(
|
|||||||
unprocessed,
|
unprocessed,
|
||||||
'%target_user%',
|
'%target_user%',
|
||||||
targetUsers
|
targetUsers
|
||||||
? targetUsers.map((user) => renderUserContent(user, noLinks)).filter<TextPart>(Boolean as any)
|
? targetUsers.map((user) => renderUserContent(user, noLinks)).filter(Boolean)
|
||||||
: 'User',
|
: 'User',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -77,5 +77,5 @@ export function renderMessageSummary(
|
|||||||
return [
|
return [
|
||||||
...renderText(emojiWithSpace),
|
...renderText(emojiWithSpace),
|
||||||
...(Array.isArray(description) ? description : [description]),
|
...(Array.isArray(description) ? description : [description]),
|
||||||
].filter<TextPart>(Boolean);
|
].filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -253,7 +253,7 @@ function organizeEntity(
|
|||||||
const parsedNestedEntities = entities
|
const parsedNestedEntities = entities
|
||||||
.filter((e, i) => i > index && e.offset >= offset && e.offset < offset + length)
|
.filter((e, i) => i > index && e.offset >= offset && e.offset < offset + length)
|
||||||
.map((e) => organizeEntity(e, entities.indexOf(e), entities, organizedEntityIndexes))
|
.map((e) => organizeEntity(e, entities.indexOf(e), entities, organizedEntityIndexes))
|
||||||
.filter<IOrganizedEntity>(Boolean as any);
|
.filter(Boolean);
|
||||||
|
|
||||||
parsedNestedEntities.forEach((parsedEntity) => {
|
parsedNestedEntities.forEach((parsedEntity) => {
|
||||||
let isChanged = false;
|
let isChanged = false;
|
||||||
|
|||||||
@ -149,7 +149,7 @@ const Chat: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
// No need for expensive global updates on users, so we avoid them
|
// No need for expensive global updates on users, so we avoid them
|
||||||
const usersById = getGlobal().users.byId;
|
const usersById = getGlobal().users.byId;
|
||||||
return actionTargetUserIds.map((userId) => usersById[userId]).filter<ApiUser>(Boolean as any);
|
return actionTargetUserIds.map((userId) => usersById[userId]).filter(Boolean);
|
||||||
}, [actionTargetUserIds]);
|
}, [actionTargetUserIds]);
|
||||||
|
|
||||||
// Sets animation excess values when `orderDiff` changes and then resets excess values to animate.
|
// Sets animation excess values when `orderDiff` changes and then resets excess values to animate.
|
||||||
|
|||||||
@ -70,7 +70,7 @@ const ChatMessageResults: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
return globalMessagesByChatId?.[chatId]?.byId[Number(messageId)];
|
return globalMessagesByChatId?.[chatId]?.byId[Number(messageId)];
|
||||||
})
|
})
|
||||||
.filter<ApiMessage>(Boolean as any)
|
.filter(Boolean)
|
||||||
.sort((a, b) => b.date - a.date);
|
.sort((a, b) => b.date - a.date);
|
||||||
}, [foundIds, globalMessagesByChatId]);
|
}, [foundIds, globalMessagesByChatId]);
|
||||||
|
|
||||||
|
|||||||
@ -152,7 +152,7 @@ const ChatResults: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
return globalMessagesByChatId?.[chatId]?.byId[Number(messageId)];
|
return globalMessagesByChatId?.[chatId]?.byId[Number(messageId)];
|
||||||
})
|
})
|
||||||
.filter<ApiMessage>(Boolean as any)
|
.filter(Boolean)
|
||||||
.sort((a, b) => b.date - a.date);
|
.sort((a, b) => b.date - a.date);
|
||||||
}, [foundIds, globalMessagesByChatId, searchQuery, searchDate]);
|
}, [foundIds, globalMessagesByChatId, searchQuery, searchDate]);
|
||||||
|
|
||||||
|
|||||||
@ -116,7 +116,7 @@ const ActionMessage: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
const targetUsers = useMemo(() => {
|
const targetUsers = useMemo(() => {
|
||||||
return targetUserIds
|
return targetUserIds
|
||||||
? targetUserIds.map((userId) => usersById?.[userId]).filter<ApiUser>(Boolean as any)
|
? targetUserIds.map((userId) => usersById?.[userId]).filter(Boolean)
|
||||||
: undefined;
|
: undefined;
|
||||||
}, [targetUserIds, usersById]);
|
}, [targetUserIds, usersById]);
|
||||||
|
|
||||||
|
|||||||
@ -272,7 +272,7 @@ addActionHandler('createChannel', (global, actions, payload) => {
|
|||||||
|
|
||||||
const members = (memberIds as string[])
|
const members = (memberIds as string[])
|
||||||
.map((id) => selectUser(global, id))
|
.map((id) => selectUser(global, id))
|
||||||
.filter<ApiUser>(Boolean as any);
|
.filter(Boolean);
|
||||||
|
|
||||||
void createChannel(title, members, about, photo);
|
void createChannel(title, members, about, photo);
|
||||||
});
|
});
|
||||||
@ -372,7 +372,7 @@ addActionHandler('createGroupChat', (global, actions, payload) => {
|
|||||||
const { title, memberIds, photo } = payload!;
|
const { title, memberIds, photo } = payload!;
|
||||||
const members = (memberIds as string[])
|
const members = (memberIds as string[])
|
||||||
.map((id) => selectUser(global, id))
|
.map((id) => selectUser(global, id))
|
||||||
.filter<ApiUser>(Boolean as any);
|
.filter(Boolean);
|
||||||
|
|
||||||
void createGroupChat(title, members, photo);
|
void createGroupChat(title, members, photo);
|
||||||
});
|
});
|
||||||
@ -1063,7 +1063,7 @@ addActionHandler('loadMoreMembers', async (global) => {
|
|||||||
addActionHandler('addChatMembers', async (global, actions, payload) => {
|
addActionHandler('addChatMembers', async (global, actions, payload) => {
|
||||||
const { chatId, memberIds } = payload;
|
const { chatId, memberIds } = payload;
|
||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
const users = (memberIds as string[]).map((userId) => selectUser(global, userId)).filter<ApiUser>(Boolean as any);
|
const users = (memberIds as string[]).map((userId) => selectUser(global, userId)).filter(Boolean);
|
||||||
|
|
||||||
if (!chat || !users.length) {
|
if (!chat || !users.length) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -618,7 +618,7 @@ addActionHandler('forwardMessages', (global, action, payload) => {
|
|||||||
const messages = fromChatId && messageIds
|
const messages = fromChatId && messageIds
|
||||||
? messageIds
|
? messageIds
|
||||||
.sort((a, b) => a - b)
|
.sort((a, b) => a - b)
|
||||||
.map((id) => selectChatMessage(global, fromChatId, id)).filter<ApiMessage>(Boolean as any)
|
.map((id) => selectChatMessage(global, fromChatId, id)).filter(Boolean)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
if (!fromChat || !toChat || !messages) {
|
if (!fromChat || !toChat || !messages) {
|
||||||
|
|||||||
@ -287,7 +287,7 @@ function getNotificationContent(chat: ApiChat, message: ApiMessage, reaction?: A
|
|||||||
|
|
||||||
const actionTargetUsers = actionTargetUserIds
|
const actionTargetUsers = actionTargetUserIds
|
||||||
? actionTargetUserIds.map((userId) => selectUser(global, userId))
|
? actionTargetUserIds.map((userId) => selectUser(global, userId))
|
||||||
.filter<ApiUser>(Boolean as any)
|
.filter(Boolean)
|
||||||
: undefined;
|
: undefined;
|
||||||
const privateChatUserId = getPrivateChatUserId(chat);
|
const privateChatUserId = getPrivateChatUserId(chat);
|
||||||
const privateChatUser = privateChatUserId ? selectUser(global, privateChatUserId) : undefined;
|
const privateChatUser = privateChatUserId ? selectUser(global, privateChatUserId) : undefined;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user