Fix some entities
Small refactor of RichTextProcessor
This commit is contained in:
parent
7f746738f5
commit
ee4d05c9e5
84
src/layer.d.ts
vendored
84
src/layer.d.ts
vendored
@ -3795,125 +3795,166 @@ export namespace ReplyMarkup {
|
||||
/**
|
||||
* @link https://core.telegram.org/type/MessageEntity
|
||||
*/
|
||||
export type MessageEntity = MessageEntity.messageEntityUnknown | MessageEntity.messageEntityMention | MessageEntity.messageEntityHashtag | MessageEntity.messageEntityBotCommand | MessageEntity.messageEntityUrl | MessageEntity.messageEntityEmail | MessageEntity.messageEntityBold | MessageEntity.messageEntityItalic | MessageEntity.messageEntityCode | MessageEntity.messageEntityPre | MessageEntity.messageEntityTextUrl | MessageEntity.messageEntityMentionName | MessageEntity.inputMessageEntityMentionName | MessageEntity.messageEntityPhone | MessageEntity.messageEntityCashtag | MessageEntity.messageEntityUnderline | MessageEntity.messageEntityStrike | MessageEntity.messageEntityBlockquote | MessageEntity.messageEntityBankCard;
|
||||
export type MessageEntity = MessageEntity.messageEntityUnknown | MessageEntity.messageEntityMention | MessageEntity.messageEntityHashtag | MessageEntity.messageEntityBotCommand | MessageEntity.messageEntityUrl | MessageEntity.messageEntityEmail | MessageEntity.messageEntityBold | MessageEntity.messageEntityItalic | MessageEntity.messageEntityCode | MessageEntity.messageEntityPre | MessageEntity.messageEntityTextUrl | MessageEntity.messageEntityMentionName | MessageEntity.inputMessageEntityMentionName | MessageEntity.messageEntityPhone | MessageEntity.messageEntityCashtag | MessageEntity.messageEntityUnderline | MessageEntity.messageEntityStrike | MessageEntity.messageEntityBlockquote | MessageEntity.messageEntityBankCard | MessageEntity.messageEntityEmoji | MessageEntity.messageEntityHighlight | MessageEntity.messageEntityLinebreak;
|
||||
|
||||
export namespace MessageEntity {
|
||||
export type messageEntityUnknown = {
|
||||
_: 'messageEntityUnknown',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityMention = {
|
||||
_: 'messageEntityMention',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityHashtag = {
|
||||
_: 'messageEntityHashtag',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityBotCommand = {
|
||||
_: 'messageEntityBotCommand',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityUrl = {
|
||||
_: 'messageEntityUrl',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityEmail = {
|
||||
_: 'messageEntityEmail',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityBold = {
|
||||
_: 'messageEntityBold',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityItalic = {
|
||||
_: 'messageEntityItalic',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityCode = {
|
||||
_: 'messageEntityCode',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityPre = {
|
||||
_: 'messageEntityPre',
|
||||
offset: number,
|
||||
length: number,
|
||||
language: string
|
||||
language: string,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityTextUrl = {
|
||||
_: 'messageEntityTextUrl',
|
||||
offset: number,
|
||||
length: number,
|
||||
url: string
|
||||
url: string,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityMentionName = {
|
||||
_: 'messageEntityMentionName',
|
||||
offset: number,
|
||||
length: number,
|
||||
user_id: number
|
||||
user_id: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type inputMessageEntityMentionName = {
|
||||
_: 'inputMessageEntityMentionName',
|
||||
offset: number,
|
||||
length: number,
|
||||
user_id: InputUser
|
||||
user_id: InputUser,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityPhone = {
|
||||
_: 'messageEntityPhone',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityCashtag = {
|
||||
_: 'messageEntityCashtag',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityUnderline = {
|
||||
_: 'messageEntityUnderline',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityStrike = {
|
||||
_: 'messageEntityStrike',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityBlockquote = {
|
||||
_: 'messageEntityBlockquote',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityBankCard = {
|
||||
_: 'messageEntityBankCard',
|
||||
offset: number,
|
||||
length: number
|
||||
length: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityEmoji = {
|
||||
_: 'messageEntityEmoji',
|
||||
offset?: number,
|
||||
length?: number,
|
||||
unicode?: string,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityHighlight = {
|
||||
_: 'messageEntityHighlight',
|
||||
offset?: number,
|
||||
length?: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
|
||||
export type messageEntityLinebreak = {
|
||||
_: 'messageEntityLinebreak',
|
||||
offset?: number,
|
||||
length?: number,
|
||||
nested?: Array<MessageEntity>
|
||||
};
|
||||
}
|
||||
|
||||
@ -8918,6 +8959,9 @@ export interface ConstructorDeclMap {
|
||||
'messageReplyHeader': MessageReplyHeader.messageReplyHeader,
|
||||
'messageReplies': MessageReplies.messageReplies,
|
||||
'peerBlocked': PeerBlocked.peerBlocked,
|
||||
'messageEntityEmoji': MessageEntity.messageEntityEmoji,
|
||||
'messageEntityHighlight': MessageEntity.messageEntityHighlight,
|
||||
'messageEntityLinebreak': MessageEntity.messageEntityLinebreak,
|
||||
}
|
||||
|
||||
export type InvokeAfterMsg = {
|
||||
|
@ -674,20 +674,20 @@ export class AppDialogsManager {
|
||||
let lastMessageText = appMessagesManager.getRichReplyText(lastMessage, '');
|
||||
|
||||
let messageText = lastMessage.message;
|
||||
let entities = RichTextProcessor.parseEntities(messageText.replace(/\n/g, ' '), {noLinebreakers: true});
|
||||
let regExp = new RegExp(escapeRegExp(highlightWord), 'gi');
|
||||
let match: any;
|
||||
let entities = RichTextProcessor.parseEntities(messageText.replace(/\n/g, ' '));
|
||||
let regExp = new RegExp(escapeRegExp(highlightWord), 'gi');
|
||||
let match: any;
|
||||
|
||||
if(!entities) entities = [];
|
||||
let found = false;
|
||||
while((match = regExp.exec(messageText)) !== null) {
|
||||
entities.push({_: 'messageEntityHighlight', length: highlightWord.length, offset: match.index});
|
||||
found = true;
|
||||
}
|
||||
if(!entities) entities = [];
|
||||
let found = false;
|
||||
while((match = regExp.exec(messageText)) !== null) {
|
||||
entities.push({_: 'messageEntityHighlight', length: highlightWord.length, offset: match.index});
|
||||
found = true;
|
||||
}
|
||||
|
||||
if(found) {
|
||||
entities.sort((a: any, b: any) => a.offset - b.offset);
|
||||
}
|
||||
if(found) {
|
||||
entities.sort((a: any, b: any) => a.offset - b.offset);
|
||||
}
|
||||
|
||||
let messageWrapped = RichTextProcessor.wrapRichText(messageText, {
|
||||
noLinebreaks: true,
|
||||
|
@ -2498,7 +2498,7 @@ export class AppMessagesManager {
|
||||
// * 80 for chatlist in landscape orientation
|
||||
text = limitSymbols(text, 75, 80);
|
||||
|
||||
let entities = RichTextProcessor.parseEntities(text.replace(/\n/g, ' '), {noLinebreakers: true});
|
||||
let entities = RichTextProcessor.parseEntities(text.replace(/\n/g, ' '));
|
||||
|
||||
messageWrapped = RichTextProcessor.wrapRichText(text, {
|
||||
noLinebreaks: true,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -34,7 +34,7 @@ const appSidebarLeft = AppSidebarLeft;
|
||||
const appMediaViewer = AppMediaViewer;
|
||||
const appDialogsManager = AppDialogsManager;
|
||||
|
||||
(window as any).Services = {
|
||||
const Services = {
|
||||
appUsersManager,
|
||||
appChatsManager,
|
||||
apiUpdatesManager,
|
||||
@ -53,3 +53,10 @@ const appDialogsManager = AppDialogsManager;
|
||||
appMediaViewer
|
||||
//appSharedMediaManager
|
||||
};
|
||||
|
||||
(window as any).Services = Services;
|
||||
|
||||
for(let i in Services) {
|
||||
// @ts-ignore
|
||||
(window as any)[i] = Services[i];
|
||||
}
|
||||
|
@ -10,7 +10,12 @@ for(const constructor of additional) {
|
||||
param.type = 'flags.-1?' + param.type;
|
||||
});
|
||||
|
||||
const realConstructor = mtproto.constructors.find(c => c.predicate == constructor.predicate);
|
||||
if(constructor.type) {
|
||||
mtproto.constructors.push(constructor);
|
||||
}
|
||||
|
||||
const realConstructor = constructor.type ? constructor : mtproto.constructors.find(c => c.predicate == constructor.predicate);
|
||||
|
||||
/* constructor.params.forEach(param => {
|
||||
const index = realConstructor.params.findIndex(_param => _param.predicate == param.predicate);
|
||||
if(index !== -1) {
|
||||
|
@ -91,4 +91,124 @@
|
||||
"params": [
|
||||
{"name": "rAbout", "type": "string"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityEmoji",
|
||||
"params": [
|
||||
{"name": "offset", "type": "number"},
|
||||
{"name": "length", "type": "number"},
|
||||
{"name": "unicode", "type": "string"},
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
],
|
||||
"type": "MessageEntity"
|
||||
}, {
|
||||
"predicate": "messageEntityHighlight",
|
||||
"params": [
|
||||
{"name": "offset", "type": "number"},
|
||||
{"name": "length", "type": "number"},
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
],
|
||||
"type": "MessageEntity"
|
||||
}, {
|
||||
"predicate": "messageEntityLinebreak",
|
||||
"params": [
|
||||
{"name": "offset", "type": "number"},
|
||||
{"name": "length", "type": "number"},
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
],
|
||||
"type": "MessageEntity"
|
||||
}, {
|
||||
"predicate": "messageEntityUnknown",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityMention",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityHashtag",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityBotCommand",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityUrl",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityEmail",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityBold",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityItalic",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityCode",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityPre",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityTextUrl",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityMentionName",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityPhone",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityCashtag",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityUnderline",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityStrike",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityBlockquote",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "messageEntityBankCard",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}, {
|
||||
"predicate": "inputMessageEntityMentionName",
|
||||
"params": [
|
||||
{"name": "nested", "type": "Array<MessageEntity>"}
|
||||
]
|
||||
}]
|
Loading…
Reference in New Issue
Block a user