Fix countries with same phone codes by main
This commit is contained in:
parent
294dbf0509
commit
526ad72267
@ -7,7 +7,8 @@ import $rootScope from "../../lib/rootScope";
|
||||
import { findUpClassName } from "../../lib/utils";
|
||||
import ButtonMenu, { ButtonMenuItemOptions } from "../buttonMenu";
|
||||
import { attachContextMenuListener, openBtnMenu, positionMenu } from "../misc";
|
||||
import { PopupButton, PopupPeer } from "../popup";
|
||||
import { PopupButton } from "../popup";
|
||||
import PopupPeer from "../popupPeer";
|
||||
import appSidebarRight from "../sidebarRight";
|
||||
|
||||
export class ChatContextMenu {
|
||||
|
@ -6,7 +6,8 @@ import appPeersManager from "../lib/appManagers/appPeersManager";
|
||||
import $rootScope from "../lib/rootScope";
|
||||
import { findUpTag } from "../lib/utils";
|
||||
import { parseMenuButtonsTo, positionMenu, openBtnMenu } from "./misc";
|
||||
import { PopupButton, PopupPeer } from "./popup";
|
||||
import { PopupButton } from "./popup";
|
||||
import PopupPeer from "./popupPeer";
|
||||
|
||||
export default class DialogsContextMenu {
|
||||
private element = document.getElementById('dialogs-contextmenu') as HTMLDivElement;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Countries, { Country, PhoneCodesMain } from "../countries";
|
||||
import mediaSizes from "../helpers/mediaSizes";
|
||||
import { isTouchSupported } from "../helpers/touchSupport";
|
||||
import { isApple } from "../helpers/userAgent";
|
||||
import Config from "../lib/config";
|
||||
|
||||
export const loadedURLs: {[url: string]: boolean} = {};
|
||||
const set = (elem: HTMLElement | HTMLImageElement | SVGImageElement | HTMLVideoElement, url: string) => {
|
||||
@ -61,30 +61,34 @@ export function putPreloader(elem: Element, returnDiv = false) {
|
||||
elem.innerHTML += html;
|
||||
}
|
||||
|
||||
let sortedCountries: Country[];
|
||||
export function formatPhoneNumber(str: string) {
|
||||
str = str.replace(/\D/g, '');
|
||||
let phoneCode = str.slice(0, 6);
|
||||
|
||||
////console.log('str', str, phoneCode);
|
||||
|
||||
let sortedCountries = Config.Countries.slice().sort((a, b) => b.phoneCode.length - a.phoneCode.length);
|
||||
if(!sortedCountries) {
|
||||
sortedCountries = Countries.slice().sort((a, b) => b.phoneCode.length - a.phoneCode.length);
|
||||
}
|
||||
|
||||
let country = sortedCountries.find((c) => {
|
||||
return c.phoneCode.split(' and ').find((c) => phoneCode.indexOf(c.replace(/\D/g, '')) == 0);
|
||||
});
|
||||
|
||||
if(!country) return {formatted: str, country};
|
||||
|
||||
country = PhoneCodesMain[country.phoneCode] || country;
|
||||
|
||||
let pattern = country ? country.pattern || country.phoneCode : '';
|
||||
if(country) {
|
||||
pattern.split('').forEach((symbol, idx) => {
|
||||
if(symbol == ' ' && str[idx] != ' ' && str.length > idx) {
|
||||
str = str.slice(0, idx) + ' ' + str.slice(idx);
|
||||
}
|
||||
});
|
||||
|
||||
/* if(country.pattern) {
|
||||
str = str.slice(0, country.pattern.length);
|
||||
} */
|
||||
}
|
||||
let pattern = country.pattern || country.phoneCode;
|
||||
pattern.split('').forEach((symbol, idx) => {
|
||||
if(symbol == ' ' && str[idx] != ' ' && str.length > idx) {
|
||||
str = str.slice(0, idx) + ' ' + str.slice(idx);
|
||||
}
|
||||
});
|
||||
|
||||
/* if(country.pattern) {
|
||||
str = str.slice(0, country.pattern.length);
|
||||
} */
|
||||
|
||||
return {formatted: str, country};
|
||||
}
|
||||
|
@ -118,28 +118,3 @@ export type PopupButton = {
|
||||
isDanger?: true,
|
||||
isCancel?: true
|
||||
};
|
||||
|
||||
export class PopupPeer extends PopupElement {
|
||||
constructor(private className: string, options: Partial<{
|
||||
peerID: number,
|
||||
title: string,
|
||||
description: string,
|
||||
buttons: Array<PopupButton>
|
||||
}> = {}) {
|
||||
super('popup-peer' + (className ? ' ' + className : ''), options.buttons);
|
||||
|
||||
let avatarEl = new AvatarElement();
|
||||
avatarEl.setAttribute('dialog', '1');
|
||||
avatarEl.setAttribute('peer', '' + options.peerID);
|
||||
avatarEl.classList.add('peer-avatar');
|
||||
|
||||
this.title.innerText = options.title || '';
|
||||
this.header.prepend(avatarEl);
|
||||
|
||||
let p = document.createElement('p');
|
||||
p.classList.add('popup-description');
|
||||
p.innerHTML = options.description;
|
||||
|
||||
this.container.insertBefore(p, this.header.nextElementSibling);
|
||||
}
|
||||
}
|
27
src/components/popupPeer.ts
Normal file
27
src/components/popupPeer.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import AvatarElement from "./avatar";
|
||||
import { PopupElement, PopupButton } from "./popup";
|
||||
|
||||
export default class PopupPeer extends PopupElement {
|
||||
constructor(private className: string, options: Partial<{
|
||||
peerID: number,
|
||||
title: string,
|
||||
description: string,
|
||||
buttons: Array<PopupButton>
|
||||
}> = {}) {
|
||||
super('popup-peer' + (className ? ' ' + className : ''), options.buttons);
|
||||
|
||||
let avatarEl = new AvatarElement();
|
||||
avatarEl.setAttribute('dialog', '1');
|
||||
avatarEl.setAttribute('peer', '' + options.peerID);
|
||||
avatarEl.classList.add('peer-avatar');
|
||||
|
||||
this.title.innerText = options.title || '';
|
||||
this.header.prepend(avatarEl);
|
||||
|
||||
let p = document.createElement('p');
|
||||
p.classList.add('popup-description');
|
||||
p.innerHTML = options.description;
|
||||
|
||||
this.container.insertBefore(p, this.header.nextElementSibling);
|
||||
}
|
||||
}
|
44
src/countries.ts
Normal file
44
src/countries.ts
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
import { formatPhoneNumber, putPreloader } from "../components/misc";
|
||||
import Scrollable from '../components/scrollable';
|
||||
import Config from '../lib/config';
|
||||
import Countries, { Country as _Country } from "../countries";
|
||||
import apiManager from "../lib/mtproto/mtprotoworker";
|
||||
import { App, Modes } from "../lib/mtproto/mtproto_config";
|
||||
import { RichTextProcessor } from '../lib/richtextprocessor';
|
||||
@ -9,13 +9,7 @@ import Page from "./page";
|
||||
import pageAuthCode from "./pageAuthCode";
|
||||
import pageSignQR from './pageSignQR';
|
||||
|
||||
|
||||
type Country = {
|
||||
name: string,
|
||||
code: string,
|
||||
phoneCode: string,
|
||||
pattern: string,
|
||||
emoji: string,
|
||||
type Country = _Country & {
|
||||
li?: HTMLLIElement[]
|
||||
};
|
||||
|
||||
@ -24,7 +18,7 @@ let btnNext: HTMLButtonElement = null;
|
||||
|
||||
let onFirstMount = () => {
|
||||
if(Modes.test) {
|
||||
Config.Countries.push({
|
||||
Countries.push({
|
||||
name: 'Test Country',
|
||||
phoneCode: '999 66',
|
||||
code: 'TC',
|
||||
@ -36,7 +30,7 @@ let onFirstMount = () => {
|
||||
}
|
||||
|
||||
//const countries: Country[] = _countries.default.filter(c => c.emoji);
|
||||
const countries: Country[] = Config.Countries.filter(c => c.emoji).sort((a, b) => a.name.localeCompare(b.name));
|
||||
const countries: Country[] = Countries.filter(c => c.emoji).sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
let lastCountrySelected: Country = null;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user