Layer 128

This commit is contained in:
Eduard Kuzmenko 2021-05-04 00:02:53 +04:00
parent 57f4be00f0
commit 21f7a1201f
16 changed files with 1801 additions and 1708 deletions

View File

@ -908,12 +908,17 @@ export default class AppSearchSuper {
} }
participants.forEach(participant => { participants.forEach(participant => {
const user = appUsersManager.getUser(participant.user_id); const peerId = appChatsManager.getParticipantPeerId(participant);
if(peerId < 0) {
return;
}
const user = appUsersManager.getUser(peerId);
if(user.pFlags.deleted) { if(user.pFlags.deleted) {
return; return;
} }
this.membersList.add(participant.user_id); this.membersList.add(peerId);
}); });
}; };
@ -1165,6 +1170,10 @@ export default class AppSearchSuper {
return !this.loaded[inputFilter] || (this.historyStorage[inputFilter] && this.usedFromHistory[inputFilter] < this.historyStorage[inputFilter].length); return !this.loaded[inputFilter] || (this.historyStorage[inputFilter] && this.usedFromHistory[inputFilter] < this.historyStorage[inputFilter].length);
}); });
if(peerId > 0) {
toLoad.findAndSplice(mediaTab => mediaTab.type === 'members');
}
if(!toLoad.length) { if(!toLoad.length) {
return; return;
} }

View File

@ -353,9 +353,11 @@ export default class AppSelectPeers {
return; return;
} }
const userIds = participants.participants.map(participant => participant.user_id); const peerIds = participants.participants.map(participant => {
userIds.findAndSplice(u => u === rootScope.myId); return appChatsManager.getParticipantPeerId(participant);
this.renderResultsFunc(userIds); });
peerIds.findAndSplice(u => u === rootScope.myId);
this.renderResultsFunc(peerIds);
if(this.list.childElementCount >= participants.count || participants.participants.length < pageCount) { if(this.list.childElementCount >= participants.count || participants.participants.length < pageCount) {
this.loadedWhat.channelParticipants = true; this.loadedWhat.channelParticipants = true;

View File

@ -11,6 +11,7 @@ import ScrollableLoader from "../../../helpers/listLoader";
import { ChannelParticipant, Chat, ChatBannedRights, Update } from "../../../layer"; import { ChannelParticipant, Chat, ChatBannedRights, Update } from "../../../layer";
import appChatsManager, { ChatRights } from "../../../lib/appManagers/appChatsManager"; import appChatsManager, { ChatRights } from "../../../lib/appManagers/appChatsManager";
import appDialogsManager from "../../../lib/appManagers/appDialogsManager"; import appDialogsManager from "../../../lib/appManagers/appDialogsManager";
import appPeersManager from "../../../lib/appManagers/appPeersManager";
import appProfileManager from "../../../lib/appManagers/appProfileManager"; import appProfileManager from "../../../lib/appManagers/appProfileManager";
import I18n, { i18n, join, LangPackKey } from "../../../lib/langPack"; import I18n, { i18n, join, LangPackKey } from "../../../lib/langPack";
import rootScope from "../../../lib/rootScope"; import rootScope from "../../../lib/rootScope";
@ -241,7 +242,7 @@ export default class AppGroupPermissionsTab extends SliderSuperTabEventable {
const add = (participant: ChannelParticipant.channelParticipantBanned, append: boolean) => { const add = (participant: ChannelParticipant.channelParticipantBanned, append: boolean) => {
const {dom} = appDialogsManager.addDialogNew({ const {dom} = appDialogsManager.addDialogNew({
dialog: participant.user_id, dialog: appPeersManager.getPeerId(participant.peer),
container: list, container: list,
drawStatus: false, drawStatus: false,
rippleEnabled: true, rippleEnabled: true,

View File

@ -4,10 +4,10 @@
* https://github.com/morethanwords/tweb/blob/master/LICENSE * https://github.com/morethanwords/tweb/blob/master/LICENSE
*/ */
import type { InputFileLocation, FileLocation } from "../layer"; import type { InputFileLocation, InputStickerSet } from "../layer";
import type { DownloadOptions } from "../lib/mtproto/apiFileManager"; import type { DownloadOptions } from "../lib/mtproto/apiFileManager";
export function getFileNameByLocation(location: InputFileLocation | FileLocation, options?: Partial<{ export function getFileNameByLocation(location: InputFileLocation, options?: Partial<{
fileName: string fileName: string
}>) { }>) {
const fileName = '';//(options?.fileName || '').split('.'); const fileName = '';//(options?.fileName || '').split('.');
@ -20,9 +20,17 @@ export function getFileNameByLocation(location: InputFileLocation | FileLocation
return (fileName[0] ? fileName[0] + '_' : '') + location.id + thumbPart + (ext ? '.' + ext : ext); return (fileName[0] ? fileName[0] + '_' : '') + location.id + thumbPart + (ext ? '.' + ext : ext);
} }
case 'fileLocationToBeDeprecated':
case 'inputPeerPhotoFileLocation': case 'inputPeerPhotoFileLocation':
case 'inputStickerSetThumb': return ['peerPhoto', location.photo_id, location.pFlags.big ? 'big' : 'small'].join('_');
case 'inputStickerSetThumb': {
const id = (location.stickerset as InputStickerSet.inputStickerSetID).id ||
(location.stickerset as InputStickerSet.inputStickerSetShortName).short_name ||
(location.stickerset as InputStickerSet.inputStickerSetDice).emoticon ||
location.stickerset._;
return ['stickerSetThumb', id, location.thumb_version].join('_');
}
case 'inputFileLocation': { case 'inputFileLocation': {
return location.volume_id + '_' + location.local_id + (ext ? '.' + ext : ext); return location.volume_id + '_' + location.local_id + (ext ? '.' + ext : ext);
} }
@ -42,4 +50,4 @@ export function getFileURL(type: FileURLType, options: DownloadOptions) {
//console.log('getFileURL encode:', performance.now() - perf, encoded); //console.log('getFileURL encode:', performance.now() - perf, encoded);
return '/' + type + '/' + encoded; return '/' + type + '/' + encoded;
} }

3394
src/layer.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
import { MOUNT_CLASS_TO } from "../../config/debug"; import { MOUNT_CLASS_TO } from "../../config/debug";
import { numberThousandSplitter } from "../../helpers/number"; import { numberThousandSplitter } from "../../helpers/number";
import { isObject, safeReplaceObject, copy, deepEqual } from "../../helpers/object"; import { isObject, safeReplaceObject, copy, deepEqual } from "../../helpers/object";
import { ChannelParticipant, Chat, ChatAdminRights, ChatBannedRights, ChatFull, ChatParticipants, InputChannel, InputChatPhoto, InputFile, InputPeer, SendMessageAction, Update, Updates } from "../../layer"; import { ChannelParticipant, Chat, ChatAdminRights, ChatBannedRights, ChatFull, ChatParticipant, ChatParticipants, InputChannel, InputChatPhoto, InputFile, InputPeer, SendMessageAction, Update, Updates } from "../../layer";
import { i18n, LangPackKey } from "../langPack"; import { i18n, LangPackKey } from "../langPack";
import apiManagerProxy from "../mtproto/mtprotoworker"; import apiManagerProxy from "../mtproto/mtprotoworker";
import apiManager from '../mtproto/mtprotoworker'; import apiManager from '../mtproto/mtprotoworker';
@ -742,11 +742,18 @@ export class AppChatsManager {
}); });
} }
public getParticipantPeerId(participant: ChannelParticipant | ChatParticipant) {
const peerId = (participant as ChannelParticipant.channelParticipantBanned).peer ?
appPeersManager.getPeerId((participant as ChannelParticipant.channelParticipantBanned).peer) :
(participant as ChatParticipant.chatParticipant).user_id;
return peerId;
}
public editBanned(id: number, participant: number | ChannelParticipant, banned_rights: ChatBannedRights) { public editBanned(id: number, participant: number | ChannelParticipant, banned_rights: ChatBannedRights) {
const userId = typeof(participant) === 'number' ? participant : participant.user_id; const peerId = typeof(participant) === 'number' ? participant : this.getParticipantPeerId(participant);
return apiManager.invokeApi('channels.editBanned', { return apiManager.invokeApi('channels.editBanned', {
channel: this.getChannelInput(id), channel: this.getChannelInput(id),
user_id: appUsersManager.getUserInput(userId), participant: appPeersManager.getInputPeerById(peerId),
banned_rights banned_rights
}).then((updates) => { }).then((updates) => {
this.onChatUpdated(id, updates); this.onChatUpdated(id, updates);
@ -759,15 +766,16 @@ export class AppChatsManager {
_: 'updateChannelParticipant', _: 'updateChannelParticipant',
channel_id: id, channel_id: id,
date: timestamp, date: timestamp,
//qts: 0, actor_id: undefined,
user_id: userId, qts: undefined,
user_id: peerId,
prev_participant: participant, prev_participant: participant,
new_participant: Object.keys(banned_rights.pFlags).length ? { new_participant: Object.keys(banned_rights.pFlags).length ? {
_: 'channelParticipantBanned', _: 'channelParticipantBanned',
date: timestamp, date: timestamp,
banned_rights, banned_rights,
kicked_by: appUsersManager.getSelf().id, kicked_by: appUsersManager.getSelf().id,
user_id: userId, peer: appPeersManager.getOutputPeer(peerId),
pFlags: {} pFlags: {}
} : undefined } : undefined
} as Update.updateChannelParticipant } as Update.updateChannelParticipant

View File

@ -705,7 +705,6 @@ export class AppMessagesManager {
w: options.width, w: options.width,
h: options.height, h: options.height,
type: 'full', type: 'full',
location: null,
size: file.size size: file.size
}; };
} else if(attachType === 'video') { } else if(attachType === 'video') {
@ -715,7 +714,6 @@ export class AppMessagesManager {
w: options.width, w: options.width,
h: options.height, h: options.height,
type: 'full', type: 'full',
location: null,
size: options.thumbBlob.size size: options.thumbBlob.size
}; };

View File

@ -15,7 +15,7 @@ import { CancellablePromise } from "../../helpers/cancellablePromise";
import { getFileNameByLocation } from "../../helpers/fileName"; import { getFileNameByLocation } from "../../helpers/fileName";
import { safeReplaceArrayInObject, defineNotNumerableProperties, isObject } from "../../helpers/object"; import { safeReplaceArrayInObject, defineNotNumerableProperties, isObject } from "../../helpers/object";
import { isSafari } from "../../helpers/userAgent"; import { isSafari } from "../../helpers/userAgent";
import { FileLocation, InputFileLocation, InputMedia, Photo, PhotoSize, PhotosPhotos } from "../../layer"; import { InputFileLocation, InputMedia, Photo, PhotoSize, PhotosPhotos } from "../../layer";
import apiManager from "../mtproto/mtprotoworker"; import apiManager from "../mtproto/mtprotoworker";
import referenceDatabase, { ReferenceContext } from "../mtproto/referenceDatabase"; import referenceDatabase, { ReferenceContext } from "../mtproto/referenceDatabase";
import { calcImageInBox } from "../../helpers/dom"; import { calcImageInBox } from "../../helpers/dom";
@ -274,13 +274,13 @@ export class AppPhotosManager {
// maybe it's a thumb // maybe it's a thumb
const isPhoto = (photoSize._ === 'photoSize' || photoSize._ === 'photoSizeProgressive') && photo.access_hash && photo.file_reference; const isPhoto = (photoSize._ === 'photoSize' || photoSize._ === 'photoSizeProgressive') && photo.access_hash && photo.file_reference;
const location: InputFileLocation.inputPhotoFileLocation | InputFileLocation.inputDocumentFileLocation | FileLocation = isPhoto ? { const location: InputFileLocation.inputPhotoFileLocation | InputFileLocation.inputDocumentFileLocation = {
_: isDocument ? 'inputDocumentFileLocation' : 'inputPhotoFileLocation', _: isDocument ? 'inputDocumentFileLocation' : 'inputPhotoFileLocation',
id: photo.id, id: photo.id,
access_hash: photo.access_hash, access_hash: photo.access_hash,
file_reference: photo.file_reference, file_reference: photo.file_reference,
thumb_size: photoSize.type thumb_size: photoSize.type
} : (photoSize as PhotoSize.photoSize).location; };
return { return {
dcId: photo.dc_id, dcId: photo.dc_id,

View File

@ -14,7 +14,7 @@ import { tsNow } from "../../helpers/date";
import { replaceContent } from "../../helpers/dom"; import { replaceContent } from "../../helpers/dom";
import renderImageFromUrl from "../../helpers/dom/renderImageFromUrl"; import renderImageFromUrl from "../../helpers/dom/renderImageFromUrl";
import sequentialDom from "../../helpers/sequentialDom"; import sequentialDom from "../../helpers/sequentialDom";
import { ChannelParticipantsFilter, ChannelsChannelParticipants, ChatFull, ChatParticipants, ChatPhoto, ExportedChatInvite, InputChannel, InputFile, InputFileLocation, PhotoSize, UserFull, UserProfilePhoto } from "../../layer"; import { ChannelParticipantsFilter, ChannelsChannelParticipants, Chat, ChatFull, ChatParticipants, ChatPhoto, ExportedChatInvite, InputChannel, InputFile, InputFileLocation, PhotoSize, UserFull, UserProfilePhoto } from "../../layer";
//import apiManager from '../mtproto/apiManager'; //import apiManager from '../mtproto/apiManager';
import apiManager from '../mtproto/mtprotoworker'; import apiManager from '../mtproto/mtprotoworker';
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
@ -97,10 +97,11 @@ export class AppProfileManager {
rootScope.on('chat_update', (chatId) => { rootScope.on('chat_update', (chatId) => {
const fullChat = this.chatsFull[chatId]; const fullChat = this.chatsFull[chatId];
const chat = appChatsManager.getChat(chatId); const chat: Chat.chat = appChatsManager.getChat(chatId);
if(!chat.photo || !fullChat) { if(!chat.photo || !fullChat) {
return; return;
} }
const emptyPhoto = chat.photo._ === 'chatPhotoEmpty'; const emptyPhoto = chat.photo._ === 'chatPhotoEmpty';
//////console.log('chat_update:', fullChat); //////console.log('chat_update:', fullChat);
if(fullChat.chat_photo && emptyPhoto !== (fullChat.chat_photo._ === 'photoEmpty')) { if(fullChat.chat_photo && emptyPhoto !== (fullChat.chat_photo._ === 'photoEmpty')) {
@ -112,9 +113,9 @@ export class AppProfileManager {
return; return;
} }
const smallUserpic = chat.photo.photo_small; const photoId = (chat.photo as ChatPhoto.chatPhoto).photo_id;
const smallPhotoSize = fullChat.chat_photo ? appPhotosManager.choosePhotoSize(fullChat.chat_photo as MyPhoto, 0, 0) : undefined; const chatFullPhotoId = fullChat.chat_photo?.id;
if(!smallPhotoSize || JSON.stringify(smallUserpic) !== JSON.stringify((smallPhotoSize as PhotoSize.photoSize).location)) { if(chatFullPhotoId !== photoId) {
delete this.chatsFull[chatId]; delete this.chatsFull[chatId];
rootScope.broadcast('chat_full_update', chatId); rootScope.broadcast('chat_full_update', chatId);
} }
@ -328,10 +329,10 @@ export class AppProfileManager {
} */ } */
} }
public getChannelParticipant(id: number, userId: number) { public getChannelParticipant(id: number, peerId: number) {
return apiManager.invokeApiSingle('channels.getParticipant', { return apiManager.invokeApiSingle('channels.getParticipant', {
channel: appChatsManager.getChannelInput(id), channel: appChatsManager.getChannelInput(id),
user_id: appUsersManager.getUserInput(userId) participant: appPeersManager.getInputPeerById(peerId),
}).then(channelParticipant => { }).then(channelParticipant => {
appUsersManager.saveApiUsers(channelParticipant.users); appUsersManager.saveApiUsers(channelParticipant.users);
return channelParticipant.participant; return channelParticipant.participant;
@ -452,8 +453,7 @@ export class AppProfileManager {
_: 'inputPeerPhotoFileLocation', _: 'inputPeerPhotoFileLocation',
pFlags: {}, pFlags: {},
peer: inputPeer, peer: inputPeer,
volume_id: photo[size].volume_id, photo_id: photo.photo_id
local_id: photo[size].local_id
}; };
if(size === 'photo_big') { if(size === 'photo_big') {
@ -536,7 +536,7 @@ export class AppProfileManager {
const photo = appPeersManager.getPeerPhoto(peerId); const photo = appPeersManager.getPeerPhoto(peerId);
const size: PeerPhotoSize = 'photo_small'; const size: PeerPhotoSize = 'photo_small';
const avatarAvailable = photo && photo[size]; const avatarAvailable = !!photo;
const avatarRendered = !!div.firstElementChild; const avatarRendered = !!div.firstElementChild;
const myId = rootScope.myId; const myId = rootScope.myId;

View File

@ -132,11 +132,10 @@ export class AppStickersManager {
const input: InputFileLocation.inputStickerSetThumb = { const input: InputFileLocation.inputStickerSetThumb = {
_: 'inputStickerSetThumb', _: 'inputStickerSetThumb',
stickerset: this.getStickerSetInput(stickerSet), stickerset: this.getStickerSetInput(stickerSet),
volume_id: thumb.location.volume_id, thumb_version: stickerSet.thumb_version
local_id: thumb.location.local_id
}; };
return {dcId, location: input, size: thumb.size, mimeType: isAnimated ? "application/x-tgsticker" : 'image/webp'}; return {dcId, location: input, size: thumb.size, mimeType: isAnimated ? 'application/x-tgsticker' : 'image/webp'};
} }
/* public getStickerSetThumbURL(stickerSet: MTStickerSet) { /* public getStickerSetThumbURL(stickerSet: MTStickerSet) {

View File

@ -15,7 +15,7 @@ import { CancellablePromise, deferredPromise } from "../../helpers/cancellablePr
import { notifyAll, notifySomeone } from "../../helpers/context"; import { notifyAll, notifySomeone } from "../../helpers/context";
import { getFileNameByLocation } from "../../helpers/fileName"; import { getFileNameByLocation } from "../../helpers/fileName";
import { nextRandomInt } from "../../helpers/random"; import { nextRandomInt } from "../../helpers/random";
import { FileLocation, InputFile, InputFileLocation, UploadFile } from "../../layer"; import { InputFile, InputFileLocation, UploadFile } from "../../layer";
import CacheStorageController from "../cacheStorage"; import CacheStorageController from "../cacheStorage";
import cryptoWorker from "../crypto/cryptoworker"; import cryptoWorker from "../crypto/cryptoworker";
import FileManager from "../filemanager"; import FileManager from "../filemanager";
@ -31,7 +31,7 @@ type Delayed = {
export type DownloadOptions = { export type DownloadOptions = {
dcId: number, dcId: number,
location: InputFileLocation | FileLocation, location: InputFileLocation,
size?: number, size?: number,
fileName?: string, fileName?: string,
mimeType?: string, mimeType?: string,
@ -150,7 +150,7 @@ export class ApiFileManager {
return false; return false;
} }
public requestFilePart(dcId: number, location: InputFileLocation | FileLocation, offset: number, limit: number, id = 0, queueId = 0, checkCancel?: () => void) { public requestFilePart(dcId: number, location: InputFileLocation, offset: number, limit: number, id = 0, queueId = 0, checkCancel?: () => void) {
return this.downloadRequest(dcId, id, async() => { return this.downloadRequest(dcId, id, async() => {
checkCancel && checkCancel(); checkCancel && checkCancel();

View File

@ -12,7 +12,7 @@ import { logger, LogTypes } from '../logger';
import type { DownloadOptions } from './apiFileManager'; import type { DownloadOptions } from './apiFileManager';
import type { WorkerTaskTemplate } from '../../types'; import type { WorkerTaskTemplate } from '../../types';
import { notifySomeone } from '../../helpers/context'; import { notifySomeone } from '../../helpers/context';
import type { InputFileLocation, FileLocation, UploadFile } from '../../layer'; import type { InputFileLocation, UploadFile } from '../../layer';
import { CancellablePromise, deferredPromise } from '../../helpers/cancellablePromise'; import { CancellablePromise, deferredPromise } from '../../helpers/cancellablePromise';
const log = logger('SW', LogTypes.Error | LogTypes.Debug | LogTypes.Log | LogTypes.Warn); const log = logger('SW', LogTypes.Error | LogTypes.Debug | LogTypes.Log | LogTypes.Warn);
@ -39,7 +39,7 @@ let taskId = 0;
export interface ServiceWorkerTask extends WorkerTaskTemplate { export interface ServiceWorkerTask extends WorkerTaskTemplate {
type: 'requestFilePart', type: 'requestFilePart',
payload: [number, InputFileLocation | FileLocation, number, number] payload: [number, InputFileLocation, number, number]
}; };
export interface ServiceWorkerTaskResponse extends WorkerTaskTemplate { export interface ServiceWorkerTaskResponse extends WorkerTaskTemplate {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ const fs = require('fs');
const allowedIPs = ['127.0.0.1']; const allowedIPs = ['127.0.0.1'];
const devMode = process.env.NODE_ENV !== 'production'; const devMode = process.env.NODE_ENV !== 'production';
const useLocal = true; const useLocal = true;
const useLocalNotLocal = false; const useLocalNotLocal = true;
if(devMode) { if(devMode) {
console.log('DEVMODE IS ON!'); console.log('DEVMODE IS ON!');