Added telegram.me support
This commit is contained in:
parent
5c66fe0ef1
commit
d86b0a01ab
@ -309,7 +309,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
LayoutSwitchService.start();
|
LayoutSwitchService.start();
|
||||||
})
|
})
|
||||||
|
|
||||||
.controller('AppIMController', function ($scope, $location, $routeParams, $modal, $rootScope, $modalStack, MtpApiManager, AppUsersManager, AppChatsManager, AppPeersManager, ContactsSelectService, ChangelogNotifyService, ErrorService, AppRuntimeManager, HttpsMigrateService, LayoutSwitchService) {
|
.controller('AppIMController', function ($scope, $location, $routeParams, $modal, $rootScope, $modalStack, MtpApiManager, AppUsersManager, AppChatsManager, AppPeersManager, ContactsSelectService, ChangelogNotifyService, ErrorService, AppRuntimeManager, HttpsMigrateService, LayoutSwitchService, LocationParamsService) {
|
||||||
|
|
||||||
$scope.$on('$routeUpdate', updateCurDialog);
|
$scope.$on('$routeUpdate', updateCurDialog);
|
||||||
|
|
||||||
@ -459,6 +459,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
ChangelogNotifyService.checkUpdate();
|
ChangelogNotifyService.checkUpdate();
|
||||||
HttpsMigrateService.start();
|
HttpsMigrateService.start();
|
||||||
LayoutSwitchService.start();
|
LayoutSwitchService.start();
|
||||||
|
LocationParamsService.start();
|
||||||
})
|
})
|
||||||
|
|
||||||
.controller('AppImDialogsController', function ($scope, $location, $q, $timeout, $routeParams, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager, PhonebookContactsService, ErrorService) {
|
.controller('AppImDialogsController', function ($scope, $location, $q, $timeout, $routeParams, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager, PhonebookContactsService, ErrorService) {
|
||||||
|
@ -7,12 +7,14 @@
|
|||||||
|
|
||||||
angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
|
angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
|
||||||
|
|
||||||
.factory('MtpApiManager', function (Storage, MtpAuthorizer, MtpNetworkerFactory, MtpSingleInstanceService, ErrorService, qSync, $q) {
|
.factory('MtpApiManager', function (Storage, MtpAuthorizer, MtpNetworkerFactory, MtpSingleInstanceService, ErrorService, qSync, $q, TelegramMeWebService) {
|
||||||
var cachedNetworkers = {},
|
var cachedNetworkers = {},
|
||||||
cachedUploadNetworkers = {},
|
cachedUploadNetworkers = {},
|
||||||
cachedExportPromise = {},
|
cachedExportPromise = {},
|
||||||
baseDcID = false;
|
baseDcID = false;
|
||||||
|
|
||||||
|
var telegramMeNotified;
|
||||||
|
|
||||||
MtpSingleInstanceService.start();
|
MtpSingleInstanceService.start();
|
||||||
|
|
||||||
Storage.get('dc').then(function (dcID) {
|
Storage.get('dc').then(function (dcID) {
|
||||||
@ -21,11 +23,19 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function telegramMeNotify (newValue) {
|
||||||
|
if (telegramMeNotified != newValue) {
|
||||||
|
telegramMeNotified = newValue;
|
||||||
|
TelegramMeWebService.setAuthorized(telegramMeNotified);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function mtpSetUserAuth (dcID, userAuth) {
|
function mtpSetUserAuth (dcID, userAuth) {
|
||||||
Storage.set({
|
Storage.set({
|
||||||
dc: dcID,
|
dc: dcID,
|
||||||
user_auth: angular.extend({dcID: dcID}, userAuth)
|
user_auth: angular.extend({dcID: dcID}, userAuth)
|
||||||
});
|
});
|
||||||
|
telegramMeNotify(true);
|
||||||
|
|
||||||
baseDcID = dcID;
|
baseDcID = dcID;
|
||||||
}
|
}
|
||||||
@ -45,11 +55,13 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
|
|||||||
return $q.all(logoutPromises).then(function () {
|
return $q.all(logoutPromises).then(function () {
|
||||||
Storage.remove('dc', 'user_auth');
|
Storage.remove('dc', 'user_auth');
|
||||||
baseDcID = false;
|
baseDcID = false;
|
||||||
|
telegramMeNotify(false);
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
Storage.remove.apply(storageKeys);
|
Storage.remove.apply(storageKeys);
|
||||||
Storage.remove('dc', 'user_auth');
|
Storage.remove('dc', 'user_auth');
|
||||||
baseDcID = false;
|
baseDcID = false;
|
||||||
error.handled = true;
|
error.handled = true;
|
||||||
|
telegramMeNotify(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -147,6 +159,7 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
|
|||||||
console.error(dT(), 'Error', error.code, error.type, baseDcID, dcID);
|
console.error(dT(), 'Error', error.code, error.type, baseDcID, dcID);
|
||||||
if (error.code == 401 && baseDcID == dcID) {
|
if (error.code == 401 && baseDcID == dcID) {
|
||||||
Storage.remove('dc', 'user_auth');
|
Storage.remove('dc', 'user_auth');
|
||||||
|
telegramMeNotify(false);
|
||||||
rejectPromise(error);
|
rejectPromise(error);
|
||||||
}
|
}
|
||||||
else if (error.code == 401 && baseDcID && dcID != baseDcID) {
|
else if (error.code == 401 && baseDcID && dcID != baseDcID) {
|
||||||
@ -210,6 +223,7 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
|
|||||||
|
|
||||||
function mtpGetUserID () {
|
function mtpGetUserID () {
|
||||||
return Storage.get('user_auth').then(function (auth) {
|
return Storage.get('user_auth').then(function (auth) {
|
||||||
|
telegramMeNotify(auth && auth.id > 0 || false);
|
||||||
return auth.id || 0;
|
return auth.id || 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4103,19 +4103,74 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
.service('TelegramMeWebService', function (Storage) {
|
||||||
|
|
||||||
// .service('LocationParamsService', function ($routeParams) {
|
var disabled = Config.Modes.test ||
|
||||||
|
Config.App.domains.indexOf(location.hostname) == -1 ||
|
||||||
|
location.protocol != 'http:' && location.protocol != 'https:' ||
|
||||||
|
location.protocol == 'https:' && location.hostname != 'web.telegram.org';
|
||||||
|
|
||||||
// var started = false;
|
function sendAsyncRequest (canRedirect) {
|
||||||
// function start () {
|
canRedirect = false;
|
||||||
// if (started) {
|
if (disabled) {
|
||||||
// return;
|
return false;
|
||||||
// }
|
}
|
||||||
// started = true;
|
Storage.get('tgme_sync').then(function (curValue) {
|
||||||
// navigator.registerProtocolHandler('web+tg', '#im?tgaddr=%s', 'Telegram Web');
|
var ts = tsNow(true);
|
||||||
// };
|
if (curValue &&
|
||||||
|
curValue.canRedirect == canRedirect &&
|
||||||
|
curValue.ts + 86400 > ts) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Storage.set({tgme_sync: {canRedirect: canRedirect, ts: ts}});
|
||||||
|
|
||||||
// return {
|
var script = $('<script>').appendTo('body')
|
||||||
// start: start
|
.on('load error', function() {
|
||||||
// };
|
script.remove();
|
||||||
// })
|
})
|
||||||
|
.attr('src', '//telegram.me/_websync_?authed=' + (canRedirect ? '1' : '0'));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
setAuthorized: sendAsyncRequest
|
||||||
|
};
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
.service('LocationParamsService', function ($rootScope, $routeParams, AppUsersManager) {
|
||||||
|
|
||||||
|
function checkTgAddr () {
|
||||||
|
if (!$routeParams.tgaddr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var matches = $routeParams.tgaddr.match(/^(web\+)?tg:(\/\/)?resolve\?domain=(.+)$/);
|
||||||
|
if (matches && matches[3]) {
|
||||||
|
AppUsersManager.resolveUsername(matches[3]).then(function (userID) {
|
||||||
|
$rootScope.$broadcast('history_focus', {
|
||||||
|
peerString: AppUsersManager.getUserString(userID)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var started = !('registerProtocolHandler' in navigator);
|
||||||
|
function start () {
|
||||||
|
if (started) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
started = true;
|
||||||
|
try {
|
||||||
|
navigator.registerProtocolHandler('tg', '#im?tgaddr=%s', 'Telegram Web');
|
||||||
|
} catch (e) {}
|
||||||
|
navigator.registerProtocolHandler('web+tg', '#im?tgaddr=%s', 'Telegram Web');
|
||||||
|
|
||||||
|
$rootScope.$on('$routeUpdate', checkTgAddr);
|
||||||
|
checkTgAddr();
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
start: start
|
||||||
|
};
|
||||||
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user