mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Wrap messageActionGeoProximityReached service message.
This commit is contained in:
parent
263d6a30f2
commit
c4af731b19
8 changed files with 101 additions and 15 deletions
|
@ -1105,6 +1105,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_action_secure_proof_of_address" = "proof of address";
|
"lng_action_secure_proof_of_address" = "proof of address";
|
||||||
"lng_action_secure_phone" = "phone number";
|
"lng_action_secure_phone" = "phone number";
|
||||||
"lng_action_secure_email" = "email address";
|
"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_received" = "{from} sent you a self-destructing photo. Please view it on your mobile.";
|
||||||
"lng_ttl_photo_sent" = "You sent a self-destructing photo.";
|
"lng_ttl_photo_sent" = "You sent a self-destructing photo.";
|
||||||
|
|
|
@ -1097,7 +1097,13 @@ ServiceAction ParseServiceAction(
|
||||||
}, [&](const MTPDmessageActionGeoProximityReached &data) {
|
}, [&](const MTPDmessageActionGeoProximityReached &data) {
|
||||||
auto content = ActionGeoProximityReached();
|
auto content = ActionGeoProximityReached();
|
||||||
content.fromId = ParsePeerId(data.vfrom_id());
|
content.fromId = ParsePeerId(data.vfrom_id());
|
||||||
|
if (content.fromId == context.selfPeerId) {
|
||||||
|
content.fromSelf = true;
|
||||||
|
}
|
||||||
content.toId = ParsePeerId(data.vto_id());
|
content.toId = ParsePeerId(data.vto_id());
|
||||||
|
if (content.toId == context.selfPeerId) {
|
||||||
|
content.toSelf = true;
|
||||||
|
}
|
||||||
content.distance = data.vdistance().v;
|
content.distance = data.vdistance().v;
|
||||||
result.content = content;
|
result.content = content;
|
||||||
}, [](const MTPDmessageActionEmpty &data) {});
|
}, [](const MTPDmessageActionEmpty &data) {});
|
||||||
|
|
|
@ -454,6 +454,8 @@ struct ActionGeoProximityReached {
|
||||||
PeerId fromId = 0;
|
PeerId fromId = 0;
|
||||||
PeerId toId = 0;
|
PeerId toId = 0;
|
||||||
int distance = 0;
|
int distance = 0;
|
||||||
|
bool fromSelf = false;
|
||||||
|
bool toSelf = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ServiceAction {
|
struct ServiceAction {
|
||||||
|
|
|
@ -1093,7 +1093,25 @@ auto HtmlWriter::Wrap::pushMessage(
|
||||||
}, [&](const ActionContactSignUp &data) {
|
}, [&](const ActionContactSignUp &data) {
|
||||||
return serviceFrom + " joined Telegram";
|
return serviceFrom + " joined Telegram";
|
||||||
}, [&](const ActionGeoProximityReached &data) {
|
}, [&](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) {
|
}, [&](const ActionPhoneNumberRequest &data) {
|
||||||
return serviceFrom + " requested your phone number";
|
return serviceFrom + " requested your phone number";
|
||||||
}, [](v::null_t) { return QByteArray(); });
|
}, [](v::null_t) { return QByteArray(); });
|
||||||
|
|
|
@ -296,7 +296,7 @@ QByteArray SerializeMessage(
|
||||||
const auto pushFrom = [&](const QByteArray &label = "from") {
|
const auto pushFrom = [&](const QByteArray &label = "from") {
|
||||||
if (message.fromId) {
|
if (message.fromId) {
|
||||||
pushBare(label, wrapPeerName(message.fromId));
|
pushBare(label, wrapPeerName(message.fromId));
|
||||||
push(label+"_id", message.fromId);
|
push(label + "_id", message.fromId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const auto pushReplyToMsgId = [&](
|
const auto pushReplyToMsgId = [&](
|
||||||
|
@ -474,8 +474,16 @@ QByteArray SerializeMessage(
|
||||||
pushActor();
|
pushActor();
|
||||||
pushAction("joined_telegram");
|
pushAction("joined_telegram");
|
||||||
}, [&](const ActionGeoProximityReached &data) {
|
}, [&](const ActionGeoProximityReached &data) {
|
||||||
pushActor();
|
pushAction("proximity_reached");
|
||||||
pushAction("proximity_reached"); // #TODO files distance from to
|
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) {
|
}, [&](const ActionPhoneNumberRequest &data) {
|
||||||
pushActor();
|
pushActor();
|
||||||
pushAction("requested_phone_number");
|
pushAction("requested_phone_number");
|
||||||
|
|
|
@ -219,6 +219,61 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
|
||||||
return result;
|
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 auto messageText = action.match([&](
|
||||||
const MTPDmessageActionChatAddUser &data) {
|
const MTPDmessageActionChatAddUser &data) {
|
||||||
return prepareChatAddUserText(data);
|
return prepareChatAddUserText(data);
|
||||||
|
@ -261,7 +316,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
|
||||||
}, [&](const MTPDmessageActionContactSignUp &data) {
|
}, [&](const MTPDmessageActionContactSignUp &data) {
|
||||||
return prepareContactSignUp();
|
return prepareContactSignUp();
|
||||||
}, [&](const MTPDmessageActionGeoProximityReached &data) {
|
}, [&](const MTPDmessageActionGeoProximityReached &data) {
|
||||||
return PreparedText{ tr::lng_message_empty(tr::now) }; // #TODO files
|
return prepareProximityReached(data);
|
||||||
}, [](const MTPDmessageActionPaymentSentMe &) {
|
}, [](const MTPDmessageActionPaymentSentMe &) {
|
||||||
LOG(("API Error: messageActionPaymentSentMe received."));
|
LOG(("API Error: messageActionPaymentSentMe received."));
|
||||||
return PreparedText{ tr::lng_message_empty(tr::now) };
|
return PreparedText{ tr::lng_message_empty(tr::now) };
|
||||||
|
|
|
@ -75,11 +75,6 @@ AlbumThumbnail::AlbumThumbnail(
|
||||||
- st::sendBoxAlbumGroupSkipRight;
|
- st::sendBoxAlbumGroupSkipRight;
|
||||||
const auto filepath = file.path;
|
const auto filepath = file.path;
|
||||||
if (filepath.isEmpty()) {
|
if (filepath.isEmpty()) {
|
||||||
//_name = filedialogDefaultName( // #TODO files
|
|
||||||
// u"image"_q,
|
|
||||||
// u".png"_q,
|
|
||||||
// QString(),
|
|
||||||
// true);
|
|
||||||
_name = "image.png";
|
_name = "image.png";
|
||||||
_status = u"%1x%2"_q.arg(
|
_status = u"%1x%2"_q.arg(
|
||||||
_fullPreview.width()
|
_fullPreview.width()
|
||||||
|
|
|
@ -89,11 +89,6 @@ void SingleFilePreview::preparePreview(const PreparedFile &file) {
|
||||||
prepareThumb(preview);
|
prepareThumb(preview);
|
||||||
const auto filepath = file.path;
|
const auto filepath = file.path;
|
||||||
if (filepath.isEmpty()) {
|
if (filepath.isEmpty()) {
|
||||||
//auto filename = filedialogDefaultName(
|
|
||||||
// qsl("image"),
|
|
||||||
// qsl(".png"),
|
|
||||||
// QString(),
|
|
||||||
// true); // #TODO files
|
|
||||||
auto filename = "image.png";
|
auto filename = "image.png";
|
||||||
_name = filename;
|
_name = filename;
|
||||||
_statusText = u"%1x%2"_q.arg(preview.width()).arg(preview.height());
|
_statusText = u"%1x%2"_q.arg(preview.width()).arg(preview.height());
|
||||||
|
|
Loading…
Add table
Reference in a new issue