예제 #1
0
Memento Memento::Default(Dialogs::Key key) {
	if (const auto peer = key.peer()) {
		return Memento(peer->id, DefaultSection(key));
	}
	return Memento(key.feed(), DefaultSection(key));
}
예제 #2
0
void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
	const auto currentPeerDate = [&] {
		if (const auto history = chat.history()) {
			if (history->scrollTopItem) {
				return history->scrollTopItem->dateTime().date();
			} else if (history->loadedAtTop()
				&& !history->isEmpty()
				&& history->peer->migrateFrom()) {
				if (const auto migrated = history->owner().historyLoaded(history->peer->migrateFrom())) {
					if (migrated->scrollTopItem) {
						// We're up in the migrated history.
						// So current date is the date of first message here.
						return history->blocks.front()->messages.front()->dateTime().date();
					}
				}
			} else if (history->chatListTimeId() != 0) {
				return ParseDateTime(history->chatListTimeId()).date();
			}
		} else if (const auto feed = chat.feed()) {
			/*if (chatScrollPosition(feed)) { // #TODO feeds save position

			} else */if (feed->chatListTimeId() != 0) {
				return ParseDateTime(feed->chatListTimeId()).date();
			}
		}
		return QDate::currentDate();
	};
	const auto maxPeerDate = [](Dialogs::Key chat) {
		if (auto history = chat.history()) {
			if (const auto channel = history->peer->migrateTo()) {
				history = channel->owner().historyLoaded(channel);
			}
			if (history && history->chatListTimeId() != 0) {
				return ParseDateTime(history->chatListTimeId()).date();
			}
		} else if (const auto feed = chat.feed()) {
			if (feed->chatListTimeId() != 0) {
				return ParseDateTime(feed->chatListTimeId()).date();
			}
		}
		return QDate::currentDate();
	};
	const auto minPeerDate = [](Dialogs::Key chat) {
		const auto startDate = [] {
			// Telegram was launched in August 2013 :)
			return QDate(2013, 8, 1);
		};
		if (const auto history = chat.history()) {
			if (const auto chat = history->peer->migrateFrom()) {
				if (const auto history = chat->owner().historyLoaded(chat)) {
					if (history->loadedAtTop()) {
						if (!history->isEmpty()) {
							return history->blocks.front()->messages.front()->dateTime().date();
						}
					} else {
						return startDate();
					}
				}
			}
			if (history->loadedAtTop()) {
				if (!history->isEmpty()) {
					return history->blocks.front()->messages.front()->dateTime().date();
				}
				return QDate::currentDate();
			}
		} else if (const auto feed = chat.feed()) {
			return startDate();
		}
		return startDate();
	};
	const auto highlighted = requestedDate.isNull()
		? currentPeerDate()
		: requestedDate;
	const auto month = highlighted;
	auto callback = [=](const QDate &date) {
		session().api().jumpToDate(chat, date);
	};
	auto box = Box<CalendarBox>(
		month,
		highlighted,
		std::move(callback));
	box->setMinDate(minPeerDate(chat));
	box->setMaxDate(maxPeerDate(chat));
	Ui::show(std::move(box));
}