Telegram Web K with changes to work inside I2P https://web.telegram.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.3 KiB

5 years ago
import { $rootScope, safeReplaceObject, copy } from "../utils";
import appPhotosManager from "./appPhotosManager";
import appDocsManager from "./appDocsManager";
import { RichTextProcessor } from "../richtextprocessor";
class AppWebPagesManager {
webpages: any = {};
pendingWebPages: any = {};
constructor() {
$rootScope.$on('apiUpdate', (e: CustomEvent) => {
let update = e.detail;
5 years ago
switch(update._) {
case 'updateWebPage':
5 years ago
this.saveWebPage(update.webpage);
break;
}
5 years ago
});
}
public saveWebPage(apiWebPage: any, messageID?: number, mediaContext?: any) {
5 years ago
if(apiWebPage.photo && apiWebPage.photo._ === 'photo') {
//appPhotosManager.savePhoto(apiWebPage.photo, mediaContext);
apiWebPage.photo = appPhotosManager.savePhoto(apiWebPage.photo, mediaContext);
} else {
5 years ago
delete apiWebPage.photo;
}
5 years ago
if(apiWebPage.document && apiWebPage.document._ === 'document') {
apiWebPage.document = appDocsManager.saveDoc(apiWebPage.document, mediaContext); // warning 11.04.2020
} else {
5 years ago
if(apiWebPage.type == 'document') {
delete apiWebPage.type;
}
5 years ago
delete apiWebPage.document;
}
5 years ago
var siteName = apiWebPage.site_name;
var shortTitle = apiWebPage.title || apiWebPage.author || siteName || '';
if(siteName && shortTitle == siteName) {
delete apiWebPage.site_name;
}
5 years ago
if(shortTitle.length > 100) {
shortTitle = shortTitle.substr(0, 80) + '...';
}
5 years ago
apiWebPage.rTitle = RichTextProcessor.wrapRichText(shortTitle, {noLinks: true, noLinebreaks: true});
var contextHashtag = '';
if(siteName == 'GitHub') {
var matches = apiWebPage.url.match(/(https?:\/\/github\.com\/[^\/]+\/[^\/]+)/);
if(matches) {
contextHashtag = matches[0] + '/issues/{1}';
}
}
5 years ago
// delete apiWebPage.description
5 years ago
var shortDescriptionText = (apiWebPage.description || '');
if(shortDescriptionText.length > 180) {
shortDescriptionText = shortDescriptionText.substr(0, 150).replace(/(\n|\s)+$/, '') + '...';
}
apiWebPage.rDescription = RichTextProcessor.wrapRichText(shortDescriptionText, {
contextSite: siteName || 'external',
contextHashtag: contextHashtag
});
5 years ago
if(apiWebPage.type != 'photo' &&
apiWebPage.type != 'video' &&
apiWebPage.type != 'gif' &&
apiWebPage.type != 'document' &&
!apiWebPage.description &&
apiWebPage.photo) {
5 years ago
apiWebPage.type = 'photo';
}
5 years ago
if(messageID) {
if(this.pendingWebPages[apiWebPage.id] === undefined) {
this.pendingWebPages[apiWebPage.id] = {};
}
5 years ago
this.pendingWebPages[apiWebPage.id][messageID] = true;
this.webpages[apiWebPage.id] = apiWebPage;
}
5 years ago
if(this.webpages[apiWebPage.id] === undefined) {
this.webpages[apiWebPage.id] = apiWebPage;
} else {
5 years ago
safeReplaceObject(this.webpages[apiWebPage.id], apiWebPage);
}
5 years ago
if(!messageID && this.pendingWebPages[apiWebPage.id] !== undefined) {
var msgs = [];
for(let msgID in this.pendingWebPages[apiWebPage.id]) {
msgs.push(msgID);
}
$rootScope.$broadcast('webpage_updated', {
id: apiWebPage.id,
msgs: msgs
5 years ago
});
}
}
public getWebPage(id: string) {
return this.webpages[id];
}
}
export default new AppWebPagesManager();