diff --git a/Telegram/Resources/lang.strings b/Telegram/Resources/lang.strings index 0c6a22e616..aa1b475e55 100644 --- a/Telegram/Resources/lang.strings +++ b/Telegram/Resources/lang.strings @@ -108,6 +108,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org "lng_server_error" = "Internal server error."; "lng_flood_error" = "Too many tries. Please try again later."; +"lng_gif_error" = "An error has occured while reading GIF animation :("; "lng_deleted" = "Unknown"; "lng_deleted_message" = "Deleted message"; diff --git a/Telegram/Resources/style.txt b/Telegram/Resources/style.txt index 9c234ea0ba..70acf8f2de 100644 --- a/Telegram/Resources/style.txt +++ b/Telegram/Resources/style.txt @@ -2191,6 +2191,7 @@ mediaviewLoaderSkip: 9px; minPhotoSize: 104px; maxMediaSize: 420px; maxStickerSize: 256px; +maxGifSize: 256px; downloadPathSkip: 10px; diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 6007046b95..4837b1bbea 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -2444,7 +2444,7 @@ namespace App { if (!::gifItems.isEmpty()) { if (HistoryItem *playing = ::gifItems.begin().value()) { if (playing->getMedia() && playing->getMedia()->type() == MediaTypeGif) { - static_cast(playing->getMedia())->stop(playing); +// static_cast(playing->getMedia())->stop(playing); } } } diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index a606c618b1..70708b29e2 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -550,7 +550,7 @@ void Application::startUpdateCheck(bool forceWait) { if (updateRequestId || updateThread || updateReply || !cAutoUpdate()) return; int32 constDelay = cBetaVersion() ? 600 : UpdateDelayConstPart, randDelay = cBetaVersion() ? 300 : UpdateDelayRandPart; - int32 updateInSecs = cLastUpdateCheck() + constDelay + (rand() % randDelay) - unixtime(); + int32 updateInSecs = cLastUpdateCheck() + constDelay + int32(MTP::nonce() % randDelay) - unixtime(); bool sendRequest = (updateInSecs <= 0 || updateInSecs > (constDelay + randDelay)); if (!sendRequest && !forceWait) { QDir updates(cWorkingDir() + "tupdates"); diff --git a/Telegram/SourceFiles/autoupdater.cpp b/Telegram/SourceFiles/autoupdater.cpp index e438ae83d7..a1a77a4ff0 100644 --- a/Telegram/SourceFiles/autoupdater.cpp +++ b/Telegram/SourceFiles/autoupdater.cpp @@ -51,7 +51,7 @@ void UpdateDownloader::initOutput() { fileName = m.captured(1).replace(QRegularExpression(qsl("[^a-zA-Z0-9_\\-]")), QString()); } if (fileName.isEmpty()) { - fileName = qsl("tupdate-%1").arg(rand()); + fileName = qsl("tupdate-%1").arg(MTP::nonce() % 1000000); } QString dirStr = cWorkingDir() + qsl("tupdates/"); fileName = dirStr + fileName; diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index df7d14eb55..f25cf048dc 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -79,7 +79,11 @@ namespace Ui { } void showLayer(LayeredWidget *box, ShowLayerOptions options) { - if (Window *w = App::wnd()) w->ui_showLayer(box, options); + if (Window *w = App::wnd()) { + w->ui_showLayer(box, options); + } else { + delete box; + } } void hideLayer(bool fast) { diff --git a/Telegram/SourceFiles/gui/animation.cpp b/Telegram/SourceFiles/gui/animation.cpp index 765557f277..aa7fee421e 100644 --- a/Telegram/SourceFiles/gui/animation.cpp +++ b/Telegram/SourceFiles/gui/animation.cpp @@ -122,10 +122,12 @@ void AnimationManager::clipReinit(ClipReader *reader) { const GifItems &items(App::gifItems()); GifItems::const_iterator it = items.constFind(reader); if (it != items.cend()) { - it.value()->initDimensions(); - if (App::main()) emit App::main()->itemResized(it.value(), true); + HistoryItem *item = it.value(); - Notify::historyItemLayoutChanged(it.value()); + item->initDimensions(); // can delete reader and items entry it + if (App::main()) emit App::main()->itemResized(item, true); + + Notify::historyItemLayoutChanged(item); } } @@ -339,7 +341,7 @@ ClipReader::ClipReader(const FileLocation &location, const QByteArray &data) : _ _clipManagers.push_back(new ClipReadManager(_clipThreads.back())); _clipThreads.back()->start(); } else { - _threadIndex = rand() % _clipThreads.size(); + _threadIndex = int32(MTP::nonce() % _clipThreads.size()); int32 loadLevel = 0x7FFFFFFF; for (int32 i = 0, l = _clipThreads.size(); i < l; ++i) { int32 level = _clipManagers.at(i)->loadLevel(); @@ -690,6 +692,8 @@ bool ClipReadManager::handleProcessResult(ClipReaderPrivate *reader, ClipProcess if (result == ClipProcessError) { if (it != _readerPointers.cend()) { it.key()->error(); + emit reinit(it.key()); + _readerPointers.erase(it); it = _readerPointers.end(); } diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index c586e8c0e9..d2a7fb77bc 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -30,6 +30,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org #include "gui/filedialog.h" #include "boxes/addcontactbox.h" +#include "boxes/confirmbox.h" #include "audio.h" #include "localstorage.h" @@ -4557,6 +4558,13 @@ HistoryGif::HistoryGif(DocumentData *document) : HistoryFileMedia() void HistoryGif::initDimensions(const HistoryItem *parent) { bool bubble = parent->hasBubble(); int32 tw = 0, th = 0; + if (_gif && _gif->state() == ClipError) { + Ui::showLayer(new InformBox(lang(lng_gif_error))); + App::unregGifItem(_gif); + delete _gif; + _gif = 0; + } + if (_gif && _gif->ready()) { tw = convertScale(_gif->width()); th = convertScale(_gif->height()); @@ -4567,13 +4575,13 @@ void HistoryGif::initDimensions(const HistoryItem *parent) { th = convertScale(_data->thumb->height()); } } - if (tw > st::maxMediaSize) { - th = (st::maxMediaSize * th) / tw; - tw = st::maxMediaSize; + if (tw > st::maxGifSize) { + th = (st::maxGifSize * th) / tw; + tw = st::maxGifSize; } - if (th > st::maxMediaSize) { - tw = (st::maxMediaSize * tw) / th; - th = st::maxMediaSize; + if (th > st::maxGifSize) { + tw = (st::maxGifSize * tw) / th; + th = st::maxGifSize; } if (!tw || !th) { tw = th = 1; @@ -4737,13 +4745,13 @@ int32 HistoryGif::resize(int32 width, const HistoryItem *parent) { th = convertScale(_data->thumb->height()); } } - if (tw > st::maxMediaSize) { - th = (st::maxMediaSize * th) / tw; - tw = st::maxMediaSize; + if (tw > st::maxGifSize) { + th = (st::maxGifSize * th) / tw; + tw = st::maxGifSize; } - if (th > st::maxMediaSize) { - tw = (st::maxMediaSize * tw) / th; - th = st::maxMediaSize; + if (th > st::maxGifSize) { + tw = (st::maxGifSize * tw) / th; + th = st::maxGifSize; } if (!tw || !th) { tw = th = 1; @@ -4809,13 +4817,13 @@ int32 HistoryGif::countHeight(const HistoryItem *parent, int32 width) const { th = convertScale(_data->thumb->height()); } } - if (tw > st::maxMediaSize) { - th = (st::maxMediaSize * th) / tw; - tw = st::maxMediaSize; + if (tw > st::maxGifSize) { + th = (st::maxGifSize * th) / tw; + tw = st::maxGifSize; } - if (th > st::maxMediaSize) { - tw = (st::maxMediaSize * tw) / th; - th = st::maxMediaSize; + if (th > st::maxGifSize) { + tw = (st::maxGifSize * tw) / th; + th = st::maxGifSize; } if (!tw || !th) { tw = th = 1;