Skip to content

Commit

Permalink
Support psa_message in chats list.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Apr 30, 2020
1 parent aabc817 commit 042ed8f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/data/data_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3723,12 +3723,12 @@ void Session::setTopPromoted(
|| (history && history->topPromotionMessage() != message)) {
if (changed) {
if (const auto history = historyLoaded(_topPromoted)) {
history->cacheTopPromoted(false, QString(), QString());
history->cacheTopPromotion(false, QString(), QString());
}
}
const auto old = std::exchange(_topPromoted, promoted);
if (history) {
history->cacheTopPromoted(true, type, message);
history->cacheTopPromotion(true, type, message);
history->requestChatListMessage();
Notify::peerUpdatedDelayed(
_topPromoted,
Expand Down
32 changes: 9 additions & 23 deletions Telegram/SourceFiles/dialogs/dialogs_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,22 @@ void Entry::cachePinnedIndex(FilterId filterId, int index) {
}
}

void Entry::cacheTopPromoted(
bool promoted,
const QString &type,
const QString &message) {
if (_isTopPromoted != promoted
|| _topPromotedType != type
|| _topPromotedMessage != message) {
_isTopPromoted = promoted;
_topPromotedType = type;
_topPromotedMessage = message;
updateChatListSortPosition();
updateChatListEntry();
if (!_isTopPromoted) {
updateChatListExistence();
}
void Entry::cacheTopPromoted(bool promoted) {
if (_isTopPromoted == promoted) {
return;
}
_isTopPromoted = promoted;
updateChatListSortPosition();
updateChatListEntry();
if (!_isTopPromoted) {
updateChatListExistence();
}
}

bool Entry::isTopPromoted() const {
return _isTopPromoted;
}

QString Entry::topPromotionType() const {
return _topPromotedType;
}

QString Entry::topPromotionMessage() const {
return _topPromotedMessage;
}

bool Entry::needUpdateInChatList() const {
return inChatList() || shouldBeInChatList();
}
Expand Down
12 changes: 3 additions & 9 deletions Telegram/SourceFiles/dialogs/dialogs_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,7 @@ class Entry {
return lookupPinnedIndex(filterId) != 0;
}
void cachePinnedIndex(FilterId filterId, int index);
void cacheTopPromoted(
bool promoted,
const QString &type,
const QString &message);
[[nodiscard]] bool isTopPromoted() const;
[[nodiscard]] QString topPromotionType() const;
[[nodiscard]] QString topPromotionMessage() const;
[[nodiscard]] uint64 sortKeyInChatList(FilterId filterId) const {
return filterId
? computeSortPosition(filterId)
Expand Down Expand Up @@ -197,6 +191,8 @@ class Entry {

[[nodiscard]] int lookupPinnedIndex(FilterId filterId) const;

void cacheTopPromoted(bool promoted);

private:
virtual void changedChatListPinHook();
void pinnedIndexChanged(int was, int now);
Expand All @@ -214,10 +210,8 @@ class Entry {
uint64 _sortKeyInChatList = 0;
uint64 _sortKeyByDate = 0;
base::flat_map<FilterId, int> _pinnedIndex;
QString _topPromotedMessage;
QString _topPromotedType;
bool _isTopPromoted = false;
TimeId _timeId = 0;
bool _isTopPromoted = false;

};

Expand Down
13 changes: 12 additions & 1 deletion Telegram/SourceFiles/dialogs/dialogs_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,18 @@ void paintRow(
auto texttop = st::dialogsPadding.y()
+ st::msgNameFont->height
+ st::dialogsSkip;
if (draft
if (promoted && !history->topPromotionMessage().isEmpty()) {
auto availableWidth = namewidth;
p.setFont(st::dialogsTextFont);
if (history->cloudDraftTextCache.isEmpty()) {
history->cloudDraftTextCache.setText(
st::dialogsTextStyle,
history->topPromotionMessage(),
Ui::DialogTextOptions());
}
p.setPen(active ? st::dialogsTextFgActive : (selected ? st::dialogsTextFgOver : st::dialogsTextFg));
history->cloudDraftTextCache.drawElided(p, nameleft, texttop, availableWidth, 1);
} else if (draft
|| (supportMode
&& Auth().supportHelper().isOccupiedBySomeone(history))) {
if (!promoted) {
Expand Down
23 changes: 23 additions & 0 deletions Telegram/SourceFiles/history/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,29 @@ void History::dialogEntryApplied() {
}
}

void History::cacheTopPromotion(
bool promoted,
const QString &type,
const QString &message) {
const auto changed = (isTopPromoted() != promoted);
cacheTopPromoted(promoted);
if (_topPromotedType != type || _topPromotedMessage != message) {
_topPromotedType = type;
_topPromotedMessage = message;
cloudDraftTextCache.clear();
} else if (changed) {
cloudDraftTextCache.clear();
}
}

QString History::topPromotionType() const {
return _topPromotedType;
}

QString History::topPromotionMessage() const {
return _topPromotedMessage;
}

bool History::clearUnreadOnClientSide() const {
if (!session().supportMode()) {
return false;
Expand Down
10 changes: 10 additions & 0 deletions Telegram/SourceFiles/history/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ class History final : public Dialogs::Entry {
MsgId maxOutboxRead);
void dialogEntryApplied();

void cacheTopPromotion(
bool promoted,
const QString &type,
const QString &message);
[[nodiscard]] QString topPromotionType() const;
[[nodiscard]] QString topPromotionMessage() const;

MsgId minMsgId() const;
MsgId maxMsgId() const;
MsgId msgIdForRead() const;
Expand Down Expand Up @@ -559,6 +566,9 @@ class History final : public Dialogs::Entry {
TimeId _lastSentDraftTime = 0;
MessageIdsList _forwardDraft;

QString _topPromotedMessage;
QString _topPromotedType;

base::flat_map<not_null<UserData*>, crl::time> _typing;
base::flat_map<not_null<UserData*>, SendAction> _sendActions;
QString _sendActionString;
Expand Down

0 comments on commit 042ed8f

Please sign in to comment.