Skip to content

Commit 99b5f29

Browse files
Merge branch 'master' into age-verification
2 parents 3df35cb + a4bfd78 commit 99b5f29

File tree

4 files changed

+62
-29
lines changed

4 files changed

+62
-29
lines changed

src/components/wrappers/document.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* https://github.com/morethanwords/tweb/blob/master/LICENSE
55
*/
66

7+
import {isIpRevealingExtension, isIpRevealingMimeType} from '../../environment/ipRevealingDocuments';
78
import MEDIA_MIME_TYPES_SUPPORTED from '../../environment/mediaMimeTypesSupport';
89
import {CancellablePromise} from '../../helpers/cancellablePromise';
910
import {clearBadCharsAndTrim} from '../../helpers/cleanSearchText';
@@ -339,7 +340,7 @@ export default async function wrapDocument({message,
339340
} else {
340341
download = appDownloadManager.downloadToDisc({media: doc, queueId});
341342

342-
if(doc.mime_type === 'image/svg+xml') {
343+
if(isIpRevealingMimeType(doc.mime_type) || isIpRevealingExtension(ext)) {
343344
confirmationPopup({
344345
descriptionLangKey: 'Chat.File.QuickLook.Svg',
345346
button: {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// https://github.com/telegramdesktop/tdesktop/blob/0514f13af0d7d1686944e7ba909df2dab16a6f5e/Telegram/SourceFiles/core/mime_type.cpp#L327
2+
const extensionsSet = new Set(['htm', 'html', 'svg', 'm4v', 'm3u', 'm3u8', 'xhtml', 'xml']);
3+
const mimeTypesSet = new Set(['text/html', 'image/svg+xml']);
4+
5+
export const isIpRevealingExtension = (extension: string) => extensionsSet.has(extension);
6+
export const isIpRevealingMimeType = (mimeType: string) => mimeTypesSet.has(mimeType);

src/lib/appManagers/appMessagesManager.ts

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {MyDocument} from './appDocsManager';
2828
import {MyPhoto} from './appPhotosManager';
2929
import DEBUG from '../../config/debug';
3030
import SlicedArray, {Slice, SliceEnd} from '../../helpers/slicedArray';
31-
import {FOLDER_ID_ALL, FOLDER_ID_ARCHIVE, GENERAL_TOPIC_ID, HIDDEN_PEER_ID, MUTE_UNTIL, NULL_PEER_ID, REAL_FOLDERS, REAL_FOLDER_ID, REPLIES_HIDDEN_CHANNEL_ID, REPLIES_PEER_ID, SERVICE_PEER_ID, TEST_NO_SAVED, THUMB_TYPE_FULL} from '../mtproto/mtproto_config';
31+
import {FOLDER_ID_ALL, FOLDER_ID_ARCHIVE, GENERAL_TOPIC_ID, HIDDEN_PEER_ID, MESSAGES_ALBUM_MAX_SIZE, MUTE_UNTIL, NULL_PEER_ID, REAL_FOLDERS, REAL_FOLDER_ID, REPLIES_HIDDEN_CHANNEL_ID, REPLIES_PEER_ID, SERVICE_PEER_ID, TEST_NO_SAVED, THUMB_TYPE_FULL} from '../mtproto/mtproto_config';
3232
import {getMiddleware} from '../../helpers/middleware';
3333
import assumeType from '../../helpers/assumeType';
3434
import copy from '../../helpers/object/copy';
@@ -7948,35 +7948,60 @@ export class AppMessagesManager extends AppManager {
79487948
}
79497949
}
79507950

7951-
// * load grouped missing messages
7952-
const firstMessage = messages[0] as Message.message;
7953-
const lastMessage = messages[messages.length - 1] as Message.message;
7951+
// * load grouped missing messages (only once per recursion)
7952+
if(!inputFilter && !recursion) {
7953+
const firstMessage = messages[0] as Message.message;
7954+
const lastMessage = messages[messages.length - 1] as Message.message;
79547955

7955-
// if(!inputFilter && !isBottomEnd && firstMessage?.grouped_id) {
7956-
// await this.getHistory({
7957-
// ...options,
7958-
// offsetId: firstMessage.mid,
7959-
// limit: 20,
7960-
// addOffset: -10
7961-
// });
7956+
const fillMissingGroupedMessages = async(bottom: boolean) => {
7957+
if(!middleware()) {
7958+
return;
7959+
}
79627960

7963-
// if(!middleware()) {
7964-
// return;
7965-
// }
7966-
// }
7961+
const {
7962+
isEnd,
7963+
history,
7964+
messages = history.map((mid) => this.getMessageByPeer(peerId, mid))
7965+
} = await this.getHistory({
7966+
...options,
7967+
offsetId: (bottom ? firstMessage : lastMessage).mid,
7968+
limit: (MESSAGES_ALBUM_MAX_SIZE + 1) * 2,
7969+
addOffset: -(MESSAGES_ALBUM_MAX_SIZE + 1)
7970+
});
79677971

7968-
// if(!inputFilter && !isTopEnd && lastMessage?.grouped_id && lastMessage.grouped_id !== firstMessage?.grouped_id) {
7969-
// await this.getHistory({
7970-
// ...options,
7971-
// offsetId: lastMessage.mid,
7972-
// limit: 20,
7973-
// addOffset: -10
7974-
// });
7972+
if(!middleware()) {
7973+
return;
7974+
}
79757975

7976-
// if(!middleware()) {
7977-
// return;
7978-
// }
7979-
// }
7976+
// * erase unfilled grouped messages if they're last elements in their history slices
7977+
if(!isEnd[bottom ? 'bottom' : 'top']) {
7978+
if(!bottom) messages.reverse();
7979+
const messagesSlice = messages.slice(0, MESSAGES_ALBUM_MAX_SIZE) as Message.message[];
7980+
const groupedIds = messagesSlice.map((message) => message.grouped_id);
7981+
const slice = messagesSlice[0] && historyStorage.history.findSlice(messagesSlice[0].mid);
7982+
if(
7983+
groupedIds[0] &&
7984+
groupedIds[0] !== groupedIds[MESSAGES_ALBUM_MAX_SIZE - 1] &&
7985+
slice?.index === (bottom ? 0 : slice.slice.length - 1)
7986+
) {
7987+
messagesSlice.forEach((message) => {
7988+
if(message.grouped_id === groupedIds[0]) {
7989+
historyStorage.history.delete(message.mid);
7990+
}
7991+
});
7992+
}
7993+
}
7994+
};
7995+
7996+
7997+
if(!isBottomEnd && firstMessage?.grouped_id) {
7998+
await fillMissingGroupedMessages(true);
7999+
}
8000+
8001+
if(!isTopEnd && lastMessage?.grouped_id && lastMessage.grouped_id !== firstMessage?.grouped_id) {
8002+
await fillMissingGroupedMessages(false);
8003+
}
8004+
}
79808005
// * grouped end
79818006

79828007
if(options.threadId) {
@@ -8085,8 +8110,8 @@ export class AppMessagesManager extends AppManager {
80858110
return this.getHistory({
80868111
peerId: message.peerId,
80878112
offsetId: message.mid,
8088-
limit: 20,
8089-
addOffset: -10
8113+
limit: (MESSAGES_ALBUM_MAX_SIZE + 1) * 2,
8114+
addOffset: -(MESSAGES_ALBUM_MAX_SIZE + 1)
80908115
});
80918116
}));
80928117
if(!middleware()) {

src/lib/mtproto/mtproto_config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const MAX_FILE_SAVE_SIZE = 20 * 1024 * 1024;
2424
export const THUMB_TYPE_FULL = '';
2525
export const TOPIC_COLORS = [0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, 0xFB6F5F];
2626
export const ATTACH_MENU_BOT_ICON_NAME = 'default_static';
27+
export const MESSAGES_ALBUM_MAX_SIZE = 10;
2728
export const MESSAGE_ID_OFFSET = 0x100000000;
2829
export const GENERAL_TOPIC_ID = MESSAGE_ID_OFFSET + 1;
2930
export const CAN_HIDE_TOPIC = false;

0 commit comments

Comments
 (0)