diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2016-11-01 14:03:54 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2016-11-01 14:15:31 +0900 |
commit | 416460b8da337bca3f12fb8bdc00371b2c56481d (patch) | |
tree | 261dddc3c817336d3568023a0f7fdf3fb4cf5974 /room.h | |
parent | 17135e362a3c7b5355934837b548ceab40af9a9f (diff) | |
download | libquotient-416460b8da337bca3f12fb8bdc00371b2c56481d.tar.gz libquotient-416460b8da337bca3f12fb8bdc00371b2c56481d.zip |
Moved MemberNameSorter from Quaternion to lib
This code is useful for any client that uses the Room class and needs to display the list of room members. Also removed an unused #include.
Diffstat (limited to 'room.h')
-rw-r--r-- | room.h | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -32,6 +32,7 @@ namespace QMatrixClient class Event; class Connection; class User; + class MemberSorter; class Room: public QObject { @@ -92,6 +93,8 @@ namespace QMatrixClient Q_INVOKABLE int highlightCount() const; Q_INVOKABLE void resetHighlightCount(); + MemberSorter memberSorter() const; + public slots: void getPreviousContent(); void userRenamed(User* user, QString oldName); @@ -138,6 +141,24 @@ namespace QMatrixClient void setLastReadEvent(User* user, QString eventId); }; + + class MemberSorter + { + public: + MemberSorter(const Room* r) : room(r) { } + + bool operator()(User* u1, User* u2) const; + + template <typename ContT> + typename ContT::size_type lowerBoundIndex(const ContT& c, + typename ContT::value_type v) const + { + return std::lower_bound(c.begin(), c.end(), v, *this) - c.begin(); + } + + private: + const Room* room; + }; } #endif // QMATRIXCLIENT_ROOM_H |