mirror of https://github.com/procxx/kepka.git
Add items to overviews inside HistoryMedia.
This allows one history item to exist in several media overviews. See voice message, which should be in VoiceFiles and RoundVoiceFiles.
This commit is contained in:
parent
2049f3e55a
commit
2377873c45
|
@ -125,13 +125,15 @@ enum HistoryMediaType {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MediaOverviewType {
|
enum MediaOverviewType {
|
||||||
OverviewPhotos = 0,
|
OverviewPhotos = 0,
|
||||||
OverviewVideos = 1,
|
OverviewVideos = 1,
|
||||||
OverviewMusicFiles = 2,
|
OverviewMusicFiles = 2,
|
||||||
OverviewFiles = 3,
|
OverviewFiles = 3,
|
||||||
OverviewVoiceFiles = 4,
|
OverviewVoiceFiles = 4,
|
||||||
OverviewLinks = 5,
|
OverviewLinks = 5,
|
||||||
OverviewChatPhotos = 6,
|
OverviewChatPhotos = 6,
|
||||||
|
OverviewRoundVoiceFiles = 7,
|
||||||
|
OverviewGIFs = 8,
|
||||||
|
|
||||||
OverviewCount
|
OverviewCount
|
||||||
};
|
};
|
||||||
|
@ -143,6 +145,7 @@ inline MTPMessagesFilter typeToMediaFilter(MediaOverviewType &type) {
|
||||||
case OverviewMusicFiles: return MTP_inputMessagesFilterMusic();
|
case OverviewMusicFiles: return MTP_inputMessagesFilterMusic();
|
||||||
case OverviewFiles: return MTP_inputMessagesFilterDocument();
|
case OverviewFiles: return MTP_inputMessagesFilterDocument();
|
||||||
case OverviewVoiceFiles: return MTP_inputMessagesFilterVoice();
|
case OverviewVoiceFiles: return MTP_inputMessagesFilterVoice();
|
||||||
|
case OverviewRoundVoiceFiles: return MTP_inputMessagesFilterRoundVoice();
|
||||||
case OverviewLinks: return MTP_inputMessagesFilterUrl();
|
case OverviewLinks: return MTP_inputMessagesFilterUrl();
|
||||||
case OverviewChatPhotos: return MTP_inputMessagesFilterChatPhotos();
|
case OverviewChatPhotos: return MTP_inputMessagesFilterChatPhotos();
|
||||||
case OverviewCount: break;
|
case OverviewCount: break;
|
||||||
|
|
|
@ -29,7 +29,7 @@ enum class MediaInBubbleState {
|
||||||
|
|
||||||
class HistoryMedia : public HistoryElement {
|
class HistoryMedia : public HistoryElement {
|
||||||
public:
|
public:
|
||||||
HistoryMedia(HistoryItem *parent) : _parent(parent) {
|
HistoryMedia(gsl::not_null<HistoryItem*> parent) : _parent(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual HistoryMediaType type() const = 0;
|
virtual HistoryMediaType type() const = 0;
|
||||||
|
@ -69,6 +69,12 @@ public:
|
||||||
virtual void updatePressed(int x, int y) {
|
virtual void updatePressed(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual int32 addToOverview(AddToOverviewMethod method) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
virtual void eraseFromOverview() {
|
||||||
|
}
|
||||||
|
|
||||||
// if we are in selecting items mode perhaps we want to
|
// if we are in selecting items mode perhaps we want to
|
||||||
// toggle selection instead of activating the pressed link
|
// toggle selection instead of activating the pressed link
|
||||||
virtual bool toggleSelectionByHandlerClick(const ClickHandlerPtr &p) const = 0;
|
virtual bool toggleSelectionByHandlerClick(const ClickHandlerPtr &p) const = 0;
|
||||||
|
@ -195,8 +201,19 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
HistoryItem *_parent;
|
int32 addToOneOverview(MediaOverviewType type, AddToOverviewMethod method) {
|
||||||
|
if (_parent->history()->addToOverview(type, _parent->id, method)) {
|
||||||
|
return (1 << type);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void eraseFromOneOverview(MediaOverviewType type) {
|
||||||
|
_parent->history()->eraseFromOverview(type, _parent->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
gsl::not_null<HistoryItem*> _parent;
|
||||||
int _width = 0;
|
int _width = 0;
|
||||||
MediaInBubbleState _inBubbleState = MediaInBubbleState::None;
|
MediaInBubbleState _inBubbleState = MediaInBubbleState::None;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -589,6 +589,24 @@ TextWithEntities HistoryPhoto::selectedText(TextSelection selection) const {
|
||||||
return captionedSelectedText(lang(lng_in_dlg_photo), _caption, selection);
|
return captionedSelectedText(lang(lng_in_dlg_photo), _caption, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 HistoryPhoto::addToOverview(AddToOverviewMethod method) {
|
||||||
|
auto result = int32(0);
|
||||||
|
if (_parent->toHistoryMessage()) {
|
||||||
|
result |= addToOneOverview(OverviewPhotos, method);
|
||||||
|
} else {
|
||||||
|
result |= addToOneOverview(OverviewChatPhotos, method);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HistoryPhoto::eraseFromOverview() {
|
||||||
|
if (_parent->toHistoryMessage()) {
|
||||||
|
eraseFromOneOverview(OverviewPhotos);
|
||||||
|
} else {
|
||||||
|
eraseFromOneOverview(OverviewChatPhotos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImagePtr HistoryPhoto::replyPreview() {
|
ImagePtr HistoryPhoto::replyPreview() {
|
||||||
return _data->makeReplyPreview();
|
return _data->makeReplyPreview();
|
||||||
}
|
}
|
||||||
|
@ -865,6 +883,14 @@ TextWithEntities HistoryVideo::selectedText(TextSelection selection) const {
|
||||||
return captionedSelectedText(lang(lng_in_dlg_video), _caption, selection);
|
return captionedSelectedText(lang(lng_in_dlg_video), _caption, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 HistoryVideo::addToOverview(AddToOverviewMethod method) {
|
||||||
|
return addToOneOverview(OverviewVideos, method);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HistoryVideo::eraseFromOverview() {
|
||||||
|
eraseFromOneOverview(OverviewVideos);
|
||||||
|
}
|
||||||
|
|
||||||
void HistoryVideo::updateStatusText() const {
|
void HistoryVideo::updateStatusText() const {
|
||||||
bool showPause = false;
|
bool showPause = false;
|
||||||
int32 statusSize = 0, realDuration = 0;
|
int32 statusSize = 0, realDuration = 0;
|
||||||
|
@ -1474,6 +1500,34 @@ TextWithEntities HistoryDocument::selectedText(TextSelection selection) const {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 HistoryDocument::addToOverview(AddToOverviewMethod method) {
|
||||||
|
auto result = int32(0);
|
||||||
|
if (_data->voice()) {
|
||||||
|
result |= addToOneOverview(OverviewVoiceFiles, method);
|
||||||
|
result |= addToOneOverview(OverviewRoundVoiceFiles, method);
|
||||||
|
} else if (_data->song()) {
|
||||||
|
if (_data->isMusic()) {
|
||||||
|
result |= addToOneOverview(OverviewMusicFiles, method);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result |= addToOneOverview(OverviewFiles, method);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HistoryDocument::eraseFromOverview() {
|
||||||
|
if (_data->voice()) {
|
||||||
|
eraseFromOneOverview(OverviewVoiceFiles);
|
||||||
|
eraseFromOneOverview(OverviewRoundVoiceFiles);
|
||||||
|
} else if (_data->song()) {
|
||||||
|
if (_data->isMusic()) {
|
||||||
|
eraseFromOneOverview(OverviewMusicFiles);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eraseFromOneOverview(OverviewFiles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
void HistoryDocument::buildStringRepresentation(Callback callback) const {
|
void HistoryDocument::buildStringRepresentation(Callback callback) const {
|
||||||
const Text emptyCaption;
|
const Text emptyCaption;
|
||||||
|
@ -2188,6 +2242,28 @@ TextWithEntities HistoryGif::selectedText(TextSelection selection) const {
|
||||||
return captionedSelectedText(mediaTypeString(), _caption, selection);
|
return captionedSelectedText(mediaTypeString(), _caption, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 HistoryGif::addToOverview(AddToOverviewMethod method) {
|
||||||
|
auto result = int32(0);
|
||||||
|
if (_data->isRoundVideo()) {
|
||||||
|
result |= addToOneOverview(OverviewRoundVoiceFiles, method);
|
||||||
|
} else if (_data->isGifv()) {
|
||||||
|
result |= addToOneOverview(OverviewGIFs, method);
|
||||||
|
} else {
|
||||||
|
result |= addToOneOverview(OverviewFiles, method);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HistoryGif::eraseFromOverview() {
|
||||||
|
if (_data->isRoundVideo()) {
|
||||||
|
eraseFromOneOverview(OverviewRoundVoiceFiles);
|
||||||
|
} else if (_data->isGifv()) {
|
||||||
|
eraseFromOneOverview(OverviewGIFs);
|
||||||
|
} else {
|
||||||
|
eraseFromOneOverview(OverviewFiles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString HistoryGif::mediaTypeString() const {
|
QString HistoryGif::mediaTypeString() const {
|
||||||
return _data->isRoundVideo() ? lang(lng_in_dlg_video_message) : qsl("GIF");
|
return _data->isRoundVideo() ? lang(lng_in_dlg_video_message) : qsl("GIF");
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,6 +139,9 @@ public:
|
||||||
QString inDialogsText() const override;
|
QString inDialogsText() const override;
|
||||||
TextWithEntities selectedText(TextSelection selection) const override;
|
TextWithEntities selectedText(TextSelection selection) const override;
|
||||||
|
|
||||||
|
int32 addToOverview(AddToOverviewMethod method) override;
|
||||||
|
void eraseFromOverview() override;
|
||||||
|
|
||||||
PhotoData *photo() const {
|
PhotoData *photo() const {
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
@ -229,6 +232,9 @@ public:
|
||||||
QString inDialogsText() const override;
|
QString inDialogsText() const override;
|
||||||
TextWithEntities selectedText(TextSelection selection) const override;
|
TextWithEntities selectedText(TextSelection selection) const override;
|
||||||
|
|
||||||
|
int32 addToOverview(AddToOverviewMethod method) override;
|
||||||
|
void eraseFromOverview() override;
|
||||||
|
|
||||||
DocumentData *getDocument() override {
|
DocumentData *getDocument() override {
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
@ -388,6 +394,9 @@ public:
|
||||||
QString inDialogsText() const override;
|
QString inDialogsText() const override;
|
||||||
TextWithEntities selectedText(TextSelection selection) const override;
|
TextWithEntities selectedText(TextSelection selection) const override;
|
||||||
|
|
||||||
|
int32 addToOverview(AddToOverviewMethod method) override;
|
||||||
|
void eraseFromOverview() override;
|
||||||
|
|
||||||
bool uploading() const override {
|
bool uploading() const override {
|
||||||
return _data->uploading();
|
return _data->uploading();
|
||||||
}
|
}
|
||||||
|
@ -486,6 +495,9 @@ public:
|
||||||
QString inDialogsText() const override;
|
QString inDialogsText() const override;
|
||||||
TextWithEntities selectedText(TextSelection selection) const override;
|
TextWithEntities selectedText(TextSelection selection) const override;
|
||||||
|
|
||||||
|
int32 addToOverview(AddToOverviewMethod method) override;
|
||||||
|
void eraseFromOverview() override;
|
||||||
|
|
||||||
bool uploading() const override {
|
bool uploading() const override {
|
||||||
return _data->uploading();
|
return _data->uploading();
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,30 +47,6 @@ inline void initTextOptions() {
|
||||||
_textDlgOptions.maxw = st::dialogsWidthMax * 2;
|
_textDlgOptions.maxw = st::dialogsWidthMax * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaOverviewType messageMediaToOverviewType(HistoryMedia *media) {
|
|
||||||
switch (media->type()) {
|
|
||||||
case MediaTypePhoto: return OverviewPhotos;
|
|
||||||
case MediaTypeVideo: return OverviewVideos;
|
|
||||||
case MediaTypeFile: return OverviewFiles;
|
|
||||||
case MediaTypeMusicFile: return media->getDocument()->isMusic() ? OverviewMusicFiles : OverviewCount;
|
|
||||||
case MediaTypeVoiceFile: return OverviewVoiceFiles;
|
|
||||||
case MediaTypeGif: {
|
|
||||||
auto document = media->getDocument();
|
|
||||||
return (document->isGifv() || document->isRoundVideo()) ? OverviewCount : OverviewFiles;
|
|
||||||
} break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
return OverviewCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
MediaOverviewType serviceMediaToOverviewType(HistoryMedia *media) {
|
|
||||||
switch (media->type()) {
|
|
||||||
case MediaTypePhoto: return OverviewChatPhotos;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
return OverviewCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
ApiWrap::RequestMessageDataCallback historyDependentItemCallback(const FullMsgId &msgId) {
|
ApiWrap::RequestMessageDataCallback historyDependentItemCallback(const FullMsgId &msgId) {
|
||||||
return [dependent = msgId](ChannelData *channel, MsgId msgId) {
|
return [dependent = msgId](ChannelData *channel, MsgId msgId) {
|
||||||
if (auto item = App::histItemById(dependent)) {
|
if (auto item = App::histItemById(dependent)) {
|
||||||
|
@ -987,13 +963,8 @@ int32 HistoryMessage::addToOverview(AddToOverviewMethod method) {
|
||||||
if (!indexInOverview()) return 0;
|
if (!indexInOverview()) return 0;
|
||||||
|
|
||||||
int32 result = 0;
|
int32 result = 0;
|
||||||
if (HistoryMedia *media = getMedia()) {
|
if (auto media = getMedia()) {
|
||||||
MediaOverviewType type = messageMediaToOverviewType(media);
|
result |= media->addToOverview(method);
|
||||||
if (type != OverviewCount) {
|
|
||||||
if (history()->addToOverview(type, id, method)) {
|
|
||||||
result |= (1 << type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (hasTextLinks()) {
|
if (hasTextLinks()) {
|
||||||
if (history()->addToOverview(OverviewLinks, id, method)) {
|
if (history()->addToOverview(OverviewLinks, id, method)) {
|
||||||
|
@ -1004,11 +975,8 @@ int32 HistoryMessage::addToOverview(AddToOverviewMethod method) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryMessage::eraseFromOverview() {
|
void HistoryMessage::eraseFromOverview() {
|
||||||
if (HistoryMedia *media = getMedia()) {
|
if (auto media = getMedia()) {
|
||||||
MediaOverviewType type = messageMediaToOverviewType(media);
|
media->eraseFromOverview();
|
||||||
if (type != OverviewCount) {
|
|
||||||
history()->eraseFromOverview(type, id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (hasTextLinks()) {
|
if (hasTextLinks()) {
|
||||||
history()->eraseFromOverview(OverviewLinks, id);
|
history()->eraseFromOverview(OverviewLinks, id);
|
||||||
|
@ -2464,22 +2432,14 @@ int32 HistoryService::addToOverview(AddToOverviewMethod method) {
|
||||||
|
|
||||||
int32 result = 0;
|
int32 result = 0;
|
||||||
if (auto media = getMedia()) {
|
if (auto media = getMedia()) {
|
||||||
MediaOverviewType type = serviceMediaToOverviewType(media);
|
result |= media->addToOverview(method);
|
||||||
if (type != OverviewCount) {
|
|
||||||
if (history()->addToOverview(type, id, method)) {
|
|
||||||
result |= (1 << type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryService::eraseFromOverview() {
|
void HistoryService::eraseFromOverview() {
|
||||||
if (auto media = getMedia()) {
|
if (auto media = getMedia()) {
|
||||||
MediaOverviewType type = serviceMediaToOverviewType(media);
|
media->eraseFromOverview();
|
||||||
if (type != OverviewCount) {
|
|
||||||
history()->eraseFromOverview(type, id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1347,20 +1347,6 @@ bool MainWidget::preloadOverview(PeerData *peer, MediaOverviewType type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::preloadOverviews(PeerData *peer) {
|
|
||||||
History *h = App::history(peer->id);
|
|
||||||
bool sending = false;
|
|
||||||
for (int32 i = 0; i < OverviewCount; ++i) {
|
|
||||||
auto type = MediaOverviewType(i);
|
|
||||||
if (type != OverviewChatPhotos && preloadOverview(peer, type)) {
|
|
||||||
sending = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sending) {
|
|
||||||
MTP::sendAnything();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWidget::overviewPreloaded(PeerData *peer, const MTPmessages_Messages &result, mtpRequestId req) {
|
void MainWidget::overviewPreloaded(PeerData *peer, const MTPmessages_Messages &result, mtpRequestId req) {
|
||||||
MediaOverviewType type = OverviewCount;
|
MediaOverviewType type = OverviewCount;
|
||||||
for (int32 i = 0; i < OverviewCount; ++i) {
|
for (int32 i = 0; i < OverviewCount; ++i) {
|
||||||
|
|
|
@ -318,7 +318,6 @@ public:
|
||||||
void jumpToDate(PeerData *peer, const QDate &date);
|
void jumpToDate(PeerData *peer, const QDate &date);
|
||||||
void searchMessages(const QString &query, PeerData *inPeer);
|
void searchMessages(const QString &query, PeerData *inPeer);
|
||||||
bool preloadOverview(PeerData *peer, MediaOverviewType type);
|
bool preloadOverview(PeerData *peer, MediaOverviewType type);
|
||||||
void preloadOverviews(PeerData *peer);
|
|
||||||
void changingMsgId(HistoryItem *row, MsgId newId);
|
void changingMsgId(HistoryItem *row, MsgId newId);
|
||||||
void itemEdited(HistoryItem *item);
|
void itemEdited(HistoryItem *item);
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,14 @@ SharedMediaWidget::SharedMediaWidget(QWidget *parent, PeerData *peer) : BlockWid
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
App::main()->preloadOverviews(peer);
|
for (auto i = 0; i != OverviewCount; ++i) {
|
||||||
if (_migrated) {
|
auto type = static_cast<MediaOverviewType>(i);
|
||||||
App::main()->preloadOverviews(_migrated->peer);
|
if (!getButtonText(type, 1).isEmpty()) {
|
||||||
|
App::main()->preloadOverview(peer, type);
|
||||||
|
if (_migrated) {
|
||||||
|
App::main()->preloadOverview(_migrated->peer, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshButtons();
|
refreshButtons();
|
||||||
|
|
Loading…
Reference in New Issue