Use first media caption for group caption.

This commit is contained in:
John Preston 2017-12-16 13:27:45 +04:00
parent 520a644150
commit 3e7ac7eb26
3 changed files with 38 additions and 14 deletions

View File

@ -650,13 +650,15 @@ void HistoryItem::finishCreate() {
void HistoryItem::finishEdition(int oldKeyboardTop) { void HistoryItem::finishEdition(int oldKeyboardTop) {
setPendingInitDimensions(); setPendingInitDimensions();
if (App::main()) { invalidateChatsListEntry();
App::main()->dlgUpdated(history()->peer, id); //if (groupId()) {
} // history()->fixGroupAfterEdition(this);
//}
// invalidate cache for drawInDialog if (isHiddenByGroup()) {
if (history()->textCachedFor == this) { // Perhaps caption was changed, we should refresh the group.
history()->textCachedFor = nullptr; const auto group = Get<HistoryMessageGroup>();
group->leader->setPendingInitDimensions();
group->leader->invalidateChatsListEntry();
} }
if (oldKeyboardTop >= 0) { if (oldKeyboardTop >= 0) {
@ -668,6 +670,17 @@ void HistoryItem::finishEdition(int oldKeyboardTop) {
App::historyUpdateDependent(this); App::historyUpdateDependent(this);
} }
void HistoryItem::invalidateChatsListEntry() {
if (App::main()) {
App::main()->dlgUpdated(history()->peer, id);
}
// invalidate cache for drawInDialog
if (history()->textCachedFor == this) {
history()->textCachedFor = nullptr;
}
}
void HistoryItem::finishEditionToEmpty() { void HistoryItem::finishEditionToEmpty() {
recountDisplayDate(); recountDisplayDate();
finishEdition(-1); finishEdition(-1);
@ -1193,6 +1206,7 @@ void HistoryItem::makeGroupLeader(
group->others = std::move(others); group->others = std::move(others);
if (!_media || !_media->applyGroup(group->others)) { if (!_media || !_media->applyGroup(group->others)) {
resetGroupMedia(group->others); resetGroupMedia(group->others);
invalidateChatsListEntry();
} }
Ensures(!isHiddenByGroup()); Ensures(!isHiddenByGroup());

View File

@ -1094,6 +1094,7 @@ protected:
} }
return nullptr; return nullptr;
} }
void invalidateChatsListEntry();
[[nodiscard]] TextSelection skipTextSelection( [[nodiscard]] TextSelection skipTextSelection(
TextSelection selection) const { TextSelection selection) const {

View File

@ -279,7 +279,7 @@ TextSelection HistoryGroupedMedia::adjustSelection(
} }
QString HistoryGroupedMedia::notificationText() const { QString HistoryGroupedMedia::notificationText() const {
return WithCaptionNotificationText(lang(lng_in_dlg_album), _caption); return WithCaptionNotificationText(lang(lng_in_dlg_photo), _caption);
} }
QString HistoryGroupedMedia::inDialogsText() const { QString HistoryGroupedMedia::inDialogsText() const {
@ -393,14 +393,23 @@ Storage::SharedMediaTypesMask HistoryGroupedMedia::sharedMediaTypes() const {
} }
void HistoryGroupedMedia::updateNeedBubbleState() { void HistoryGroupedMedia::updateNeedBubbleState() {
auto captionText = [&] { const auto getItemCaption = [](const Element &element) {
for (const auto &element : _elements) { if (const auto media = element.item->getMedia()) {
auto result = element.content->getCaption(); return media->getCaption();
if (!result.text.isEmpty()) { }
return result; return element.content->getCaption();
};
const auto captionText = [&] {
auto result = getItemCaption(_elements.front());
if (result.text.isEmpty()) {
return result;
}
for (auto i = 1, count = int(_elements.size()); i != count; ++i) {
if (!getItemCaption(_elements[i]).text.isEmpty()) {
return TextWithEntities();
} }
} }
return TextWithEntities(); return result;
}(); }();
_caption.setText( _caption.setText(
st::messageTextStyle, st::messageTextStyle,