Show voice chat start time in service message.

This commit is contained in:
John Preston 2021-04-09 18:33:38 +04:00
parent 4ecd1049b2
commit ae74c8a6b8
4 changed files with 74 additions and 21 deletions

View File

@ -1109,8 +1109,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_action_invite_users_and_last" = "{accumulated} and {user}";
"lng_action_group_call_started_group" = "{from} started a voice chat";
"lng_action_group_call_started_channel" = "Voice chat started";
"lng_action_group_call_scheduled_group" = "{from} scheduled a voice chat";
"lng_action_group_call_scheduled_channel" = "Voice chat scheduled";
"lng_action_group_call_scheduled_group" = "{from} scheduled a voice chat for {date}";
"lng_action_group_call_scheduled_channel" = "Voice chat scheduled for {date}";
"lng_action_group_call_finished" = "Voice chat finished ({duration})";
"lng_action_add_user" = "{from} added {user}";
"lng_action_add_users_many" = "{from} added {users}";

View File

@ -1111,8 +1111,8 @@ auto HtmlWriter::Wrap::pushMessage(
}, [&](const ActionGroupCallScheduled &data) {
const auto dateText = FormatDateTime(data.date);
return isChannel
? "Voice chat is scheduled " + dateText
: (serviceFrom + " scheduled voice chat " + dateText);
? "Voice chat scheduled for " + dateText
: (serviceFrom + " scheduled a voice chat for " + dateText);
}, [](v::null_t) { return QByteArray(); });
if (!serviceText.isEmpty()) {

View File

@ -29,6 +29,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_group_call.h" // Data::GroupCall::id().
#include "core/application.h"
#include "core/click_handler_types.h"
#include "base/unixtime.h"
#include "base/timer_rpl.h"
#include "calls/calls_instance.h" // Core::App().calls().joinGroupCall.
#include "window/notifications_manager.h"
#include "window/window_controller.h"
@ -410,20 +412,6 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
return result;
};
auto prepareGroupCallScheduled = [this](const MTPDmessageActionGroupCallScheduled &action) {
auto result = PreparedText{};
if (history()->peer->isBroadcast()) {
result.text = tr::lng_action_group_call_scheduled_channel(tr::now);
} else {
result.links.push_back(fromLink());
result.text = tr::lng_action_group_call_scheduled_group(
tr::now,
lt_from,
fromLinkText());
}
return result;
};
const auto messageText = action.match([&](
const MTPDmessageActionChatAddUser &data) {
return prepareChatAddUserText(data);
@ -480,7 +468,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
}, [&](const MTPDmessageActionSetMessagesTTL &data) {
return prepareSetMessagesTTL(data);
}, [&](const MTPDmessageActionGroupCallScheduled &data) {
return prepareGroupCallScheduled(data);
return prepareCallScheduledText(data.vschedule_date().v);
}, [](const MTPDmessageActionEmpty &) {
return PreparedText{ tr::lng_message_empty(tr::now) };
});
@ -745,7 +733,8 @@ HistoryService::PreparedText HistoryService::prepareGameScoreText() {
HistoryService::PreparedText HistoryService::preparePaymentSentText() {
auto result = PreparedText {};
auto payment = Get<HistoryServicePayment>();
const auto payment = Get<HistoryServicePayment>();
Assert(payment != nullptr);
auto invoiceTitle = [&] {
if (payment->msg) {
@ -762,13 +751,75 @@ HistoryService::PreparedText HistoryService::preparePaymentSentText() {
result.text = tr::lng_action_payment_done(tr::now, lt_amount, payment->amount, lt_user, history()->peer->name);
} else {
result.text = tr::lng_action_payment_done_for(tr::now, lt_amount, payment->amount, lt_user, history()->peer->name, lt_invoice, invoiceTitle);
if (payment && payment->msg) {
if (payment->msg) {
result.links.push_back(payment->lnk);
}
}
return result;
}
HistoryService::PreparedText HistoryService::prepareCallScheduledText(
TimeId scheduleDate) {
const auto call = Get<HistoryServiceOngoingCall>();
Assert(call != nullptr);
const auto scheduled = base::unixtime::parse(scheduleDate);
const auto date = scheduled.date();
const auto now = QDateTime::currentDateTime();
const auto secsToDateAddDays = [&](int days) {
return now.secsTo(QDateTime(date.addDays(days), QTime(0, 0)));
};
auto result = PreparedText();
const auto prepareWithDate = [&](const QString &date) {
if (history()->peer->isBroadcast()) {
result.text = tr::lng_action_group_call_scheduled_channel(
tr::now,
lt_date,
date);
} else {
result.links.push_back(fromLink());
result.text = tr::lng_action_group_call_scheduled_group(
tr::now,
lt_from,
fromLinkText(),
lt_date,
date);
}
};
const auto time = scheduled.time().toString(cTimeFormat());
const auto prepareGeneric = [&] {
prepareWithDate(tr::lng_group_call_starts_date(
tr::now,
lt_date,
langDayOfMonthFull(date),
lt_time,
time));
};
auto nextIn = TimeId(0);
if (now.date().addDays(1) < scheduled.date()) {
nextIn = secsToDateAddDays(-1);
prepareGeneric();
} else if (now.date().addDays(1) == scheduled.date()) {
nextIn = secsToDateAddDays(0);
prepareWithDate(
tr::lng_group_call_starts_tomorrow(tr::now, lt_time, time));
} else if (now.date() == scheduled.date()) {
nextIn = secsToDateAddDays(1);
prepareWithDate(
tr::lng_group_call_starts_today(tr::now, lt_time, time));
} else {
prepareGeneric();
}
if (nextIn) {
call->lifetime = base::timer_once(
(nextIn + 2) * crl::time(1000)
) | rpl::start_with_next([=] {
updateText(prepareCallScheduledText(scheduleDate));
});
}
return result;
}
HistoryService::HistoryService(
not_null<History*> history,
const MTPDmessage &data,

View File

@ -164,6 +164,8 @@ private:
PreparedText prepareInvitedToCallText(
const QVector<MTPint> &users,
uint64 linkCallId);
PreparedText prepareCallScheduledText(
TimeId scheduleDate);
friend class HistoryView::Service;