Commit 8b2512c5 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Ming Rui Zhang

messagesadapter: clear conversation uid cache if it is currently selected

For clearConversationHistory and removeConversation

Gitlab: #252

Change-Id: I3008cf20ddace5d3395465bd328a460c72e4c07f
parent 9ef94561
......@@ -59,7 +59,7 @@ Item {
ContextMenuGenerator.addMenuItem(qsTr("Clear conversation"),
"qrc:/images/icons/ic_clear_24px.svg",
function (){
UtilsAdapter.clearConversationHistory(
MessagesAdapter.clearConversationHistory(
responsibleAccountId,
responsibleConvUid)
})
......@@ -68,7 +68,7 @@ Item {
ContextMenuGenerator.addMenuItem(qsTr("Remove contact"),
"qrc:/images/icons/round-remove_circle-24px.svg",
function (){
UtilsAdapter.removeConversation(
MessagesAdapter.removeConversation(
responsibleAccountId,
responsibleConvUid)
})
......
......@@ -119,10 +119,9 @@ ListView {
sequence: "Ctrl+Shift+L"
context: Qt.ApplicationShortcut
enabled: root.visible
onActivated: {
UtilsAdapter.clearConversationHistory(AccountAdapter.currentAccountId,
UtilsAdapter.getCurrConvId())
}
onActivated: MessagesAdapter.clearConversationHistory(
AccountAdapter.currentAccountId,
UtilsAdapter.getCurrConvId())
}
Shortcut {
......@@ -138,11 +137,10 @@ ListView {
sequence: "Ctrl+Shift+Delete"
context: Qt.ApplicationShortcut
enabled: root.visible
onActivated: {
UtilsAdapter.removeConversation(AccountAdapter.currentAccountId,
UtilsAdapter.getCurrConvId(),
false)
}
onActivated: MessagesAdapter.removeConversation(
AccountAdapter.currentAccountId,
UtilsAdapter.getCurrConvId(),
false)
}
Shortcut {
......
......@@ -665,6 +665,8 @@ MessagesAdapter::refuseInvitation(const QString& convUid)
const auto currentConvUid = convUid.isEmpty() ? LRCInstance::getCurrentConvUid() : convUid;
LRCInstance::getCurrentConversationModel()->removeConversation(currentConvUid, false);
setInvitation(false);
if (convUid == currentConvUid_)
currentConvUid_.clear();
emit navigateToWelcomePageRequested();
}
......@@ -674,6 +676,25 @@ MessagesAdapter::blockConversation(const QString& convUid)
const auto currentConvUid = convUid.isEmpty() ? LRCInstance::getCurrentConvUid() : convUid;
LRCInstance::getCurrentConversationModel()->removeConversation(currentConvUid, true);
setInvitation(false);
if (convUid == currentConvUid_)
currentConvUid_.clear();
emit contactBanned();
emit navigateToWelcomePageRequested();
}
void
MessagesAdapter::clearConversationHistory(const QString& accountId, const QString& uid)
{
LRCInstance::getAccountInfo(accountId).conversationModel->clearHistory(uid);
if (uid == currentConvUid_)
currentConvUid_.clear();
}
void
MessagesAdapter::removeConversation(const QString& accountId, const QString& uid, bool banContact)
{
LRCInstance::getAccountInfo(accountId).conversationModel->removeConversation(uid, banContact);
if (uid == currentConvUid_)
currentConvUid_.clear();
emit navigateToWelcomePageRequested();
}
......@@ -41,6 +41,10 @@ protected:
Q_INVOKABLE void connectConversationModel();
Q_INVOKABLE void sendContactRequest();
Q_INVOKABLE void updateConversationForAddedContact();
Q_INVOKABLE void removeConversation(const QString& accountId,
const QString& uid,
bool banContact = false);
Q_INVOKABLE void clearConversationHistory(const QString& accountId, const QString& uid);
/*
* JS Q_INVOKABLE.
......
......@@ -157,18 +157,6 @@ UtilsAdapter::setConversationFilter(const QString& filter)
LRCInstance::getCurrentConversationModel()->setFilter(filter);
}
void
UtilsAdapter::clearConversationHistory(const QString& accountId, const QString& uid)
{
LRCInstance::getAccountInfo(accountId).conversationModel->clearHistory(uid);
}
void
UtilsAdapter::removeConversation(const QString& accountId, const QString& uid, bool banContact)
{
LRCInstance::getAccountInfo(accountId).conversationModel->removeConversation(uid, banContact);
}
const QString
UtilsAdapter::getCurrConvId()
{
......
......@@ -43,10 +43,6 @@ public:
Q_INVOKABLE bool createStartupLink();
Q_INVOKABLE QString GetRingtonePath();
Q_INVOKABLE bool checkStartupLink();
Q_INVOKABLE void removeConversation(const QString& accountId,
const QString& uid,
bool banContact = false);
Q_INVOKABLE void clearConversationHistory(const QString& accountId, const QString& uid);
Q_INVOKABLE void setConversationFilter(const QString& filter);
Q_INVOKABLE int getTotalUnreadMessages();
Q_INVOKABLE int getTotalPendingRequest();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment