From febcb7cb354c929c54e1604907ad44d00fc993db Mon Sep 17 00:00:00 2001 From: morethanwords Date: Tue, 1 Sep 2020 22:59:49 +0300 Subject: [PATCH] Fix album order --- .../emoticonsDropdown/tabs/emoji.ts | 10 +++---- src/components/wrappers.ts | 28 +++++++++---------- src/lib/appManagers/appImManager.ts | 2 ++ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/components/emoticonsDropdown/tabs/emoji.ts b/src/components/emoticonsDropdown/tabs/emoji.ts index d002bd67..9d60c7cd 100644 --- a/src/components/emoticonsDropdown/tabs/emoji.ts +++ b/src/components/emoticonsDropdown/tabs/emoji.ts @@ -69,7 +69,7 @@ export default class EmojiTab implements EmoticonsTab { emoji = emoji.split('-').reduce((prev, curr) => prev + String.fromCodePoint(parseInt(curr, 16)), ''); - this.appendEmoji(emoji/* .replace(/[\ufe0f\u2640\u2642\u2695]/g, '') */, itemsDiv, false, false); + this.appendEmoji(emoji/* .replace(/[\ufe0f\u2640\u2642\u2695]/g, '') */, itemsDiv, false/* , false */); /* if(category == 'Smileys & Emotion') { console.log('appended emoji', emoji, itemsDiv.children[itemsDiv.childElementCount - 1].innerHTML, emojiUnicode(emoji)); @@ -122,7 +122,7 @@ export default class EmojiTab implements EmoticonsTab { this.init = null; } - private appendEmoji(emoji: string, container: HTMLElement, prepend = false, unified = false) { + private appendEmoji(emoji: string, container: HTMLElement, prepend = false/* , unified = false */) { //const emoji = details.unified; //const emoji = (details.unified as string).split('-') //.reduce((prev, curr) => prev + String.fromCodePoint(parseInt(curr, 16)), ''); @@ -130,7 +130,7 @@ export default class EmojiTab implements EmoticonsTab { const spanEmoji = document.createElement('span'); let kek: string; - if(unified) { + /* if(unified) { kek = RichTextProcessor.wrapRichText('_', { entities: [{ _: 'messageEntityEmoji', @@ -139,9 +139,9 @@ export default class EmojiTab implements EmoticonsTab { unicode: emoji }] }); - } else { + } else { */ kek = RichTextProcessor.wrapEmojiText(emoji); - } + //} /* if(!kek.includes('emoji')) { console.log(emoji, kek, spanEmoji, emoji.length, new TextEncoder().encode(emoji), emojiUnicode(emoji)); diff --git a/src/components/wrappers.ts b/src/components/wrappers.ts index 8c0cc731..b1e34714 100644 --- a/src/components/wrappers.ts +++ b/src/components/wrappers.ts @@ -718,35 +718,35 @@ export function wrapAlbum({groupID, attachmentDiv, middleware, uploading, lazyLo uploading?: boolean, isOut: boolean }) { - let items: {size: MTPhotoSize, media: any, message: any}[] = []; + const items: {size: MTPhotoSize, media: any, message: any}[] = []; - // higher msgID will be the last in album - let storage = appMessagesManager.groupedMessagesStorage[groupID]; - for(let mid in storage) { - let m = appMessagesManager.getMessage(+mid); - let media = m.media.photo || m.media.document; + // !higher msgID will be the FIRST in album + const storage = Object.keys(appMessagesManager.groupedMessagesStorage[groupID]).map(id => +id).sort((a, b) => a - b); + for(const mid of storage) { + const m = appMessagesManager.getMessage(mid); + const media = m.media.photo || m.media.document; - let size: any = media._ == 'photo' ? appPhotosManager.choosePhotoSize(media, 480, 480) : {w: media.w, h: media.h}; + const size: any = media._ == 'photo' ? appPhotosManager.choosePhotoSize(media, 480, 480) : {w: media.w, h: media.h}; items.push({size, media, message: m}); } - let spacing = 2; - let layouter = new Layouter(items.map(i => ({w: i.size.w, h: i.size.h})), mediaSizes.active.album.width, 100, spacing); - let layout = layouter.layout(); + const spacing = 2; + const layouter = new Layouter(items.map(i => ({w: i.size.w, h: i.size.h})), mediaSizes.active.album.width, 100, spacing); + const layout = layouter.layout(); //console.log('layout:', layout, items.map(i => ({w: i.size.w, h: i.size.h}))); /* let borderRadius = window.getComputedStyle(realParent).getPropertyValue('border-radius'); let brSplitted = fillPropertyValue(borderRadius); */ - for(let {geometry, sides} of layout) { - let item = items.shift(); + for(const {geometry, sides} of layout) { + const item = items.shift(); if(!item) { console.error('no item for layout!'); continue; } - let {size, media, message} = item; - let div = document.createElement('div'); + const {size, media, message} = item; + const div = document.createElement('div'); div.classList.add('album-item'); div.dataset.mid = message.mid; diff --git a/src/lib/appManagers/appImManager.ts b/src/lib/appManagers/appImManager.ts index 890603ad..1413f4ae 100644 --- a/src/lib/appManagers/appImManager.ts +++ b/src/lib/appManagers/appImManager.ts @@ -893,6 +893,8 @@ export class AppImManager { }); }); + targets.sort((a, b) => a.mid - b.mid); + let idx = targets.findIndex(t => t.mid == messageID); this.log('open mediaViewer single with ids:', ids, idx, targets);