bool CalendarTemplateElement::loadFromRecord( const Record& record, util::Env& env ) { bool result(false); if(record.isDefined(TABLE_COL_ID)) { RegistryKeyType value(record.getDefault<RegistryKeyType>(TABLE_COL_ID, 0)); if(value != getKey()) { result = true; setKey(value); } } // Rank if(record.isDefined(CalendarTemplateElementTableSync::COL_RANK)) { size_t value( record.getDefault<size_t>(CalendarTemplateElementTableSync::COL_RANK, 0) ); if(value != getRank()) { result = true; setRank(value); } } // Min date if(record.isDefined(CalendarTemplateElementTableSync::COL_MIN_DATE)) { date value(neg_infin); if(!record.get<string>(CalendarTemplateElementTableSync::COL_MIN_DATE).empty()) { try { value = from_string(record.get<string>(CalendarTemplateElementTableSync::COL_MIN_DATE)); } catch(...) { } } if(value != getMinDate()) { result = true; setMinDate(value); } } // Max date if(record.isDefined(CalendarTemplateElementTableSync::COL_MAX_DATE)) { date value(pos_infin); if(!record.get<string>(CalendarTemplateElementTableSync::COL_MAX_DATE).empty()) { try { value = from_string(record.get<string>(CalendarTemplateElementTableSync::COL_MAX_DATE)); } catch(...) { } } if(value != getMaxDate()) { result = true; setMaxDate(value); } } // Days modulo if(record.isDefined(CalendarTemplateElementTableSync::COL_INTERVAL)) { days value( record.getDefault<long>(CalendarTemplateElementTableSync::COL_INTERVAL, 0) ); if(value != getStep()) { result = true; setStep(value); } } // Operation if(record.isDefined(CalendarTemplateElementTableSync::COL_POSITIVE)) { Operation value( static_cast<Operation>( record.getDefault<int>(CalendarTemplateElementTableSync::COL_POSITIVE, 0) ) ); if(value != getOperation()) { result = true; setOperation(value); } } // Included calendar // if(linkLevel > FIELDS_ONLY_LOAD_LEVEL) { if(record.isDefined(CalendarTemplateElementTableSync::COL_INCLUDE_ID)) { CalendarTemplate* value(NULL); RegistryKeyType iid( record.getDefault<RegistryKeyType>( CalendarTemplateElementTableSync::COL_INCLUDE_ID, 0 ) ); if(iid > 0) try { value = CalendarTemplateTableSync::GetEditable(iid, env).get(); } catch (ObjectNotFoundException<CalendarTemplate> e) { Log::GetInstance().warn("Data corrupted in " + CalendarTemplateElementTableSync::TABLE.NAME + "/" + CalendarTemplateElementTableSync::COL_INCLUDE_ID, e); } if(value != getInclude()) { result = true; setInclude(value); } } } // Link with calendar template // if(linkLevel == UP_LINKS_LOAD_LEVEL || linkLevel == UP_DOWN_LINKS_LOAD_LEVEL || linkLevel == ALGORITHMS_OPTIMIZATION_LOAD_LEVEL) { if(record.isDefined(CalendarTemplateElementTableSync::COL_CALENDAR_ID)) { CalendarTemplate* value(NULL); RegistryKeyType id( record.getDefault<RegistryKeyType>( CalendarTemplateElementTableSync::COL_CALENDAR_ID, 0 ) ); if(id > 0) try { value = CalendarTemplateTableSync::GetEditable(id, env).get(); } catch (ObjectNotFoundException<CalendarTemplate> e) { Log::GetInstance().warn("Data corrupted in " + CalendarTemplateElementTableSync::TABLE.NAME + "/" + CalendarTemplateElementTableSync::COL_CALENDAR_ID, e); } if(value != getCalendar()) { result = true; setCalendar(value); } } } return result; }
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)); }