mirror of https://github.com/procxx/kepka.git
				
				
				
			Create dialog rows only with known folders.
This commit is contained in:
		
							parent
							
								
									854870683b
								
							
						
					
					
						commit
						f3ed7a674a
					
				| 
						 | 
				
			
			@ -234,8 +234,14 @@ void Folder::requestChatListMessage() {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TimeId Folder::adjustedChatListTimeId() const {
 | 
			
		||||
	return _chatsList.empty()
 | 
			
		||||
		? TimeId(0)
 | 
			
		||||
		: (*_chatsList.begin())->entry()->adjustedChatListTimeId();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Folder::unreadCount() const {
 | 
			
		||||
	return _unreadCount ? *_unreadCount : 0;
 | 
			
		||||
	return _unreadCount.value_or(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
rpl::producer<int> Folder::unreadCountValue() const {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,7 +30,7 @@ struct FolderUpdate {
 | 
			
		|||
 | 
			
		||||
//MessagePosition FeedPositionFromMTP(const MTPFeedPosition &position); // #feed
 | 
			
		||||
 | 
			
		||||
class Folder : public Dialogs::Entry {
 | 
			
		||||
class Folder final : public Dialogs::Entry {
 | 
			
		||||
public:
 | 
			
		||||
	static constexpr auto kId = 1;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -58,6 +58,7 @@ public:
 | 
			
		|||
	//bool unreadMark() const;
 | 
			
		||||
	//int unreadCountForBadge() const; // unreadCount || unreadMark ? 1 : 0.
 | 
			
		||||
 | 
			
		||||
	TimeId adjustedChatListTimeId() const override;
 | 
			
		||||
	int unreadCount() const;
 | 
			
		||||
	bool unreadCountKnown() const;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1435,9 +1435,11 @@ void Session::addSavedPeersAfter(const QDateTime &date) {
 | 
			
		|||
		saved.remove(lastDate, lastPeer);
 | 
			
		||||
 | 
			
		||||
		const auto history = session().data().history(lastPeer);
 | 
			
		||||
		if (!history->chatListTimeId()) {
 | 
			
		||||
			history->setChatListTimeId(ServerTimeFromParsed(lastDate));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Session::addAllSavedPeers() {
 | 
			
		||||
	addSavedPeersAfter(QDateTime());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -91,7 +91,7 @@ void Entry::updateChatListSortPosition() {
 | 
			
		|||
		? ProxyPromotedDialogPos()
 | 
			
		||||
		: isPinnedDialog()
 | 
			
		||||
		? PinnedDialogPos(_pinnedIndex)
 | 
			
		||||
		: DialogPosFromDate(adjustChatListTimeId());
 | 
			
		||||
		: DialogPosFromDate(adjustedChatListTimeId());
 | 
			
		||||
	if (needUpdateInChatList()) {
 | 
			
		||||
		setChatListExistence(true);
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -112,7 +112,7 @@ void Entry::setChatListExistence(bool exists) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TimeId Entry::adjustChatListTimeId() const {
 | 
			
		||||
TimeId Entry::adjustedChatListTimeId() const {
 | 
			
		||||
	return chatListTimeId();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -145,13 +145,11 @@ PositionChange Entry::adjustByPosInChatList(Mode list) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void Entry::setChatListTimeId(TimeId date) {
 | 
			
		||||
	if (_timeId && _timeId >= date) {
 | 
			
		||||
		if (!inChatList(Dialogs::Mode::All)) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	_timeId = date;
 | 
			
		||||
	updateChatListSortPosition();
 | 
			
		||||
	if (const auto folder = this->folder()) {
 | 
			
		||||
		folder->updateChatListSortPosition();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Entry::posInChatList(Dialogs::Mode list) const {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,6 +79,7 @@ public:
 | 
			
		|||
	void setChatListTimeId(TimeId date);
 | 
			
		||||
	virtual void updateChatListExistence();
 | 
			
		||||
	bool needUpdateInChatList() const;
 | 
			
		||||
	virtual TimeId adjustedChatListTimeId() const;
 | 
			
		||||
 | 
			
		||||
	virtual bool toImportant() const = 0;
 | 
			
		||||
	virtual bool shouldBeInChatList() const = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -92,6 +93,9 @@ public:
 | 
			
		|||
	virtual const base::flat_set<QString> &chatListNameWords() const = 0;
 | 
			
		||||
	virtual const base::flat_set<QChar> &chatListFirstLetters() const = 0;
 | 
			
		||||
 | 
			
		||||
	virtual bool folderKnown() const {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	virtual Data::Folder *folder() const {
 | 
			
		||||
		return nullptr;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -119,7 +123,6 @@ public:
 | 
			
		|||
	mutable Text lastItemTextCache;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	virtual TimeId adjustChatListTimeId() const;
 | 
			
		||||
	virtual void changedInChatListHook(Mode list, bool added);
 | 
			
		||||
	virtual void changedChatListPinHook();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -629,6 +629,9 @@ HistoryItem *History::addNewMessage(
 | 
			
		|||
			setLastMessage(item);
 | 
			
		||||
			if (type == NewMessageUnread) {
 | 
			
		||||
				newItemAdded(item);
 | 
			
		||||
				if (!folderKnown()) {
 | 
			
		||||
					session().api().requestDialogEntry(this);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			return item;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -1806,8 +1809,12 @@ std::shared_ptr<AdminLog::LocalIdManager> History::adminLogIdManager() {
 | 
			
		|||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool History::folderKnown() const {
 | 
			
		||||
	return _folder.has_value();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Data::Folder *History::folder() const {
 | 
			
		||||
	return _folder;
 | 
			
		||||
	return _folder.value_or(nullptr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void History::setFolder(
 | 
			
		||||
| 
						 | 
				
			
			@ -1824,36 +1831,41 @@ void History::clearFolder() {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void History::setFolderPointer(Data::Folder *folder) {
 | 
			
		||||
	using Mode = Dialogs::Mode;
 | 
			
		||||
 | 
			
		||||
	if (_folder == folder) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	using Mode = Dialogs::Mode;
 | 
			
		||||
	const auto wasAll = inChatList(Mode::All);
 | 
			
		||||
	const auto wasImportant = wasAll && inChatList(Mode::Important);
 | 
			
		||||
	if (wasAll) {
 | 
			
		||||
	const auto wasKnown = folderKnown();
 | 
			
		||||
	const auto wasInAll = inChatList(Mode::All);
 | 
			
		||||
	const auto wasInImportant = wasInAll && inChatList(Mode::Important);
 | 
			
		||||
	if (wasInAll) {
 | 
			
		||||
		removeFromChatList(Mode::All);
 | 
			
		||||
		if (wasImportant) {
 | 
			
		||||
		if (wasInImportant) {
 | 
			
		||||
			removeFromChatList(Mode::Important);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	const auto was = std::exchange(_folder, folder);
 | 
			
		||||
	const auto was = _folder.value_or(nullptr);
 | 
			
		||||
	_folder = folder;
 | 
			
		||||
	if (was) {
 | 
			
		||||
		was->unregisterOne(this);
 | 
			
		||||
	}
 | 
			
		||||
	if (wasAll) {
 | 
			
		||||
	if (wasInAll) {
 | 
			
		||||
		addToChatList(Mode::All);
 | 
			
		||||
		if (wasImportant) {
 | 
			
		||||
		if (wasInImportant) {
 | 
			
		||||
			addToChatList(Mode::Important);
 | 
			
		||||
		}
 | 
			
		||||
		owner().chatsListChanged(was);
 | 
			
		||||
		owner().chatsListChanged(_folder);
 | 
			
		||||
		owner().chatsListChanged(folder);
 | 
			
		||||
	} else if (!wasKnown) {
 | 
			
		||||
		updateChatListSortPosition();
 | 
			
		||||
	}
 | 
			
		||||
	if (_folder) {
 | 
			
		||||
		_folder->registerOne(this);
 | 
			
		||||
	if (folder) {
 | 
			
		||||
		folder->registerOne(this);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TimeId History::adjustChatListTimeId() const {
 | 
			
		||||
TimeId History::adjustedChatListTimeId() const {
 | 
			
		||||
	const auto result = chatListTimeId();
 | 
			
		||||
	if (const auto draft = cloudDraft()) {
 | 
			
		||||
		if (!Data::draftIsNull(draft) && !session().supportMode()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2415,7 +2427,7 @@ bool History::useProxyPromotion() const {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
bool History::shouldBeInChatList() const {
 | 
			
		||||
	if (peer->migrateTo() || folder() != nullptr) {
 | 
			
		||||
	if (peer->migrateTo() || !folderKnown()) {
 | 
			
		||||
		return false;
 | 
			
		||||
	} else if (isPinnedDialog()) {
 | 
			
		||||
		return true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -323,6 +323,7 @@ public:
 | 
			
		|||
 | 
			
		||||
	std::shared_ptr<AdminLog::LocalIdManager> adminLogIdManager();
 | 
			
		||||
 | 
			
		||||
	bool folderKnown() const override;
 | 
			
		||||
	Data::Folder *folder() const override;
 | 
			
		||||
	void setFolder(
 | 
			
		||||
		not_null<Data::Folder*> folder,
 | 
			
		||||
| 
						 | 
				
			
			@ -416,7 +417,7 @@ private:
 | 
			
		|||
		not_null<Element*> view);
 | 
			
		||||
	void removeNotification(not_null<HistoryItem*> item);
 | 
			
		||||
 | 
			
		||||
	TimeId adjustChatListTimeId() const override;
 | 
			
		||||
	TimeId adjustedChatListTimeId() const override;
 | 
			
		||||
	void changedInChatListHook(Dialogs::Mode list, bool added) override;
 | 
			
		||||
	void changedChatListPinHook() override;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -476,7 +477,7 @@ private:
 | 
			
		|||
	bool _loadedAtTop = false;
 | 
			
		||||
	bool _loadedAtBottom = true;
 | 
			
		||||
 | 
			
		||||
	Data::Folder *_folder = nullptr;
 | 
			
		||||
	std::optional<Data::Folder*> _folder;
 | 
			
		||||
 | 
			
		||||
	std::optional<MsgId> _inboxReadBefore;
 | 
			
		||||
	std::optional<MsgId> _outboxReadBefore;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue