Update API scheme.

This commit is contained in:
John Preston 2021-04-01 15:58:39 +04:00
parent 1cc1f380d0
commit 7cbe158d00
10 changed files with 91 additions and 28 deletions

View File

@ -68,7 +68,7 @@ inputMediaVenue#c13d1c11 geo_point:InputGeoPoint title:string address:string pro
inputMediaPhotoExternal#e5bbfe1a flags:# url:string ttl_seconds:flags.0?int = InputMedia;
inputMediaDocumentExternal#fb52dc99 flags:# url:string ttl_seconds:flags.0?int = InputMedia;
inputMediaGame#d33f43f3 id:InputGame = InputMedia;
inputMediaInvoice#f4e096c3 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string provider_data:DataJSON start_param:string = InputMedia;
inputMediaInvoice#f4e096c3 flags:# multiple_allowed:flags.1?true can_forward:flags.2?true title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string provider_data:DataJSON start_param:string = InputMedia;
inputMediaGeoLive#971fa843 flags:# stopped:flags.0?true geo_point:InputGeoPoint heading:flags.2?int period:flags.1?int proximity_notification_radius:flags.3?int = InputMedia;
inputMediaPoll#f94e5f1 flags:# poll:Poll correct_answers:flags.0?Vector<bytes> solution:flags.1?string solution_entities:flags.1?Vector<MessageEntity> = InputMedia;
inputMediaDice#e66fbf7b emoticon:string = InputMedia;
@ -186,6 +186,7 @@ messageActionGeoProximityReached#98e0d697 from_id:Peer to_id:Peer distance:int =
messageActionGroupCall#7a0d7f42 flags:# call:InputGroupCall duration:flags.0?int = MessageAction;
messageActionInviteToGroupCall#76b9f11a call:InputGroupCall users:Vector<int> = MessageAction;
messageActionSetMessagesTTL#aa1afbfd period:int = MessageAction;
messageActionGroupCallScheduled#b3a07661 call:InputGroupCall schedule_date:int = MessageAction;
dialog#2c171f72 flags:# pinned:flags.2?true unread_mark:flags.3?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int = Dialog;
dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog;
@ -648,7 +649,7 @@ inputBotInlineMessageMediaGeo#96929a85 flags:# geo_point:InputGeoPoint heading:f
inputBotInlineMessageMediaVenue#417bbf11 flags:# geo_point:InputGeoPoint title:string address:string provider:string venue_id:string venue_type:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage;
inputBotInlineMessageMediaContact#a6edbffd flags:# phone_number:string first_name:string last_name:string vcard:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage;
inputBotInlineMessageGame#4b425864 flags:# reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage;
inputBotInlineMessageMediaInvoice#d5348d85 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string provider_data:DataJSON start_param:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage;
inputBotInlineMessageMediaInvoice#d5348d85 flags:# multiple_allowed:flags.1?true can_forward:flags.3?true title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string provider_data:DataJSON start_param:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage;
inputBotInlineResult#88bf9319 flags:# id:string type:string title:flags.1?string description:flags.2?string url:flags.3?string thumb:flags.4?InputWebDocument content:flags.5?InputWebDocument send_message:InputBotInlineMessage = InputBotInlineResult;
inputBotInlineResultPhoto#a8d864a7 id:string type:string photo:InputPhoto send_message:InputBotInlineMessage = InputBotInlineResult;
@ -794,7 +795,7 @@ dataJSON#7d748d04 data:string = DataJSON;
labeledPrice#cb296bf8 label:string amount:long = LabeledPrice;
invoice#24b6f6cd flags:# test:flags.0?true name_requested:flags.1?true phone_requested:flags.2?true email_requested:flags.3?true shipping_address_requested:flags.4?true flexible:flags.5?true phone_to_provider:flags.6?true email_to_provider:flags.7?true multiple_allowed:flags.9?true can_forward:flags.10?true currency:string prices:Vector<LabeledPrice> min_tip_amount:flags.8?long max_tip_amount:flags.8?long default_tip_amount:flags.8?long = Invoice;
invoice#cd886e0 flags:# test:flags.0?true name_requested:flags.1?true phone_requested:flags.2?true email_requested:flags.3?true shipping_address_requested:flags.4?true flexible:flags.5?true phone_to_provider:flags.6?true email_to_provider:flags.7?true currency:string prices:Vector<LabeledPrice> max_tip_amount:flags.8?long suggested_tip_amounts:flags.8?Vector<long> = Invoice;
paymentCharge#ea02c27e id:string provider_charge_id:string = PaymentCharge;
@ -1203,7 +1204,7 @@ peerBlocked#e8fd8014 peer_id:Peer date:int = PeerBlocked;
stats.messageStats#8999f295 views_graph:StatsGraph = stats.MessageStats;
groupCallDiscarded#7780bcb4 id:long access_hash:long duration:int = GroupCall;
groupCall#c0c2052e flags:# join_muted:flags.1?true can_change_join_muted:flags.2?true join_date_asc:flags.6?true id:long access_hash:long participants_count:int params:flags.0?DataJSON title:flags.3?string stream_dc_id:flags.4?int record_start_date:flags.5?int version:int = GroupCall;
groupCall#c95c6654 flags:# join_muted:flags.1?true can_change_join_muted:flags.2?true join_date_asc:flags.6?true schedule_start_subscribed:flags.8?true id:long access_hash:long participants_count:int params:flags.0?DataJSON title:flags.3?string stream_dc_id:flags.4?int record_start_date:flags.5?int schedule_date:flags.7?int version:int = GroupCall;
inputGroupCall#d8aa840f id:long access_hash:long = InputGroupCall;
@ -1615,7 +1616,7 @@ phone.discardCall#b2cbc1c0 flags:# video:flags.0?true peer:InputPhoneCall durati
phone.setCallRating#59ead627 flags:# user_initiative:flags.0?true peer:InputPhoneCall rating:int comment:string = Updates;
phone.saveCallDebug#277add7e peer:InputPhoneCall debug:DataJSON = Bool;
phone.sendSignalingData#ff7a9383 peer:InputPhoneCall data:bytes = Bool;
phone.createGroupCall#bd3dabe0 peer:InputPeer random_id:int = Updates;
phone.createGroupCall#48cdc6d8 flags:# peer:InputPeer random_id:int title:flags.0?string schedule_date:flags.1?int = Updates;
phone.joinGroupCall#b132ff7b flags:# muted:flags.0?true call:InputGroupCall join_as:InputPeer invite_hash:flags.1?string params:DataJSON = Updates;
phone.leaveGroupCall#500377f9 call:InputGroupCall source:int = Updates;
phone.inviteToGroupCall#7b393160 call:InputGroupCall users:Vector<InputUser> = Updates;
@ -1629,6 +1630,9 @@ phone.editGroupCallParticipant#d975eb80 flags:# muted:flags.0?true call:InputGro
phone.editGroupCallTitle#1ca6ac0a call:InputGroupCall title:string = Updates;
phone.getGroupCallJoinAs#ef7c213a peer:InputPeer = phone.JoinAsPeers;
phone.exportGroupCallInvite#e6aa647f flags:# can_self_unmute:flags.0?true call:InputGroupCall = phone.ExportedGroupCallInvite;
phone.toggleGroupCallStartSubscription#219c34e6 call:InputGroupCall subscribed:Bool = Updates;
phone.startScheduledGroupCall#5680e342 call:InputGroupCall = Updates;
phone.saveDefaultGroupCallJoinAs#575e1f8c peer:InputPeer join_as:InputPeer = Bool;
langpack.getLangPack#f2f2330a lang_pack:string lang_code:string = LangPackDifference;
langpack.getStrings#efea3803 lang_pack:string lang_code:string keys:Vector<string> = Vector<LangPackString>;

View File

@ -328,8 +328,11 @@ bool GroupCall::showChooseJoinAs() const {
void GroupCall::start() {
_createRequestId = _api.request(MTPphone_CreateGroupCall(
MTP_flags(0),
_peer->input,
MTP_int(openssl::RandomValue<int32>())
MTP_int(openssl::RandomValue<int32>()),
MTPstring(), // title
MTPint() // schedule_date
)).done([=](const MTPUpdates &result) {
_acceptFields = true;
_peer->session().api().applyUpdates(result);

View File

@ -1129,22 +1129,28 @@ ServiceAction ParseServiceAction(
}
result.content = content;
}, [&](const MTPDmessageActionSetMessagesTTL &data) {
// #TODO ttl
result.content = ActionSetMessagesTTL{
.period = data.vperiod().v,
};
}, [&](const MTPDmessageActionGroupCallScheduled &data) {
result.content = ActionGroupCallScheduled{
.date = data.vschedule_date().v,
};
}, [](const MTPDmessageActionEmpty &data) {});
return result;
}
File &Message::file() {
const auto service = &action.content;
if (const auto photo = std::get_if<ActionChatEditPhoto>(service)) {
const auto content = &action.content;
if (const auto photo = std::get_if<ActionChatEditPhoto>(content)) {
return photo->photo.image.file;
}
return media.file();
}
const File &Message::file() const {
const auto service = &action.content;
if (const auto photo = std::get_if<ActionChatEditPhoto>(service)) {
const auto content = &action.content;
if (const auto photo = std::get_if<ActionChatEditPhoto>(content)) {
return photo->photo.image.file;
}
return media.file();

View File

@ -466,6 +466,14 @@ struct ActionInviteToGroupCall {
std::vector<int32> userIds;
};
struct ActionSetMessagesTTL {
TimeId period = 0;
};
struct ActionGroupCallScheduled {
TimeId date = 0;
};
struct ServiceAction {
std::variant<
v::null_t,
@ -492,7 +500,9 @@ struct ServiceAction {
ActionPhoneNumberRequest,
ActionGeoProximityReached,
ActionGroupCall,
ActionInviteToGroupCall> content;
ActionInviteToGroupCall,
ActionSetMessagesTTL,
ActionGroupCallScheduled> content;
};
ServiceAction ParseServiceAction(

View File

@ -1082,15 +1082,37 @@ auto HtmlWriter::Wrap::pushMessage(
}, [&](const ActionPhoneNumberRequest &data) {
return serviceFrom + " requested your phone number";
}, [&](const ActionGroupCall &data) {
return "Group call"
+ (data.duration
? (" (" + QString::number(data.duration) + " seconds)")
: QString()).toUtf8();
const auto durationText = (data.duration
? (" (" + QString::number(data.duration) + " seconds)")
: QString()).toUtf8();
return isChannel
? ("Voice chat" + durationText)
: (serviceFrom + " started voice chat" + durationText);
}, [&](const ActionInviteToGroupCall &data) {
return serviceFrom
+ " invited "
+ peers.wrapUserNames(data.userIds)
+ " to the voice chat";
}, [&](const ActionSetMessagesTTL &data) {
const auto periodText = (data.period == 7 * 86400)
? "7 days"
: (data.period == 86400)
? "24 hours"
: QByteArray();
return isChannel
? (data.period
? "New messages will auto-delete in " + periodText
: "New messages will not auto-delete")
: (data.period
? (serviceFrom
+ " has set messages to auto-delete in " + periodText)
: (serviceFrom
+ " has set messages not to auto-delete"));
}, [&](const ActionGroupCallScheduled &data) {
const auto dateText = FormatDateTime(data.date);
return isChannel
? "Voice chat is scheduled " + dateText
: (serviceFrom + " scheduled voice chat " + dateText);
}, [](v::null_t) { return QByteArray(); });
if (!serviceText.isEmpty()) {

View File

@ -497,6 +497,14 @@ QByteArray SerializeMessage(
pushActor();
pushAction("invite_to_group_call");
pushUserNames(data.userIds);
}, [&](const ActionSetMessagesTTL &data) {
pushActor();
pushAction("set_messages_ttl");
push("period", data.period);
}, [&](const ActionGroupCallScheduled &data) {
pushActor();
pushAction("group_call_scheduled");
push("schedule_date", data.date);
}, [](v::null_t) {});
if (v::is_null(message.action.content)) {

View File

@ -405,6 +405,15 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
return result;
};
auto prepareGroupCallScheduled = [this](const MTPDmessageActionGroupCallScheduled &action) {
const auto callId = CallIdFromInput(action.vcall());
const auto peer = history()->peer;
const auto linkCallId = PeerHasThisCall(peer, callId).value_or(false)
? callId
: 0;
return prepareStartedCallText(linkCallId);
};
const auto messageText = action.match([&](
const MTPDmessageActionChatAddUser &data) {
return prepareChatAddUserText(data);
@ -460,6 +469,8 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
return prepareInviteToGroupCall(data);
}, [&](const MTPDmessageActionSetMessagesTTL &data) {
return prepareSetMessagesTTL(data);
}, [&](const MTPDmessageActionGroupCallScheduled &data) {
return prepareGroupCallScheduled(data);
}, [](const MTPDmessageActionEmpty &) {
return PreparedText{ tr::lng_message_empty(tr::now) };
});

View File

@ -293,14 +293,19 @@ void Form::processReceipt(const MTPDpayments_paymentReceipt &data) {
}
void Form::processInvoice(const MTPDinvoice &data) {
const auto suggested = data.vsuggested_tip_amounts().value_or_empty();
_invoice = Ui::Invoice{
.cover = std::move(_invoice.cover),
.prices = ParsePrices(data.vprices()),
.tipsMin = ParsePriceAmount(data.vmin_tip_amount().value_or_empty()),
.suggestedTips = ranges::views::all(
suggested
) | ranges::views::transform(
&MTPlong::v
) | ranges::views::transform(
ParsePriceAmount
) | ranges::to_vector,
.tipsMax = ParsePriceAmount(data.vmax_tip_amount().value_or_empty()),
.tipsSelected = ParsePriceAmount(
data.vdefault_tip_amount().value_or_empty()),
.currency = qs(data.vcurrency()),
.isNameRequested = data.is_name_requested(),
@ -746,10 +751,7 @@ void Form::setShippingOption(const QString &id) {
}
void Form::setTips(int64 value) {
_invoice.tipsSelected = std::clamp(
value,
_invoice.tipsMin,
_invoice.tipsMax);
_invoice.tipsSelected = std::min(value, _invoice.tipsMax);
}
void Form::processShippingOptions(const QVector<MTPShippingOption> &data) {

View File

@ -179,7 +179,6 @@ void Panel::chooseShippingOption(const ShippingOptions &options) {
}
void Panel::chooseTips(const Invoice &invoice) {
const auto min = invoice.tipsMin;
const auto max = invoice.tipsMax;
const auto now = invoice.tipsSelected;
const auto currency = invoice.currency;
@ -223,9 +222,7 @@ void Panel::chooseTips(const Invoice &invoice) {
errorWrap->hide(anim::type::instant);
box->addButton(tr::lng_settings_save(), [=] {
const auto value = row->value().toLongLong();
if (value < min) {
row->showError();
} else if (value > max) {
if (value > max) {
row->showError();
errorWrap->show(anim::type::normal);
} else {

View File

@ -39,7 +39,7 @@ struct Invoice {
Cover cover;
std::vector<LabeledPrice> prices;
int64 tipsMin = 0;
std::vector<int64> suggestedTips;
int64 tipsMax = 0;
int64 tipsSelected = 0;
QString currency;