Browse Source

Fix chat menu opening

Generate sending from_id
master
Eduard Kuzmenko 4 years ago
parent
commit
0ff02268ee
  1. 6
      src/components/buttonMenuToggle.ts
  2. 5
      src/components/chat/bubbles.ts
  3. 11
      src/components/chat/topbar.ts
  4. 109
      src/lib/appManagers/appMessagesManager.ts

6
src/components/buttonMenuToggle.ts

@ -4,7 +4,7 @@ import ButtonIcon from "./buttonIcon";
import ButtonMenu, { ButtonMenuItemOptions } from "./buttonMenu"; import ButtonMenu, { ButtonMenuItemOptions } from "./buttonMenu";
import { closeBtnMenu, openBtnMenu } from "./misc"; import { closeBtnMenu, openBtnMenu } from "./misc";
const ButtonMenuToggle = (options: Partial<{noRipple: true, onlyMobile: true, listenerSetter: ListenerSetter}> = {}, direction: 'bottom-left' | 'top-left', buttons: ButtonMenuItemOptions[], onOpen?: () => void) => { const ButtonMenuToggle = (options: Partial<{noRipple: true, onlyMobile: true, listenerSetter: ListenerSetter}> = {}, direction: 'bottom-left' | 'top-left', buttons: ButtonMenuItemOptions[], onOpen?: (e: Event) => void) => {
const button = ButtonIcon('more btn-menu-toggle', options); const button = ButtonIcon('more btn-menu-toggle', options);
const btnMenu = ButtonMenu(buttons, options.listenerSetter); const btnMenu = ButtonMenu(buttons, options.listenerSetter);
@ -15,7 +15,7 @@ const ButtonMenuToggle = (options: Partial<{noRipple: true, onlyMobile: true, li
}; };
// TODO: refactor for attachClickEvent, because if move finger after touchstart, it will start anyway // TODO: refactor for attachClickEvent, because if move finger after touchstart, it will start anyway
const ButtonMenuToggleHandler = (el: HTMLElement, onOpen?: () => void, options?: AttachClickOptions) => { const ButtonMenuToggleHandler = (el: HTMLElement, onOpen?: (e: Event) => void, options?: AttachClickOptions) => {
const add = options?.listenerSetter ? options.listenerSetter.add.bind(options.listenerSetter, el) : el.addEventListener.bind(el); const add = options?.listenerSetter ? options.listenerSetter.add.bind(options.listenerSetter, el) : el.addEventListener.bind(el);
add(CLICK_EVENT_NAME, (e: Event) => { add(CLICK_EVENT_NAME, (e: Event) => {
@ -29,7 +29,7 @@ const ButtonMenuToggleHandler = (el: HTMLElement, onOpen?: () => void, options?:
if(el.classList.contains('menu-open')) { if(el.classList.contains('menu-open')) {
closeBtnMenu(); closeBtnMenu();
} else { } else {
onOpen && onOpen(); onOpen && onOpen(e);
openBtnMenu(openedMenu); openBtnMenu(openedMenu);
} }
}); });

5
src/components/chat/bubbles.ts

@ -2120,7 +2120,8 @@ export default class ChatBubbles {
let savedFrom = ''; let savedFrom = '';
if((this.peerId < 0 && !our) || message.fwd_from || message.reply_to_mid) { // chat const needName = (peerId < 0 && (peerId != message.fromId || our)) && message.fromId !== rootScope.myId;
if(needName || message.fwd_from || message.reply_to_mid) { // chat
let title = this.appPeersManager.getPeerTitle(message.fwdFromId || message.fromId); let title = this.appPeersManager.getPeerTitle(message.fwdFromId || message.fromId);
const isForwardFromChannel = message.from_id && message.from_id._ == 'peerChannel' && message.fromId == message.fwdFromId; const isForwardFromChannel = message.from_id && message.from_id._ == 'peerChannel' && message.fromId == message.fwdFromId;
@ -2186,7 +2187,7 @@ export default class ChatBubbles {
bubble.classList.add('is-reply'); bubble.classList.add('is-reply');
} }
if(!bubble.classList.contains('sticker') && (peerId < 0 && (peerId != message.fromId || our)) && message.fromId !== rootScope.myId) { if(!bubble.classList.contains('sticker') && needName) {
let nameDiv = document.createElement('div'); let nameDiv = document.createElement('div');
nameDiv.classList.add('name'); nameDiv.classList.add('name');
nameDiv.innerHTML = title; nameDiv.innerHTML = title;

11
src/components/chat/topbar.ts

@ -97,7 +97,8 @@ export default class ChatTopbar {
this.chatAudio = new ChatAudio(this, this.chat, this.appMessagesManager, this.appPeersManager); this.chatAudio = new ChatAudio(this, this.chat, this.appMessagesManager, this.appPeersManager);
if(this.menuButtons.length) { if(this.menuButtons.length) {
this.btnMore = ButtonMenuToggle({listenerSetter: this.listenerSetter}, 'bottom-left', this.menuButtons, () => { this.btnMore = ButtonMenuToggle({listenerSetter: this.listenerSetter}, 'bottom-left', this.menuButtons, (e) => {
cancelEvent(e);
this.menuButtons.forEach(button => { this.menuButtons.forEach(button => {
button.element.classList.toggle('hide', !button.verify()); button.element.classList.toggle('hide', !button.verify());
}); });
@ -118,7 +119,7 @@ export default class ChatTopbar {
this.listenerSetter.add(window, 'resize', this.onResize); this.listenerSetter.add(window, 'resize', this.onResize);
mediaSizes.addListener('changeScreen', this.onChangeScreen); mediaSizes.addListener('changeScreen', this.onChangeScreen);
this.listenerSetter.add(this.container, 'click', (e) => { attachClickEvent(this.container, (e) => {
const container: HTMLElement = findUpClassName(e.target, 'pinned-container'); const container: HTMLElement = findUpClassName(e.target, 'pinned-container');
if(container) { if(container) {
cancelEvent(e); cancelEvent(e);
@ -135,12 +136,12 @@ export default class ChatTopbar {
} else { } else {
this.appSidebarRight.toggleSidebar(true); this.appSidebarRight.toggleSidebar(true);
} }
}); }, {listenerSetter: this.listenerSetter});
this.listenerSetter.add(this.btnBack, 'click', (e) => { attachClickEvent(this.btnBack, (e) => {
cancelEvent(e); cancelEvent(e);
this.chat.appImManager.setPeer(0); this.chat.appImManager.setPeer(0);
}); }, {listenerSetter: this.listenerSetter});
} }
public constructPeerHelpers() { public constructPeerHelpers() {

109
src/lib/appManagers/appMessagesManager.ts

@ -455,45 +455,28 @@ export class AppMessagesManager {
peerId = appPeersManager.getPeerMigratedTo(peerId) || peerId; peerId = appPeersManager.getPeerMigratedTo(peerId) || peerId;
var entities = options.entities || []; let entities = options.entities || [];
if(!options.viaBotId) { if(!options.viaBotId) {
text = RichTextProcessor.parseMarkdown(text, entities); text = RichTextProcessor.parseMarkdown(text, entities);
} }
var sendEntites = this.getInputEntities(entities); let sendEntites = this.getInputEntities(entities);
if(!sendEntites.length) { if(!sendEntites.length) {
sendEntites = undefined; sendEntites = undefined;
} }
var messageId = this.generateTempMessageId(peerId); const messageId = this.generateTempMessageId(peerId);
var randomIdS = randomLong(); const randomIdS = randomLong();
var pFlags: any = {}; const replyToMsgId = options.replyToMsgId ? this.getLocalMessageId(options.replyToMsgId) : undefined;
var replyToMsgId = options.replyToMsgId ? this.getLocalMessageId(options.replyToMsgId) : undefined; const isChannel = appPeersManager.isChannel(peerId);
var isChannel = appPeersManager.isChannel(peerId); const isBroadcast = appPeersManager.isBroadcast(peerId);
var isMegagroup = isChannel && appPeersManager.isMegagroup(peerId);
var asChannel = isChannel && !isMegagroup ? true : false;
var message: any;
var fromId = appUsersManager.getSelf().id;
if(peerId != fromId) {
pFlags.out = true;
if(!isChannel && !appUsersManager.isBot(peerId)) {
pFlags.unread = true;
}
}
if(asChannel) {
fromId = 0;
pFlags.post = true;
}
message = { const message: any = {
_: 'message', _: 'message',
id: messageId, id: messageId,
from_id: appPeersManager.getOutputPeer(fromId), from_id: this.generateFromId(peerId),
peer_id: appPeersManager.getOutputPeer(peerId), peer_id: appPeersManager.getOutputPeer(peerId),
pFlags, pFlags: this.generateFlags(peerId),
date: options.scheduleDate || (tsNow(true) + serverTimeManager.serverTimeOffset), date: options.scheduleDate || (tsNow(true) + serverTimeManager.serverTimeOffset),
message: text, message: text,
random_id: randomIdS, random_id: randomIdS,
@ -501,7 +484,7 @@ export class AppMessagesManager {
via_bot_id: options.viaBotId, via_bot_id: options.viaBotId,
reply_markup: options.reply_markup, reply_markup: options.reply_markup,
entities: entities, entities: entities,
views: asChannel && 1, views: isBroadcast && 1,
pending: true pending: true
}; };
@ -512,7 +495,7 @@ export class AppMessagesManager {
}; };
} }
var toggleError = (on: any) => { const toggleError = (on: any) => {
if(on) { if(on) {
message.error = true; message.error = true;
} else { } else {
@ -523,12 +506,12 @@ export class AppMessagesManager {
message.send = () => { message.send = () => {
toggleError(false); toggleError(false);
var sentRequestOptions: any = {}; const sentRequestOptions: any = {};
if(this.pendingAfterMsgs[peerId]) { if(this.pendingAfterMsgs[peerId]) {
sentRequestOptions.afterMessageId = this.pendingAfterMsgs[peerId].messageId; sentRequestOptions.afterMessageId = this.pendingAfterMsgs[peerId].messageId;
} }
var apiPromise: any; let apiPromise: any;
if(options.viaBotId) { if(options.viaBotId) {
apiPromise = apiManager.invokeApiAfter('messages.sendInlineBotResult', { apiPromise = apiManager.invokeApiAfter('messages.sendInlineBotResult', {
peer: appPeersManager.getInputPeerById(peerId), peer: appPeersManager.getInputPeerById(peerId),
@ -631,7 +614,7 @@ export class AppMessagesManager {
//this.checkSendOptions(options); //this.checkSendOptions(options);
const messageId = this.generateTempMessageId(peerId); const messageId = this.generateTempMessageId(peerId);
const randomIdS = randomLong(); const randomIdS = randomLong();
const pFlags: any = {}; const pFlags = this.generateFlags(peerId);
const replyToMsgId = options.replyToMsgId ? this.getLocalMessageId(options.replyToMsgId) : undefined; const replyToMsgId = options.replyToMsgId ? this.getLocalMessageId(options.replyToMsgId) : undefined;
const isChannel = appPeersManager.isChannel(peerId); const isChannel = appPeersManager.isChannel(peerId);
const isMegagroup = isChannel && appPeersManager.isMegagroup(peerId); const isMegagroup = isChannel && appPeersManager.isMegagroup(peerId);
@ -777,20 +760,6 @@ export class AppMessagesManager {
this.log('AMM: sendFile', attachType, apiFileName, file.type, options); this.log('AMM: sendFile', attachType, apiFileName, file.type, options);
let fromId = appUsersManager.getSelf().id;
if(peerId != fromId) {
pFlags.out = true;
if(!isChannel && !appUsersManager.isBot(peerId)) {
pFlags.unread = true;
}
}
if(asChannel) {
fromId = 0;
pFlags.post = true;
}
const preloader = new ProgressivePreloader(null, true, false, 'prepend'); const preloader = new ProgressivePreloader(null, true, false, 'prepend');
const media = { const media = {
@ -810,7 +779,7 @@ export class AppMessagesManager {
const message: any = { const message: any = {
_: 'message', _: 'message',
id: messageId, id: messageId,
from_id: appPeersManager.getOutputPeer(fromId), from_id: this.generateFromId(peerId),
peer_id: appPeersManager.getOutputPeer(peerId), peer_id: appPeersManager.getOutputPeer(peerId),
pFlags, pFlags,
date, date,
@ -1198,25 +1167,12 @@ export class AppMessagesManager {
break; */ break; */
} }
let pFlags: any = {};
if(peerId != fromId) {
pFlags.out = true;
if(!appUsersManager.isBot(peerId)) {
pFlags.unread = true;
}
}
if(asChannel) {
fromId = 0;
pFlags.post = true;
}
const message: any = { const message: any = {
_: 'message', _: 'message',
id: messageId, id: messageId,
from_id: appPeersManager.getOutputPeer(fromId), from_id: this.generateFromId(peerId),
peer_id: appPeersManager.getOutputPeer(peerId), peer_id: appPeersManager.getOutputPeer(peerId),
pFlags, pFlags: this.generateFlags(peerId),
date: options.scheduleDate || (tsNow(true) + serverTimeManager.serverTimeOffset), date: options.scheduleDate || (tsNow(true) + serverTimeManager.serverTimeOffset),
message: '', message: '',
media, media,
@ -1352,6 +1308,35 @@ export class AppMessagesManager {
return header; return header;
} }
/**
* Generate correct from_id according to anonymous or broadcast
*/
public generateFromId(peerId: number) {
if(peerId < 0 && (appPeersManager.isBroadcast(peerId) || appPeersManager.getPeer(peerId).admin_rights?.pFlags?.anonymous)) {
return undefined;
} else {
return appPeersManager.getOutputPeer(peerId);
}
}
public generateFlags(peerId: number) {
const pFlags: any = {};
const fromId = appUsersManager.getSelf().id;
if(peerId !== fromId) {
pFlags.out = true;
if(!appPeersManager.isChannel(peerId) && !appUsersManager.isBot(peerId)) {
pFlags.unread = true;
}
}
if(appPeersManager.isBroadcast(peerId)) {
pFlags.post = true;
}
return pFlags;
}
private setDialogIndexByMessage(dialog: MTDialog.dialog, message: MyMessage) { private setDialogIndexByMessage(dialog: MTDialog.dialog, message: MyMessage) {
if(!dialog.pFlags.pinned || !dialog.index) { if(!dialog.pFlags.pinned || !dialog.index) {
dialog.index = this.dialogsStorage.generateDialogIndex(message.date); dialog.index = this.dialogsStorage.generateDialogIndex(message.date);

Loading…
Cancel
Save