Skip to content

Commit

Permalink
[Entities] Add support for Phone, PreCode
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-nadymov committed Oct 16, 2019
1 parent 4952660 commit 53a6125
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"homepage": "http://evgeny-nadymov.github.io/telegram-react",
"name": "telegram_react",
"version": "0.0.468",
"version": "0.0.469",
"private": true,
"dependencies": {
"@material-ui/core": "^3.9.2",
Expand Down
2 changes: 1 addition & 1 deletion src/Stores/CacheStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { EventEmitter } from 'events';
import { debounce } from '../Utils/Common';
import CacheManager from '../Workers/CacheManager';
import BasicGroupStore from './BasicGroupStore';
import ChatStore from './ChatStore';
Expand All @@ -14,7 +15,6 @@ import OptionStore from './OptionStore';
import SupergroupStore from './SupergroupStore';
import UserStore from './UserStore';
import TdLibController from '../Controllers/TdLibController';
import { debounce } from '../Utils/Common';

class CacheStore extends EventEmitter {
constructor() {
Expand Down
118 changes: 76 additions & 42 deletions src/Utils/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
isChatMuted
} from './Chat';
import { openUser } from './../Actions/Client';
import { getPhotoSize, getSize } from './Common';
import { getPhotoSize } from './Common';
import { download, saveOrDownload } from './File';
import { getAudioTitle } from './Media';
import { getServiceMessageContent } from './ServiceMessage';
Expand Down Expand Up @@ -108,13 +108,13 @@ function stopPropagation(event) {
event.stopPropagation();
}

function searchCurrentChatByHashtag(event, hashtag) {
function searchCurrentChat(event, text) {
event.stopPropagation();
event.preventDefault();

const { chatId } = AppStore;

searchChat(chatId, hashtag);
searchChat(chatId, text);
}

function getFormattedText(text) {
Expand All @@ -136,88 +136,122 @@ function getFormattedText(text) {
text.entities[i].offset + text.entities[i].length
);
switch (text.entities[i].type['@type']) {
case 'textEntityTypeUrl': {
case 'textEntityTypeBold': {
result.push(<strong key={text.entities[i].offset}>{entityText}</strong>);
break;
}
case 'textEntityTypeBotCommand': {
const command = entityText.length > 0 && entityText[0] === '/' ? substring(entityText, 1) : entityText;
result.push(
<SafeLink key={text.entities[i].offset} url={entityText}>
<a
key={text.entities[i].offset}
onClick={stopPropagation}
href={`tg://bot_command?command=${command}&bot=`}>
{entityText}
</SafeLink>
</a>
);
break;
}
case 'textEntityTypeTextUrl': {
let url = entityText;
const { url: typeUrl } = text.entities[i].type;
if (typeUrl) {
url = typeUrl;
}

case 'textEntityTypeCashtag': {
result.push(
<SafeLink key={text.entities[i].offset} url={url}>
<a key={text.entities[i].offset} onClick={event => searchCurrentChat(event, entityText)}>
{entityText}
</SafeLink>
</a>
);
break;
}
case 'textEntityTypeBold':
result.push(<strong key={text.entities[i].offset}>{entityText}</strong>);
break;
case 'textEntityTypeItalic':
result.push(<em key={text.entities[i].offset}>{entityText}</em>);
break;
case 'textEntityTypeCode':
case 'textEntityTypeCode': {
result.push(<code key={text.entities[i].offset}>{entityText}</code>);
break;
case 'textEntityTypePre':
}
case 'textEntityTypeEmailAddress': {
result.push(
<pre key={text.entities[i].offset}>
<code>{entityText}</code>
</pre>
<a
key={text.entities[i].offset}
href={`mailto:${entityText}`}
onClick={stopPropagation}
target='_blank'
rel='noopener noreferrer'>
{entityText}
</a>
);
break;
case 'textEntityTypeMention':
}
case 'textEntityTypeHashtag': {
result.push(
<MentionLink key={text.entities[i].offset} username={entityText}>
<a key={text.entities[i].offset} onClick={event => searchCurrentChat(event, entityText)}>
{entityText}
</MentionLink>
</a>
);
break;
case 'textEntityTypeMentionName':
}
case 'textEntityTypeItalic': {
result.push(<em key={text.entities[i].offset}>{entityText}</em>);
break;
}
case 'textEntityTypeMentionName': {
result.push(
<MentionLink key={text.entities[i].offset} userId={text.entities[i].type.user_id}>
{entityText}
</MentionLink>
);
break;
case 'textEntityTypeHashtag':
}
case 'textEntityTypeMention': {
result.push(
<a key={text.entities[i].offset} onClick={event => searchCurrentChatByHashtag(event, entityText)}>
<MentionLink key={text.entities[i].offset} username={entityText}>
{entityText}
</a>
</MentionLink>
);
break;
case 'textEntityTypeEmailAddress':
}
case 'textEntityTypePhoneNumber': {
result.push(
<a
key={text.entities[i].offset}
href={`tel:${entityText}`}
onClick={stopPropagation}
href={`mailto:${entityText}`}
target='_blank'
rel='noopener noreferrer'>
{entityText}
</a>
);
break;
case 'textEntityTypeBotCommand':
let command = entityText.length > 0 && entityText[0] === '/' ? substring(entityText, 1) : entityText;
}
case 'textEntityTypePre': {
result.push(<pre key={text.entities[i].offset}>{entityText}</pre>);
break;
}
case 'textEntityTypePreCode': {
result.push(
<a
key={text.entities[i].offset}
onClick={stopPropagation}
href={`tg://bot_command?command=${command}&bot=`}>
<pre key={text.entities[i].offset}>
<code>{entityText}</code>
</pre>
);
break;
}
case 'textEntityTypeTextUrl': {
let url = entityText;
const { url: typeUrl } = text.entities[i].type;
if (typeUrl) {
url = typeUrl;
}

result.push(
<SafeLink key={text.entities[i].offset} url={url}>
{entityText}
</a>
</SafeLink>
);
break;
}
case 'textEntityTypeUrl': {
result.push(
<SafeLink key={text.entities[i].offset} url={entityText}>
{entityText}
</SafeLink>
);
break;
}
default:
result.push(entityText);
break;
Expand Down
14 changes: 8 additions & 6 deletions src/registerServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,16 @@ export async function subscribeNotifications() {
if (endpoint && p256dh_base64url && auth_base64url) {
const { authorizationState } = ApplicationStore;
if (isAuthorizationReady(authorizationState)) {
const deviceToken = {
'@type': 'deviceTokenWebPush',
endpoint,
p256dh_base64url,
auth_base64url
};
console.log('[SW] registerDevice', deviceToken);
const result = await TdLibController.send({
'@type': 'registerDevice',
device_token: {
'@type': 'deviceTokenWebPush',
endpoint,
p256dh_base64url,
auth_base64url
},
device_token: deviceToken,
other_user_ids: []
});
console.log('[SW] registerDevice result', result);
Expand Down

0 comments on commit 53a6125

Please sign in to comment.