Sync: Fix support for tgaddr parameter
This commit is contained in:
parent
b47f8c765e
commit
9fe5ca5c45
@ -30,7 +30,6 @@ import {
|
|||||||
import { hasStoredSession } from '../util/sessions';
|
import { hasStoredSession } from '../util/sessions';
|
||||||
import { INITIAL_STATE } from './initial';
|
import { INITIAL_STATE } from './initial';
|
||||||
import { parseLocationHash } from '../util/routing';
|
import { parseLocationHash } from '../util/routing';
|
||||||
import { LOCATION_HASH } from '../hooks/useHistoryBack';
|
|
||||||
import { isUserId } from '../modules/helpers';
|
import { isUserId } from '../modules/helpers';
|
||||||
import { getOrderedIds } from '../util/folderManager';
|
import { getOrderedIds } from '../util/folderManager';
|
||||||
|
|
||||||
@ -120,7 +119,7 @@ function readCache(initialState: GlobalState): GlobalState {
|
|||||||
...cached,
|
...cached,
|
||||||
};
|
};
|
||||||
|
|
||||||
const parsedMessageList = !IS_SINGLE_COLUMN_LAYOUT ? parseLocationHash(LOCATION_HASH) : undefined;
|
const parsedMessageList = !IS_SINGLE_COLUMN_LAYOUT ? parseLocationHash() : undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...newState,
|
...newState,
|
||||||
|
|||||||
@ -81,7 +81,6 @@ async function loadAndReplaceMessages() {
|
|||||||
let areMessagesLoaded = false;
|
let areMessagesLoaded = false;
|
||||||
|
|
||||||
let global = getGlobal();
|
let global = getGlobal();
|
||||||
const { chatId: currentChatId, threadId: currentThreadId } = selectCurrentMessageList(global) || {};
|
|
||||||
|
|
||||||
// Memoize drafts
|
// Memoize drafts
|
||||||
const draftChatIds = Object.keys(global.messages.byChatId);
|
const draftChatIds = Object.keys(global.messages.byChatId);
|
||||||
@ -94,8 +93,10 @@ async function loadAndReplaceMessages() {
|
|||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
if (currentChatId) {
|
const { chatId: currentChatId, threadId: currentThreadId } = selectCurrentMessageList(global) || {};
|
||||||
const result = await loadTopMessages(global.chats.byId[currentChatId]);
|
const currentChat = currentChatId ? global.chats.byId[currentChatId] : undefined;
|
||||||
|
if (currentChatId && currentChat) {
|
||||||
|
const result = await loadTopMessages(currentChat);
|
||||||
global = getGlobal();
|
global = getGlobal();
|
||||||
const { chatId: newCurrentChatId } = selectCurrentMessageList(global) || {};
|
const { chatId: newCurrentChatId } = selectCurrentMessageList(global) || {};
|
||||||
const threadInfo = currentThreadId && selectThreadInfo(global, currentChatId, currentThreadId);
|
const threadInfo = currentThreadId && selectThreadInfo(global, currentChatId, currentThreadId);
|
||||||
|
|||||||
@ -1,18 +1,23 @@
|
|||||||
import { MessageList, MessageListType } from '../global/types';
|
import { MessageList, MessageListType } from '../global/types';
|
||||||
import { MAIN_THREAD_ID } from '../api/types';
|
import { MAIN_THREAD_ID } from '../api/types';
|
||||||
|
|
||||||
export const createMessageHash = (messageList: MessageList): string => (
|
import { LOCATION_HASH } from '../hooks/useHistoryBack';
|
||||||
messageList.chatId.toString()
|
|
||||||
+ (messageList.type !== 'thread' ? `_${messageList.type}`
|
|
||||||
: (messageList.threadId !== -1 ? `_${messageList.threadId}` : ''))
|
|
||||||
);
|
|
||||||
|
|
||||||
export const parseLocationHash = (value: string): MessageList | undefined => {
|
export function createMessageHash(messageList: MessageList) {
|
||||||
if (!value) return undefined;
|
const typeOrThreadId = messageList.type !== 'thread' ? (
|
||||||
|
`_${messageList.type}`
|
||||||
|
) : messageList.threadId !== -1 ? (
|
||||||
|
`_${messageList.threadId}`
|
||||||
|
) : '';
|
||||||
|
|
||||||
const [chatId, typeOrThreadId] = value.replace(/^#/, '').split('_');
|
return `${messageList.chatId}${typeOrThreadId}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (!chatId) return undefined;
|
export function parseLocationHash() {
|
||||||
|
if (!LOCATION_HASH) return undefined;
|
||||||
|
|
||||||
|
const [chatId, typeOrThreadId] = LOCATION_HASH.replace(/^#/, '').split('_');
|
||||||
|
if (!chatId?.match(/^-?\d+$/)) return undefined;
|
||||||
|
|
||||||
const isType = ['thread', 'pinned', 'scheduled'].includes(typeOrThreadId);
|
const isType = ['thread', 'pinned', 'scheduled'].includes(typeOrThreadId);
|
||||||
|
|
||||||
@ -21,4 +26,4 @@ export const parseLocationHash = (value: string): MessageList | undefined => {
|
|||||||
type: Boolean(typeOrThreadId) && isType ? (typeOrThreadId as MessageListType) : 'thread',
|
type: Boolean(typeOrThreadId) && isType ? (typeOrThreadId as MessageListType) : 'thread',
|
||||||
threadId: Boolean(typeOrThreadId) && !isType ? Number(typeOrThreadId) : MAIN_THREAD_ID,
|
threadId: Boolean(typeOrThreadId) && !isType ? Number(typeOrThreadId) : MAIN_THREAD_ID,
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user