Skip to content

Commit

Permalink
Remove dead code & small refactorings using the std library
Browse files Browse the repository at this point in the history
  • Loading branch information
mujx committed Mar 3, 2018
1 parent 24a937b commit 9d54b4f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 103 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 0 additions & 38 deletions include/RoomMessages.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/RoomState.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class RoomState
{
public:
RoomState();
RoomState() = default;
RoomState(const mtx::responses::Timeline &timeline);
RoomState(const mtx::responses::State &state);

Expand Down
43 changes: 0 additions & 43 deletions src/RoomMessages.cc

This file was deleted.

1 change: 0 additions & 1 deletion src/RoomState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "RoomState.h"

RoomState::RoomState() {}
RoomState::RoomState(const mtx::responses::Timeline &timeline)
{
updateFromEvents(timeline.events);
Expand Down
16 changes: 5 additions & 11 deletions src/timeline/TimelineView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "Config.h"
#include "FloatingButton.h"
#include "RoomMessages.h"
#include "Utils.h"

#include "timeline/TimelineView.h"
Expand Down Expand Up @@ -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;
}

for (const auto &msg : pending_sent_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;
};

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
Expand Down
14 changes: 6 additions & 8 deletions src/timeline/TimelineViewManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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();
});
}

0 comments on commit 9d54b4f

Please sign in to comment.