From c27db173ce713de11bbc4240b472fe41d7c37b16 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Fri, 21 Jul 2017 18:34:44 +0200 Subject: [PATCH] Start distant chat using helper on ChatCache --- retroshare-qml-app/src/ChatCache.qml | 31 +++++++++++++++++++ retroshare-qml-app/src/Contacts.qml | 7 ----- .../src/GxsIdentityDelegate.qml | 17 +++++----- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/retroshare-qml-app/src/ChatCache.qml b/retroshare-qml-app/src/ChatCache.qml index 6e7b55c72..34854a083 100644 --- a/retroshare-qml-app/src/ChatCache.qml +++ b/retroshare-qml-app/src/ChatCache.qml @@ -136,4 +136,35 @@ QtObject } + property QtObject chatHelper: QtObject + { + id: chatHelper + property var gxs_id + property var name + property var cb + + function startDistantChat (own_gxs_id, gxs_id, name, cb) + { + console.log("startDistantChat()") + chatHelper.gxs_id = gxs_id + chatHelper.name = name + chatHelper.cb = cb + var jsonData = { "own_gxs_hex": own_gxs_id, + "remote_gxs_hex": gxs_id } + rsApi.request("/chat/initiate_distant_chat", + JSON.stringify(jsonData), + startDistantChatCB) + + } + + function startDistantChatCB (par) + { + var chatId = JSON.parse(par.response).data.chat_id + lastMessageCache.setRemoteGXS(chatId, { gxs: gxs_id, name: name}) + cb(chatId) + } + } + + + } diff --git a/retroshare-qml-app/src/Contacts.qml b/retroshare-qml-app/src/Contacts.qml index 415c33eb8..07bd62511 100644 --- a/retroshare-qml-app/src/Contacts.qml +++ b/retroshare-qml-app/src/Contacts.qml @@ -132,13 +132,6 @@ Item rsApi.request("/chat/unread_msgs", "", refreshUnreadCallback) } - function startChatCallback(par) - { - var chId = JSON.parse(par.response).data.chat_id - stackView.push("qrc:/ChatView.qml", {'chatId': chId}) - } - - /** This must be equivalent to p3GxsTunnelService::makeGxsTunnelId(...) */ function getChatId(from_gxs, to_gxs) diff --git a/retroshare-qml-app/src/GxsIdentityDelegate.qml b/retroshare-qml-app/src/GxsIdentityDelegate.qml index 41ad5454f..650cf6551 100644 --- a/retroshare-qml-app/src/GxsIdentityDelegate.qml +++ b/retroshare-qml-app/src/GxsIdentityDelegate.qml @@ -53,11 +53,7 @@ Item if(model.own) contactsView.own_gxs_id = model.gxs_id else { - var jsonData = { "own_gxs_hex": contactsView.own_gxs_id, - "remote_gxs_hex": model.gxs_id } - rsApi.request("/chat/initiate_distant_chat", - JSON.stringify(jsonData), - startDistantChatCB) + startDistantChat() } } @@ -278,11 +274,14 @@ Item "qrc:/ContactDetails.qml", {md: contactsListView.model.get(index)}) } - function startDistantChatCB (par) + + function startDistantChat () { - var chId = JSON.parse(par.response).data.chat_id - ChatCache.lastMessageCache.setRemoteGXS(chId, { gxs: model.gxs_id, name: model.name}) - contactsView.startChatCallback (par) + ChatCache.chatHelper.startDistantChat(contactsView.own_gxs_id, model.gxs_id, model.name, + function (chatId) + { + stackView.push("qrc:/ChatView.qml", {'chatId': chatId}) + }) } }