diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 6a939ec7e..55fe15cf6 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1105,6 +1105,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_action_secure_proof_of_address" = "proof of address"; "lng_action_secure_phone" = "phone number"; "lng_action_secure_email" = "email address"; +"lng_action_proximity_reached" = "{from} is now within {distance} from {user}"; +"lng_action_proximity_reached_you" = "{from} is now within {distance} from you"; +"lng_action_you_proximity_reached" = "You are now within {distance} from {user}"; +"lng_action_proximity_distance_m#one" = "{count} meter"; +"lng_action_proximity_distance_m#other" = "{count} metres"; +"lng_action_proximity_distance_km#one" = "{count} km"; +"lng_action_proximity_distance_km#other" = "{count} km"; "lng_ttl_photo_received" = "{from} sent you a self-destructing photo. Please view it on your mobile."; "lng_ttl_photo_sent" = "You sent a self-destructing photo."; diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index 3819cbec1..bbe8522cb 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -1097,7 +1097,13 @@ ServiceAction ParseServiceAction( }, [&](const MTPDmessageActionGeoProximityReached &data) { auto content = ActionGeoProximityReached(); content.fromId = ParsePeerId(data.vfrom_id()); + if (content.fromId == context.selfPeerId) { + content.fromSelf = true; + } content.toId = ParsePeerId(data.vto_id()); + if (content.toId == context.selfPeerId) { + content.toSelf = true; + } content.distance = data.vdistance().v; result.content = content; }, [](const MTPDmessageActionEmpty &data) {}); diff --git a/Telegram/SourceFiles/export/data/export_data_types.h b/Telegram/SourceFiles/export/data/export_data_types.h index 70fbf56af..8454d58c5 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.h +++ b/Telegram/SourceFiles/export/data/export_data_types.h @@ -454,6 +454,8 @@ struct ActionGeoProximityReached { PeerId fromId = 0; PeerId toId = 0; int distance = 0; + bool fromSelf = false; + bool toSelf = false; }; struct ServiceAction { diff --git a/Telegram/SourceFiles/export/output/export_output_html.cpp b/Telegram/SourceFiles/export/output/export_output_html.cpp index c527decca..6684724f9 100644 --- a/Telegram/SourceFiles/export/output/export_output_html.cpp +++ b/Telegram/SourceFiles/export/output/export_output_html.cpp @@ -1093,7 +1093,25 @@ auto HtmlWriter::Wrap::pushMessage( }, [&](const ActionContactSignUp &data) { return serviceFrom + " joined Telegram"; }, [&](const ActionGeoProximityReached &data) { - return serviceFrom + " reached"; // #TODO files distance from to + const auto fromName = peers.wrapPeerName(data.fromId); + const auto toName = peers.wrapPeerName(data.toId); + const auto distance = [&]() -> QString { + if (data.distance >= 1000) { + const auto km = (10 * (data.distance / 10)) / 1000.; + return QString::number(km) + " km"; + } else if (data.distance == 1) { + return "1 meter"; + } else { + return QString::number(data.distance) + " meters"; + } + }().toUtf8(); + if (data.fromSelf) { + return "You are now within " + distance + " from " + toName; + } else if (data.toSelf) { + return fromName + " is now within " + distance + " from you"; + } else { + return fromName + " is now within " + distance + " from " + toName; + } }, [&](const ActionPhoneNumberRequest &data) { return serviceFrom + " requested your phone number"; }, [](v::null_t) { return QByteArray(); }); diff --git a/Telegram/SourceFiles/export/output/export_output_json.cpp b/Telegram/SourceFiles/export/output/export_output_json.cpp index 20d6169b5..f079b017d 100644 --- a/Telegram/SourceFiles/export/output/export_output_json.cpp +++ b/Telegram/SourceFiles/export/output/export_output_json.cpp @@ -296,7 +296,7 @@ QByteArray SerializeMessage( const auto pushFrom = [&](const QByteArray &label = "from") { if (message.fromId) { pushBare(label, wrapPeerName(message.fromId)); - push(label+"_id", message.fromId); + push(label + "_id", message.fromId); } }; const auto pushReplyToMsgId = [&]( @@ -474,8 +474,16 @@ QByteArray SerializeMessage( pushActor(); pushAction("joined_telegram"); }, [&](const ActionGeoProximityReached &data) { - pushActor(); - pushAction("proximity_reached"); // #TODO files distance from to + pushAction("proximity_reached"); + if (data.fromId) { + pushBare("from", wrapPeerName(data.fromId)); + push("from_id", data.fromId); + } + if (data.toId) { + pushBare("to", wrapPeerName(data.toId)); + push("to_id", data.toId); + } + push("distance", data.distance); }, [&](const ActionPhoneNumberRequest &data) { pushActor(); pushAction("requested_phone_number"); diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 70b50a101..b21206af7 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -219,6 +219,61 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { return result; }; + auto prepareProximityReached = [this](const MTPDmessageActionGeoProximityReached &action) { + auto result = PreparedText{}; + const auto fromId = peerFromMTP(action.vfrom_id()); + const auto fromPeer = history()->owner().peer(fromId); + const auto toId = peerFromMTP(action.vto_id()); + const auto toPeer = history()->owner().peer(toId); + const auto selfId = _from->session().userPeerId(); + const auto distanceMeters = action.vdistance().v; + const auto distance = [&] { + if (distanceMeters >= 1000) { + const auto km = (10 * (distanceMeters / 10)) / 1000.; + return tr::lng_action_proximity_distance_km( + tr::now, + lt_count, + km); + } else { + return tr::lng_action_proximity_distance_m( + tr::now, + lt_count, + distanceMeters); + } + }(); + result.text = [&] { + if (fromId == selfId) { + result.links.push_back(toPeer->createOpenLink()); + return tr::lng_action_you_proximity_reached( + tr::now, + lt_distance, + distance, + lt_user, + textcmdLink(1, toPeer->name)); + } else if (toId == selfId) { + result.links.push_back(fromPeer->createOpenLink()); + return tr::lng_action_proximity_reached_you( + tr::now, + lt_from, + textcmdLink(1, fromPeer->name), + lt_distance, + distance); + } else { + result.links.push_back(fromPeer->createOpenLink()); + result.links.push_back(toPeer->createOpenLink()); + return tr::lng_action_proximity_reached( + tr::now, + lt_from, + textcmdLink(1, fromPeer->name), + lt_distance, + distance, + lt_user, + textcmdLink(2, toPeer->name)); + } + }(); + return result; + }; + const auto messageText = action.match([&]( const MTPDmessageActionChatAddUser &data) { return prepareChatAddUserText(data); @@ -261,7 +316,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { }, [&](const MTPDmessageActionContactSignUp &data) { return prepareContactSignUp(); }, [&](const MTPDmessageActionGeoProximityReached &data) { - return PreparedText{ tr::lng_message_empty(tr::now) }; // #TODO files + return prepareProximityReached(data); }, [](const MTPDmessageActionPaymentSentMe &) { LOG(("API Error: messageActionPaymentSentMe received.")); return PreparedText{ tr::lng_message_empty(tr::now) }; diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp index fdbc47c77..cefa697ba 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp @@ -75,11 +75,6 @@ AlbumThumbnail::AlbumThumbnail( - st::sendBoxAlbumGroupSkipRight; const auto filepath = file.path; if (filepath.isEmpty()) { - //_name = filedialogDefaultName( // #TODO files - // u"image"_q, - // u".png"_q, - // QString(), - // true); _name = "image.png"; _status = u"%1x%2"_q.arg( _fullPreview.width() diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_single_file_preview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_single_file_preview.cpp index 480044c6e..61119b362 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_single_file_preview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_single_file_preview.cpp @@ -89,11 +89,6 @@ void SingleFilePreview::preparePreview(const PreparedFile &file) { prepareThumb(preview); const auto filepath = file.path; if (filepath.isEmpty()) { - //auto filename = filedialogDefaultName( - // qsl("image"), - // qsl(".png"), - // QString(), - // true); // #TODO files auto filename = "image.png"; _name = filename; _statusText = u"%1x%2"_q.arg(preview.width()).arg(preview.height());