Browse Source

Fixed travel by message id (search by date)

master
morethanwords 4 years ago
parent
commit
6832fdc551
  1. 2
      src/lib/appManagers/appDialogsManager.ts
  2. 29
      src/lib/appManagers/appImManager.ts
  3. 4
      src/lib/appManagers/appMessagesManager.ts
  4. 12
      src/lib/utils.ts
  5. 2
      src/scss/partials/_chatBubble.scss

2
src/lib/appManagers/appDialogsManager.ts

@ -929,7 +929,7 @@ export class AppDialogsManager {
} }
} }
if(lastMessage._ == 'messageEmpty') { if(lastMessage._ == 'messageEmpty' || (lastMessage._ == 'messageService' && !lastMessage.rReply)) {
dom.lastMessageSpan.innerHTML = ''; dom.lastMessageSpan.innerHTML = '';
dom.lastTimeSpan.innerHTML = ''; dom.lastTimeSpan.innerHTML = '';
delete dom.listEl.dataset.mid; delete dom.listEl.dataset.mid;

29
src/lib/appManagers/appImManager.ts

@ -1,6 +1,6 @@
//import apiManager from '../mtproto/apiManager'; //import apiManager from '../mtproto/apiManager';
import apiManager from '../mtproto/mtprotoworker'; import apiManager from '../mtproto/mtprotoworker';
import { $rootScope, numberWithCommas, findUpClassName, formatNumber, placeCaretAtEnd, findUpTag, langPack, whichChild, cancelEvent } from "../utils"; import { $rootScope, numberWithCommas, findUpClassName, formatNumber, placeCaretAtEnd, findUpTag, langPack, whichChild, cancelEvent, getObjectKeysAndSort } from "../utils";
import appUsersManager from "./appUsersManager"; import appUsersManager from "./appUsersManager";
import appMessagesManager, { Dialog } from "./appMessagesManager"; import appMessagesManager, { Dialog } from "./appMessagesManager";
import appPeersManager from "./appPeersManager"; import appPeersManager from "./appPeersManager";
@ -44,8 +44,6 @@ appSidebarLeft; // just to include
const testScroll = false; const testScroll = false;
const IGNOREACTIONS = ['messageActionChannelMigrateFrom'];
class ChatContextMenu { class ChatContextMenu {
private element = document.getElementById('bubble-contextmenu') as HTMLDivElement; private element = document.getElementById('bubble-contextmenu') as HTMLDivElement;
private buttons: { private buttons: {
@ -671,7 +669,7 @@ export class AppImManager {
// set new mids to album items for mediaViewer // set new mids to album items for mediaViewer
if(message.grouped_id) { if(message.grouped_id) {
let items = bubble.querySelectorAll('.album-item'); let items = bubble.querySelectorAll('.album-item');
let groupIDs = Object.keys(appMessagesManager.groupedMessagesStorage[message.grouped_id]).map(i => +i).sort((a, b) => a - b); let groupIDs = getObjectKeysAndSort(appMessagesManager.groupedMessagesStorage[message.grouped_id]);
(Array.from(items) as HTMLElement[]).forEach((item, idx) => { (Array.from(items) as HTMLElement[]).forEach((item, idx) => {
item.dataset.mid = '' + groupIDs[idx]; item.dataset.mid = '' + groupIDs[idx];
}); });
@ -1393,6 +1391,13 @@ export class AppImManager {
////console.timeEnd('appImManager cleanup'); ////console.timeEnd('appImManager cleanup');
} }
private findMountedBubbleByMsgID(mid: number) {
return this.bubbles[getObjectKeysAndSort(this.bubbles).find(id => {
if(id < mid) return false;
return !!this.bubbles[id]?.parentElement;
})];
}
public setPeer(peerID: number, lastMsgID?: number) { public setPeer(peerID: number, lastMsgID?: number) {
//console.time('appImManager setPeer'); //console.time('appImManager setPeer');
//console.time('appImManager setPeer pre promise'); //console.time('appImManager setPeer pre promise');
@ -1434,8 +1439,9 @@ export class AppImManager {
if(samePeer) { if(samePeer) {
if(this.bubbles[lastMsgID]) { if(this.bubbles[lastMsgID]) {
if(isTarget) { if(isTarget) {
this.scrollable.scrollIntoView(this.bubbles[lastMsgID]); const bubble = this.findMountedBubbleByMsgID(lastMsgID);
this.highlightBubble(this.bubbles[lastMsgID]); this.scrollable.scrollIntoView(bubble);
this.highlightBubble(bubble);
} else if(dialog && lastMsgID == topMessage) { } else if(dialog && lastMsgID == topMessage) {
this.log('will scroll down', this.scroll.scrollTop, this.scroll.scrollHeight); this.log('will scroll down', this.scroll.scrollTop, this.scroll.scrollHeight);
this.scroll.scrollTop = this.scroll.scrollHeight; this.scroll.scrollTop = this.scroll.scrollHeight;
@ -1545,7 +1551,10 @@ export class AppImManager {
this.scrollable.scrollTop = this.scrollable.scrollHeight; this.scrollable.scrollTop = this.scrollable.scrollHeight;
} }
const bubble = forwardingUnread ? (this.firstUnreadBubble || this.bubbles[lastMsgID]) : this.bubbles[lastMsgID]; let bubble: HTMLElement = forwardingUnread ? (this.firstUnreadBubble || this.bubbles[lastMsgID]) : this.bubbles[lastMsgID];
if(!bubble?.parentElement) {
bubble = this.findMountedBubbleByMsgID(lastMsgID);
}
this.scrollable.scrollIntoView(bubble, samePeer/* , fromUp */); this.scrollable.scrollIntoView(bubble, samePeer/* , fromUp */);
if(!forwardingUnread) { if(!forwardingUnread) {
@ -1722,7 +1731,7 @@ export class AppImManager {
} }
} }
public highlightBubble(element: HTMLDivElement) { public highlightBubble(element: HTMLElement) {
if(element.dataset.timeout) { if(element.dataset.timeout) {
clearTimeout(+element.dataset.timeout); clearTimeout(+element.dataset.timeout);
element.classList.remove('is-selected'); element.classList.remove('is-selected');
@ -1933,7 +1942,7 @@ export class AppImManager {
if(message._ == 'messageService') { if(message._ == 'messageService') {
let action = message.action; let action = message.action;
let _ = action._; let _ = action._;
if(IGNOREACTIONS.indexOf(_) !== -1) { if(langPack.hasOwnProperty(_) && !langPack[_]) {
return bubble; return bubble;
} }
@ -2823,7 +2832,7 @@ export class AppImManager {
let ids: number[]; let ids: number[];
if((reverse && this.loadedTopTimes > 2) || (!reverse && this.loadedBottomTimes > 2)) { if((reverse && this.loadedTopTimes > 2) || (!reverse && this.loadedBottomTimes > 2)) {
ids = Object.keys(this.bubbles).map(i => +i).sort((a, b) => a - b); ids = getObjectKeysAndSort(this.bubbles);
} }
//let removeCount = loadCount / 2; //let removeCount = loadCount / 2;

4
src/lib/appManagers/appMessagesManager.ts

@ -2389,7 +2389,7 @@ export class AppMessagesManager {
break; break;
case 'messageActionHistoryClear': case 'messageActionHistoryClear':
apiMessage.deleted = true; //apiMessage.deleted = true;
apiMessage.clear_history = true; apiMessage.clear_history = true;
apiMessage.pFlags.out = false; apiMessage.pFlags.out = false;
apiMessage.pFlags.unread = false; apiMessage.pFlags.unread = false;
@ -2505,7 +2505,7 @@ export class AppMessagesManager {
//this.log('message action:', action); //this.log('message action:', action);
messageText = '<i>' + str + '</i>'; messageText = str ? '<i>' + str + '</i>' : '';
} }
let messageWrapped = ''; let messageWrapped = '';

12
src/lib/utils.ts

@ -222,7 +222,7 @@ export function generatePathData(x: number, y: number, width: number, height: nu
return data.join(' '); return data.join(' ');
}; };
export const langPack = { export const langPack: {[actionType: string]: string} = {
"messageActionChatCreate": "created the group", "messageActionChatCreate": "created the group",
"messageActionChatEditTitle": "changed group name", "messageActionChatEditTitle": "changed group name",
"messageActionChatEditPhoto": "changed group photo", "messageActionChatEditPhoto": "changed group photo",
@ -240,7 +240,9 @@ export const langPack = {
"messageActionChannelEditTitle": "Channel renamed", "messageActionChannelEditTitle": "Channel renamed",
"messageActionChannelEditPhoto": "Channel photo updated", "messageActionChannelEditPhoto": "Channel photo updated",
"messageActionChannelDeletePhoto": "Channel photo removed", "messageActionChannelDeletePhoto": "Channel photo removed",
"messageActionHistoryClear": "History cleared", "messageActionHistoryClear": "",//"History cleared",
"messageActionChannelMigrateFrom": "",
"messageActionPhoneCall.in_ok": "Incoming Call", "messageActionPhoneCall.in_ok": "Incoming Call",
"messageActionPhoneCall.out_ok": "Outgoing Call", "messageActionPhoneCall.out_ok": "Outgoing Call",
@ -311,6 +313,12 @@ export function findUpAttribute(el: any, attribute: string): HTMLElement {
return null; return null;
} }
export function getObjectKeysAndSort(object: any, sort: 'asc' | 'desc' = 'asc') {
const ids = Object.keys(object).map(i => +i);
if(sort == 'asc') return ids.sort((a, b) => a - b);
else return ids.sort((a, b) => b - a);
}
export function whichChild(elem: Node) { export function whichChild(elem: Node) {
let i = 0; let i = 0;
// @ts-ignore // @ts-ignore

2
src/scss/partials/_chatBubble.scss

@ -301,7 +301,7 @@ $bubble-margin: .25rem;
&:not(.sticker) .attachment { &:not(.sticker) .attachment {
padding-top: .5rem; padding-top: .5rem;
padding-bottom: 1.5rem; padding-bottom: 1.5rem;
max-width: fit-content!important; //max-width: fit-content!important;
max-height: fit-content!important; max-height: fit-content!important;
span.emoji { span.emoji {

Loading…
Cancel
Save