Browse Source

Support current WebK auth

master
Eduard Kuzmenko 3 years ago
parent
commit
e314c421b6
  1. 2
      src/lib/appManagers/appDialogsManager.ts
  2. 24
      src/lib/appManagers/appStateManager.ts
  3. 2
      src/lib/mtproto/apiManager.ts
  4. 26
      src/test_webk_auth_migration.js

2
src/lib/appManagers/appDialogsManager.ts

@ -710,6 +710,8 @@ export class AppDialogsManager { @@ -710,6 +710,8 @@ export class AppDialogsManager {
private onListLengthChange = () => {
//return;
if(this.filterId < 2) return;
const emptyFolder = this.chatList.parentElement.querySelector('.empty-folder');
if(this.scroll.loadedAll.bottom && !this.chatList.childElementCount) {

24
src/lib/appManagers/appStateManager.ts

@ -199,9 +199,10 @@ export class AppStateManager extends EventListenerBase<{ @@ -199,9 +199,10 @@ export class AppStateManager extends EventListenerBase<{
const promises: Promise<any>[] = ALL_KEYS.map(key => stateStorage.get(key))
.concat(sessionStorage.get('user_auth'))
.concat(stateStorage.get('user_auth' as any)) // support old webk format
.concat(storagesPromises);
Promise.all(promises).then((arr) => {
Promise.all(promises).then(async(arr) => {
/* const self = this;
const skipHandleKeys = new Set(['isProxy', 'filters', 'drafts']);
const getHandler = (path?: string) => {
@ -275,6 +276,27 @@ export class AppStateManager extends EventListenerBase<{ @@ -275,6 +276,27 @@ export class AppStateManager extends EventListenerBase<{
}
}
let shiftedWebKAuth = arr.shift() as UserAuth | number;
if(!auth && shiftedWebKAuth) { // support old webk auth
auth = shiftedWebKAuth;
const keys: string[] = ['dc', 'server_time_offset', 'xt_instance'];
for(let i = 1; i <= 5; ++i) {
keys.push(`dc${i}_server_salt`);
keys.push(`dc${i}_auth_key`);
}
const values = await Promise.all(keys.map(key => stateStorage.get(key as any)));
keys.push('user_auth');
values.push(typeof(auth) === 'number' ? {dcID: values[0] || App.baseDcId, id: auth} : auth);
let obj: any = {};
keys.forEach((key, idx) => {
obj[key] = values[idx];
});
await sessionStorage.set(obj);
}
if(auth) {
// ! Warning ! DON'T delete this
state.authState = {_: 'authStateSignedIn'};

2
src/lib/mtproto/apiManager.ts

@ -160,7 +160,7 @@ export class ApiManager { @@ -160,7 +160,7 @@ export class ApiManager {
// WebPushApiManager.forceUnsubscribe(); // WARNING
const storageResult = await Promise.all(storageKeys.map(key => sessionStorage.get(key as any)));
const logoutPromises = [];
const logoutPromises: Promise<any>[] = [];
for(let i = 0; i < storageResult.length; i++) {
if(storageResult[i]) {
logoutPromises.push(this.invokeApi('auth.logOut', {}, {dcId: i + 1, ignoreErrors: true}));

26
src/test_webk_auth_migration.js

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
(async function asd() {
const auth = 1;
const keys = ['dc', 'server_time_offset', 'xt_instance'];
for(let i = 1; i <= 5; ++i) {
keys.push(`dc${i}_server_salt`);
keys.push(`dc${i}_auth_key`);
}
const values = await Promise.all(keys.map(key => appStorage.get(key)));
keys.push('user_auth');
values.push(typeof(auth) === 'number' ? {dcID: values[0] || 2, id: auth} : auth);
let obj = {};
keys.forEach((key, idx) => {
obj[key] = values[idx];
});
window.exported = obj;
console.log(obj);
})();
copy(JSON.stringify(window.exported));
var obj = JSON.parse();
appStorage.set(obj);
Loading…
Cancel
Save