1
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-04-01 23:00:58 +00:00

Fix layout of some media, enable GIF autoplay.

This commit is contained in:
John Preston 2018-01-19 15:13:06 +03:00
parent d326c7e3fa
commit e6baf8ef5b
17 changed files with 66 additions and 194 deletions

View File

@ -970,13 +970,15 @@ bool DocumentData::setRemoteVersion(int32 version) {
}
void DocumentData::setRemoteLocation(int32 dc, uint64 access) {
_dc = dc;
_access = access;
if (isValid()) {
if (_location.check()) {
Local::writeFileLocation(mediaKey(), _location);
} else {
_location = Local::readFileLocation(mediaKey());
if (_dc != dc || _access != access) {
_dc = dc;
_access = access;
if (isValid()) {
if (_location.check()) {
Local::writeFileLocation(mediaKey(), _location);
} else {
_location = Local::readFileLocation(mediaKey());
}
}
}
}

View File

@ -850,7 +850,7 @@ QString MediaWebPage::pinnedTextSubstring() const {
}
bool MediaWebPage::allowsEdit() const {
return false;
return true;
}
bool MediaWebPage::updateInlineResultMedia(const MTPMessageMedia &media) {

View File

@ -786,7 +786,6 @@ void Session::documentConvert(
}
documentApplyFields(original, data);
if (idChanged) {
// #TODO check audio, sticker, GIF animation, saved GIF?..
const auto newKey = original->mediaKey();
if (oldKey != newKey) {
if (original->isVoiceMessage()) {
@ -842,7 +841,6 @@ void Session::documentApplyFields(
document->setattributes(attributes);
document->setRemoteVersion(version);
if (dc != 0 && access != 0) {
// #TODO was "!document->isValid()" - check if it is fine for convert
document->setRemoteLocation(dc, access);
}
document->date = date;

View File

@ -242,11 +242,8 @@ bool isLayerShown() {
void autoplayMediaInlineAsync(const FullMsgId &msgId) {
if (auto main = App::main()) {
InvokeQueued(main, [msgId] {
if (auto item = App::histItemById(msgId)) {
// #TODO GIFs
//if (auto media = item->getMedia()) {
// media->playInline(true);
//}
if (const auto item = App::histItemById(msgId)) {
Auth().data().requestItemPlayInline(item);
}
});
}

View File

@ -1462,7 +1462,6 @@ void History::addItemToBlock(not_null<HistoryItem*> item) {
HistoryInner::ElementDelegate()));
const auto view = block->messages.back().get();
view->attachToBlock(block, block->messages.size() - 1);
view->previousInBlocksChanged();
if (isBuildingFrontBlock() && _buildingFrontBlock->expectedItemsCount > 0) {
--_buildingFrontBlock->expectedItemsCount;
@ -2014,7 +2013,6 @@ not_null<HistoryItem*> History::addNewInTheMiddle(
item->createView(
HistoryInner::ElementDelegate()));
(*it)->attachToBlock(block.get(), itemIndex);
(*it)->previousInBlocksChanged();
if (itemIndex + 1 < block->messages.size()) {
for (auto i = itemIndex + 1, l = int(block->messages.size()); i != l; ++i) {
block->messages[i]->setIndexInBlock(i);
@ -2028,63 +2026,6 @@ not_null<HistoryItem*> History::addNewInTheMiddle(
return item;
}
//
//HistoryView::Element *History::findNextItem(
// not_null<HistoryView::Element*> view) const {
// const auto nextBlockIndex = view->block()->indexInHistory() + 1;
// const auto nextItemIndex = view->indexInBlock() + 1;
// if (nextItemIndex < int(view->block()->messages.size())) {
// return view->block()->messages[nextItemIndex].get();
// } else if (nextBlockIndex < int(blocks.size())) {
// return blocks[nextBlockIndex]->messages.front().get();
// }
// return nullptr;
//}
//
//HistoryView::Element *History::findPreviousItem(
// not_null<HistoryView::Element*> view) const {
// const auto blockIndex = view->block()->indexInHistory();
// const auto itemIndex = view->indexInBlock();
// if (itemIndex > 0) {
// return view->block()->messages[itemIndex - 1].get();
// } else if (blockIndex > 0) {
// return blocks[blockIndex - 1]->messages.back().get();
// }
// return nullptr;
//}
//
//not_null<HistoryView::Element*> History::findGroupFirst(
// not_null<HistoryView::Element*> view) const {
// const auto group = view->Get<HistoryView::Group>();
// Assert(group != nullptr);
// Assert(group->leader != nullptr);
//
// const auto leaderGroup = (group->leader == view)
// ? group
// : group->leader->Get<HistoryView::Group>();
// Assert(leaderGroup != nullptr);
//
// return leaderGroup->others.empty()
// ? group->leader
// : leaderGroup->others.front().get();
//}
//
//not_null<HistoryView::Element*> History::findGroupLast(
// not_null<HistoryView::Element*> view) const {
// const auto group = view->Get<HistoryView::Group>();
// Assert(group != nullptr);
//
// return group->leader;
//}
//
//void History::recountGroupingAround(not_null<HistoryItem*> item) {
// Expects(item->history() == this);
//
// if (item->mainView() && item->groupId()) {
// const auto [groupFrom, groupTill] = recountGroupingFromTill(item->mainView());
// recountGrouping(groupFrom, groupTill);
// }
//}
int History::chatListUnreadCount() const {
const auto result = unreadCount();
@ -2115,65 +2056,6 @@ void History::paintUserpic(
int size) const {
peer->paintUserpic(p, x, y, size);
}
//
//auto History::recountGroupingFromTill(not_null<HistoryView::Element*> view)
//-> std::pair<not_null<HistoryView::Element*>, not_null<HistoryView::Element*>> {
// const auto recountFromItem = [&] {
// if (const auto prev = findPreviousItem(view)) {
// if (prev->data()->groupId()) {
// return findGroupFirst(prev);
// }
// }
// return view;
// }();
// if (recountFromItem == view && !view->data()->groupId()) {
// return { view, view };
// }
// const auto recountTillItem = [&] {
// if (const auto next = findNextItem(view)) {
// if (next->data()->groupId()) {
// return findGroupLast(next);
// }
// }
// return view;
// }();
// return { recountFromItem, recountTillItem };
//}
//
//void History::recountGrouping(
// not_null<HistoryView::Element*> from,
// not_null<HistoryView::Element*> till) {
// from->validateGroupId();
// auto others = std::vector<not_null<HistoryView::Element*>>();
// auto currentGroupId = from->data()->groupId();
// auto prev = from;
// while (prev != till) {
// auto item = findNextItem(prev);
// item->validateGroupId();
// const auto groupId = item->data()->groupId();
// if (currentGroupId) {
// if (groupId == currentGroupId) {
// others.push_back(prev);
// } else {
// for (const auto other : others) {
// other->makeGroupMember(prev);
// }
// prev->makeGroupLeader(base::take(others));
// currentGroupId = groupId;
// }
// } else if (groupId) {
// currentGroupId = groupId;
// }
// prev = item;
// }
//
// if (currentGroupId) {
// for (const auto other : others) {
// other->makeGroupMember(prev);
// }
// till->makeGroupLeader(base::take(others));
// }
//}
void History::startBuildingFrontBlock(int expectedItemsCount) {
Assert(!isBuildingFrontBlock());

View File

@ -329,7 +329,6 @@ public:
}
HistoryItemsList validateForwardDraft();
void setForwardDraft(MessageIdsList &&items);
void recountGroupingAround(not_null<HistoryItem*> item);
bool needUpdateInChatList() const override;
bool toImportant() const override {
@ -456,20 +455,6 @@ private:
void addItemsToLists(const std::vector<not_null<HistoryItem*>> &items);
void clearSendAction(not_null<UserData*> from);
HistoryView::Element *findPreviousItem(
not_null<HistoryView::Element*> view) const;
HistoryView::Element *findNextItem(
not_null<HistoryView::Element*> view) const;
not_null<HistoryView::Element*> findGroupFirst(
not_null<HistoryView::Element*> view) const;
not_null<HistoryView::Element*> findGroupLast(
not_null<HistoryView::Element*> view) const;
auto recountGroupingFromTill(not_null<HistoryView::Element*> view)
-> std::pair<not_null<HistoryView::Element*>, not_null<HistoryView::Element*>>;
void recountGrouping(
not_null<HistoryView::Element*> from,
not_null<HistoryView::Element*> till);
enum class Flag {
f_has_pending_resized_items = (1 << 0),
f_pending_resize = (1 << 1),

View File

@ -197,9 +197,6 @@ public:
bool emptyText() const {
return _text.isEmpty();
}
Text cloneText() const {
return _text;
}
bool isPinned() const;
bool canPin() const;

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item.h"
#include "history/view/history_view_element.h"
#include "storage/storage_shared_media.h"
#include "ui/text_options.h"
Storage::SharedMediaTypesMask HistoryMedia::sharedMediaTypes() const {
return {};
@ -23,6 +24,24 @@ QSize HistoryMedia::countCurrentSize(int newWidth) {
return QSize(qMin(newWidth, maxWidth()), minHeight());
}
Text HistoryMedia::createCaption(not_null<HistoryItem*> item) const {
if (item->emptyText()) {
return Text();
}
const auto minResizeWidth = st::minPhotoSize
- st::msgPadding.left()
- st::msgPadding.right();
auto result = Text(minResizeWidth);
result.setMarkedText(
st::messageTextStyle,
item->originalText(),
Ui::ItemTextOptions(item));
if (const auto width = _parent->skipBlockWidth()) {
result.updateSkipBlock(width, _parent->skipBlockHeight());
}
return result;
}
TextSelection HistoryMedia::skipSelection(TextSelection selection) const {
return HistoryView::UnshiftItemSelection(
selection,

View File

@ -241,6 +241,7 @@ public:
protected:
QSize countCurrentSize(int newWidth) override;
Text createCaption(not_null<HistoryItem*> item) const;
not_null<Element*> _parent;
MediaInBubbleState _inBubbleState = MediaInBubbleState::None;

View File

@ -379,7 +379,7 @@ void HistoryGroupedMedia::updateNeedBubbleState() {
return true;
}();
if (hasCaption) {
_caption = _parts.front().item->cloneText();
_caption = createCaption(_parts.front().item);
}
_needBubble = computeNeedBubble();
}

View File

@ -228,7 +228,7 @@ HistoryPhoto::HistoryPhoto(
std::make_shared<PhotoOpenClickHandler>(_data, fullId),
std::make_shared<PhotoSaveClickHandler>(_data, fullId),
std::make_shared<PhotoCancelClickHandler>(_data, fullId));
_caption = realParent->cloneText();
_caption = createCaption(realParent);
create(realParent->fullId());
}
@ -731,7 +731,7 @@ HistoryVideo::HistoryVideo(
, _data(document)
, _thumbw(1)
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) {
_caption = realParent->cloneText();
_caption = createCaption(realParent);
setDocumentLinks(_data, realParent);
@ -1199,7 +1199,7 @@ HistoryDocument::HistoryDocument(
, DocumentViewRegister(parent, document)
, _data(document) {
const auto item = parent->data();
auto caption = item->cloneText();
auto caption = createCaption(item);
createComponents(!caption.isEmpty());
if (auto named = Get<HistoryDocumentNamed>()) {
@ -1308,7 +1308,7 @@ QSize HistoryDocument::countOptimalSize() {
if (auto named = Get<HistoryDocumentNamed>()) {
accumulate_max(maxWidth, tleft + named->_namew + tright);
accumulate_max(maxWidth, st::msgMaxWidth);
accumulate_min(maxWidth, st::msgMaxWidth);
}
auto minHeight = 0;
@ -1952,7 +1952,7 @@ HistoryGif::HistoryGif(
setStatusSize(FileStatusSizeReady);
_caption = item->cloneText();
_caption = createCaption(item);
_data->thumb->load();
}
@ -2117,7 +2117,9 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM
auto displayLoading = (item->id < 0) || _data->displayLoading();
auto selected = (selection == FullSelection);
auto videoFinished = _gif && (_gif->mode() == Media::Clip::Reader::Mode::Video) && (_gif->state() == Media::Clip::State::Finished);
auto videoFinished = _gif
&& (_gif->mode() == Media::Clip::Reader::Mode::Video)
&& (_gif->state() == Media::Clip::State::Finished);
if (loaded && cAutoPlayGif() && ((!_gif && !_gif.isBad()) || videoFinished)) {
Ui::autoplayMediaInlineAsync(item->fullId());
}
@ -3087,7 +3089,7 @@ QSize HistoryContact::countOptimalSize() {
}
accumulate_max(maxWidth, tleft + _name.maxWidth() + tright);
accumulate_max(maxWidth, st::msgMaxWidth);
accumulate_min(maxWidth, st::msgMaxWidth);
auto minHeight = 0;
if (_userId) {
minHeight = st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom();

View File

@ -851,10 +851,6 @@ void HistoryMessage::replaceBuyWithReceiptInMarkup() {
}
}
int32 HistoryMessage::plainMaxWidth() const {
return st::msgPadding.left() + _text.maxWidth() + st::msgPadding.right();
}
void HistoryMessage::applyEdition(const MTPDmessage &message) {
int keyboardTop = -1;
//if (!pendingResize()) {// #TODO edit bot message
@ -941,33 +937,6 @@ Storage::SharedMediaTypesMask HistoryMessage::sharedMediaTypes() const {
return result;
}
//void HistoryMessage::setMedia(const MTPMessageMedia *media) {
// #TODO grouping and games
//bool mediaRemovedSkipBlock = false;
//if (_media) {
// // Don't update Game media because we loose the consumed text of the message.
// if (_media->type() == MediaTypeGame) {
// return;
// }
// mediaRemovedSkipBlock = _media->isDisplayed() && _media->isBubbleBottom();
// _media.reset();
//}
//refreshMedia(media);
//auto mediaDisplayed = _media && _media->isDisplayed();
//if (mediaDisplayed && _media->isBubbleBottom() && !mediaRemovedSkipBlock) {
// _text.removeSkipBlock();
// _textWidth = -1;
// _textHeight = 0;
//} else if (mediaRemovedSkipBlock && (!mediaDisplayed || !_media->isBubbleBottom())) {
// _text.updateSkipBlock(skipBlockWidth(), skipBlockHeight());
// _textWidth = -1;
// _textHeight = 0;
//}
//_history->recountGroupingAround(this);
//}
void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
for_const (auto &entity, textWithEntities.entities) {
auto type = entity.type();

View File

@ -94,8 +94,6 @@ public:
not_null<HistoryMessage*> item,
const MTPMessageMedia &media);
int32 plainMaxWidth() const;
bool allowsForward() const override;
bool allowsEdit(const QDateTime &now) const override;
bool uploading() const;

View File

@ -573,6 +573,14 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> cont
) | rpl::start_with_next([this](auto item) {
item->refreshMainView();
}, lifetime());
Auth().data().itemPlayInlineRequest(
) | rpl::start_with_next([this](auto item) {
if (const auto view = item->mainView()) {
if (const auto media = view->media()) {
media->playInline(true);
}
}
}, lifetime());
subscribe(Auth().data().contactsLoaded(), [this](bool) {
if (_peer) {
updateReportSpamStatus();

View File

@ -491,6 +491,7 @@ void Element::attachToBlock(not_null<HistoryBlock*> block, int index) {
_block = block;
_indexInBlock = index;
_data->setMainView(this);
previousInBlocksChanged();
}
void Element::removeFromBlock() {

View File

@ -257,7 +257,7 @@ QSize Message::performCountOptimalSize() {
item->_textHeight = 0;
}
maxWidth = item->plainMaxWidth();
maxWidth = plainMaxWidth();
minHeight = hasVisibleText() ? item->_text.minHeight() : 0;
if (!mediaOnBottom) {
minHeight += st::msgPadding.bottom();
@ -604,6 +604,9 @@ void Message::paintViaBotIdInfo(Painter &p, QRect &trect, bool selected) const {
}
void Message::paintText(Painter &p, QRect &trect, TextSelection selection) const {
if (!hasVisibleText()) {
return;
}
const auto item = message();
const auto outbg = hasOutLayout();
@ -890,6 +893,9 @@ bool Message::getStateText(
QRect &trect,
not_null<HistoryTextState*> outResult,
HistoryStateRequest request) const {
if (!hasVisibleText()) {
return false;
}
const auto item = message();
if (trect.contains(point)) {
*outResult = HistoryTextState(item, item->_text.getState(
@ -1209,6 +1215,12 @@ int Message::timeLeft() const {
return result;
}
int Message::plainMaxWidth() const {
return st::msgPadding.left()
+ (hasVisibleText() ? message()->_text.maxWidth() : 0)
+ st::msgPadding.right();
}
void Message::initLogEntryOriginal() {
if (const auto log = message()->Get<HistoryMessageLogEntryOriginal>()) {
AddComponents(LogEntryOriginal::Bit());
@ -1478,7 +1490,7 @@ QRect Message::countGeometry() const {
auto maxwidth = qMin(st::msgMaxWidth, maxWidth());
if (media && media->width() < maxwidth) {
maxwidth = qMax(media->width(), qMin(maxwidth, item->plainMaxWidth()));
maxwidth = qMax(media->width(), qMin(maxwidth, plainMaxWidth()));
}
const auto outbg = hasOutLayout();

View File

@ -138,6 +138,7 @@ private:
HistoryMessageEdited *displayedEditBadge();
void initTime();
int timeLeft() const;
int plainMaxWidth() const;
HistoryWebPage *logEntryOriginal() const;