Message List: Fix missing avatars in big channel messages
This commit is contained in:
parent
1285499e96
commit
d4d6166ede
@ -42,12 +42,26 @@ export function addPhotoToLocalDb(photo: GramJs.TypePhoto) {
|
||||
}
|
||||
}
|
||||
|
||||
export function addChatToLocalDb(chat: GramJs.TypeChat) {
|
||||
if (chat instanceof GramJs.Chat || chat instanceof GramJs.Channel) {
|
||||
localDb.chats[buildApiPeerId(chat.id, chat instanceof GramJs.Chat ? 'chat' : 'channel')] = chat;
|
||||
function addChatToLocalDb(chat: GramJs.Chat | GramJs.Channel, noOverwrite = false) {
|
||||
const id = buildApiPeerId(chat.id, chat instanceof GramJs.Chat ? 'chat' : 'channel');
|
||||
if (!noOverwrite || !localDb.chats[id]) {
|
||||
localDb.chats[id] = chat;
|
||||
}
|
||||
}
|
||||
|
||||
export function addUserToLocalDb(user: GramJs.User) {
|
||||
localDb.users[buildApiPeerId(user.id, 'user')] = user;
|
||||
export function addUserToLocalDb(user: GramJs.User, shouldOverwrite = false) {
|
||||
const id = buildApiPeerId(user.id, 'user');
|
||||
if (shouldOverwrite || !localDb.users[id]) {
|
||||
localDb.users[id] = user;
|
||||
}
|
||||
}
|
||||
|
||||
export function addEntitiesWithPhotosToLocalDb(entities: (GramJs.TypeUser | GramJs.TypeChat)[]) {
|
||||
entities.forEach((entity) => {
|
||||
if (entity instanceof GramJs.User && entity.photo) {
|
||||
addUserToLocalDb(entity);
|
||||
} else if ((entity instanceof GramJs.Chat || entity instanceof GramJs.Channel) && entity.photo) {
|
||||
addChatToLocalDb(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import { buildInputPeer, generateRandomBigInt } from '../gramjsBuilders';
|
||||
import { buildApiUser } from '../apiBuilders/users';
|
||||
import { buildApiBotInlineMediaResult, buildApiBotInlineResult, buildBotSwitchPm } from '../apiBuilders/bots';
|
||||
import { buildApiChatFromPreview } from '../apiBuilders/chats';
|
||||
import { addUserToLocalDb } from '../helpers';
|
||||
import { addEntitiesWithPhotosToLocalDb, addUserToLocalDb } from '../helpers';
|
||||
|
||||
export function init() {
|
||||
}
|
||||
@ -84,7 +84,7 @@ export async function fetchInlineBotResults({
|
||||
return undefined;
|
||||
}
|
||||
|
||||
result.users.map(addUserToLocalDb);
|
||||
addEntitiesWithPhotosToLocalDb(result.users);
|
||||
|
||||
return {
|
||||
isGallery: Boolean(result.gallery),
|
||||
|
||||
@ -13,7 +13,7 @@ import {
|
||||
} from '../apiBuilders/calls';
|
||||
import { buildApiUser } from '../apiBuilders/users';
|
||||
import { buildApiChatFromPreview } from '../apiBuilders/chats';
|
||||
import { addChatToLocalDb, addUserToLocalDb } from '../helpers';
|
||||
import { addEntitiesWithPhotosToLocalDb } from '../helpers';
|
||||
import { GROUP_CALL_PARTICIPANTS_LIMIT } from '../../../config';
|
||||
|
||||
let onUpdate: OnApiUpdate;
|
||||
@ -35,8 +35,8 @@ export async function getGroupCall({
|
||||
return undefined;
|
||||
}
|
||||
|
||||
result.users.map(addUserToLocalDb);
|
||||
result.chats.map(addChatToLocalDb);
|
||||
addEntitiesWithPhotosToLocalDb(result.users);
|
||||
addEntitiesWithPhotosToLocalDb(result.chats);
|
||||
|
||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
||||
@ -122,8 +122,8 @@ export async function fetchGroupCallParticipants({
|
||||
return undefined;
|
||||
}
|
||||
|
||||
result.users.map(addUserToLocalDb);
|
||||
result.chats.map(addChatToLocalDb);
|
||||
addEntitiesWithPhotosToLocalDb(result.users);
|
||||
addEntitiesWithPhotosToLocalDb(result.chats);
|
||||
|
||||
const users = result.users.map(buildApiUser).filter<ApiUser>(Boolean as any);
|
||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
||||
|
||||
@ -30,7 +30,6 @@ import {
|
||||
import { buildApiMessage, buildMessageDraft } from '../apiBuilders/messages';
|
||||
import { buildApiUser, buildApiUsersAndStatuses } from '../apiBuilders/users';
|
||||
import { buildCollectionByKey } from '../../../util/iteratees';
|
||||
import localDb from '../localDb';
|
||||
import {
|
||||
buildInputEntity,
|
||||
buildInputPeer,
|
||||
@ -40,7 +39,7 @@ import {
|
||||
buildChatBannedRights,
|
||||
buildChatAdminRights,
|
||||
} from '../gramjsBuilders';
|
||||
import { addChatToLocalDb, addMessageToLocalDb } from '../helpers';
|
||||
import { addEntitiesWithPhotosToLocalDb, addMessageToLocalDb } from '../helpers';
|
||||
import { buildApiPeerId, getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
||||
|
||||
const MAX_INT_32 = 2 ** 31 - 1;
|
||||
@ -1105,15 +1104,11 @@ function updateLocalDb(result: (
|
||||
GramJs.messages.Chats | GramJs.messages.ChatsSlice | GramJs.TypeUpdates
|
||||
)) {
|
||||
if ('users' in result) {
|
||||
result.users.forEach((user) => {
|
||||
if (user instanceof GramJs.User) {
|
||||
localDb.users[buildApiPeerId(user.id, 'user')] = user;
|
||||
}
|
||||
});
|
||||
addEntitiesWithPhotosToLocalDb(result.users);
|
||||
}
|
||||
|
||||
if ('chats' in result) {
|
||||
result.chats.forEach(addChatToLocalDb);
|
||||
addEntitiesWithPhotosToLocalDb(result.chats);
|
||||
}
|
||||
|
||||
if ('messages' in result) {
|
||||
|
||||
@ -18,7 +18,7 @@ import { buildApiUser, buildApiUserFromFull, buildApiUsersAndStatuses } from '..
|
||||
import { buildApiChatFromPreview } from '../apiBuilders/chats';
|
||||
import { buildApiPhoto } from '../apiBuilders/common';
|
||||
import localDb from '../localDb';
|
||||
import { addChatToLocalDb, addPhotoToLocalDb } from '../helpers';
|
||||
import { addEntitiesWithPhotosToLocalDb, addPhotoToLocalDb } from '../helpers';
|
||||
import { buildApiPeerId } from '../apiBuilders/peers';
|
||||
|
||||
let onUpdate: OnApiUpdate;
|
||||
@ -249,7 +249,7 @@ export async function fetchProfilePhotos(user?: ApiUser, chat?: ApiChat) {
|
||||
|
||||
function updateLocalDb(result: (GramJs.photos.Photos | GramJs.photos.PhotosSlice | GramJs.messages.Chats)) {
|
||||
if ('chats' in result) {
|
||||
result.chats.forEach(addChatToLocalDb);
|
||||
addEntitiesWithPhotosToLocalDb(result.chats);
|
||||
}
|
||||
|
||||
if ('photos' in result) {
|
||||
|
||||
@ -31,7 +31,12 @@ import {
|
||||
import localDb from './localDb';
|
||||
import { omitVirtualClassFields } from './apiBuilders/helpers';
|
||||
import { DEBUG } from '../../config';
|
||||
import { addMessageToLocalDb, addPhotoToLocalDb, resolveMessageApiChatId } from './helpers';
|
||||
import {
|
||||
addMessageToLocalDb,
|
||||
addEntitiesWithPhotosToLocalDb,
|
||||
addPhotoToLocalDb,
|
||||
resolveMessageApiChatId,
|
||||
} from './helpers';
|
||||
import { buildApiNotifyException, buildPrivacyKey, buildPrivacyRules } from './apiBuilders/misc';
|
||||
import { buildApiPhoto } from './apiBuilders/common';
|
||||
import {
|
||||
@ -56,37 +61,36 @@ export function init(_onUpdate: OnApiUpdate) {
|
||||
const sentMessageIds = new Set();
|
||||
let serverTimeOffset = 0;
|
||||
|
||||
function addEntities(entities: (GramJs.TypeUser | GramJs.TypeChat)[] | undefined) {
|
||||
if (entities?.length) {
|
||||
entities
|
||||
.filter((e) => e instanceof GramJs.User)
|
||||
.map(buildApiUser)
|
||||
.forEach((user) => {
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
function dispatchUserAndChatUpdates(entities: (GramJs.TypeUser | GramJs.TypeChat)[]) {
|
||||
entities
|
||||
.filter((e) => e instanceof GramJs.User)
|
||||
.map(buildApiUser)
|
||||
.forEach((user) => {
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
|
||||
onUpdate({
|
||||
'@type': 'updateUser',
|
||||
id: user.id,
|
||||
user,
|
||||
});
|
||||
onUpdate({
|
||||
'@type': 'updateUser',
|
||||
id: user.id,
|
||||
user,
|
||||
});
|
||||
entities
|
||||
.filter((e) => e instanceof GramJs.Chat || e instanceof GramJs.Channel)
|
||||
.map((e) => buildApiChatFromPreview(e))
|
||||
.forEach((chat) => {
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
onUpdate({
|
||||
'@type': 'updateChat',
|
||||
id: chat.id,
|
||||
chat,
|
||||
});
|
||||
entities
|
||||
.filter((e) => e instanceof GramJs.Chat || e instanceof GramJs.Channel)
|
||||
.map((e) => buildApiChatFromPreview(e))
|
||||
.forEach((chat) => {
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
|
||||
onUpdate({
|
||||
'@type': 'updateChat',
|
||||
id: chat.id,
|
||||
chat,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
||||
@ -150,7 +154,11 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
addEntities(update._entities);
|
||||
const entities = update._entities;
|
||||
if (entities) {
|
||||
addEntitiesWithPhotosToLocalDb(entities);
|
||||
dispatchUserAndChatUpdates(entities);
|
||||
}
|
||||
|
||||
if (update instanceof GramJs.UpdateNewScheduledMessage) {
|
||||
onUpdate({
|
||||
@ -818,7 +826,11 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
||||
});
|
||||
} else if (update instanceof GramJs.UpdateGroupCallParticipants) {
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
addEntities(update._entities);
|
||||
const entities = update._entities;
|
||||
if (entities) {
|
||||
addEntitiesWithPhotosToLocalDb(entities);
|
||||
dispatchUserAndChatUpdates(entities);
|
||||
}
|
||||
|
||||
onUpdate({
|
||||
'@type': 'updateGroupCallParticipants',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user