requestDirectChat
Use Quotient::connection::requestDirectChat directly as it can already handle all the conditions.
This commit is contained in:
@@ -399,29 +399,6 @@ bool NeoChatConnection::directChatExists(Quotient::User *user)
|
|||||||
return directChats().contains(user);
|
return directChats().contains(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeoChatConnection::openOrCreateDirectChat(const QString &userId)
|
|
||||||
{
|
|
||||||
if (auto user = this->user(userId)) {
|
|
||||||
openOrCreateDirectChat(user);
|
|
||||||
} else {
|
|
||||||
qWarning() << "openOrCreateDirectChat: Couldn't get user object for ID " << userId << ", unable to open/request direct chat.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NeoChatConnection::openOrCreateDirectChat(User *user)
|
|
||||||
{
|
|
||||||
const auto existing = directChats();
|
|
||||||
|
|
||||||
if (existing.contains(user)) {
|
|
||||||
const auto room = this->room(existing.value(user));
|
|
||||||
if (room) {
|
|
||||||
RoomManager::instance().resolveResource(room->id());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
requestDirectChat(user->id());
|
|
||||||
}
|
|
||||||
|
|
||||||
qsizetype NeoChatConnection::directChatNotifications() const
|
qsizetype NeoChatConnection::directChatNotifications() const
|
||||||
{
|
{
|
||||||
qsizetype notifications = 0;
|
qsizetype notifications = 0;
|
||||||
|
|||||||
@@ -154,20 +154,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
Q_INVOKABLE bool directChatExists(Quotient::User *user);
|
Q_INVOKABLE bool directChatExists(Quotient::User *user);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Join a direct chat with the given user ID.
|
|
||||||
*
|
|
||||||
* If a direct chat with the user doesn't exist one is created and then joined.
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void openOrCreateDirectChat(const QString &userId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Join a direct chat with the given user object.
|
|
||||||
*
|
|
||||||
* If a direct chat with the user doesn't exist one is created and then joined.
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void openOrCreateDirectChat(Quotient::User *user);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the account data with \param type as a formatted JSON string.
|
* @brief Get the account data with \param type as a formatted JSON string.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -255,9 +255,6 @@ Kirigami.ApplicationWindow {
|
|||||||
Connections {
|
Connections {
|
||||||
target: root.connection
|
target: root.connection
|
||||||
|
|
||||||
function onDirectChatAvailable(directChat) {
|
|
||||||
RoomManager.resolveResource(directChat.id);
|
|
||||||
}
|
|
||||||
function onNewKeyVerificationSession(session) {
|
function onNewKeyVerificationSession(session) {
|
||||||
root.pageStack.pushDialogLayer(Qt.createComponent("org.kde.neochat", "KeyVerificationDialog"), {
|
root.pageStack.pushDialogLayer(Qt.createComponent("org.kde.neochat", "KeyVerificationDialog"), {
|
||||||
session: session
|
session: session
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ Kirigami.Dialog {
|
|||||||
text: i18n("OK")
|
text: i18n("OK")
|
||||||
icon.name: "dialog-ok"
|
icon.name: "dialog-ok"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
root.connection.openOrCreateDirectChat(userIdText.text);
|
root.connection.requestDirectChat(userIdText.text);
|
||||||
root.accept();
|
root.accept();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ Kirigami.Dialog {
|
|||||||
text: root.connection.directChatExists(root.user) ? i18nc("%1 is the name of the user.", "Chat with %1", root.room ? root.room.member(root.user.id).htmlSafeDisplayName : QmlUtils.escapeString(root.user.displayName)) : i18n("Invite to private chat")
|
text: root.connection.directChatExists(root.user) ? i18nc("%1 is the name of the user.", "Chat with %1", root.room ? root.room.member(root.user.id).htmlSafeDisplayName : QmlUtils.escapeString(root.user.displayName)) : i18n("Invite to private chat")
|
||||||
icon.name: "document-send"
|
icon.name: "document-send"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
root.connection.openOrCreateDirectChat(root.user.id);
|
root.connection.requestDirectChat(root.user.id);
|
||||||
root.close();
|
root.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ SearchPage {
|
|||||||
text: displayName
|
text: displayName
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
root.connection.openOrCreateDirectChat(userDelegate.userId);
|
root.connection.requestDirectChat(userDelegate.userId);
|
||||||
root.closeDialog();
|
root.closeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -437,7 +437,19 @@ void RoomManager::setConnection(NeoChatConnection *connection)
|
|||||||
if (m_connection == connection) {
|
if (m_connection == connection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_connection != nullptr) {
|
||||||
|
m_connection->disconnect(this);
|
||||||
|
}
|
||||||
|
|
||||||
m_connection = connection;
|
m_connection = connection;
|
||||||
|
|
||||||
|
if (m_connection != nullptr) {
|
||||||
|
connect(m_connection, &NeoChatConnection::directChatAvailable, this, [this](Quotient::Room *directChat) {
|
||||||
|
resolveResource(directChat->id());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Q_EMIT connectionChanged();
|
Q_EMIT connectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user