From e323d3fb32e881a62017d3995138cb1d708ab28e Mon Sep 17 00:00:00 2001 From: Global Server Date: Sat, 1 Jan 2022 12:28:21 +0100 Subject: [PATCH] Support for geochats --- package-lock.json | 50 ++++----- src/components/inputField.ts | 7 +- src/components/peerProfile.ts | 49 +++++++-- src/components/sidebarLeft/index.ts | 17 +++ src/components/sidebarLeft/tabs/newGroup.ts | 109 ++++++++++++++++--- src/components/sidebarRight/tabs/chatType.ts | 4 +- src/lang.ts | 3 + src/lib/appManagers/appChatsManager.ts | 29 ++++- src/lib/mtproto/schema.ts | 2 +- src/lib/mtproto/tl_utils.ts | 2 +- src/scripts/out/langPack.strings | 3 + 11 files changed, 214 insertions(+), 61 deletions(-) diff --git a/package-lock.json b/package-lock.json index aca2c729..c1d52c0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7540,7 +7540,7 @@ "version": "3.5.1", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.1.tgz", "integrity": "sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw==", - "dev": true, + "devOptional": true, "dependencies": { "anymatch": "~3.1.1", "braces": "~3.0.2", @@ -7561,7 +7561,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", - "dev": true, + "devOptional": true, "dependencies": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" @@ -7574,7 +7574,7 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", - "dev": true, + "devOptional": true, "engines": { "node": ">=8" } @@ -7583,7 +7583,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, + "devOptional": true, "dependencies": { "fill-range": "^7.0.1" }, @@ -7595,7 +7595,7 @@ "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, + "devOptional": true, "dependencies": { "to-regex-range": "^5.0.1" }, @@ -7607,7 +7607,6 @@ "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, "hasInstallScript": true, "optional": true, "os": [ @@ -7621,7 +7620,7 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", - "dev": true, + "devOptional": true, "dependencies": { "is-glob": "^4.0.1" }, @@ -7633,7 +7632,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "dev": true, + "devOptional": true, "dependencies": { "binary-extensions": "^2.0.0" }, @@ -7645,7 +7644,7 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, + "devOptional": true, "engines": { "node": ">=0.12.0" } @@ -7654,7 +7653,7 @@ "version": "3.5.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.5.0.tgz", "integrity": "sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ==", - "dev": true, + "devOptional": true, "dependencies": { "picomatch": "^2.2.1" }, @@ -7666,7 +7665,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, + "devOptional": true, "dependencies": { "is-number": "^7.0.0" }, @@ -19361,7 +19360,7 @@ "version": "2.2.2", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", - "dev": true, + "devOptional": true, "engines": { "node": ">=8.6" }, @@ -25658,7 +25657,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/watchpack-chokidar2/-/watchpack-chokidar2-2.0.1.tgz", "integrity": "sha512-nCFfBIPKr5Sh61s4LPpy1Wtfi0HE8isJ3d2Yb5/Ppw2P2B/3eVSEBjKfN0fmHJSK14+31KwMKmcrzs2GM4P0Ww==", - "dev": true, "optional": true, "dependencies": { "chokidar": "^2.1.8" @@ -25669,7 +25667,6 @@ "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.8.tgz", "integrity": "sha512-ZmZUazfOzf0Nve7duiCKD23PFSCs4JPoYyccjUFF3aQkQadqBhfzhjkwBH2mNOG9cTBwhamM37EIsIkZw3nRgg==", "deprecated": "Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.", - "dev": true, "optional": true, "dependencies": { "anymatch": "^2.0.0", @@ -33044,7 +33041,7 @@ "version": "3.5.1", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.1.tgz", "integrity": "sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw==", - "dev": true, + "devOptional": true, "requires": { "anymatch": "~3.1.1", "braces": "~3.0.2", @@ -33060,7 +33057,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", - "dev": true, + "devOptional": true, "requires": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" @@ -33070,13 +33067,13 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", - "dev": true + "devOptional": true }, "braces": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, + "devOptional": true, "requires": { "fill-range": "^7.0.1" } @@ -33085,7 +33082,7 @@ "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, + "devOptional": true, "requires": { "to-regex-range": "^5.0.1" } @@ -33094,14 +33091,13 @@ "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, "optional": true }, "glob-parent": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", - "dev": true, + "devOptional": true, "requires": { "is-glob": "^4.0.1" } @@ -33110,7 +33106,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "dev": true, + "devOptional": true, "requires": { "binary-extensions": "^2.0.0" } @@ -33119,13 +33115,13 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true + "devOptional": true }, "readdirp": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.5.0.tgz", "integrity": "sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ==", - "dev": true, + "devOptional": true, "requires": { "picomatch": "^2.2.1" } @@ -33134,7 +33130,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, + "devOptional": true, "requires": { "is-number": "^7.0.0" } @@ -42059,7 +42055,7 @@ "version": "2.2.2", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", - "dev": true + "devOptional": true }, "pify": { "version": "4.0.1", @@ -46911,7 +46907,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/watchpack-chokidar2/-/watchpack-chokidar2-2.0.1.tgz", "integrity": "sha512-nCFfBIPKr5Sh61s4LPpy1Wtfi0HE8isJ3d2Yb5/Ppw2P2B/3eVSEBjKfN0fmHJSK14+31KwMKmcrzs2GM4P0Ww==", - "dev": true, "optional": true, "requires": { "chokidar": "^2.1.8" @@ -46921,7 +46916,6 @@ "version": "2.1.8", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.8.tgz", "integrity": "sha512-ZmZUazfOzf0Nve7duiCKD23PFSCs4JPoYyccjUFF3aQkQadqBhfzhjkwBH2mNOG9cTBwhamM37EIsIkZw3nRgg==", - "dev": true, "optional": true, "requires": { "anymatch": "^2.0.0", diff --git a/src/components/inputField.ts b/src/components/inputField.ts index d1378ead..29f87cd6 100644 --- a/src/components/inputField.ts +++ b/src/components/inputField.ts @@ -77,8 +77,9 @@ export type InputFieldOptions = { maxLength?: number, showLengthOn?: number, plainText?: true, - animate?: true, + animate?: boolean, required?: boolean, + canBeEdited?: boolean, validate?: () => boolean }; @@ -108,7 +109,7 @@ class InputField { options.showLengthOn = Math.min(40, Math.round(options.maxLength / 3)); } - const {placeholder, maxLength, showLengthOn, name, plainText} = options; + const {placeholder, maxLength, showLengthOn, name, plainText, canBeEdited} = options; let label = options.label || options.labelText; @@ -119,7 +120,7 @@ class InputField { } this.container.innerHTML = ` -
+
`; input = this.container.firstElementChild as HTMLElement; diff --git a/src/components/peerProfile.ts b/src/components/peerProfile.ts index 2557d40b..faa96203 100644 --- a/src/components/peerProfile.ts +++ b/src/components/peerProfile.ts @@ -47,9 +47,10 @@ export default class PeerProfile { private username: Row; private phone: Row; private notifications: Row; + private location: Row; private cleaned: boolean; - private setBioTimeout: number; + private setMoreDetailsTimeout: number; private setPeerStatusInterval: number; private peerId: PeerId; @@ -64,6 +65,7 @@ export default class PeerProfile { public init() { this.init = null; + this.element = document.createElement('div'); this.element.classList.add('profile-content'); @@ -122,13 +124,25 @@ export default class PeerProfile { } }); + this.location = new Row({ + title: ' ', + subtitleLangKey: 'AttachLocation', + icon: 'location' + }); + this.notifications = new Row({ checkboxField: new CheckboxField({toggle: true}), titleLangKey: 'Notifications', icon: 'unmute' }); - this.section.content.append(this.phone.container, this.username.container, this.bio.container, this.notifications.container); + this.section.content.append( + this.phone.container, + this.username.container, + this.location.container, + this.bio.container, + this.notifications.container + ); this.element.append(this.section.container, generateDelimiter()); @@ -156,7 +170,7 @@ export default class PeerProfile { rootScope.addEventListener('peer_bio_edit', (peerId) => { if(peerId === this.peerId) { - this.setBio(true); + this.setMoreDetails(true); } }); @@ -193,11 +207,12 @@ export default class PeerProfile { this.bio.container.style.display = 'none'; this.phone.container.style.display = 'none'; this.username.container.style.display = 'none'; + this.location.container.style.display = 'none'; this.notifications.container.style.display = ''; this.notifications.checkboxField.checked = true; - if(this.setBioTimeout) { - window.clearTimeout(this.setBioTimeout); - this.setBioTimeout = 0; + if(this.setMoreDetailsTimeout) { + window.clearTimeout(this.setMoreDetailsTimeout); + this.setMoreDetailsTimeout = 0; } } @@ -275,7 +290,7 @@ export default class PeerProfile { //membersLi.style.display = appPeersManager.isBroadcast(peerId) ? 'none' : ''; } */ - this.setBio(); + this.setMoreDetails(); replaceContent(this.name, new PeerTitle({ peerId, @@ -290,10 +305,10 @@ export default class PeerProfile { this.setPeerStatus(true); } - public setBio(override?: true) { - if(this.setBioTimeout) { - window.clearTimeout(this.setBioTimeout); - this.setBioTimeout = 0; + public setMoreDetails(override?: true) { + if(this.setMoreDetailsTimeout) { + window.clearTimeout(this.setMoreDetailsTimeout); + this.setMoreDetailsTimeout = 0; } const peerId = this.peerId; @@ -314,6 +329,8 @@ export default class PeerProfile { if(userFull.rAbout && peerId !== rootScope.myId) { setText(userFull.rAbout, this.bio); } + + this.location.container.style.display = 'none'; //this.log('userFull', userFull); return true; @@ -331,13 +348,21 @@ export default class PeerProfile { setText(RichTextProcessor.wrapRichText(chatFull.about), this.bio); } + // @ts-ignore + if(chatFull?.location?._ == 'channelLocation') { + // @ts-ignore + setText(RichTextProcessor.wrapRichText(chatFull.location.address), this.location); + }else{ + this.location.container.style.display = 'none'; + } + return true; }); } promise.then((canSetNext) => { if(canSetNext) { - this.setBioTimeout = window.setTimeout(() => this.setBio(true), 60e3); + this.setMoreDetailsTimeout = window.setTimeout(() => this.setMoreDetails(true), 60e3); } }); } diff --git a/src/components/sidebarLeft/index.ts b/src/components/sidebarLeft/index.ts index e989fa6c..d5767b0c 100644 --- a/src/components/sidebarLeft/index.ts +++ b/src/components/sidebarLeft/index.ts @@ -42,6 +42,7 @@ import { closeBtnMenu } from "../misc"; import { indexOfAndSplice } from "../../helpers/array"; import ButtonIcon from "../buttonIcon"; import confirmationPopup from "../confirmationPopup"; +import { InputFile } from "../../layer"; export const LEFT_COLUMN_ACTIVE_CLASSNAME = 'is-left-column-shown'; @@ -84,6 +85,18 @@ export class AppSidebarLeft extends SidebarSlider { }); }; + const onNewGeoGroupClick = () => { + new AppAddMembersTab(this).open({ + type: 'chat', + skippable: true, // you can create geogroups without members + takeOut: (peerIds) => { + new AppNewGroupTab(this).open(peerIds, true); + }, + title: 'GroupAddMembers', + placeholder: 'SendMessageTo' + }); + }; + const onContactsClick = () => { new AppContactsTab(this).open(); }; @@ -235,6 +248,10 @@ export class AppSidebarLeft extends SidebarSlider { icon: 'newgroup', text: 'NewGroup', onClick: onNewGroupClick + },{ + icon: 'newgroup', + text: 'NewGeoGroup', + onClick: onNewGeoGroupClick }, { icon: 'newprivate', text: 'NewPrivateChat', diff --git a/src/components/sidebarLeft/tabs/newGroup.ts b/src/components/sidebarLeft/tabs/newGroup.ts index c3baa209..9a8773f4 100644 --- a/src/components/sidebarLeft/tabs/newGroup.ts +++ b/src/components/sidebarLeft/tabs/newGroup.ts @@ -16,13 +16,29 @@ import AvatarEdit from "../../avatarEdit"; import { i18n } from "../../../lib/langPack"; import ButtonCorner from "../../buttonCorner"; +interface OpenStreetMapInterface { + place_id?: number; + license?: string; + osm_type?: string; + osm_id?: number; + lat?: string; + lon?: string; + display_name: string; + address?: object; + boundingbox?: object; +} + export default class AppNewGroupTab extends SliderSuperTab { private searchGroup = new SearchGroup(true, 'contacts', true, 'new-group-members disable-hover', false); private avatarEdit: AvatarEdit; private uploadAvatar: () => Promise = null; private peerIds: PeerId[]; + private isGeoChat: boolean = false; private nextBtn: HTMLButtonElement; private groupNameInputField: InputField; + private groupLocationInputField: InputField; + private userLocationCoords: { lat: number, long: number }; + private userLocationAddress: string; protected init() { this.container.classList.add('new-group-container'); @@ -40,11 +56,22 @@ export default class AppNewGroupTab extends SliderSuperTab { maxLength: 128 }); - inputWrapper.append(this.groupNameInputField.container); + this.groupLocationInputField = new InputField({ + label: 'ChannelGeoGroupLocation', + name: 'location', + canBeEdited: false + }); + + inputWrapper.append( + this.groupNameInputField.container, + this.groupLocationInputField.container + ); this.groupNameInputField.input.addEventListener('input', () => { const value = this.groupNameInputField.value; - this.nextBtn.classList.toggle('is-visible', !!value.length && !this.groupNameInputField.input.classList.contains('error')); + let valueCheck = !!value.length && !this.groupNameInputField.input.classList.contains('error'); + if(this.isGeoChat) valueCheck = valueCheck && !!this.userLocationCoords && !!this.userLocationAddress; + this.nextBtn.classList.toggle('is-visible', !!valueCheck); }); this.nextBtn = ButtonCorner({icon: 'arrow_next'}); @@ -52,17 +79,35 @@ export default class AppNewGroupTab extends SliderSuperTab { this.nextBtn.addEventListener('click', () => { const title = this.groupNameInputField.value; - this.nextBtn.disabled = true; - appChatsManager.createChat(title, this.peerIds.map(peerId => peerId.toUserId())).then((chatId) => { - if(this.uploadAvatar) { - this.uploadAvatar().then((inputFile) => { - appChatsManager.editPhoto(chatId, inputFile); - }); - } - - appSidebarLeft.removeTabFromHistory(this); - appSidebarLeft.selectTab(0); - }); + if(this.isGeoChat){ + if(!this.userLocationAddress || !this.userLocationCoords) return; + appChatsManager.createGeoChat(title, '', this.userLocationCoords, this.userLocationAddress).then((chatId) => { + if(this.uploadAvatar) { + this.uploadAvatar().then((inputFile) => { + appChatsManager.editPhoto(chatId, inputFile); + }); + } + + if(this.peerIds.length){ + appChatsManager.inviteToChannel(chatId, this.peerIds); + } + + appSidebarLeft.removeTabFromHistory(this); + appSidebarLeft.selectTab(0); + }); + }else{ + this.nextBtn.disabled = true; + appChatsManager.createChat(title, this.peerIds.map(peerId => peerId.toUserId())).then((chatId) => { + if(this.uploadAvatar) { + this.uploadAvatar().then((inputFile) => { + appChatsManager.editPhoto(chatId, inputFile); + }); + } + + appSidebarLeft.removeTabFromHistory(this); + appSidebarLeft.selectTab(0); + }); + } }); const chatsContainer = document.createElement('div'); @@ -78,14 +123,25 @@ export default class AppNewGroupTab extends SliderSuperTab { this.avatarEdit.clear(); this.uploadAvatar = null; this.groupNameInputField.value = ''; + this.groupLocationInputField.container.classList.add('hide'); this.nextBtn.disabled = false; } - public open(peerIds: PeerId[]) { + public open(peerIds: PeerId[], isGeoChat: boolean = false) { const result = super.open(); result.then(() => { + this.isGeoChat = isGeoChat; this.peerIds = peerIds; + if(isGeoChat){ + this.setTitle('NewGeoGroup'); + this.groupLocationInputField.container.classList.remove('hide'); + this.groupLocationInputField.setValueSilently('Locating...'); + this.startLocating(); + }else{ + this.groupLocationInputField.container.classList.add('hide'); + } + this.peerIds.forEach(userId => { let {dom} = appDialogsManager.addDialogNew({ dialog: userId, @@ -105,4 +161,29 @@ export default class AppNewGroupTab extends SliderSuperTab { return result; } + + private startLocating(){ + navigator.geolocation.getCurrentPosition(location => { + this.userLocationCoords = { + lat: location.coords.latitude, + long: location.coords.longitude + }; + + let uri = "https://nominatim.openstreetmap.org/reverse"; + uri += "?lat="+location.coords.latitude; + uri += "&lon="+location.coords.longitude; + uri += "&format=json"; + uri += "&addressdetails=1"; + uri += "&accept-language=en"; + fetch(uri) + // @ts-ignore + .then((response) => response.json() as OpenStreetMapInterface) + .then( + (response: OpenStreetMapInterface) => { + this.userLocationAddress = response.display_name; + this.groupLocationInputField.setValueSilently(response.display_name); + } + ); + }); + } } \ No newline at end of file diff --git a/src/components/sidebarRight/tabs/chatType.ts b/src/components/sidebarRight/tabs/chatType.ts index 64a5ef3e..8420644c 100644 --- a/src/components/sidebarRight/tabs/chatType.ts +++ b/src/components/sidebarRight/tabs/chatType.ts @@ -6,7 +6,7 @@ import { copyTextToClipboard } from "../../../helpers/clipboard"; import { randomLong } from "../../../helpers/random"; -import { Chat, ChatFull, ExportedChatInvite } from "../../../layer"; +import { Chat, ChatFull, ExportedChatInvite, ChannelLocation } from "../../../layer"; import appChatsManager from "../../../lib/appManagers/appChatsManager"; import appProfileManager from "../../../lib/appManagers/appProfileManager"; import Button from "../../button"; @@ -81,6 +81,8 @@ export default class AppChatTypeTab extends SliderSuperTabEventable { } }); + let uri = ''; + const btnRevoke = Button('btn-primary btn-transparent danger', {icon: 'delete', text: 'RevokeLink'}); attachClickEvent(btnRevoke, () => { diff --git a/src/lang.ts b/src/lang.ts index 709d11d3..105c8815 100644 --- a/src/lang.ts +++ b/src/lang.ts @@ -1,4 +1,5 @@ const lang = { + "GrantPermissions":"Grant me permissions", "Animations": "Animations", "AttachAlbum": "Album", "Appearance.Color.Hex": "HEX", @@ -231,6 +232,7 @@ const lang = { "UsernameHelpLink": "This link opens a chat with you:\n%1$s", "NewChannel": "New Channel", "NewGroup": "New Group", + "NewGeoGroup": "New Geo-Group", "Contacts": "Contacts", "SavedMessages": "Saved Messages", "Settings": "Settings", @@ -399,6 +401,7 @@ const lang = { "MegaPrivateInfo": "Private groups can only be joined if you were invited or have an invite link.", "ChannelPrivateLinkHelp": "People can join your channel by following this link. You can revoke the link any time.", "MegaPrivateLinkHelp": "People can join your group by following this link. You can revoke the link any time.", + "ChannelGeoGroupLocation":"Group location", "RevokeButton": "Revoke", "RevokeLink": "Revoke Link", "RevokeAlert": "Are you sure you want to revoke this link? Once the link is revoked, no one will be able to join using it.", diff --git a/src/lib/appManagers/appChatsManager.ts b/src/lib/appManagers/appChatsManager.ts index 79d08d56..307e5030 100644 --- a/src/lib/appManagers/appChatsManager.ts +++ b/src/lib/appManagers/appChatsManager.ts @@ -11,7 +11,7 @@ import DEBUG, { MOUNT_CLASS_TO } from "../../config/debug"; import { isObject, safeReplaceObject, copy, deepEqual } from "../../helpers/object"; -import { ChannelParticipant, Chat, ChatAdminRights, ChatBannedRights, ChatParticipant, ChatPhoto, InputChannel, InputChatPhoto, InputFile, InputPeer, Update, Updates } from "../../layer"; +import { InputGeoPoint, ChannelParticipant, Chat, ChatAdminRights, ChatBannedRights, ChatParticipant, ChatPhoto, InputChannel, InputChatPhoto, InputFile, InputPeer, Update, Updates } from "../../layer"; import apiManagerProxy from "../mtproto/mtprotoworker"; import apiManager from '../mtproto/mtprotoworker'; import { RichTextProcessor } from "../richtextprocessor"; @@ -498,6 +498,33 @@ export class AppChatsManager { }); } + public createGeoChat(title: string, about: string, gpoint: { + lat: number, + long: number + }, address: string): Promise { + let geo_point = { + _: 'inputGeoPoint', + lat: gpoint['lat'], + long: gpoint['long'] + } as InputGeoPoint; + + // NON TOCCARE STO PEZZO MAI PIĆ¹ NELLA VITA + return apiManager.invokeApi('channels.createChannel', { + megagroup: true, + title, + about, + geo_point, + address + }).then((updates) => { + apiUpdatesManager.processUpdateMessage(updates); + + const channelId = (updates as any).chats[0].id; + rootScope.dispatchEvent('history_focus', {peerId: channelId.toPeerId(true)}); + + return channelId; + }); + } + public inviteToChannel(id: ChatId, userIds: UserId[]) { const input = this.getChannelInput(id); const usersInputs = userIds.map(u => appUsersManager.getUserInput(u)); diff --git a/src/lib/mtproto/schema.ts b/src/lib/mtproto/schema.ts index e31bd235..1bdc8465 100644 --- a/src/lib/mtproto/schema.ts +++ b/src/lib/mtproto/schema.ts @@ -36,4 +36,4 @@ export default {"MTProto":{"constructors":[{"id":481674261,"predicate":"vector", constructorsIndex?: {[id: number]: number} }, layer: number, -}; +}; \ No newline at end of file diff --git a/src/lib/mtproto/tl_utils.ts b/src/lib/mtproto/tl_utils.ts index 69bba4a1..3d948b5b 100644 --- a/src/lib/mtproto/tl_utils.ts +++ b/src/lib/mtproto/tl_utils.ts @@ -829,4 +829,4 @@ class TLDeserialization { MOUNT_CLASS_TO.TLDeserialization = TLDeserialization; MOUNT_CLASS_TO.TLSerialization = TLSerialization; -export { TLDeserialization, TLSerialization }; +export { TLDeserialization, TLSerialization }; \ No newline at end of file diff --git a/src/scripts/out/langPack.strings b/src/scripts/out/langPack.strings index 4e528933..aaa853d4 100644 --- a/src/scripts/out/langPack.strings +++ b/src/scripts/out/langPack.strings @@ -1,3 +1,6 @@ +"GrantPermissions" = "Grant permissions" +"NewGeoGroup" = "New GeoGroup" +"ChannelGeoGroupLocation" = "Group location" "Animations" = "Animations"; "AttachAlbum" = "Album"; "BlockModal.Search.Placeholder" = "Block user...";