mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Merge branch 'master' of ssh://github.com/Nheko-Reborn/nheko
This commit is contained in:
commit
a8877c39f4
8 changed files with 49 additions and 22 deletions
|
@ -354,7 +354,7 @@ if(USE_BUNDLED_MTXCLIENT)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
MatrixClient
|
MatrixClient
|
||||||
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
|
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
|
||||||
GIT_TAG cad81d1677a4845366b93112f8f2e267ee8c9ae0
|
GIT_TAG f364a5e83db3f1978b6c3d3453accae02c9267c3
|
||||||
)
|
)
|
||||||
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
|
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
|
||||||
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
|
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
|
||||||
|
|
|
@ -152,7 +152,7 @@
|
||||||
"name": "mtxclient",
|
"name": "mtxclient",
|
||||||
"sources": [
|
"sources": [
|
||||||
{
|
{
|
||||||
"commit": "cad81d1677a4845366b93112f8f2e267ee8c9ae0",
|
"commit": "f364a5e83db3f1978b6c3d3453accae02c9267c3",
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/Nheko-Reborn/mtxclient.git"
|
"url": "https://github.com/Nheko-Reborn/mtxclient.git"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1208,10 +1208,11 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
for (const auto &ev : res.account_data.events)
|
for (const auto &ev : res.account_data.events)
|
||||||
std::visit(
|
std::visit(
|
||||||
[&txn, &accountDataDb](const auto &event) {
|
[&txn, &accountDataDb](const auto &event) {
|
||||||
|
auto j = json(event);
|
||||||
lmdb::dbi_put(txn,
|
lmdb::dbi_put(txn,
|
||||||
accountDataDb,
|
accountDataDb,
|
||||||
lmdb::val(to_string(event.type)),
|
lmdb::val(j["type"].get<std::string>()),
|
||||||
lmdb::val(json(event).dump()));
|
lmdb::val(j.dump()));
|
||||||
},
|
},
|
||||||
ev);
|
ev);
|
||||||
}
|
}
|
||||||
|
@ -1242,10 +1243,11 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
for (const auto &evt : room.second.account_data.events) {
|
for (const auto &evt : room.second.account_data.events) {
|
||||||
std::visit(
|
std::visit(
|
||||||
[&txn, &accountDataDb](const auto &event) {
|
[&txn, &accountDataDb](const auto &event) {
|
||||||
|
auto j = json(event);
|
||||||
lmdb::dbi_put(txn,
|
lmdb::dbi_put(txn,
|
||||||
accountDataDb,
|
accountDataDb,
|
||||||
lmdb::val(to_string(event.type)),
|
lmdb::val(j["type"].get<std::string>()),
|
||||||
lmdb::val(json(event).dump()));
|
lmdb::val(j.dump()));
|
||||||
},
|
},
|
||||||
evt);
|
evt);
|
||||||
|
|
||||||
|
@ -1391,10 +1393,11 @@ Cache::saveInvite(lmdb::txn &txn,
|
||||||
} else {
|
} else {
|
||||||
std::visit(
|
std::visit(
|
||||||
[&txn, &statesdb](auto msg) {
|
[&txn, &statesdb](auto msg) {
|
||||||
|
auto j = json(msg);
|
||||||
bool res = lmdb::dbi_put(txn,
|
bool res = lmdb::dbi_put(txn,
|
||||||
statesdb,
|
statesdb,
|
||||||
lmdb::val(to_string(msg.type)),
|
lmdb::val(j["type"].get<std::string>()),
|
||||||
lmdb::val(json(msg).dump()));
|
lmdb::val(j.dump()));
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
nhlog::db()->warn("couldn't save data: {}",
|
nhlog::db()->warn("couldn't save data: {}",
|
||||||
|
|
|
@ -900,9 +900,14 @@ void
|
||||||
ChatPage::joinRoom(const QString &room)
|
ChatPage::joinRoom(const QString &room)
|
||||||
{
|
{
|
||||||
const auto room_id = room.toStdString();
|
const auto room_id = room.toStdString();
|
||||||
|
joinRoomVia(room_id, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatPage::joinRoomVia(const std::string &room_id, const std::vector<std::string> &via)
|
||||||
|
{
|
||||||
http::client()->join_room(
|
http::client()->join_room(
|
||||||
room_id, [this, room_id](const mtx::responses::RoomId &, mtx::http::RequestErr err) {
|
room_id, via, [this, room_id](const mtx::responses::RoomId &, mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
emit showNotification(
|
emit showNotification(
|
||||||
tr("Failed to join room: %1")
|
tr("Failed to join room: %1")
|
||||||
|
@ -1291,7 +1296,7 @@ ChatPage::startChat(QString userid)
|
||||||
|
|
||||||
mtx::requests::CreateRoom req;
|
mtx::requests::CreateRoom req;
|
||||||
req.preset = mtx::requests::Preset::PrivateChat;
|
req.preset = mtx::requests::Preset::PrivateChat;
|
||||||
req.visibility = mtx::requests::Visibility::Private;
|
req.visibility = mtx::common::RoomVisibility::Private;
|
||||||
if (utils::localUser() != userid)
|
if (utils::localUser() != userid)
|
||||||
req.invite = {userid.toStdString()};
|
req.invite = {userid.toStdString()};
|
||||||
emit ChatPage::instance()->createRoom(req);
|
emit ChatPage::instance()->createRoom(req);
|
||||||
|
@ -1380,7 +1385,7 @@ ChatPage::handleMatrixUri(const QByteArray &uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == "join") {
|
if (action == "join") {
|
||||||
joinRoom(mxid1);
|
joinRoomVia(targetRoomId, vias);
|
||||||
}
|
}
|
||||||
} else if (sigil1 == "room") {
|
} else if (sigil1 == "room") {
|
||||||
auto joined_rooms = cache::joinedRooms();
|
auto joined_rooms = cache::joinedRooms();
|
||||||
|
@ -1398,7 +1403,7 @@ ChatPage::handleMatrixUri(const QByteArray &uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == "join") {
|
if (action == "join") {
|
||||||
joinRoom(mxid1);
|
joinRoomVia(mxid1.toStdString(), vias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,7 @@ public slots:
|
||||||
void leaveRoom(const QString &room_id);
|
void leaveRoom(const QString &room_id);
|
||||||
void createRoom(const mtx::requests::CreateRoom &req);
|
void createRoom(const mtx::requests::CreateRoom &req);
|
||||||
void joinRoom(const QString &room);
|
void joinRoom(const QString &room);
|
||||||
|
void joinRoomVia(const std::string &room_id, const std::vector<std::string> &via);
|
||||||
|
|
||||||
void inviteUser(QString userid, QString reason);
|
void inviteUser(QString userid, QString reason);
|
||||||
void kickUser(QString userid, QString reason);
|
void kickUser(QString userid, QString reason);
|
||||||
|
|
|
@ -115,9 +115,9 @@ CreateRoom::CreateRoom(QWidget *parent)
|
||||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
||||||
[this](const QString &text) {
|
[this](const QString &text) {
|
||||||
if (text == "Private") {
|
if (text == "Private") {
|
||||||
request_.visibility = mtx::requests::Visibility::Private;
|
request_.visibility = mtx::common::RoomVisibility::Private;
|
||||||
} else {
|
} else {
|
||||||
request_.visibility = mtx::requests::Visibility::Public;
|
request_.visibility = mtx::common::RoomVisibility::Public;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -67,11 +67,25 @@ EventStore::EventStore(std::string room_id, QObject *)
|
||||||
if (newFirst == first)
|
if (newFirst == first)
|
||||||
fetchMore();
|
fetchMore();
|
||||||
else {
|
else {
|
||||||
emit beginInsertRows(toExternalIdx(newFirst),
|
if (this->last != std::numeric_limits<uint64_t>::max()) {
|
||||||
toExternalIdx(this->first - 1));
|
emit beginInsertRows(toExternalIdx(newFirst),
|
||||||
this->first = newFirst;
|
toExternalIdx(this->first - 1));
|
||||||
emit endInsertRows();
|
this->first = newFirst;
|
||||||
emit fetchedMore();
|
emit endInsertRows();
|
||||||
|
emit fetchedMore();
|
||||||
|
} else {
|
||||||
|
auto range = cache::client()->getTimelineRange(room_id_);
|
||||||
|
|
||||||
|
if (range && range->last - range->first != 0) {
|
||||||
|
emit beginInsertRows(0, int(range->last - range->first));
|
||||||
|
this->first = range->first;
|
||||||
|
this->last = range->last;
|
||||||
|
emit endInsertRows();
|
||||||
|
emit fetchedMore();
|
||||||
|
} else {
|
||||||
|
fetchMore();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
|
@ -247,15 +261,19 @@ EventStore::handleSync(const mtx::responses::Timeline &events)
|
||||||
nhlog::db()->warn("{} called from a different thread!", __func__);
|
nhlog::db()->warn("{} called from a different thread!", __func__);
|
||||||
|
|
||||||
auto range = cache::client()->getTimelineRange(room_id_);
|
auto range = cache::client()->getTimelineRange(room_id_);
|
||||||
if (!range)
|
if (!range) {
|
||||||
|
emit beginResetModel();
|
||||||
|
this->first = std::numeric_limits<uint64_t>::max();
|
||||||
|
this->last = std::numeric_limits<uint64_t>::max();
|
||||||
|
emit endResetModel();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (events.limited) {
|
if (events.limited) {
|
||||||
emit beginResetModel();
|
emit beginResetModel();
|
||||||
this->last = range->last;
|
this->last = range->last;
|
||||||
this->first = range->first;
|
this->first = range->first;
|
||||||
emit endResetModel();
|
emit endResetModel();
|
||||||
|
|
||||||
} else if (range->last > this->last) {
|
} else if (range->last > this->last) {
|
||||||
emit beginInsertRows(toExternalIdx(this->last + 1), toExternalIdx(range->last));
|
emit beginInsertRows(toExternalIdx(this->last + 1), toExternalIdx(range->last));
|
||||||
this->last = range->last;
|
this->last = range->last;
|
||||||
|
|
|
@ -74,7 +74,7 @@ public:
|
||||||
|
|
||||||
int size() const
|
int size() const
|
||||||
{
|
{
|
||||||
return last != std::numeric_limits<uint64_t>::max()
|
return (last != std::numeric_limits<uint64_t>::max() && last >= first)
|
||||||
? static_cast<int>(last - first) + 1
|
? static_cast<int>(last - first) + 1
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue