Browse Source

Disabled selecting outgoing messages

Fix polls
master
Eduard Kuzmenko 4 years ago
parent
commit
6e57d69a5a
  1. 2
      src/components/chat/bubbles.ts
  2. 18
      src/components/chat/contextMenu.ts
  3. 4
      src/components/chat/selection.ts
  4. 18
      src/helpers/dom.ts
  5. 1
      src/helpers/object.ts
  6. 5
      src/lib/appManagers/appMessagesManager.ts
  7. 14
      src/lib/appManagers/appPollsManager.ts

2
src/components/chat/bubbles.ts

@ -1948,7 +1948,7 @@ export default class ChatBubbles {
chat: this.chat chat: this.chat
}); });
} else { } else {
const withTail = !isAndroid && !isApple && doc.type != 'round' && !message.message && withReplies; const withTail = !isAndroid && !isApple && doc.type != 'round' && !message.message && !withReplies;
if(withTail) bubble.classList.add('with-media-tail'); if(withTail) bubble.classList.add('with-media-tail');
wrapVideo({ wrapVideo({
doc, doc,

18
src/components/chat/contextMenu.ts

@ -17,6 +17,7 @@ export default class ChatContextMenu {
private buttons: (ButtonMenuItemOptions & {verify: () => boolean, notDirect?: () => boolean, withSelection?: true})[]; private buttons: (ButtonMenuItemOptions & {verify: () => boolean, notDirect?: () => boolean, withSelection?: true})[];
private element: HTMLElement; private element: HTMLElement;
private isSelectable: boolean;
private target: HTMLElement; private target: HTMLElement;
private isTargetAGroupedItem: boolean; private isTargetAGroupedItem: boolean;
public peerId: number; public peerId: number;
@ -60,6 +61,7 @@ export default class ChatContextMenu {
} }
} }
this.isSelectable = this.chat.selection.canSelectBubble(bubble);
this.peerId = this.chat.peerId; this.peerId = this.chat.peerId;
//this.msgID = msgID; //this.msgID = msgID;
this.target = e.target as HTMLElement; this.target = e.target as HTMLElement;
@ -145,7 +147,7 @@ export default class ChatContextMenu {
icon: 'send2', icon: 'send2',
text: 'Send Now', text: 'Send Now',
onClick: this.onSendScheduledClick, onClick: this.onSendScheduledClick,
verify: () => this.chat.type === 'scheduled' verify: () => this.chat.type === 'scheduled' && !this.message.pFlags.is_outgoing
}, { }, {
icon: 'send2', icon: 'send2',
text: 'Send Now selected', text: 'Send Now selected',
@ -172,7 +174,7 @@ export default class ChatContextMenu {
text: 'Reply', text: 'Reply',
onClick: this.onReplyClick, onClick: this.onReplyClick,
verify: () => (this.peerId > 0 || this.appChatsManager.hasRights(-this.peerId, 'send')) && verify: () => (this.peerId > 0 || this.appChatsManager.hasRights(-this.peerId, 'send')) &&
this.mid > 0 && !this.message.pFlags.is_outgoing &&
!!this.chat.input.messageInput && !!this.chat.input.messageInput &&
this.chat.type !== 'scheduled'/* , this.chat.type !== 'scheduled'/* ,
cancelEvent: true */ cancelEvent: true */
@ -197,7 +199,7 @@ export default class ChatContextMenu {
icon: 'pin', icon: 'pin',
text: 'Pin', text: 'Pin',
onClick: this.onPinClick, onClick: this.onPinClick,
verify: () => this.mid > 0 && verify: () => !this.message.pFlags.is_outgoing &&
this.message._ != 'messageService' && this.message._ != 'messageService' &&
!this.message.pFlags.pinned && !this.message.pFlags.pinned &&
this.appPeersManager.canPinMessage(this.peerId) && this.appPeersManager.canPinMessage(this.peerId) &&
@ -222,26 +224,28 @@ export default class ChatContextMenu {
onClick: this.onStopPoll, onClick: this.onStopPoll,
verify: () => { verify: () => {
const poll = this.message.media?.poll; const poll = this.message.media?.poll;
return this.appMessagesManager.canEditMessage(this.message, 'poll') && poll && !poll.pFlags.closed && this.mid > 0; return this.appMessagesManager.canEditMessage(this.message, 'poll') && poll && !poll.pFlags.closed && !this.message.pFlags.is_outgoing;
}/* , }/* ,
cancelEvent: true */ cancelEvent: true */
}, { }, {
icon: 'forward', icon: 'forward',
text: 'Forward', text: 'Forward',
onClick: this.onForwardClick, onClick: this.onForwardClick,
verify: () => this.mid > 0 && this.chat.type !== 'scheduled' verify: () => this.chat.type !== 'scheduled' && !this.message.pFlags.is_outgoing
}, { }, {
icon: 'forward', icon: 'forward',
text: 'Forward selected', text: 'Forward selected',
onClick: this.onForwardClick, onClick: this.onForwardClick,
verify: () => this.chat.selection.selectionForwardBtn && this.chat.selection.selectedMids.has(this.mid) && !this.chat.selection.selectionForwardBtn.hasAttribute('disabled'), verify: () => this.chat.selection.selectionForwardBtn &&
this.chat.selection.selectedMids.has(this.mid) &&
!this.chat.selection.selectionForwardBtn.hasAttribute('disabled'),
notDirect: () => true, notDirect: () => true,
withSelection: true withSelection: true
}, { }, {
icon: 'select', icon: 'select',
text: 'Select', text: 'Select',
onClick: this.onSelectClick, onClick: this.onSelectClick,
verify: () => !this.message.action && !this.chat.selection.selectedMids.has(this.mid), verify: () => !this.message.action && !this.chat.selection.selectedMids.has(this.mid) && this.isSelectable,
notDirect: () => true, notDirect: () => true,
withSelection: true withSelection: true
}, { }, {

4
src/components/chat/selection.ts

@ -443,7 +443,7 @@ export default class ChatSelection {
this.updateBubbleSelection(bubble, !found); this.updateBubbleSelection(bubble, !found);
}; };
private canSelectBubble(bubble: HTMLElement) { public canSelectBubble(bubble: HTMLElement) {
return !bubble.classList.contains('service'); return !bubble.classList.contains('service') && !bubble.classList.contains('is-sending');
} }
} }

18
src/helpers/dom.ts

@ -123,57 +123,41 @@ export function getRichValue(field: HTMLElement, entities?: MessageEntity[]) {
RichTextProcessor.combineSameEntities(entities); RichTextProcessor.combineSameEntities(entities);
} }
console.log('getRichValue:', value, entities); //console.log('getRichValue:', value, entities);
return value; return value;
} }
MOUNT_CLASS_TO && (MOUNT_CLASS_TO.getRichValue = getRichValue); MOUNT_CLASS_TO && (MOUNT_CLASS_TO.getRichValue = getRichValue);
const markdownTypes = {
bold: '**',
underline: '_-_',
italic: '__',
monospace: '`',
pre: '``',
strikethrough: '~~'
};
export type MarkdownType = 'bold' | 'italic' | 'underline' | 'strikethrough' | 'monospace' | 'link'; export type MarkdownType = 'bold' | 'italic' | 'underline' | 'strikethrough' | 'monospace' | 'link';
export type MarkdownTag = { export type MarkdownTag = {
match: string, match: string,
markdown: string | ((node: HTMLElement) => string),
entityName: 'messageEntityBold' | 'messageEntityUnderline' | 'messageEntityItalic' | 'messageEntityPre' | 'messageEntityStrike' | 'messageEntityTextUrl'; entityName: 'messageEntityBold' | 'messageEntityUnderline' | 'messageEntityItalic' | 'messageEntityPre' | 'messageEntityStrike' | 'messageEntityTextUrl';
}; };
export const markdownTags: {[type in MarkdownType]: MarkdownTag} = { export const markdownTags: {[type in MarkdownType]: MarkdownTag} = {
bold: { bold: {
match: '[style*="font-weight"], b', match: '[style*="font-weight"], b',
markdown: markdownTypes.bold,
entityName: 'messageEntityBold' entityName: 'messageEntityBold'
}, },
underline: { underline: {
match: '[style*="underline"], u', match: '[style*="underline"], u',
markdown: markdownTypes.underline,
entityName: 'messageEntityUnderline' entityName: 'messageEntityUnderline'
}, },
italic: { italic: {
match: '[style*="italic"], i', match: '[style*="italic"], i',
markdown: markdownTypes.italic,
entityName: 'messageEntityItalic' entityName: 'messageEntityItalic'
}, },
monospace: { monospace: {
match: '[style*="monospace"], [face="monospace"]', match: '[style*="monospace"], [face="monospace"]',
markdown: markdownTypes.monospace,
entityName: 'messageEntityPre' entityName: 'messageEntityPre'
}, },
strikethrough: { strikethrough: {
match: '[style*="line-through"], strike', match: '[style*="line-through"], strike',
markdown: markdownTypes.strikethrough,
entityName: 'messageEntityStrike' entityName: 'messageEntityStrike'
}, },
link: { link: {
match: 'A', match: 'A',
markdown: (node: HTMLElement) => `[${(node.parentElement as HTMLAnchorElement).href}](${node.nodeValue})`,
entityName: 'messageEntityTextUrl' entityName: 'messageEntityTextUrl'
} }
}; };

1
src/helpers/object.ts

@ -11,6 +11,7 @@ export function copy<T>(obj: T): T {
//handle Array //handle Array
if(Array.isArray(obj)) { if(Array.isArray(obj)) {
// @ts-ignore
const clonedArr: T = obj.map(el => copy(el)) as any as T; const clonedArr: T = obj.map(el => copy(el)) as any as T;
return clonedArr; return clonedArr;
} }

5
src/lib/appManagers/appMessagesManager.ts

@ -402,7 +402,9 @@ export class AppMessagesManager {
} }
let entities = options.entities || []; let entities = options.entities || [];
if(text) {
text = RichTextProcessor.parseMarkdown(text, entities); text = RichTextProcessor.parseMarkdown(text, entities);
}
const schedule_date = options.scheduleDate || (message.pFlags.is_scheduled ? message.date : undefined); const schedule_date = options.scheduleDate || (message.pFlags.is_scheduled ? message.date : undefined);
return apiManager.invokeApi('messages.editMessage', { return apiManager.invokeApi('messages.editMessage', {
@ -410,7 +412,7 @@ export class AppMessagesManager {
id: message.id, id: message.id,
message: text, message: text,
media: options.newMedia, media: options.newMedia,
entities: entities ? this.getInputEntities(entities) : undefined, entities: entities.length ? this.getInputEntities(entities) : undefined,
no_webpage: options.noWebPage, no_webpage: options.noWebPage,
schedule_date schedule_date
}).then((updates) => { }).then((updates) => {
@ -1162,7 +1164,6 @@ export class AppMessagesManager {
const isMegagroup = isChannel && appPeersManager.isMegagroup(peerId); const isMegagroup = isChannel && appPeersManager.isMegagroup(peerId);
const asChannel = isChannel && !isMegagroup ? true : false; const asChannel = isChannel && !isMegagroup ? true : false;
let fromId = appUsersManager.getSelf().id;
let media; let media;
switch(inputMedia._) { switch(inputMedia._) {
case 'inputMediaPoll': { case 'inputMediaPoll': {

14
src/lib/appManagers/appPollsManager.ts

@ -78,7 +78,7 @@ export class AppPollsManager {
constructor() { constructor() {
rootScope.on('apiUpdate', (e) => { rootScope.on('apiUpdate', (e) => {
let update = e.detail; const update = e.detail;
this.handleUpdate(update); this.handleUpdate(update);
}); });
@ -122,7 +122,11 @@ export class AppPollsManager {
} }
public saveResults(poll: Poll, results: PollResults) { public saveResults(poll: Poll, results: PollResults) {
if(this.results[poll.id]) {
results = Object.assign(this.results[poll.id], results);
} else {
this.results[poll.id] = results; this.results[poll.id] = results;
}
if(!results.pFlags.min) { // ! https://core.telegram.org/constructor/pollResults - min if(!results.pFlags.min) { // ! https://core.telegram.org/constructor/pollResults - min
poll.chosenIndexes.length = 0; poll.chosenIndexes.length = 0;
@ -157,7 +161,7 @@ export class AppPollsManager {
poll, poll,
correct_answers: correctAnswers, correct_answers: correctAnswers,
solution, solution,
solution_entities: solutionEntities solution_entities: solutionEntities?.length ? solutionEntities : undefined
}; };
} }
@ -181,7 +185,7 @@ export class AppPollsManager {
return apiManager.invokeApi('messages.sendVote', { return apiManager.invokeApi('messages.sendVote', {
peer: inputPeer, peer: inputPeer,
msg_id: message.id, msg_id: appMessagesManager.getLocalMessageId(message.mid),
options options
}).then(updates => { }).then(updates => {
this.log('sendVote updates:', updates); this.log('sendVote updates:', updates);
@ -194,7 +198,7 @@ export class AppPollsManager {
return apiManager.invokeApi('messages.getPollResults', { return apiManager.invokeApi('messages.getPollResults', {
peer: inputPeer, peer: inputPeer,
msg_id: message.id msg_id: appMessagesManager.getLocalMessageId(message.mid)
}).then(updates => { }).then(updates => {
apiUpdatesManager.processUpdateMessage(updates); apiUpdatesManager.processUpdateMessage(updates);
this.log('getResults updates:', updates); this.log('getResults updates:', updates);
@ -204,7 +208,7 @@ export class AppPollsManager {
public getVotes(message: any, option?: Uint8Array, offset?: string, limit = 20) { public getVotes(message: any, option?: Uint8Array, offset?: string, limit = 20) {
return apiManager.invokeApi('messages.getPollVotes', { return apiManager.invokeApi('messages.getPollVotes', {
peer: appPeersManager.getInputPeerById(message.peerId), peer: appPeersManager.getInputPeerById(message.peerId),
id: message.id, id: appMessagesManager.getLocalMessageId(message.mid),
option, option,
offset, offset,
limit limit

Loading…
Cancel
Save