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. 7
      src/lib/appManagers/appMessagesManager.ts
  7. 16
      src/lib/appManagers/appPollsManager.ts

2
src/components/chat/bubbles.ts

@ -1948,7 +1948,7 @@ export default class ChatBubbles { @@ -1948,7 +1948,7 @@ export default class ChatBubbles {
chat: this.chat
});
} 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');
wrapVideo({
doc,

18
src/components/chat/contextMenu.ts

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

4
src/components/chat/selection.ts

@ -443,7 +443,7 @@ export default class ChatSelection { @@ -443,7 +443,7 @@ export default class ChatSelection {
this.updateBubbleSelection(bubble, !found);
};
private canSelectBubble(bubble: HTMLElement) {
return !bubble.classList.contains('service');
public canSelectBubble(bubble: HTMLElement) {
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[]) { @@ -123,57 +123,41 @@ export function getRichValue(field: HTMLElement, entities?: MessageEntity[]) {
RichTextProcessor.combineSameEntities(entities);
}
console.log('getRichValue:', value, entities);
//console.log('getRichValue:', value, entities);
return value;
}
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 MarkdownTag = {
match: string,
markdown: string | ((node: HTMLElement) => string),
entityName: 'messageEntityBold' | 'messageEntityUnderline' | 'messageEntityItalic' | 'messageEntityPre' | 'messageEntityStrike' | 'messageEntityTextUrl';
};
export const markdownTags: {[type in MarkdownType]: MarkdownTag} = {
bold: {
match: '[style*="font-weight"], b',
markdown: markdownTypes.bold,
entityName: 'messageEntityBold'
},
underline: {
match: '[style*="underline"], u',
markdown: markdownTypes.underline,
entityName: 'messageEntityUnderline'
},
italic: {
match: '[style*="italic"], i',
markdown: markdownTypes.italic,
entityName: 'messageEntityItalic'
},
monospace: {
match: '[style*="monospace"], [face="monospace"]',
markdown: markdownTypes.monospace,
entityName: 'messageEntityPre'
},
strikethrough: {
match: '[style*="line-through"], strike',
markdown: markdownTypes.strikethrough,
entityName: 'messageEntityStrike'
},
link: {
match: 'A',
markdown: (node: HTMLElement) => `[${(node.parentElement as HTMLAnchorElement).href}](${node.nodeValue})`,
entityName: 'messageEntityTextUrl'
}
};

1
src/helpers/object.ts

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

7
src/lib/appManagers/appMessagesManager.ts

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

16
src/lib/appManagers/appPollsManager.ts

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

Loading…
Cancel
Save