2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Display online count in the info profile section.

This commit is contained in:
John Preston
2017-10-22 15:07:57 +03:00
parent 508fa14385
commit 856ca22aad
13 changed files with 229 additions and 45 deletions

View File

@@ -20,6 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#include "boxes/peer_list_box.h"
#include <rpl/range.h>
#include "styles/style_boxes.h"
#include "styles/style_dialogs.h"
#include "styles/style_widgets.h"
@@ -230,6 +231,10 @@ void PeerListController::peerListSearchRefreshRows() {
delegate()->peerListRefreshRows();
}
rpl::producer<int> PeerListController::onlineCountValue() const {
return rpl::single(0);
}
void PeerListController::setDescriptionText(const QString &text) {
if (text.isEmpty()) {
setDescription(nullptr);
@@ -308,6 +313,7 @@ bool PeerListRow::checked() const {
void PeerListRow::setCustomStatus(const QString &status) {
setStatusText(status);
_statusType = StatusType::Custom;
_statusValidTill = 0;
}
void PeerListRow::clearCustomStatus() {
@@ -320,12 +326,15 @@ void PeerListRow::refreshStatus() {
return;
}
_statusType = StatusType::LastSeen;
_statusValidTill = 0;
if (auto user = peer()->asUser()) {
auto time = unixtime();
setStatusText(App::onlineText(user, time));
if (App::onlineColorUse(user, time)) {
_statusType = StatusType::Online;
}
_statusValidTill = getms()
+ App::onlineWillChangeIn(user, time);
} else if (auto chat = peer()->asChat()) {
if (!chat->amIn()) {
setStatusText(lang(lng_chat_status_unaccessible));
@@ -341,6 +350,10 @@ void PeerListRow::refreshStatus() {
}
}
TimeMs PeerListRow::refreshStatusTime() const {
return _statusValidTill;
}
void PeerListRow::refreshName(const style::PeerListItem &st) {
if (!_initialized) {
return;
@@ -505,6 +518,7 @@ PeerListContent::PeerListContent(
invalidatePixmapsCache();
}
});
_repaintByStatus.setCallback([this] { update(); });
}
void PeerListContent::appendRow(std::unique_ptr<PeerListRow> row) {
@@ -773,15 +787,18 @@ void PeerListContent::clearSearchRows() {
}
void PeerListContent::paintEvent(QPaintEvent *e) {
QRect r(e->rect());
Painter p(this);
p.fillRect(r, _st.item.button.textBg);
auto clip = e->rect();
p.fillRect(clip, _st.item.button.textBg);
auto repaintByStatusAfter = _repaintByStatus.remainingTime();
auto repaintAfterMin = repaintByStatusAfter;
auto rowsTopCached = rowsTop();
auto ms = getms();
auto yFrom = r.y() - rowsTopCached;
auto yTo = r.y() + r.height() - rowsTopCached;
auto yFrom = clip.y() - rowsTopCached;
auto yTo = clip.y() + clip.height() - rowsTopCached;
p.translate(0, rowsTopCached);
auto count = shownRowsCount();
if (count > 0) {
@@ -789,10 +806,19 @@ void PeerListContent::paintEvent(QPaintEvent *e) {
auto to = ceilclamp(yTo, _rowHeight, 0, count);
p.translate(0, from * _rowHeight);
for (auto index = from; index != to; ++index) {
paintRow(p, ms, RowIndex(index));
auto repaintAfter = paintRow(p, ms, RowIndex(index));
if (repaintAfter >= 0
&& (repaintAfterMin < 0
|| repaintAfterMin > repaintAfter)) {
repaintAfterMin = repaintAfter;
}
p.translate(0, _rowHeight);
}
}
if (repaintAfterMin != repaintByStatusAfter) {
Assert(repaintAfterMin >= 0);
_repaintByStatus.callOnce(repaintAfterMin);
}
}
int PeerListContent::resizeGetHeight(int newWidth) {
@@ -894,10 +920,16 @@ void PeerListContent::setPressed(Selected pressed) {
_pressed = pressed;
}
void PeerListContent::paintRow(Painter &p, TimeMs ms, RowIndex index) {
TimeMs PeerListContent::paintRow(Painter &p, TimeMs ms, RowIndex index) {
auto row = getRow(index);
Assert(row != nullptr);
row->lazyInitialize(_st.item);
auto refreshStatusAt = row->refreshStatusTime();
if (refreshStatusAt >= 0 && ms >= refreshStatusAt) {
row->refreshStatus();
refreshStatusAt = row->refreshStatusTime();
}
auto peer = row->peer();
auto user = peer->asUser();
@@ -968,6 +1000,7 @@ void PeerListContent::paintRow(Painter &p, TimeMs ms, RowIndex index) {
} else {
row->paintStatusText(p, _st.item, _st.item.statusPosition.x(), _st.item.statusPosition.y(), statusw, width(), selected);
}
return (refreshStatusAt - ms);
}
void PeerListContent::selectSkip(int direction) {

View File

@@ -112,6 +112,7 @@ public:
Custom,
};
void refreshStatus();
TimeMs refreshStatusTime() const;
void setAbsoluteIndex(int index) {
_absoluteIndex = index;
@@ -199,6 +200,7 @@ private:
Text _name;
Text _status;
StatusType _statusType = StatusType::Online;
TimeMs _statusValidTill = 0;
OrderedSet<QChar> _nameFirstChars;
int _absoluteIndex = -1;
State _disabledState = State::Active;
@@ -237,7 +239,7 @@ public:
virtual int peerListFullRowsCount() = 0;
virtual PeerListRow *peerListFindRow(PeerListRowId id) = 0;
virtual void peerListSortRows(base::lambda<bool(PeerListRow &a, PeerListRow &b)> compare) = 0;
virtual void peerListPartitionRows(base::lambda<bool(PeerListRow &a)> border) = 0;
virtual int peerListPartitionRows(base::lambda<bool(PeerListRow &a)> border) = 0;
template <typename PeerDataRange>
void peerListAddSelectedRows(PeerDataRange &&range) {
@@ -324,6 +326,8 @@ public:
void peerListSearchAddRow(not_null<PeerData*> peer) override;
void peerListSearchRefreshRows() override;
virtual rpl::producer<int> onlineCountValue() const;
rpl::lifetime &lifetime() {
return _lifetime;
}
@@ -479,7 +483,7 @@ private:
RowIndex findRowIndex(not_null<PeerListRow*> row, RowIndex hint = RowIndex());
QRect getActionRect(not_null<PeerListRow*> row, RowIndex index) const;
void paintRow(Painter &p, TimeMs ms, RowIndex index);
TimeMs paintRow(Painter &p, TimeMs ms, RowIndex index);
void addRowEntry(not_null<PeerListRow*> row);
void addToSearchIndex(not_null<PeerListRow*> row);
@@ -535,6 +539,7 @@ private:
QPoint _lastMousePosition;
std::vector<std::unique_ptr<PeerListRow>> _searchRows;
base::Timer _repaintByStatus;
};
@@ -619,16 +624,19 @@ public:
});
});
}
void peerListPartitionRows(
int peerListPartitionRows(
base::lambda<bool(PeerListRow &a)> border) override {
_content->reorderRows([border = std::move(border)](
auto result = 0;
_content->reorderRows([border = std::move(border), &result](
auto &&begin,
auto &&end) {
std::stable_partition(begin, end, [&border](
auto edge = std::stable_partition(begin, end, [&border](
auto &&current) {
return border(*current);
});
result = (edge - begin);
});
return result;
}
protected: