| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | /*
 | 
					
						
							|  |  |  | This file is part of Telegram Desktop, | 
					
						
							| 
									
										
										
										
											2018-01-03 13:23:14 +03:00
										 |  |  | the official desktop application for the Telegram messaging service. | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 13:23:14 +03:00
										 |  |  | For license and copyright information please follow this link: | 
					
						
							|  |  |  | https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | */ | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "dialogs/dialogs_row.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PeerData; | 
					
						
							|  |  |  | namespace Dialogs { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-13 15:45:11 +03:00
										 |  |  | enum class SortMode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 18:22:39 +04:00
										 |  |  | class List final { | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-17 17:04:30 +04:00
										 |  |  | 	List(SortMode sortMode, FilterId filterId = 0); | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 	List(const List &other) = delete; | 
					
						
							|  |  |  | 	List &operator=(const List &other) = delete; | 
					
						
							| 
									
										
										
										
											2019-04-16 18:05:56 +04:00
										 |  |  | 	List(List &&other) = default; | 
					
						
							|  |  |  | 	List &operator=(List &&other) = default; | 
					
						
							|  |  |  | 	~List() = default; | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int size() const { | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 		return _rows.size(); | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	bool empty() const { | 
					
						
							|  |  |  | 		return _rows.empty(); | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:04 +03:00
										 |  |  | 	bool contains(Key key) const { | 
					
						
							|  |  |  | 		return _rowByKey.find(key) != _rowByKey.end(); | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:04 +03:00
										 |  |  | 	Row *getRow(Key key) const { | 
					
						
							|  |  |  | 		const auto i = _rowByKey.find(key); | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 		return (i != _rowByKey.end()) ? i->second.get() : nullptr; | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	Row *rowAtY(int y, int h) const { | 
					
						
							|  |  |  | 		const auto i = cfind(y, h); | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 		if (i == cend() || (*i)->pos() != ((y > 0) ? (y / h) : 0)) { | 
					
						
							|  |  |  | 			return nullptr; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return *i; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	not_null<Row*> addToEnd(Key key); | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:04 +03:00
										 |  |  | 	Row *adjustByName(Key key); | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	not_null<Row*> addByName(Key key); | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:04 +03:00
										 |  |  | 	bool moveToTop(Key key); | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	void adjustByDate(not_null<Row*> row); | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:04 +03:00
										 |  |  | 	bool del(Key key, Row *replacedBy = nullptr); | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	using const_iterator = std::vector<not_null<Row*>>::const_iterator; | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 	using iterator = const_iterator; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	const_iterator cbegin() const { return _rows.cbegin(); } | 
					
						
							|  |  |  | 	const_iterator cend() const { return _rows.cend(); } | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 	const_iterator begin() const { return cbegin(); } | 
					
						
							|  |  |  | 	const_iterator end() const { return cend(); } | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	iterator begin() { return cbegin(); } | 
					
						
							|  |  |  | 	iterator end() { return cend(); } | 
					
						
							|  |  |  | 	const_iterator cfind(Row *value) const; | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 	const_iterator find(Row *value) const { return cfind(value); } | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	iterator find(Row *value) { return cfind(value); } | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 	const_iterator cfind(int y, int h) const { | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 		const auto index = std::max(y, 0) / h; | 
					
						
							|  |  |  | 		return _rows.begin() + std::min(index, size()); | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	const_iterator find(int y, int h) const { return cfind(y, h); } | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	iterator find(int y, int h) { return cfind(y, h); } | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	void adjustByName(not_null<Row*> row); | 
					
						
							|  |  |  | 	void rotate( | 
					
						
							|  |  |  | 		std::vector<not_null<Row*>>::iterator first, | 
					
						
							|  |  |  | 		std::vector<not_null<Row*>>::iterator middle, | 
					
						
							|  |  |  | 		std::vector<not_null<Row*>>::iterator last); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SortMode _sortMode = SortMode(); | 
					
						
							| 
									
										
										
										
											2020-03-17 17:04:30 +04:00
										 |  |  | 	FilterId _filterId = 0; | 
					
						
							| 
									
										
										
										
											2019-04-16 15:37:50 +04:00
										 |  |  | 	std::vector<not_null<Row*>> _rows; | 
					
						
							|  |  |  | 	std::map<Key, std::unique_ptr<Row>> _rowByKey; | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:04 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-09 22:45:55 +04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace Dialogs
 |