From 94d0414fb0d9a3c58e794c2380ee87df53794b9f Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Wed, 20 Jul 2022 18:58:08 +0200 Subject: [PATCH] Bot description video & photo --- src/components/chat/bubbles.ts | 7 ++++++- src/components/wrappers/video.ts | 2 +- src/lib/appManagers/appPhotosManager.ts | 2 +- src/lib/appManagers/appProfileManager.ts | 8 ++++++++ src/lib/mtproto/referenceDatabase.ts | 12 +++++++++++- src/scss/partials/_chatBubble.scss | 4 ++++ 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/components/chat/bubbles.ts b/src/components/chat/bubbles.ts index 82271087..ecc3749c 100644 --- a/src/components/chat/bubbles.ts +++ b/src/components/chat/bubbles.ts @@ -3881,6 +3881,7 @@ export default class ChatBubbles { group: CHAT_ANIMATION_GROUP, loadPromises, autoDownload: this.chat.autoDownload, + noInfo: message.mid < 0 }); //} } else { @@ -4084,6 +4085,7 @@ export default class ChatBubbles { useSearch: !(message as Message.message).pFlags.is_scheduled, isScheduled: (message as Message.message).pFlags.is_scheduled } : undefined, + noInfo: message.mid < 0 }); } } else { @@ -5336,7 +5338,10 @@ export default class ChatBubbles { } const message = await this.generateLocalFirstMessage(false, (message) => { - message.message = userFull.bot_info.description; + const botInfo = userFull.bot_info; + message.message = botInfo.description; + if(botInfo.description_document) message.media = {_: 'messageMediaDocument', document: botInfo.description_document}; + if(botInfo.description_photo) message.media = {_: 'messageMediaPhoto', photo: botInfo.description_photo}; }); if(!middleware()) { diff --git a/src/components/wrappers/video.ts b/src/components/wrappers/video.ts index 7db1a23d..bd8e6561 100644 --- a/src/components/wrappers/video.ts +++ b/src/components/wrappers/video.ts @@ -68,7 +68,7 @@ export default async function wrapVideo({doc, container, message, boxWidth, boxH isOut?: boolean, middleware?: () => boolean, lazyLoadQueue?: LazyLoadQueue, - noInfo?: true, + noInfo?: boolean, noPlayButton?: boolean, group?: string, onlyPreview?: boolean, diff --git a/src/lib/appManagers/appPhotosManager.ts b/src/lib/appManagers/appPhotosManager.ts index 31de6492..b07634fb 100644 --- a/src/lib/appManagers/appPhotosManager.ts +++ b/src/lib/appManagers/appPhotosManager.ts @@ -26,7 +26,7 @@ export class AppPhotosManager extends AppManager { } = {}; public savePhoto(photo: Photo, context?: ReferenceContext) { - if(photo._ === 'photoEmpty') return undefined; + if(!photo || photo._ === 'photoEmpty') return; /* if(photo.id === TEST_FILE_REFERENCE) { console.warn('Testing FILE_REFERENCE_EXPIRED'); diff --git a/src/lib/appManagers/appProfileManager.ts b/src/lib/appManagers/appProfileManager.ts index 0cdbee98..a66edbc2 100644 --- a/src/lib/appManagers/appProfileManager.ts +++ b/src/lib/appManagers/appProfileManager.ts @@ -19,6 +19,7 @@ import getPeerId from "./utils/peers/getPeerId"; import getPhotoInput from "./utils/photos/getPhotoInput"; import getParticipantPeerId from "./utils/chats/getParticipantPeerId"; import ctx from "../../environment/ctx"; +import { ReferenceContext } from "../mtproto/referenceDatabase"; export type UserTyping = Partial<{userId: UserId, action: SendMessageAction, timeout: number}>; @@ -180,6 +181,13 @@ export class AppProfileManager extends AppManager { userFull.profile_photo = this.appPhotosManager.savePhoto(userFull.profile_photo, {type: 'profilePhoto', peerId}); } + const botInfo = userFull.bot_info; + if(botInfo) { + const referenceContext: ReferenceContext = {type: 'userFull', userId: id}; + botInfo.description_document = this.appDocsManager.saveDoc(botInfo.description_document, referenceContext); + botInfo.description_photo = this.appPhotosManager.savePhoto(botInfo.description_photo, referenceContext); + } + this.appNotificationsManager.savePeerSettings({ peerId, settings: userFull.notify_settings diff --git a/src/lib/mtproto/referenceDatabase.ts b/src/lib/mtproto/referenceDatabase.ts index e7ad34ea..ecc9767f 100644 --- a/src/lib/mtproto/referenceDatabase.ts +++ b/src/lib/mtproto/referenceDatabase.ts @@ -10,7 +10,7 @@ import bytesToHex from "../../helpers/bytes/bytesToHex"; import deepEqual from "../../helpers/object/deepEqual"; import { AppManager } from "../appManagers/manager"; -export type ReferenceContext = ReferenceContext.referenceContextProfilePhoto | ReferenceContext.referenceContextMessage | ReferenceContext.referenceContextEmojiesSounds | ReferenceContext.referenceContextReactions; +export type ReferenceContext = ReferenceContext.referenceContextProfilePhoto | ReferenceContext.referenceContextMessage | ReferenceContext.referenceContextEmojiesSounds | ReferenceContext.referenceContextReactions | ReferenceContext.referenceContextUserFull; export namespace ReferenceContext { export type referenceContextProfilePhoto = { type: 'profilePhoto', @@ -30,6 +30,11 @@ export namespace ReferenceContext { export type referenceContextReactions = { type: 'reactions' }; + + export type referenceContextUserFull = { + type: 'userFull', + userId: UserId + }; } export type ReferenceBytes = Photo.photo['file_reference']; @@ -139,6 +144,11 @@ export class ReferenceDatabase extends AppManager { break; } + case 'userFull': { + promise = Promise.resolve(this.appProfileManager.getProfile(context.userId, true)); + break; + } + default: { this.log.warn('refreshReference: not implemented context', context); return Promise.reject(); diff --git a/src/scss/partials/_chatBubble.scss b/src/scss/partials/_chatBubble.scss index 42982232..3bbe860d 100644 --- a/src/scss/partials/_chatBubble.scss +++ b/src/scss/partials/_chatBubble.scss @@ -935,6 +935,10 @@ $bubble-beside-button-width: 38px; flex: 1 1 auto; } + .attachment { + pointer-events: none; + } + .bubble-content-wrapper { max-width: 100%; }