2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Replace self-destruct media service messages text.

Also support runtime components with align up to std::max_align_t.
This commit is contained in:
John Preston
2017-07-17 23:09:55 +03:00
parent 2e0513a30f
commit 9bd89121e8
7 changed files with 211 additions and 53 deletions

View File

@@ -220,6 +220,13 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
}
}
void HistoryService::setSelfDestruct(HistoryServiceSelfDestruct::Type type, int ttlSeconds) {
UpdateComponents(HistoryServiceSelfDestruct::Bit());
auto selfdestruct = Get<HistoryServiceSelfDestruct>();
selfdestruct->timeToLive = ttlSeconds * 1000LL;
selfdestruct->type = type;
}
bool HistoryService::updateDependent(bool force) {
auto dependent = GetDependentData();
t_assert(dependent != nullptr);
@@ -393,10 +400,14 @@ HistoryService::PreparedText HistoryService::preparePaymentSentText() {
return result;
}
HistoryService::HistoryService(gsl::not_null<History*> history, const MTPDmessage &message) :
HistoryItem(history, message.vid.v, message.vflags.v, ::date(message.vdate), message.has_from_id() ? message.vfrom_id.v : 0) {
createFromMtp(message);
}
HistoryService::HistoryService(gsl::not_null<History*> history, const MTPDmessageService &message) :
HistoryItem(history, message.vid.v, mtpCastFlags(message.vflags.v), ::date(message.vdate), message.has_from_id() ? message.vfrom_id.v : 0) {
createFromMtp(message);
setMessageByAction(message.vaction);
}
HistoryService::HistoryService(gsl::not_null<History*> history, MsgId msgId, QDateTime date, const PreparedText &message, MTPDmessage::Flags flags, int32 from, PhotoData *photo) :
@@ -521,6 +532,35 @@ int HistoryService::resizeContentGetHeight() {
return _height;
}
void HistoryService::markMediaAsReadHook() {
if (auto selfdestruct = Get<HistoryServiceSelfDestruct>()) {
if (!selfdestruct->destructAt) {
selfdestruct->destructAt = getms(true) + selfdestruct->timeToLive;
App::histories().selfDestructIn(this, selfdestruct->timeToLive);
}
}
}
TimeMs HistoryService::getSelfDestructIn(TimeMs now) {
if (auto selfdestruct = Get<HistoryServiceSelfDestruct>()) {
if (selfdestruct->destructAt > 0) {
if (selfdestruct->destructAt <= now) {
auto text = [selfdestruct] {
switch (selfdestruct->type) {
case HistoryServiceSelfDestruct::Type::Photo: return lang(lng_ttl_photo_expired);
case HistoryServiceSelfDestruct::Type::Video: return lang(lng_ttl_video_expired);
}
Unexpected("Type in HistoryServiceSelfDestruct::Type");
};
setServiceText({ text() });
return 0;
}
return selfdestruct->destructAt - now;
}
}
return 0;
}
bool HistoryService::hasPoint(QPoint point) const {
auto g = countGeometry();
if (g.width() < 1) {
@@ -580,6 +620,48 @@ HistoryTextState HistoryService::getState(QPoint point, HistoryStateRequest requ
return result;
}
void HistoryService::createFromMtp(const MTPDmessage &message) {
auto mediaType = message.vmedia.type();
switch (mediaType) {
case mtpc_messageMediaPhoto: {
if (message.is_media_unread()) {
auto &photo = message.vmedia.c_messageMediaPhoto();
t_assert(photo.has_ttl_seconds());
setSelfDestruct(HistoryServiceSelfDestruct::Type::Photo, photo.vttl_seconds.v);
if (out()) {
setServiceText({ lang(lng_ttl_photo_sent) });
} else {
auto result = PreparedText();
result.links.push_back(fromLink());
result.text = lng_ttl_photo_received(lt_from, fromLinkText());
setServiceText(std::move(result));
}
} else {
setServiceText({ lang(lng_ttl_photo_expired) });
}
} break;
case mtpc_messageMediaDocument: {
if (message.is_media_unread()) {
auto &document = message.vmedia.c_messageMediaDocument();
t_assert(document.has_ttl_seconds());
setSelfDestruct(HistoryServiceSelfDestruct::Type::Video, document.vttl_seconds.v);
if (out()) {
setServiceText({ lang(lng_ttl_video_sent) });
} else {
auto result = PreparedText();
result.links.push_back(fromLink());
result.text = lng_ttl_video_received(lt_from, fromLinkText());
setServiceText(std::move(result));
}
} else {
setServiceText({ lang(lng_ttl_video_expired) });
}
} break;
default: Unexpected("Media type in HistoryService::createFromMtp()");
}
}
void HistoryService::createFromMtp(const MTPDmessageService &message) {
if (message.vaction.type() == mtpc_messageActionGameScore) {
UpdateComponents(HistoryServiceGameScore::Bit());