Wait for key when no colon in input
This commit is contained in:
parent
45b016521e
commit
c4a46fb334
@ -21,9 +21,9 @@ export default class AutocompleteHelper extends EventListenerBase<{
|
|||||||
protected resetTarget: () => void;
|
protected resetTarget: () => void;
|
||||||
|
|
||||||
constructor(appendTo: HTMLElement,
|
constructor(appendTo: HTMLElement,
|
||||||
private listType: 'xy' | 'x' | 'y',
|
protected listType: 'xy' | 'x' | 'y',
|
||||||
private onSelect: (target: Element) => boolean | void,
|
protected onSelect: (target: Element) => boolean | void,
|
||||||
private waitForKey?: string
|
protected waitForKey?: string
|
||||||
) {
|
) {
|
||||||
super(false);
|
super(false);
|
||||||
|
|
||||||
|
69
src/components/chat/commandsHelper.ts
Normal file
69
src/components/chat/commandsHelper.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import { BotCommand } from "../../layer";
|
||||||
|
import RichTextProcessor from "../../lib/richtextprocessor";
|
||||||
|
import AvatarElement from "../avatar";
|
||||||
|
import Scrollable from "../scrollable";
|
||||||
|
import AutocompleteHelper from "./autocompleteHelper";
|
||||||
|
|
||||||
|
export default class CommandsHelper extends AutocompleteHelper {
|
||||||
|
private scrollable: Scrollable;
|
||||||
|
|
||||||
|
constructor(appendTo: HTMLElement) {
|
||||||
|
super(appendTo, 'y', (target) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
this.container.classList.add('commands-helper');
|
||||||
|
}
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
this.list = document.createElement('div');
|
||||||
|
this.list.classList.add('commands-helper-commands');
|
||||||
|
|
||||||
|
this.container.append(this.list);
|
||||||
|
|
||||||
|
this.scrollable = new Scrollable(this.container);
|
||||||
|
|
||||||
|
this.addEventListener('visible', () => {
|
||||||
|
setTimeout(() => { // it is not rendered yet
|
||||||
|
this.scrollable.container.scrollTop = 0;
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public renderCommands(commands: {userId: number, command: BotCommand}[]) {
|
||||||
|
if(this.init) {
|
||||||
|
if(!commands.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.init();
|
||||||
|
this.init = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(commands.length) {
|
||||||
|
this.list.innerHTML = '';
|
||||||
|
commands.forEach(command => {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.classList.add('commands-helper-command');
|
||||||
|
|
||||||
|
const avatar = new AvatarElement();
|
||||||
|
avatar.classList.add('avatar-30');
|
||||||
|
avatar.setAttribute('dialog', '0');
|
||||||
|
avatar.setAttribute('peer', '' + command.userId);
|
||||||
|
|
||||||
|
const name = document.createElement('div');
|
||||||
|
name.classList.add('commands-helper-command-name');
|
||||||
|
name.innerText = '/' + command.command.command;
|
||||||
|
|
||||||
|
const description = document.createElement('div');
|
||||||
|
description.classList.add('commands-helper-command-description');
|
||||||
|
description.innerHTML = RichTextProcessor.wrapEmojiText(command.command.description);
|
||||||
|
|
||||||
|
div.append(avatar, name, description);
|
||||||
|
this.list.append(div);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.toggle(!commands.length);
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,7 @@ export default class EmojiHelper extends AutocompleteHelper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public renderEmojis(emojis: string[]) {
|
public renderEmojis(emojis: string[], waitForKey: boolean) {
|
||||||
if(this.init) {
|
if(this.init) {
|
||||||
if(!emojis.length) {
|
if(!emojis.length) {
|
||||||
return;
|
return;
|
||||||
@ -46,6 +46,7 @@ export default class EmojiHelper extends AutocompleteHelper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.waitForKey = waitForKey ? 'ArrowUp' : undefined;
|
||||||
this.toggle(!emojis.length);
|
this.toggle(!emojis.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import PopupNewMedia from '../popups/newMedia';
|
|||||||
import { toast } from "../toast";
|
import { toast } from "../toast";
|
||||||
import { wrapReply } from "../wrappers";
|
import { wrapReply } from "../wrappers";
|
||||||
import InputField from '../inputField';
|
import InputField from '../inputField';
|
||||||
import { MessageEntity, DraftMessage } from '../../layer';
|
import { MessageEntity, DraftMessage, BotInfo, BotCommand } from '../../layer';
|
||||||
import StickersHelper from './stickersHelper';
|
import StickersHelper from './stickersHelper';
|
||||||
import ButtonIcon from '../buttonIcon';
|
import ButtonIcon from '../buttonIcon';
|
||||||
import DivAndCaption from '../divAndCaption';
|
import DivAndCaption from '../divAndCaption';
|
||||||
@ -60,6 +60,8 @@ import { MarkdownType, markdownTags } from '../../helpers/dom/getRichElementValu
|
|||||||
import getRichValueWithCaret from '../../helpers/dom/getRichValueWithCaret';
|
import getRichValueWithCaret from '../../helpers/dom/getRichValueWithCaret';
|
||||||
import EmojiHelper from './emojiHelper';
|
import EmojiHelper from './emojiHelper';
|
||||||
import setRichFocus from '../../helpers/dom/setRichFocus';
|
import setRichFocus from '../../helpers/dom/setRichFocus';
|
||||||
|
import SearchIndex from '../../lib/searchIndex';
|
||||||
|
import CommandsHelper from './commandsHelper';
|
||||||
|
|
||||||
const RECORD_MIN_TIME = 500;
|
const RECORD_MIN_TIME = 500;
|
||||||
const POSTING_MEDIA_NOT_ALLOWED = 'Posting media content isn\'t allowed in this group.';
|
const POSTING_MEDIA_NOT_ALLOWED = 'Posting media content isn\'t allowed in this group.';
|
||||||
@ -130,6 +132,7 @@ export default class ChatInput {
|
|||||||
readonly executedHistory: string[] = [];
|
readonly executedHistory: string[] = [];
|
||||||
private canUndoFromHTML = '';
|
private canUndoFromHTML = '';
|
||||||
|
|
||||||
|
private commandsHelper: CommandsHelper;
|
||||||
private emojiHelper: EmojiHelper;
|
private emojiHelper: EmojiHelper;
|
||||||
private stickersHelper: StickersHelper;
|
private stickersHelper: StickersHelper;
|
||||||
private listenerSetter: ListenerSetter;
|
private listenerSetter: ListenerSetter;
|
||||||
@ -363,6 +366,7 @@ export default class ChatInput {
|
|||||||
this.newMessageWrapper.append(...[this.btnToggleEmoticons, this.inputMessageContainer, this.btnScheduled, this.attachMenu, this.recordTimeEl, this.fileInput].filter(Boolean));
|
this.newMessageWrapper.append(...[this.btnToggleEmoticons, this.inputMessageContainer, this.btnScheduled, this.attachMenu, this.recordTimeEl, this.fileInput].filter(Boolean));
|
||||||
|
|
||||||
this.rowsWrapper.append(this.replyElements.container);
|
this.rowsWrapper.append(this.replyElements.container);
|
||||||
|
this.commandsHelper = new CommandsHelper(this.rowsWrapper);
|
||||||
this.emojiHelper = new EmojiHelper(this.rowsWrapper, this);
|
this.emojiHelper = new EmojiHelper(this.rowsWrapper, this);
|
||||||
this.stickersHelper = new StickersHelper(this.rowsWrapper);
|
this.stickersHelper = new StickersHelper(this.rowsWrapper);
|
||||||
this.rowsWrapper.append(this.newMessageWrapper);
|
this.rowsWrapper.append(this.newMessageWrapper);
|
||||||
@ -1267,30 +1271,27 @@ export default class ChatInput {
|
|||||||
} else {
|
} else {
|
||||||
this.hideSuggestions()
|
this.hideSuggestions()
|
||||||
}
|
}
|
||||||
} else if (!matches[1] && matches[2] == '/') { // commands
|
} else */ /* if(!matches[1] && matches[2][0] === '/') { // commands
|
||||||
if (this.commands && this.commands.index) {
|
if(this.chat.peerId > 0) {
|
||||||
if (query.length) {
|
this.chat.appProfileManager.getProfileByPeerId(this.chat.peerId).then(full => {
|
||||||
var foundObject = SearchIndexManager.search(query, this.commands.index)
|
const botInfos: BotInfo.botInfo[] = [].concat(full.bot_info);
|
||||||
var foundCommands = []
|
const index = new SearchIndex<string>(false, false);
|
||||||
var command
|
|
||||||
for (var i = 0, length = this.commands.list.length; i < length; i++) {
|
const commands: Map<string, {userId: number, command: BotCommand}> = new Map();
|
||||||
command = this.commands.list[i]
|
botInfos.forEach(botInfo => {
|
||||||
if (foundObject[command.value]) {
|
botInfo.commands.forEach(botCommand => {
|
||||||
foundCommands.push(command)
|
commands.set(botCommand.command, {userId: botInfo.user_id, command: botCommand});
|
||||||
}
|
index.indexObject(botCommand.command, '/' + botCommand.command);
|
||||||
}
|
});
|
||||||
} else {
|
});
|
||||||
var foundCommands = this.commands.list
|
|
||||||
}
|
const found = index.search(matches[2]);
|
||||||
if (foundCommands.length) {
|
const filtered = Array.from(found).map(command => commands.get(command));
|
||||||
this.showCommandsSuggestions(foundCommands)
|
this.commandsHelper.renderCommands(filtered);
|
||||||
} else {
|
console.log('found commands', found, filtered);
|
||||||
this.hideSuggestions()
|
});
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.hideSuggestions()
|
|
||||||
}
|
}
|
||||||
} else *//* if(firstChar === ':') */ { // emoji
|
} else */ { // emoji
|
||||||
if(value.match(/^\s*:(.+):\s*$/)) {
|
if(value.match(/^\s*:(.+):\s*$/)) {
|
||||||
this.emojiHelper.toggle(true);
|
this.emojiHelper.toggle(true);
|
||||||
return;
|
return;
|
||||||
@ -1299,7 +1300,7 @@ export default class ChatInput {
|
|||||||
this.appEmojiManager.getBothEmojiKeywords().then(() => {
|
this.appEmojiManager.getBothEmojiKeywords().then(() => {
|
||||||
const q = matches[2].replace(/^:/, '');
|
const q = matches[2].replace(/^:/, '');
|
||||||
const emojis = this.appEmojiManager.searchEmojis(q);
|
const emojis = this.appEmojiManager.searchEmojis(q);
|
||||||
this.emojiHelper.renderEmojis(emojis);
|
this.emojiHelper.renderEmojis(emojis, matches[2][0] !== ':');
|
||||||
//console.log(emojis);
|
//console.log(emojis);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import appUsersManager, { User } from "./appUsersManager";
|
|||||||
type PeerPhotoSize = 'photo_small' | 'photo_big';
|
type PeerPhotoSize = 'photo_small' | 'photo_big';
|
||||||
|
|
||||||
export class AppProfileManager {
|
export class AppProfileManager {
|
||||||
private botInfos: any = {};
|
//private botInfos: any = {};
|
||||||
private usersFull: {[id: string]: UserFull.userFull} = {};
|
private usersFull: {[id: string]: UserFull.userFull} = {};
|
||||||
public chatsFull: {[id: string]: ChatFull} = {};
|
public chatsFull: {[id: string]: ChatFull} = {};
|
||||||
private fullPromises: {[peerId: string]: Promise<ChatFull.chatFull | ChatFull.channelFull | UserFull>} = {};
|
private fullPromises: {[peerId: string]: Promise<ChatFull.chatFull | ChatFull.channelFull | UserFull>} = {};
|
||||||
@ -122,7 +122,7 @@ export class AppProfileManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveBotInfo(botInfo: any) {
|
/* public saveBotInfo(botInfo: any) {
|
||||||
const botId = botInfo && botInfo.user_id;
|
const botId = botInfo && botInfo.user_id;
|
||||||
if(!botId) {
|
if(!botId) {
|
||||||
return null;
|
return null;
|
||||||
@ -140,7 +140,7 @@ export class AppProfileManager {
|
|||||||
description: botInfo.description,
|
description: botInfo.description,
|
||||||
commands: commands
|
commands: commands
|
||||||
};
|
};
|
||||||
}
|
} */
|
||||||
|
|
||||||
public getProfile(id: number, override?: true): Promise<UserFull> {
|
public getProfile(id: number, override?: true): Promise<UserFull> {
|
||||||
if(this.usersFull[id] && !override) {
|
if(this.usersFull[id] && !override) {
|
||||||
@ -167,9 +167,9 @@ export class AppProfileManager {
|
|||||||
|
|
||||||
appNotificationsManager.savePeerSettings(id, userFull.notify_settings);
|
appNotificationsManager.savePeerSettings(id, userFull.notify_settings);
|
||||||
|
|
||||||
if(userFull.bot_info) {
|
/* if(userFull.bot_info) {
|
||||||
userFull.bot_info = this.saveBotInfo(userFull.bot_info) as any;
|
userFull.bot_info = this.saveBotInfo(userFull.bot_info) as any;
|
||||||
}
|
} */
|
||||||
|
|
||||||
//appMessagesManager.savePinnedMessage(id, userFull.pinned_msg_id);
|
//appMessagesManager.savePinnedMessage(id, userFull.pinned_msg_id);
|
||||||
|
|
||||||
|
33
src/scss/partials/_chatCommandsHelper.scss
Normal file
33
src/scss/partials/_chatCommandsHelper.scss
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
.commands-helper {
|
||||||
|
left: 0;
|
||||||
|
//width: 320px !important;
|
||||||
|
|
||||||
|
.scrollable {
|
||||||
|
position: relative;
|
||||||
|
max-height: 232px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-commands {
|
||||||
|
padding: .5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-command {
|
||||||
|
height: 3.125rem;
|
||||||
|
display: flex;
|
||||||
|
padding: 0 .75rem;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
@include hover();
|
||||||
|
|
||||||
|
&-name {
|
||||||
|
margin-left: .875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-description {
|
||||||
|
margin-left: .5625rem;
|
||||||
|
color: var(--secondary-text-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,29 @@
|
|||||||
.emoji-helper {
|
.emoji-helper {
|
||||||
height: 50px;
|
height: 50px;
|
||||||
padding: .25rem !important;
|
padding: .25rem 0 !important;
|
||||||
|
|
||||||
> .scrollable {
|
> .scrollable {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.super-emojis {
|
.super-emojis {
|
||||||
display: flex;
|
display: block;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
/* display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start; */
|
||||||
|
|
||||||
|
&:before, &:after {
|
||||||
|
display: inline-block;
|
||||||
|
content: " ";
|
||||||
|
//flex: 0 0 auto;
|
||||||
|
width: .1875rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.super-emoji {
|
/* .super-emoji {
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
}
|
} */
|
||||||
|
|
||||||
.super-emoji:not(.active) {
|
.super-emoji:not(.active) {
|
||||||
@include hover() {
|
@include hover() {
|
||||||
|
@ -236,6 +236,7 @@ html.night {
|
|||||||
@import "partials/chatMarkupTooltip";
|
@import "partials/chatMarkupTooltip";
|
||||||
@import "partials/chatStickersHelper";
|
@import "partials/chatStickersHelper";
|
||||||
@import "partials/chatEmojiHelper";
|
@import "partials/chatEmojiHelper";
|
||||||
|
@import "partials/chatCommandsHelper";
|
||||||
@import "partials/chatSearch";
|
@import "partials/chatSearch";
|
||||||
@import "partials/chatDrop";
|
@import "partials/chatDrop";
|
||||||
@import "partials/crop";
|
@import "partials/crop";
|
||||||
@ -1266,23 +1267,24 @@ middle-ellipsis-element {
|
|||||||
// ! No chrome 56 support
|
// ! No chrome 56 support
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-column-gap: 2.44px;
|
grid-column-gap: 2.44px;
|
||||||
grid-template-columns: repeat(auto-fill, 42px);
|
grid-template-columns: repeat(auto-fill, 2.625rem);
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
||||||
font-size: 2.25rem;
|
font-size: 2.125rem;
|
||||||
line-height: 2.25rem;
|
line-height: 2.125rem;
|
||||||
|
|
||||||
.super-emoji {
|
.super-emoji {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin: 0 1.44px; // ! magic number
|
margin: 0 .0625rem;
|
||||||
padding: 4px 4px;
|
padding: .25rem;
|
||||||
line-height: inherit;
|
line-height: inherit;
|
||||||
border-radius: 8px;
|
border-radius: $border-radius;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
vertical-align: middle;
|
||||||
|
|
||||||
width: 42px;
|
width: 2.625rem;
|
||||||
height: 42px;
|
height: 2.625rem;
|
||||||
|
|
||||||
html:not(.emoji-supported) & {
|
html:not(.emoji-supported) & {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user