2017-12-13 18:10:48 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-12-13 18:10:48 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-12-13 18:10:48 +00:00
|
|
|
*/
|
|
|
|
#include "history/history_media_grouped.h"
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
#include "history/history_item_components.h"
|
2017-12-13 18:10:48 +00:00
|
|
|
#include "history/history_media_types.h"
|
|
|
|
#include "history/history_message.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/view/history_view_element.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_media_types.h"
|
2017-12-13 18:10:48 +00:00
|
|
|
#include "storage/storage_shared_media.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "ui/grouped_layout.h"
|
2017-12-28 13:06:06 +00:00
|
|
|
#include "ui/text_options.h"
|
2017-12-13 18:10:48 +00:00
|
|
|
#include "styles/style_history.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "layout.h"
|
2017-12-13 18:10:48 +00:00
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
HistoryGroupedMedia::Part::Part(not_null<HistoryItem*> item)
|
|
|
|
: item(item) {
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HistoryGroupedMedia::HistoryGroupedMedia(
|
2018-01-14 16:02:25 +00:00
|
|
|
not_null<Element*> parent,
|
2018-01-17 16:21:01 +00:00
|
|
|
const std::vector<not_null<HistoryItem*>> &items)
|
2017-12-15 16:25:47 +00:00
|
|
|
: HistoryMedia(parent)
|
|
|
|
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) {
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto result = applyGroup(items);
|
2017-12-13 18:10:48 +00:00
|
|
|
|
|
|
|
Ensures(result);
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
QSize HistoryGroupedMedia::countOptimalSize() {
|
2017-12-15 16:25:47 +00:00
|
|
|
if (_caption.hasSkipBlock()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
_caption.updateSkipBlock(
|
2017-12-15 16:25:47 +00:00
|
|
|
_parent->skipBlockWidth(),
|
|
|
|
_parent->skipBlockHeight());
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
std::vector<QSize> sizes;
|
2018-01-14 16:02:25 +00:00
|
|
|
sizes.reserve(_parts.size());
|
|
|
|
for (const auto &part : _parts) {
|
|
|
|
const auto &media = part.content;
|
2017-12-13 18:10:48 +00:00
|
|
|
media->initDimensions();
|
|
|
|
sizes.push_back(media->sizeForGrouping());
|
|
|
|
}
|
|
|
|
|
2017-12-19 16:57:42 +00:00
|
|
|
const auto layout = Ui::LayoutMediaGroup(
|
2017-12-13 18:10:48 +00:00
|
|
|
sizes,
|
|
|
|
st::historyGroupWidthMax,
|
|
|
|
st::historyGroupWidthMin,
|
|
|
|
st::historyGroupSkip);
|
2018-01-14 16:02:25 +00:00
|
|
|
Assert(layout.size() == _parts.size());
|
2017-12-13 18:10:48 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
auto maxWidth = 0;
|
|
|
|
auto minHeight = 0;
|
2017-12-13 18:10:48 +00:00
|
|
|
for (auto i = 0, count = int(layout.size()); i != count; ++i) {
|
|
|
|
const auto &item = layout[i];
|
2018-01-13 12:45:11 +00:00
|
|
|
accumulate_max(maxWidth, item.geometry.x() + item.geometry.width());
|
|
|
|
accumulate_max(minHeight, item.geometry.y() + item.geometry.height());
|
2018-01-14 16:02:25 +00:00
|
|
|
_parts[i].initialGeometry = item.geometry;
|
|
|
|
_parts[i].sides = item.sides;
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
|
|
|
|
if (!_caption.isEmpty()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto captionw = maxWidth - st::msgPadding.left() - st::msgPadding.right();
|
|
|
|
minHeight += st::mediaCaptionSkip + _caption.countHeight(captionw);
|
2017-12-15 16:25:47 +00:00
|
|
|
if (isBubbleBottom()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
minHeight += st::msgPadding.bottom();
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
return { maxWidth, minHeight };
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
QSize HistoryGroupedMedia::countCurrentSize(int newWidth) {
|
|
|
|
accumulate_min(newWidth, maxWidth());
|
|
|
|
auto newHeight = 0;
|
|
|
|
if (newWidth < st::historyGroupWidthMin) {
|
|
|
|
return { newWidth, newHeight };
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto initialSpacing = st::historyGroupSkip;
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto factor = newWidth / float64(maxWidth());
|
2017-12-13 18:10:48 +00:00
|
|
|
const auto scale = [&](int value) {
|
|
|
|
return int(std::round(value * factor));
|
|
|
|
};
|
|
|
|
const auto spacing = scale(initialSpacing);
|
2018-01-14 16:02:25 +00:00
|
|
|
for (auto &part : _parts) {
|
|
|
|
const auto sides = part.sides;
|
|
|
|
const auto initialGeometry = part.initialGeometry;
|
2017-12-13 18:10:48 +00:00
|
|
|
const auto needRightSkip = !(sides & RectPart::Right);
|
|
|
|
const auto needBottomSkip = !(sides & RectPart::Bottom);
|
|
|
|
const auto initialLeft = initialGeometry.x();
|
|
|
|
const auto initialTop = initialGeometry.y();
|
|
|
|
const auto initialRight = initialLeft
|
|
|
|
+ initialGeometry.width()
|
|
|
|
+ (needRightSkip ? initialSpacing : 0);
|
|
|
|
const auto initialBottom = initialTop
|
|
|
|
+ initialGeometry.height()
|
|
|
|
+ (needBottomSkip ? initialSpacing : 0);
|
|
|
|
const auto left = scale(initialLeft);
|
|
|
|
const auto top = scale(initialTop);
|
|
|
|
const auto width = scale(initialRight)
|
|
|
|
- left
|
|
|
|
- (needRightSkip ? spacing : 0);
|
|
|
|
const auto height = scale(initialBottom)
|
|
|
|
- top
|
|
|
|
- (needBottomSkip ? spacing : 0);
|
2018-01-14 16:02:25 +00:00
|
|
|
part.geometry = QRect(left, top, width, height);
|
2017-12-13 18:10:48 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
accumulate_max(newHeight, top + height);
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
|
|
|
|
if (!_caption.isEmpty()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto captionw = newWidth - st::msgPadding.left() - st::msgPadding.right();
|
|
|
|
newHeight += st::mediaCaptionSkip + _caption.countHeight(captionw);
|
2017-12-15 16:25:47 +00:00
|
|
|
if (isBubbleBottom()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
newHeight += st::msgPadding.bottom();
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
return { newWidth, newHeight };
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void HistoryGroupedMedia::refreshParentId(
|
|
|
|
not_null<HistoryItem*> realParent) {
|
2018-01-14 16:02:25 +00:00
|
|
|
for (const auto &part : _parts) {
|
2018-01-17 16:21:01 +00:00
|
|
|
part.content->refreshParentId(part.item);
|
2017-12-18 13:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
void HistoryGroupedMedia::draw(
|
|
|
|
Painter &p,
|
|
|
|
const QRect &clip,
|
|
|
|
TextSelection selection,
|
|
|
|
TimeMs ms) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
for (auto i = 0, count = int(_parts.size()); i != count; ++i) {
|
|
|
|
const auto &part = _parts[i];
|
|
|
|
const auto partSelection = (selection == FullSelection)
|
2017-12-15 16:25:47 +00:00
|
|
|
? FullSelection
|
|
|
|
: IsGroupItemSelection(selection, i)
|
|
|
|
? FullSelection
|
|
|
|
: TextSelection();
|
2018-01-14 16:02:25 +00:00
|
|
|
auto corners = Ui::GetCornersFromSides(part.sides);
|
2017-12-13 18:10:48 +00:00
|
|
|
if (!isBubbleTop()) {
|
|
|
|
corners &= ~(RectPart::TopLeft | RectPart::TopRight);
|
|
|
|
}
|
|
|
|
if (!isBubbleBottom() || !_caption.isEmpty()) {
|
|
|
|
corners &= ~(RectPart::BottomLeft | RectPart::BottomRight);
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
part.content->drawGrouped(
|
2017-12-13 18:10:48 +00:00
|
|
|
p,
|
|
|
|
clip,
|
2018-01-14 16:02:25 +00:00
|
|
|
partSelection,
|
2017-12-13 18:10:48 +00:00
|
|
|
ms,
|
2018-01-14 16:02:25 +00:00
|
|
|
part.geometry,
|
2017-12-13 18:10:48 +00:00
|
|
|
corners,
|
2018-01-14 16:02:25 +00:00
|
|
|
&part.cacheKey,
|
|
|
|
&part.cache);
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
|
|
|
|
// date
|
|
|
|
const auto selected = (selection == FullSelection);
|
|
|
|
if (!_caption.isEmpty()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto captionw = width() - st::msgPadding.left() - st::msgPadding.right();
|
2017-12-15 16:25:47 +00:00
|
|
|
const auto outbg = _parent->hasOutLayout();
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto captiony = height()
|
2017-12-15 16:25:47 +00:00
|
|
|
- (isBubbleBottom() ? st::msgPadding.bottom() : 0)
|
|
|
|
- _caption.countHeight(captionw);
|
|
|
|
p.setPen(outbg ? (selected ? st::historyTextOutFgSelected : st::historyTextOutFg) : (selected ? st::historyTextInFgSelected : st::historyTextInFg));
|
|
|
|
_caption.draw(p, st::msgPadding.left(), captiony, captionw, style::al_left, 0, -1, selection);
|
2018-01-14 16:02:25 +00:00
|
|
|
} else if (_parent->media() == this) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto fullRight = width();
|
|
|
|
auto fullBottom = height();
|
2018-01-11 13:07:29 +00:00
|
|
|
if (needInfoDisplay()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
_parent->drawInfo(p, fullRight, fullBottom, width(), selected, InfoDisplayOverImage);
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
if (!_parent->hasBubble() && _parent->displayRightAction()) {
|
|
|
|
auto fastShareLeft = (fullRight + st::historyFastShareLeft);
|
|
|
|
auto fastShareTop = (fullBottom - st::historyFastShareBottom - st::historyFastShareSize);
|
2018-01-13 12:45:11 +00:00
|
|
|
_parent->drawRightAction(p, fastShareLeft, fastShareTop, width());
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
HistoryTextState HistoryGroupedMedia::getPartState(
|
2017-12-13 18:10:48 +00:00
|
|
|
QPoint point,
|
|
|
|
HistoryStateRequest request) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
for (const auto &part : _parts) {
|
|
|
|
if (part.geometry.contains(point)) {
|
|
|
|
auto result = part.content->getStateGrouped(
|
|
|
|
part.geometry,
|
2017-12-13 18:10:48 +00:00
|
|
|
point,
|
|
|
|
request);
|
2018-01-17 16:21:01 +00:00
|
|
|
result.itemId = part.item->fullId();
|
2017-12-15 16:25:47 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
return HistoryTextState(_parent->data());
|
2017-12-16 07:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HistoryTextState HistoryGroupedMedia::getState(
|
|
|
|
QPoint point,
|
|
|
|
HistoryStateRequest request) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
auto result = getPartState(point, request);
|
2017-12-16 07:20:04 +00:00
|
|
|
if (!result.link && !_caption.isEmpty()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto captionw = width() - st::msgPadding.left() - st::msgPadding.right();
|
|
|
|
const auto captiony = height()
|
2017-12-15 16:25:47 +00:00
|
|
|
- (isBubbleBottom() ? st::msgPadding.bottom() : 0)
|
|
|
|
- _caption.countHeight(captionw);
|
2018-01-13 12:45:11 +00:00
|
|
|
if (QRect(st::msgPadding.left(), captiony, captionw, height() - captiony).contains(point)) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return HistoryTextState(_parent->data(), _caption.getState(
|
2017-12-15 16:25:47 +00:00
|
|
|
point - QPoint(st::msgPadding.left(), captiony),
|
|
|
|
captionw,
|
|
|
|
request.forText()));
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
} else if (_parent->media() == this) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto fullRight = width();
|
|
|
|
auto fullBottom = height();
|
2017-12-15 16:25:47 +00:00
|
|
|
if (_parent->pointInTime(fullRight, fullBottom, point, InfoDisplayOverImage)) {
|
|
|
|
result.cursor = HistoryInDateCursorState;
|
|
|
|
}
|
|
|
|
if (!_parent->hasBubble() && _parent->displayRightAction()) {
|
|
|
|
auto fastShareLeft = (fullRight + st::historyFastShareLeft);
|
|
|
|
auto fastShareTop = (fullBottom - st::historyFastShareBottom - st::historyFastShareSize);
|
|
|
|
if (QRect(fastShareLeft, fastShareTop, st::historyFastShareSize, st::historyFastShareSize).contains(point)) {
|
|
|
|
result.link = _parent->rightActionLink();
|
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-16 07:20:04 +00:00
|
|
|
return result;
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryGroupedMedia::toggleSelectionByHandlerClick(
|
|
|
|
const ClickHandlerPtr &p) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
for (const auto &part : _parts) {
|
|
|
|
if (part.content->toggleSelectionByHandlerClick(p)) {
|
2017-12-13 18:10:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryGroupedMedia::dragItemByHandler(const ClickHandlerPtr &p) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
for (const auto &part : _parts) {
|
|
|
|
if (part.content->dragItemByHandler(p)) {
|
2017-12-13 18:10:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextSelection HistoryGroupedMedia::adjustSelection(
|
|
|
|
TextSelection selection,
|
|
|
|
TextSelectType type) const {
|
|
|
|
return _caption.adjustSelection(selection, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextWithEntities HistoryGroupedMedia::selectedText(
|
|
|
|
TextSelection selection) const {
|
2017-12-16 15:00:20 +00:00
|
|
|
if (!IsSubGroupSelection(selection)) {
|
|
|
|
return WithCaptionSelectedText(
|
|
|
|
lang(lng_in_dlg_album),
|
|
|
|
_caption,
|
|
|
|
selection);
|
2018-01-14 16:02:25 +00:00
|
|
|
} else if (IsGroupItemSelection(selection, int(_parts.size()) - 1)) {
|
2017-12-16 15:00:20 +00:00
|
|
|
return main()->selectedText(FullSelection);
|
|
|
|
}
|
|
|
|
return TextWithEntities();
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryGroupedMedia::clickHandlerActiveChanged(
|
|
|
|
const ClickHandlerPtr &p,
|
|
|
|
bool active) {
|
2018-01-14 16:02:25 +00:00
|
|
|
for (const auto &part : _parts) {
|
|
|
|
part.content->clickHandlerActiveChanged(p, active);
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryGroupedMedia::clickHandlerPressedChanged(
|
|
|
|
const ClickHandlerPtr &p,
|
|
|
|
bool pressed) {
|
2018-01-14 16:02:25 +00:00
|
|
|
for (const auto &part : _parts) {
|
|
|
|
part.content->clickHandlerPressedChanged(p, pressed);
|
|
|
|
if (pressed && part.content->dragItemByHandler(p)) {
|
2018-01-17 16:21:01 +00:00
|
|
|
// #TODO drag by item from album
|
|
|
|
// App::pressedLinkItem(part.view);
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<HistoryMedia> HistoryGroupedMedia::takeLastFromGroup() {
|
2018-01-14 16:02:25 +00:00
|
|
|
return std::move(_parts.back().content);
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryGroupedMedia::applyGroup(
|
2018-01-17 16:21:01 +00:00
|
|
|
const std::vector<not_null<HistoryItem*>> &items) {
|
|
|
|
if (items.empty()) {
|
2017-12-13 18:10:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
if (validateGroupParts(items)) {
|
2017-12-13 18:10:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto pushElement = [&](not_null<HistoryItem*> item) {
|
|
|
|
const auto media = item->media();
|
|
|
|
Assert(media != nullptr && media->canBeGrouped());
|
|
|
|
|
|
|
|
_parts.push_back(Part(item));
|
|
|
|
_parts.back().content = media->createView(_parent, item);
|
|
|
|
};
|
|
|
|
ranges::for_each(items, pushElement);
|
2017-12-13 18:10:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool HistoryGroupedMedia::validateGroupParts(
|
2018-01-17 16:21:01 +00:00
|
|
|
const std::vector<not_null<HistoryItem*>> &items) const {
|
|
|
|
if (_parts.size() != items.size()) {
|
2017-12-13 18:10:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
for (auto i = 0, count = int(items.size()); i != count; ++i) {
|
|
|
|
if (_parts[i].item != items[i]) {
|
2017-12-13 18:10:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<HistoryMedia*> HistoryGroupedMedia::main() const {
|
2018-01-14 16:02:25 +00:00
|
|
|
Expects(!_parts.empty());
|
2017-12-13 18:10:48 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
return _parts.back().content.get();
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryGroupedMedia::hasReplyPreview() const {
|
|
|
|
return main()->hasReplyPreview();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr HistoryGroupedMedia::replyPreview() {
|
|
|
|
return main()->replyPreview();
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:25:21 +00:00
|
|
|
TextWithEntities HistoryGroupedMedia::getCaption() const {
|
|
|
|
return main()->getCaption();
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
Storage::SharedMediaTypesMask HistoryGroupedMedia::sharedMediaTypes() const {
|
|
|
|
return main()->sharedMediaTypes();
|
|
|
|
}
|
|
|
|
|
2017-12-19 16:57:42 +00:00
|
|
|
PhotoData *HistoryGroupedMedia::getPhoto() const {
|
|
|
|
return main()->getPhoto();
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *HistoryGroupedMedia::getDocument() const {
|
|
|
|
return main()->getDocument();
|
|
|
|
}
|
|
|
|
|
2017-12-16 16:32:10 +00:00
|
|
|
HistoryMessageEdited *HistoryGroupedMedia::displayedEditBadge() const {
|
|
|
|
if (!_caption.isEmpty()) {
|
2018-01-17 16:21:01 +00:00
|
|
|
return _parts.front().item->Get<HistoryMessageEdited>();
|
2017-12-16 16:32:10 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
void HistoryGroupedMedia::updateNeedBubbleState() {
|
2018-01-18 13:59:22 +00:00
|
|
|
const auto hasCaption = [&] {
|
|
|
|
if (_parts.front().item->emptyText()) {
|
|
|
|
return false;
|
2017-12-16 09:27:45 +00:00
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
for (auto i = 1, count = int(_parts.size()); i != count; ++i) {
|
2018-01-18 13:59:22 +00:00
|
|
|
if (!_parts[i].item->emptyText()) {
|
|
|
|
return false;
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-18 13:59:22 +00:00
|
|
|
return true;
|
2017-12-13 18:10:48 +00:00
|
|
|
}();
|
2018-01-18 13:59:22 +00:00
|
|
|
if (hasCaption) {
|
2018-01-19 12:13:06 +00:00
|
|
|
_caption = createCaption(_parts.front().item);
|
2018-01-18 13:59:22 +00:00
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
_needBubble = computeNeedBubble();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryGroupedMedia::needsBubble() const {
|
|
|
|
return _needBubble;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryGroupedMedia::computeNeedBubble() const {
|
|
|
|
if (!_caption.isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto item = _parent->data()) {
|
|
|
|
if (item->viaBot()
|
|
|
|
|| item->Has<HistoryMessageReply>()
|
|
|
|
|| _parent->displayForwardedFrom()
|
|
|
|
|| _parent->displayFromName()
|
2018-01-13 12:45:11 +00:00
|
|
|
) {
|
2017-12-16 13:09:53 +00:00
|
|
|
return true;
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-11 13:07:29 +00:00
|
|
|
|
|
|
|
bool HistoryGroupedMedia::needInfoDisplay() const {
|
2018-01-14 16:02:25 +00:00
|
|
|
return (_parent->data()->id < 0 || _parent->isUnderCursor());
|
2018-01-11 13:07:29 +00:00
|
|
|
}
|