void FileUploader::currentFailed() { Queue::iterator j = queue.find(uploading); if (j != queue.end()) { if (j->type() == PreparePhoto) { emit photoFailed(j.key()); } else if (j->type() == PrepareDocument) { DocumentData *doc = App::document(j->id()); if (doc->status == FileUploading) { doc->status = FileUploadFailed; } emit documentFailed(j.key()); } else if (j->type() == PrepareAudio) { AudioData *audio = App::audio(j->id()); if (audio->status == FileUploading) { audio->status = FileUploadFailed; } emit audioFailed(j.key()); } queue.erase(j); } requestsSent.clear(); docRequestsSent.clear(); dcMap.clear(); uploading = FullMsgId(); sentSize = 0; for (int i = 0; i < MTPUploadSessionsCount; ++i) { sentSizes[i] = 0; } sendNext(); }
void PlayerWidget::nextPressed() { if (isHidden()) return; History *history = _msgmigrated ? _migrated : _history; const History::MediaOverview *o = history ? &history->overview[OverviewAudioDocuments] : 0; if (audioPlayer() && o && _index >= 0 && _index < o->size() - 1) { startPlay(FullMsgId(history->channelId(), o->at(_index + 1))); } else if (o && (_index == o->size() - 1) && _msgmigrated && _history->overviewLoaded(OverviewAudioDocuments)) { o = &_history->overview[OverviewAudioDocuments]; if (!o->isEmpty()) { startPlay(FullMsgId(_history->channelId(), o->at(0))); } } }
void PlayerWidget::prevPressed() { if (isHidden()) return; History *history = _msgmigrated ? _migrated : _history; const History::MediaOverview *o = history ? &history->overview[OverviewAudioDocuments] : 0; if (audioPlayer() && o && _index > 0 && _index <= o->size() && !o->isEmpty()) { startPlay(FullMsgId(history->channelId(), o->at(_index - 1))); } else if (!_index && _history && _migrated && !_msgmigrated) { o = &_migrated->overview[OverviewAudioDocuments]; if (!o->isEmpty()) { startPlay(FullMsgId(_migrated->channelId(), o->at(o->size() - 1))); } } }
void PlayerWidget::findCurrent() { _index = -1; if (!_history) return; const History::MediaOverview *o = &_history->overview[OverviewAudioDocuments]; if (_history->channelId() == _song.msgId.channel) { for (int i = 0, l = o->size(); i < l; ++i) { if (o->at(i) == _song.msgId.msg) { _index = i; break; } } } if (_index < 0) return; if (_index < o->size() - 1) { if (HistoryItem *next = App::histItemById(_history->channelId(), o->at(_index + 1))) { if (HistoryDocument *document = static_cast<HistoryDocument*>(next->getMedia())) { if (document->document()->already(true).isEmpty() && document->document()->data.isEmpty()) { if (!document->document()->loader) { DocumentOpenLink::doOpen(document->document()); document->document()->openOnSave = 0; document->document()->openOnSaveMsgId = FullMsgId(); } } } } } }
void PlayerWidget::nextPressed() { if (isHidden()) return; const History::MediaOverview *o = _history ? &_history->overview[OverviewAudioDocuments] : 0; if (audioPlayer() && o && _index >= 0 && _index < o->size() - 1) { startPlay(FullMsgId(_history->channelId(), o->at(_index + 1))); } }
base::optional<FullMsgId> SharedMediaWithLastSlice::LastFullMsgId( const SparseIdsMergedSlice &slice) { if (slice.fullCount() == 0) { return FullMsgId(); } else if (slice.size() == 0 || slice.skippedAfter() != 0) { return base::none; } return slice[slice.size() - 1]; }
void MessagesSliceBuilder::mergeSliceData( std::optional<int> count, const base::flat_set<MessagePosition> &messageIds, std::optional<int> skippedBefore, std::optional<int> skippedAfter) { if (messageIds.empty()) { if (count && _fullCount != count) { _fullCount = count; if (*_fullCount <= _ids.size()) { _fullCount = _ids.size(); _skippedBefore = _skippedAfter = 0; } } fillSkippedAndSliceToLimits(); return; } if (count) { _fullCount = count; } const auto impossible = MessagePosition(-1, FullMsgId()); auto wasMinId = _ids.empty() ? impossible : _ids.front(); auto wasMaxId = _ids.empty() ? impossible : _ids.back(); _ids.merge(messageIds.begin(), messageIds.end()); auto adjustSkippedBefore = [&](MessagePosition oldId, int oldSkippedBefore) { auto it = _ids.find(oldId); Assert(it != _ids.end()); _skippedBefore = oldSkippedBefore - (it - _ids.begin()); accumulate_max(*_skippedBefore, 0); }; if (skippedBefore) { adjustSkippedBefore(messageIds.front(), *skippedBefore); } else if (wasMinId != impossible && _skippedBefore) { adjustSkippedBefore(wasMinId, *_skippedBefore); } else { _skippedBefore = std::nullopt; } auto adjustSkippedAfter = [&](MessagePosition oldId, int oldSkippedAfter) { auto it = _ids.find(oldId); Assert(it != _ids.end()); _skippedAfter = oldSkippedAfter - (_ids.end() - it - 1); accumulate_max(*_skippedAfter, 0); }; if (skippedAfter) { adjustSkippedAfter(messageIds.back(), *skippedAfter); } else if (wasMaxId != impossible && _skippedAfter) { adjustSkippedAfter(wasMaxId, *_skippedAfter); } else { _skippedAfter = std::nullopt; } fillSkippedAndSliceToLimits(); }
void Entry::updateChatListEntry() const { if (const auto main = App::main()) { if (inChatList(Mode::All)) { main->repaintDialogRow( Mode::All, mainChatListLink(Mode::All)); if (inChatList(Mode::Important)) { main->repaintDialogRow( Mode::Important, mainChatListLink(Mode::Important)); } } if (Auth().supportMode() && !Auth().settings().supportAllSearchResults()) { main->repaintDialogRow({ _key, FullMsgId() }); } } }
void FileUploader::unpause() { _paused = FullMsgId(); sendNext(); }
void FileUploader::sendNext() { if (sentSize >= MaxUploadFileParallelSize || _paused.msg) return; bool killing = killSessionsTimer.isActive(); if (queue.isEmpty()) { if (!killing) { killSessionsTimer.start(MTPAckSendWaiting + MTPKillFileSessionTimeout); } return; } if (killing) { killSessionsTimer.stop(); } Queue::iterator i = uploading.msg ? queue.find(uploading) : queue.begin(); if (!uploading.msg) { uploading = i.key(); } else if (i == queue.end()) { i = queue.begin(); uploading = i.key(); } int todc = 0; for (int dc = 1; dc < MTPUploadSessionsCount; ++dc) { if (sentSizes[dc] < sentSizes[todc]) { todc = dc; } } UploadFileParts &parts(i->file ? (i->type() == PreparePhoto ? i->file->fileparts : i->file->thumbparts) : i->media.parts); uint64 partsOfId(i->file ? (i->type() == PreparePhoto ? i->file->id : i->file->thumbId) : i->media.thumbId); if (parts.isEmpty()) { if (i->docSentParts >= i->docPartsCount) { if (requestsSent.isEmpty() && docRequestsSent.isEmpty()) { if (i->type() == PreparePhoto) { emit photoReady(uploading, MTP_inputFile(MTP_long(i->id()), MTP_int(i->partsCount), MTP_string(i->filename()), MTP_string(i->file ? i->file->filemd5 : i->media.jpeg_md5))); } else if (i->type() == PrepareDocument) { QByteArray docMd5(32, Qt::Uninitialized); hashMd5Hex(i->md5Hash.result(), docMd5.data()); MTPInputFile doc = (i->docSize > UseBigFilesFrom) ? MTP_inputFileBig(MTP_long(i->id()), MTP_int(i->docPartsCount), MTP_string(i->filename())) : MTP_inputFile(MTP_long(i->id()), MTP_int(i->docPartsCount), MTP_string(i->filename()), MTP_string(docMd5)); if (i->partsCount) { emit thumbDocumentReady(uploading, doc, MTP_inputFile(MTP_long(i->thumbId()), MTP_int(i->partsCount), MTP_string(i->file ? i->file->thumbname : (qsl("thumb.") + i->media.thumbExt)), MTP_string(i->file ? i->file->thumbmd5 : i->media.jpeg_md5))); } else { emit documentReady(uploading, doc); } } else if (i->type() == PrepareAudio) { QByteArray audioMd5(32, Qt::Uninitialized); hashMd5Hex(i->md5Hash.result(), audioMd5.data()); MTPInputFile audio = (i->docSize > UseBigFilesFrom) ? MTP_inputFileBig(MTP_long(i->id()), MTP_int(i->docPartsCount), MTP_string(i->filename())) : MTP_inputFile(MTP_long(i->id()), MTP_int(i->docPartsCount), MTP_string(i->filename()), MTP_string(audioMd5)); emit audioReady(uploading, audio); } queue.remove(uploading); uploading = FullMsgId(); sendNext(); } return; } QByteArray &content(i->file ? i->file->content : i->media.data); QByteArray toSend; if (content.isEmpty()) { if (!i->docFile) { i->docFile.reset(new QFile(i->file ? i->file->filepath : i->media.file)); if (!i->docFile->open(QIODevice::ReadOnly)) { currentFailed(); return; } } toSend = i->docFile->read(i->docPartSize); if (i->docSize <= UseBigFilesFrom) { i->md5Hash.feed(toSend.constData(), toSend.size()); } } else { toSend = content.mid(i->docSentParts * i->docPartSize, i->docPartSize); if ((i->type() == PrepareDocument || i->type() == PrepareAudio) && i->docSentParts <= UseBigFilesFrom) { i->md5Hash.feed(toSend.constData(), toSend.size()); } } if (toSend.size() > i->docPartSize || (toSend.size() < i->docPartSize && i->docSentParts + 1 != i->docPartsCount)) { currentFailed(); return; } mtpRequestId requestId; if (i->docSize > UseBigFilesFrom) { requestId = MTP::send(MTPupload_SaveBigFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_int(i->docPartsCount), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]); } else { requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]); } docRequestsSent.insert(requestId, i->docSentParts); dcMap.insert(requestId, todc); sentSize += i->docPartSize; sentSizes[todc] += i->docPartSize; i->docSentParts++; } else { UploadFileParts::iterator part = parts.begin(); mtpRequestId requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(partsOfId), MTP_int(part.key()), MTP_string(part.value())), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]); requestsSent.insert(requestId, part.value()); dcMap.insert(requestId, todc); sentSize += part.value().size(); sentSizes[todc] += part.value().size(); parts.erase(part); } nextTimer.start(UploadRequestInterval); }
void Controller::setActiveChatEntry(Dialogs::Key key) { setActiveChatEntry({ key, FullMsgId() }); }