Skip to content

Commit

Permalink
Delay link/notification handling until chatListCreated
Browse files Browse the repository at this point in the history
(hopefully) fixes #412
  • Loading branch information
jgibbon committed May 26, 2021
1 parent bd9df7b commit df1f20c
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions qml/pages/OverviewPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Page {
property int ownUserId;
property bool chatListCreated: false;

// link handler:
property string urlToOpen: null;
property var chatToOpen: null; //null or [chatId, messageId]

onStatusChanged: {
if (status === PageStatus.Active && initializationCompleted && !chatListCreated && !logoutLoading) {
updateContent();
Expand All @@ -45,15 +49,12 @@ Page {
Connections {
target: dBusAdaptor
onPleaseOpenMessage: {
Debug.log("[OverviewPage] Opening chat from external call...")
if (chatListCreated) {
pageStack.pop(overviewPage, PageStackAction.Immediate)
pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : chatListModel.getById(chatId) }, PageStackAction.Immediate)
}
Debug.log("[OverviewPage] Opening chat from external requested: ", chatId);
openMessage(chatId, messageId);
}
onPleaseOpenUrl: {
Debug.log("[OverviewPage] Opening URL requested: ", url);
Functions.handleLink(url);
openUrl(url);
}
}

Expand All @@ -73,6 +74,8 @@ Page {
titleInteractionHint.opacity = 1.0;
appSettings.remainingInteractionHints = remainingInteractionHints - 1;
}
openUrl();
openMessage();
}
}

Expand Down Expand Up @@ -115,6 +118,29 @@ Page {
}
}

function openMessage(chatId, messageId) {
if(chatId && messageId) {
chatToOpen = [chatId, messageId];
}
if(chatListCreated && chatToOpen && chatToOpen.length === 2) { // messageId not handled (yet)
Debug.log("[OverviewPage] Opening Chat: ", chatToOpen[0]);
pageStack.pop(overviewPage, PageStackAction.Immediate);
pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : chatListModel.getById(chatToOpen[0]) }, PageStackAction.Immediate);
chatToOpen = null;
}
}

function openUrl(url) {
if(url && url.length > 0) {
urlToOpen = url;
}
if(chatListCreated && urlToOpen && urlToOpen.length > 1) {
Debug.log("[OverviewPage] Opening URL: ", urlToOpen);
Functions.handleLink(urlToOpen);
urlToOpen = null;
}
}

function setPageStatus() {
switch (overviewPage.connectionState) {
case TelegramAPI.WaitingForNetwork:
Expand Down

0 comments on commit df1f20c

Please sign in to comment.