requestDirectChat

Use Quotient::connection::requestDirectChat directly as it can already handle all the conditions.
This commit is contained in:
James Graham
2024-10-04 16:52:05 +00:00
parent a314e56425
commit e26392ce94
7 changed files with 15 additions and 43 deletions

View File

@@ -399,29 +399,6 @@ bool NeoChatConnection::directChatExists(Quotient::User *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 notifications = 0;

View File

@@ -154,20 +154,6 @@ public:
*/
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.
*/

View File

@@ -255,9 +255,6 @@ Kirigami.ApplicationWindow {
Connections {
target: root.connection
function onDirectChatAvailable(directChat) {
RoomManager.resolveResource(directChat.id);
}
function onNewKeyVerificationSession(session) {
root.pageStack.pushDialogLayer(Qt.createComponent("org.kde.neochat", "KeyVerificationDialog"), {
session: session

View File

@@ -38,7 +38,7 @@ Kirigami.Dialog {
text: i18n("OK")
icon.name: "dialog-ok"
onTriggered: {
root.connection.openOrCreateDirectChat(userIdText.text);
root.connection.requestDirectChat(userIdText.text);
root.accept();
}
}

View File

@@ -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")
icon.name: "document-send"
onTriggered: {
root.connection.openOrCreateDirectChat(root.user.id);
root.connection.requestDirectChat(root.user.id);
root.close();
}
}

View File

@@ -59,7 +59,7 @@ SearchPage {
text: displayName
onClicked: {
root.connection.openOrCreateDirectChat(userDelegate.userId);
root.connection.requestDirectChat(userDelegate.userId);
root.closeDialog();
}

View File

@@ -437,7 +437,19 @@ void RoomManager::setConnection(NeoChatConnection *connection)
if (m_connection == connection) {
return;
}
if (m_connection != nullptr) {
m_connection->disconnect(this);
}
m_connection = connection;
if (m_connection != nullptr) {
connect(m_connection, &NeoChatConnection::directChatAvailable, this, [this](Quotient::Room *directChat) {
resolveResource(directChat->id());
});
}
Q_EMIT connectionChanged();
}