void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) { const auto history = App::history(peerId); const auto textWithTags = TextWithTags { qs(draft.vmessage), ConvertEntitiesToTextTags( draft.has_entities() ? TextUtilities::EntitiesFromMTP(draft.ventities.v) : EntitiesInText()) }; auto replyTo = draft.has_reply_to_msg_id() ? draft.vreply_to_msg_id.v : MsgId(0); if (history->skipCloudDraft(textWithTags.text, replyTo, draft.vdate.v)) { return; } auto cloudDraft = std::make_unique<Draft>( textWithTags, replyTo, MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX), draft.is_no_webpage()); cloudDraft->date = draft.vdate.v; history->setCloudDraft(std::move(cloudDraft)); history->createLocalDraftFromCloud(); if (Auth().supportMode()) { history->updateChatListEntry(); Auth().supportHelper().cloudDraftChanged(history); } else { history->updateChatListSortPosition(); } if (const auto main = App::main()) { main->applyCloudDraft(history); } }
MessageCursor readDraftPositions(const PeerId &peer) { DraftsMap::iterator j = _draftsPositionsMap.find(peer); if (j == _draftsPositionsMap.cend()) { return MessageCursor(); } FileReadDescriptor draft; if (!readEncryptedFile(draft, toFilePart(j.value()))) { clearKey(j.value()); _draftsPositionsMap.erase(j); return MessageCursor(); } quint64 draftPeer; qint32 curPosition, curAnchor, curScroll; draft.stream >> draftPeer >> curPosition >> curAnchor >> curScroll; return (draftPeer == peer) ? MessageCursor(curPosition, curAnchor, curScroll) : MessageCursor(); }
void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) { auto history = App::history(peerId); auto text = TextWithEntities { qs(draft.vmessage), draft.has_entities() ? TextUtilities::EntitiesFromMTP(draft.ventities.v) : EntitiesInText() }; auto textWithTags = TextWithTags { TextUtilities::ApplyEntities(text), ConvertEntitiesToTextTags(text.entities) }; auto replyTo = draft.has_reply_to_msg_id() ? draft.vreply_to_msg_id.v : MsgId(0); auto cloudDraft = std::make_unique<Draft>(textWithTags, replyTo, MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX), draft.is_no_webpage()); cloudDraft->date = draft.vdate.v; history->setCloudDraft(std::move(cloudDraft)); history->createLocalDraftFromCloud(); history->updateChatListSortPosition(); if (auto main = App::main()) { main->applyCloudDraft(history); } }