2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-30 22:16:14 +00:00

Start SendAsButton in HistoryWidget.

This commit is contained in:
John Preston
2021-11-09 16:10:51 +04:00
parent c849d17667
commit 4691cff3f6
15 changed files with 390 additions and 4 deletions

View File

@@ -11,6 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_user.h"
#include "data/data_changes.h"
#include "main/main_session.h"
#include "ui/image/image_prepare.h"
#include "base/unixtime.h"
namespace Data {
@@ -445,4 +448,51 @@ bool ChannelHasActiveCall(not_null<ChannelData*> channel) {
return (channel->flags() & ChannelDataFlag::CallNotEmpty);
}
rpl::producer<QImage> PeerUserpicImageValue(
not_null<PeerData*> peer,
int size) {
return PeerUserpicImageValue(peer, size, ImageRoundRadius::Ellipse);
}
rpl::producer<QImage> PeerUserpicImageValue(
not_null<PeerData*> peer,
int size,
ImageRoundRadius radius) {
return [=](auto consumer) {
auto result = rpl::lifetime();
struct State {
std::shared_ptr<CloudImageView> view;
rpl::lifetime waiting;
InMemoryKey key = {};
bool empty = true;
Fn<void()> push;
};
const auto state = result.make_state<State>();
state->push = [=] {
const auto key = peer->userpicUniqueKey(state->view);
const auto loading = !state->view || state->view->image();
if (loading && !state->waiting) {
peer->session().downloaderTaskFinished(
) | rpl::start_with_next(state->push, state->waiting);
} else if (!loading && state->waiting) {
state->waiting.destroy();
}
if (!state->empty && (loading || key == state->key)) {
return;
}
state->key = key;
state->empty = false;
consumer.put_next(
peer->generateUserpicImage(state->view, size, radius));
};
peer->session().changes().peerFlagsValue(
peer,
PeerUpdate::Flag::Photo
) | rpl::start_with_next(state->push, result);
return result;
};
}
} // namespace Data