Remove dead code & small refactorings using the std library

This commit is contained in:
Konstantinos Sideris 2018-03-03 22:08:56 +02:00
parent 564d51943e
commit 7f7f3a805b
7 changed files with 12 additions and 103 deletions

View file

@ -196,7 +196,6 @@ set(SRC_FILES
src/RegisterPage.cc
src/RoomInfoListItem.cc
src/RoomList.cc
src/RoomMessages.cc
src/RoomState.cc
src/RunGuard.cc
src/SideBarActions.cc

View file

@ -1,38 +0,0 @@
/*
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <QJsonArray>
#include <QJsonDocument>
#include "Deserializable.h"
class RoomMessages : public Deserializable
{
public:
void deserialize(const QJsonDocument &data) override;
QString start() const { return start_; };
QString end() const { return end_; };
QJsonArray chunk() const { return chunk_; };
private:
QString start_;
QString end_;
QJsonArray chunk_;
};

View file

@ -26,7 +26,7 @@
class RoomState
{
public:
RoomState();
RoomState() = default;
RoomState(const mtx::responses::Timeline &timeline);
RoomState(const mtx::responses::State &state);

View file

@ -1,43 +0,0 @@
/*
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "RoomMessages.h"
void
RoomMessages::deserialize(const QJsonDocument &data)
{
if (!data.isObject())
throw DeserializationException("response is not a JSON object");
QJsonObject object = data.object();
if (!object.contains("start"))
throw DeserializationException("start key is missing");
if (!object.contains("end"))
throw DeserializationException("end key is missing");
if (!object.contains("chunk"))
throw DeserializationException("chunk key is missing");
if (!object.value("chunk").isArray())
throw DeserializationException("chunk isn't a JSON array");
start_ = object.value("start").toString();
end_ = object.value("end").toString();
chunk_ = object.value("chunk").toArray();
}

View file

@ -22,7 +22,6 @@
#include "RoomState.h"
RoomState::RoomState() {}
RoomState::RoomState(const mtx::responses::Timeline &timeline)
{
updateFromEvents(timeline.events);

View file

@ -21,7 +21,6 @@
#include "Config.h"
#include "FloatingButton.h"
#include "RoomMessages.h"
#include "Utils.h"
#include "timeline/TimelineView.h"
@ -578,17 +577,12 @@ TimelineView::isPendingMessage(const QString &txnid,
if (sender != local_userid)
return false;
for (const auto &msg : pending_msgs_) {
if (QString::number(msg.txn_id) == txnid)
return true;
}
auto match_txnid = [txnid](const auto &msg) -> bool {
return QString::number(msg.txn_id) == txnid;
};
for (const auto &msg : pending_sent_msgs_) {
if (QString::number(msg.txn_id) == txnid)
return true;
}
return false;
return std::any_of(pending_msgs_.cbegin(), pending_msgs_.cend(), match_txnid) ||
std::any_of(pending_sent_msgs_.cbegin(), pending_sent_msgs_.cend(), match_txnid);
}
void

View file

@ -206,8 +206,8 @@ TimelineViewManager::addRoom(const QString &room_id)
void
TimelineViewManager::sync(const mtx::responses::Rooms &rooms)
{
for (auto it = rooms.join.cbegin(); it != rooms.join.cend(); ++it) {
auto roomid = QString::fromStdString(it->first);
for (const auto &room : rooms.join) {
auto roomid = QString::fromStdString(room.first);
if (!timelineViewExists(roomid)) {
qDebug() << "Ignoring event from unknown room" << roomid;
@ -216,7 +216,7 @@ TimelineViewManager::sync(const mtx::responses::Rooms &rooms)
auto view = views_.at(roomid);
view->addEvents(it->second.timeline);
view->addEvents(room.second.timeline);
}
}
@ -309,9 +309,7 @@ TimelineViewManager::displayName(const QString &userid)
bool
TimelineViewManager::hasLoaded() const
{
for (const auto &view : views_)
if (!view.second->hasLoaded())
return false;
return true;
return std::all_of(views_.cbegin(), views_.cend(), [](const auto &view) {
return view.second->hasLoaded();
});
}