Fix marking newly created rooms as DM automatically

fixes #1718
This commit is contained in:
Nicolas Werner 2024-06-04 00:37:23 +02:00
parent 9f5982e180
commit d0d95df89d
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

@ -986,8 +986,15 @@ ChatPage::createRoom(const mtx::requests::CreateRoom &req)
return;
}
bool direct = req.is_direct;
std::string direct_user;
if (direct && !req.invite.empty())
direct_user = req.invite.front();
http::client()->create_room(
req, [this](const mtx::responses::CreateRoom &res, mtx::http::RequestErr err) {
req,
[this, direct, direct_user](const mtx::responses::CreateRoom &res,
mtx::http::RequestErr err) {
if (err) {
const auto err_code = mtx::errors::to_string(err->matrix_error.errcode);
const auto error = err->matrix_error.error;
@ -1000,6 +1007,16 @@ ChatPage::createRoom(const mtx::requests::CreateRoom &req)
}
QString newRoomId = QString::fromStdString(res.room_id.to_string());
if (direct && !direct_user.empty()) {
utils::markRoomAsDirect(newRoomId,
{RoomMember{
.user_id = QString::fromStdString(direct_user),
.display_name = "",
.avatar_url = "",
}});
}
emit showNotification(tr("Room %1 created.").arg(newRoomId));
emit newRoom(newRoomId);
emit changeToRoom(newRoomId);