Mark rooms as direct chats
Either by accepting an invite or manually using /converttodm and revert with /converttoroom.
This commit is contained in:
parent
4dc5b647c6
commit
3d92e8ae60
@ -660,8 +660,8 @@ ChatPage::trySync()
|
|||||||
http::client()->sync(
|
http::client()->sync(
|
||||||
opts, [this, since = opts.since](const mtx::responses::Sync &res, mtx::http::RequestErr err) {
|
opts, [this, since = opts.since](const mtx::responses::Sync &res, mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
const auto error = QString::fromStdString(err->matrix_error.error);
|
const auto error = QString::fromStdString(err->matrix_error.error);
|
||||||
const auto msg = tr("Please try to login again: %1").arg(error);
|
const auto msg = tr("Please try to login again: %1").arg(error);
|
||||||
|
|
||||||
if ((http::is_logged_in() &&
|
if ((http::is_logged_in() &&
|
||||||
(err->matrix_error.errcode == mtx::errors::ErrorCode::M_UNKNOWN_TOKEN ||
|
(err->matrix_error.errcode == mtx::errors::ErrorCode::M_UNKNOWN_TOKEN ||
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "EventAccessors.h"
|
#include "EventAccessors.h"
|
||||||
|
#include "Logging.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "UserSettingsPage.h"
|
#include "UserSettingsPage.h"
|
||||||
|
|
||||||
@ -813,3 +814,65 @@ utils::isReply(const mtx::events::collections::TimelineEvents &e)
|
|||||||
{
|
{
|
||||||
return mtx::accessors::relations(e).reply_to().has_value();
|
return mtx::accessors::relations(e).reply_to().has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
utils::removeDirectFromRoom(QString roomid)
|
||||||
|
{
|
||||||
|
http::client()->get_account_data<mtx::events::account_data::Direct>(
|
||||||
|
[roomid](mtx::events::account_data::Direct ev, mtx::http::RequestErr e) {
|
||||||
|
if (e && e->status_code == 404)
|
||||||
|
ev = {};
|
||||||
|
else if (e) {
|
||||||
|
nhlog::net()->error("Failed to retrieve m.direct: {}", *e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto r = roomid.toStdString();
|
||||||
|
|
||||||
|
for (auto it = ev.user_to_rooms.begin(); it != ev.user_to_rooms.end();) {
|
||||||
|
for (auto rit = it->second.begin(); rit != it->second.end();) {
|
||||||
|
if (r == *rit)
|
||||||
|
rit = it->second.erase(rit);
|
||||||
|
else
|
||||||
|
++rit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it->second.empty())
|
||||||
|
it = ev.user_to_rooms.erase(it);
|
||||||
|
else
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
|
http::client()->put_account_data(ev, [r](mtx::http::RequestErr e) {
|
||||||
|
if (e)
|
||||||
|
nhlog::net()->error("Failed to update m.direct: {}", *e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
void
|
||||||
|
utils::markRoomAsDirect(QString roomid, std::vector<RoomMember> members)
|
||||||
|
{
|
||||||
|
http::client()->get_account_data<mtx::events::account_data::Direct>(
|
||||||
|
[roomid, members](mtx::events::account_data::Direct ev, mtx::http::RequestErr e) {
|
||||||
|
if (e && e->status_code == 404)
|
||||||
|
ev = {};
|
||||||
|
else if (e) {
|
||||||
|
nhlog::net()->error("Failed to retrieve m.direct: {}", *e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto local = utils::localUser();
|
||||||
|
auto r = roomid.toStdString();
|
||||||
|
|
||||||
|
for (const auto &m : members) {
|
||||||
|
if (m.user_id != local) {
|
||||||
|
ev.user_to_rooms[m.user_id.toStdString()].push_back(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
http::client()->put_account_data(ev, [r](mtx::http::RequestErr e) {
|
||||||
|
if (e)
|
||||||
|
nhlog::net()->error("Failed to update m.direct: {}", *e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
|
#include <CacheStructs.h>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
@ -304,4 +305,10 @@ readImage(const QByteArray &data);
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
isReply(const mtx::events::collections::TimelineEvents &e);
|
isReply(const mtx::events::collections::TimelineEvents &e);
|
||||||
|
|
||||||
|
void
|
||||||
|
removeDirectFromRoom(QString roomid);
|
||||||
|
|
||||||
|
void
|
||||||
|
markRoomAsDirect(QString roomid, std::vector<RoomMember> members);
|
||||||
}
|
}
|
||||||
|
@ -645,6 +645,11 @@ InputBar::command(QString command, QString args)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nhlog::net()->error("Could not resolve goto: {}", args.toStdString());
|
nhlog::net()->error("Could not resolve goto: {}", args.toStdString());
|
||||||
|
} else if (command == "converttodm") {
|
||||||
|
utils::markRoomAsDirect(this->room->roomId(),
|
||||||
|
cache::getMembers(this->room->roomId().toStdString(), 0, -1));
|
||||||
|
} else if (command == "converttoroom") {
|
||||||
|
utils::removeDirectFromRoom(this->room->roomId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -627,6 +627,8 @@ RoomlistModel::acceptInvite(QString roomid)
|
|||||||
if (invites.contains(roomid)) {
|
if (invites.contains(roomid)) {
|
||||||
// Don't remove invite yet, so that we can switch to it
|
// Don't remove invite yet, so that we can switch to it
|
||||||
ChatPage::instance()->joinRoom(roomid);
|
ChatPage::instance()->joinRoom(roomid);
|
||||||
|
utils::markRoomAsDirect(roomid,
|
||||||
|
cache::client()->getMembersFromInvite(roomid.toStdString(), 0, -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user