Browse Source

Calls incompatibility toast

master
Eduard Kuzmenko 3 years ago
parent
commit
634c0bc55b
  1. 7
      src/components/toast.ts
  2. 1
      src/lang.ts
  3. 21
      src/lib/appManagers/appCallsManager.ts
  4. 9
      src/lib/appManagers/appImManager.ts
  5. 2
      src/lib/calls/callInstance.ts
  6. 1
      src/lib/rootScope.ts
  7. 2
      src/scss/partials/_chatlist.scss

7
src/components/toast.ts

@ -5,7 +5,7 @@
*/ */
import replaceContent from "../helpers/dom/replaceContent"; import replaceContent from "../helpers/dom/replaceContent";
import { i18n, LangPackKey } from "../lib/langPack"; import { FormatterArguments, i18n, LangPackKey } from "../lib/langPack";
const toastEl = document.createElement('div'); const toastEl = document.createElement('div');
toastEl.classList.add('toast'); toastEl.classList.add('toast');
@ -21,7 +21,8 @@ export function toast(content: string | Node) {
} }
export function toastNew(options: Partial<{ export function toastNew(options: Partial<{
langPackKey: LangPackKey langPackKey: LangPackKey,
langPackArguments: FormatterArguments
}>) { }>) {
toast(i18n(options.langPackKey)); toast(i18n(options.langPackKey, options.langPackArguments));
} }

1
src/lang.ts

@ -688,6 +688,7 @@ const lang = {
"PrivacyPhoneInfo4": "This public link opens a chat with you:", "PrivacyPhoneInfo4": "This public link opens a chat with you:",
"ReportChatIllegalDrugs": "Illegal Drugs", "ReportChatIllegalDrugs": "Illegal Drugs",
"ReportChatPersonalDetails": "Personal Details", "ReportChatPersonalDetails": "Personal Details",
"VoipPeerIncompatible": "**%1$s**'s app is using an incompatible protocol. They need to update their app before you can call them.",
// * macos // * macos
"AccountSettings.Filters": "Chat Folders", "AccountSettings.Filters": "Chat Folders",

21
src/lib/appManagers/appCallsManager.ts

@ -15,12 +15,14 @@ import indexOfAndSplice from "../../helpers/array/indexOfAndSplice";
import insertInDescendSortedArray from "../../helpers/array/insertInDescendSortedArray"; import insertInDescendSortedArray from "../../helpers/array/insertInDescendSortedArray";
import AudioAssetPlayer from "../../helpers/audioAssetPlayer"; import AudioAssetPlayer from "../../helpers/audioAssetPlayer";
import bytesCmp from "../../helpers/bytes/bytesCmp"; import bytesCmp from "../../helpers/bytes/bytesCmp";
import compareVersion from "../../helpers/compareVersion";
import safeReplaceObject from "../../helpers/object/safeReplaceObject"; import safeReplaceObject from "../../helpers/object/safeReplaceObject";
import { nextRandomUint } from "../../helpers/random"; import { nextRandomUint } from "../../helpers/random";
import tsNow from "../../helpers/tsNow"; import tsNow from "../../helpers/tsNow";
import { InputPhoneCall, MessagesDhConfig, PhoneCall, PhoneCallDiscardReason, PhoneCallProtocol, PhonePhoneCall } from "../../layer"; import { InputPhoneCall, MessagesDhConfig, PhoneCall, PhoneCallDiscardReason, PhoneCallProtocol, PhonePhoneCall } from "../../layer";
import CallInstance from "../calls/callInstance"; import CallInstance from "../calls/callInstance";
import CALL_STATE from "../calls/callState"; import CALL_STATE from "../calls/callState";
import getCallProtocol from "../calls/p2P/getCallProtocol";
import { logger } from "../logger"; import { logger } from "../logger";
import apiManager from "../mtproto/mtprotoworker"; import apiManager from "../mtproto/mtprotoworker";
import { NULL_PEER_ID } from "../mtproto/mtproto_config"; import { NULL_PEER_ID } from "../mtproto/mtproto_config";
@ -74,6 +76,12 @@ export class AppCallsManager {
case 'phoneCallAccepted': { case 'phoneCallAccepted': {
if(instance) { if(instance) {
if(!this.verifyProtocolCompatibility(call.protocol)) {
instance.hangUp('phoneCallDiscardReasonDisconnect');
rootScope.dispatchEvent('call_incompatible', instance.interlocutorUserId);
break;
}
instance.confirmCall(); instance.confirmCall();
} }
@ -82,6 +90,11 @@ export class AppCallsManager {
case 'phoneCallRequested': { case 'phoneCallRequested': {
if(!instance) { if(!instance) {
if(!this.verifyProtocolCompatibility(call.protocol)) {
rootScope.dispatchEvent('call_incompatible', call.admin_id);
break;
}
instance = this.createCallInstance({ instance = this.createCallInstance({
isOutgoing: false, isOutgoing: false,
interlocutorUserId: call.admin_id interlocutorUserId: call.admin_id
@ -324,6 +337,14 @@ export class AppCallsManager {
}); });
} }
private verifyProtocolCompatibility(protocol: PhoneCallProtocol) {
const my = getCallProtocol();
const myVersion = my.library_versions[0];
return !protocol.library_versions.find(version => {
return compareVersion(myVersion, version) > 0;
});
}
public async discardCall(callId: CallId, duration: number, reason: PhoneCallDiscardReason['_'], video?: boolean) { public async discardCall(callId: CallId, duration: number, reason: PhoneCallDiscardReason['_'], video?: boolean) {
if(!this.getCall(callId)) { if(!this.getCall(callId)) {
return; return;

9
src/lib/appManagers/appImManager.ts

@ -377,6 +377,15 @@ export class AppImManager {
popup.show(); popup.show();
}); });
rootScope.addEventListener('call_incompatible', (userId) => {
toastNew({
langPackKey: 'VoipPeerIncompatible',
langPackArguments: [
new PeerTitle({peerId: userId.toPeerId()}).element
]
});
});
} }
// ! do not remove this line // ! do not remove this line

2
src/lib/calls/callInstance.ts

@ -14,6 +14,7 @@ import type { ApiUpdatesManager } from "../appManagers/apiUpdatesManager";
import type { AppCallsManager, CallId } from "../appManagers/appCallsManager"; import type { AppCallsManager, CallId } from "../appManagers/appCallsManager";
import { logger } from "../logger"; import { logger } from "../logger";
import type { ApiManagerProxy } from "../mtproto/mtprotoworker"; import type { ApiManagerProxy } from "../mtproto/mtprotoworker";
import rootScope from "../rootScope";
import CallConnectionInstance from "./callConnectionInstance"; import CallConnectionInstance from "./callConnectionInstance";
import CallInstanceBase from "./callInstanceBase"; import CallInstanceBase from "./callInstanceBase";
import CALL_STATE from "./callState"; import CALL_STATE from "./callState";
@ -847,6 +848,7 @@ export default class CallInstance extends CallInstanceBase<{
} catch(err) { } catch(err) {
this.log.error('wrong signaling data', str); this.log.error('wrong signaling data', str);
this.hangUp('phoneCallDiscardReasonDisconnect'); this.hangUp('phoneCallDiscardReasonDisconnect');
rootScope.dispatchEvent('call_incompatible', this.interlocutorUserId);
} }
} }
} }

1
src/lib/rootScope.ts

@ -160,6 +160,7 @@ export type BroadcastEvents = {
'call_instance': {hasCurrent: boolean, instance: CallInstance}, 'call_instance': {hasCurrent: boolean, instance: CallInstance},
'call_accepting': CallInstance, // это костыль. используется при параллельном вызове, чтобы заменить звонок в topbarCall 'call_accepting': CallInstance, // это костыль. используется при параллельном вызове, чтобы заменить звонок в topbarCall
'call_incompatible': UserId,
'quick_reaction': string, 'quick_reaction': string,

2
src/scss/partials/_chatlist.scss

@ -372,7 +372,7 @@ ul.chatlist {
top: 50%; top: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
line-height: 1; line-height: 1;
font-size: 1.25rem; font-size: 1rem;
} }
.media-photo { .media-photo {

Loading…
Cancel
Save