Refresh caption Text after media is being sent.

Fixes #4488.
This commit is contained in:
John Preston 2018-03-13 13:19:06 +03:00
parent 57d0b1d215
commit f792b0052f
9 changed files with 69 additions and 4 deletions

View File

@ -923,6 +923,7 @@ namespace {
: nullptr);
existing->setViewsCount(m.has_views() ? m.vviews.v : -1);
existing->indexAsNewItem();
Auth().data().requestItemTextRefresh(existing);
if (existing->mainView()) {
App::checkSavedGif(existing);
return true;

View File

@ -256,6 +256,16 @@ rpl::producer<not_null<HistoryItem*>> Session::itemViewRefreshRequest() const {
return _itemViewRefreshRequest.events();
}
void Session::requestItemTextRefresh(not_null<HistoryItem*> item) {
if (const auto i = _views.find(item); i != _views.end()) {
for (const auto view : i->second) {
if (const auto media = view->media()) {
media->parentTextUpdated();
}
}
}
}
void Session::requestAnimationPlayInline(not_null<HistoryItem*> item) {
_animationPlayInlineRequest.fire_copy(item);
}

View File

@ -80,6 +80,7 @@ public:
[[nodiscard]] rpl::producer<not_null<ViewElement*>> viewResizeRequest() const;
void requestItemViewRefresh(not_null<HistoryItem*> item);
[[nodiscard]] rpl::producer<not_null<HistoryItem*>> itemViewRefreshRequest() const;
void requestItemTextRefresh(not_null<HistoryItem*> item);
void requestAnimationPlayInline(not_null<HistoryItem*> item);
[[nodiscard]] rpl::producer<not_null<HistoryItem*>> animationPlayInlineRequest() const;
void notifyHistoryUnloaded(not_null<const History*> history);
@ -468,6 +469,7 @@ private:
rpl::event_stream<not_null<const HistoryItem*>> _itemResizeRequest;
rpl::event_stream<not_null<ViewElement*>> _viewResizeRequest;
rpl::event_stream<not_null<HistoryItem*>> _itemViewRefreshRequest;
rpl::event_stream<not_null<HistoryItem*>> _itemTextRefreshRequest;
rpl::event_stream<not_null<HistoryItem*>> _animationPlayInlineRequest;
rpl::event_stream<not_null<const HistoryItem*>> _itemRemoved;
rpl::event_stream<not_null<const ViewElement*>> _viewRemoved;

View File

@ -222,6 +222,8 @@ public:
// Should be called only by Data::Session.
virtual void updateSharedContactUserId(UserId userId) {
}
virtual void parentTextUpdated() {
}
virtual ~HistoryMedia() = default;

View File

@ -13,12 +13,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h"
#include "data/data_media_types.h"
#include "data/data_session.h"
#include "storage/storage_shared_media.h"
#include "lang/lang_keys.h"
#include "ui/grouped_layout.h"
#include "ui/text_options.h"
#include "styles/style_history.h"
#include "auth_session.h"
#include "layout.h"
#include "styles/style_history.h"
namespace {
@ -391,6 +393,10 @@ void HistoryGroupedMedia::updateNeedBubbleState() {
_needBubble = computeNeedBubble();
}
void HistoryGroupedMedia::parentTextUpdated() {
Auth().data().requestViewResize(_parent);
}
bool HistoryGroupedMedia::needsBubble() const {
return _needBubble;
}

View File

@ -79,6 +79,8 @@ public:
return true;
}
void parentTextUpdated() override;
private:
struct Part {
Part(not_null<HistoryItem*> item);

View File

@ -681,6 +681,13 @@ bool HistoryPhoto::needsBubble() const {
return false;
}
void HistoryPhoto::parentTextUpdated() {
_caption = (_parent->media() == this)
? createCaption(_parent->data())
: Text();
Auth().data().requestViewResize(_parent);
}
HistoryVideo::HistoryVideo(
not_null<Element*> parent,
not_null<HistoryItem*> realParent,
@ -1112,6 +1119,13 @@ bool HistoryVideo::needsBubble() const {
return false;
}
void HistoryVideo::parentTextUpdated() {
_caption = (_parent->media() == this)
? createCaption(_parent->data())
: Text();
Auth().data().requestViewResize(_parent);
}
void HistoryVideo::updateStatusText() const {
auto showPause = false;
auto statusSize = 0;
@ -1832,6 +1846,20 @@ void HistoryDocument::refreshParentId(not_null<HistoryItem*> realParent) {
}
}
void HistoryDocument::parentTextUpdated() {
auto caption = (_parent->media() == this)
? createCaption(_parent->data())
: Text();
if (!caption.isEmpty()) {
AddComponents(HistoryDocumentCaptioned::Bit());
auto captioned = Get<HistoryDocumentCaptioned>();
captioned->_caption = std::move(caption);
} else {
RemoveComponents(HistoryDocumentCaptioned::Bit());
}
Auth().data().requestViewResize(_parent);
}
TextWithEntities HistoryDocument::getCaption() const {
if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
return captioned->_caption.originalTextWithEntities();
@ -2543,6 +2571,13 @@ QString HistoryGif::additionalInfoString() const {
return QString();
}
void HistoryGif::parentTextUpdated() {
_caption = (_parent->media() == this)
? createCaption(_parent->data())
: Text();
Auth().data().requestViewResize(_parent);
}
int HistoryGif::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const {
int result = 0;
if (forwarded) {

View File

@ -190,6 +190,8 @@ public:
return _data->loaded();
}
void parentTextUpdated() override;
protected:
float64 dataProgress() const override;
bool dataFinished() const override;
@ -278,6 +280,8 @@ public:
return isBubbleBottom() && _caption.isEmpty();
}
void parentTextUpdated() override;
protected:
float64 dataProgress() const override;
bool dataFinished() const override;
@ -354,6 +358,7 @@ public:
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
void refreshParentId(not_null<HistoryItem*> realParent) override;
void parentTextUpdated() override;
protected:
float64 dataProgress() const override;
@ -427,6 +432,8 @@ public:
return _data->loaded();
}
void parentTextUpdated() override;
~HistoryGif();
protected:

View File

@ -732,8 +732,6 @@ void HistoryMessage::refreshSentMedia(const MTPMessageMedia *media) {
refreshMedia(media);
if (wasGrouped) {
Auth().data().groups().refreshMessage(this);
} else {
Auth().data().requestItemViewRefresh(this);
}
}
@ -957,7 +955,9 @@ Storage::SharedMediaTypesMask HistoryMessage::sharedMediaTypes() const {
void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
for_const (auto &entity, textWithEntities.entities) {
auto type = entity.type();
if (type == EntityInTextUrl || type == EntityInTextCustomUrl || type == EntityInTextEmail) {
if (type == EntityInTextUrl
|| type == EntityInTextCustomUrl
|| type == EntityInTextEmail) {
_flags |= MTPDmessage_ClientFlag::f_has_text_links;
break;
}