Show correct phrase in local join messages.

This commit is contained in:
John Preston 2021-10-14 15:42:51 +04:00
parent 721aac57a5
commit 2ade6be146
6 changed files with 40 additions and 19 deletions

View file

@ -2113,6 +2113,7 @@ void Updates::feedUpdate(const MTPUpdate &update) {
auto &d = update.c_updateChannel(); auto &d = update.c_updateChannel();
if (const auto channel = session().data().channelLoaded(d.vchannel_id())) { if (const auto channel = session().data().channelLoaded(d.vchannel_id())) {
channel->inviter = UserId(0); channel->inviter = UserId(0);
channel->inviteViaRequest = false;
if (channel->amIn()) { if (channel->amIn()) {
if (channel->isMegagroup() if (channel->isMegagroup()
&& !channel->amCreator() && !channel->amCreator()

View file

@ -1618,9 +1618,13 @@ void ApiWrap::requestSelfParticipant(not_null<ChannelData*> channel) {
return; return;
} }
const auto finalize = [=](UserId inviter, TimeId inviteDate) { const auto finalize = [=](
UserId inviter = -1,
TimeId inviteDate = 0,
bool inviteViaRequest = false) {
channel->inviter = inviter; channel->inviter = inviter;
channel->inviteDate = inviteDate; channel->inviteDate = inviteDate;
channel->inviteViaRequest = inviteViaRequest;
if (const auto history = _session->data().historyLoaded(channel)) { if (const auto history = _session->data().historyLoaded(channel)) {
if (history->lastMessageKnown()) { if (history->lastMessageKnown()) {
history->checkLocalMessages(); history->checkLocalMessages();
@ -1641,7 +1645,10 @@ void ApiWrap::requestSelfParticipant(not_null<ChannelData*> channel) {
const auto &participant = data.vparticipant(); const auto &participant = data.vparticipant();
participant.match([&](const MTPDchannelParticipantSelf &data) { participant.match([&](const MTPDchannelParticipantSelf &data) {
finalize(data.vinviter_id().v, data.vdate().v); finalize(
data.vinviter_id().v,
data.vdate().v,
data.is_via_invite());
}, [&](const MTPDchannelParticipantCreator &) { }, [&](const MTPDchannelParticipantCreator &) {
if (channel->mgInfo) { if (channel->mgInfo) {
channel->mgInfo->creator = _session->user(); channel->mgInfo->creator = _session->user();
@ -1654,13 +1661,13 @@ void ApiWrap::requestSelfParticipant(not_null<ChannelData*> channel) {
finalize(inviter, data.vdate().v); finalize(inviter, data.vdate().v);
}, [&](const MTPDchannelParticipantBanned &data) { }, [&](const MTPDchannelParticipantBanned &data) {
LOG(("API Error: Got self banned participant.")); LOG(("API Error: Got self banned participant."));
finalize(-1, 0); finalize();
}, [&](const MTPDchannelParticipant &data) { }, [&](const MTPDchannelParticipant &data) {
LOG(("API Error: Got self regular participant.")); LOG(("API Error: Got self regular participant."));
finalize(-1, 0); finalize();
}, [&](const MTPDchannelParticipantLeft &data) { }, [&](const MTPDchannelParticipantLeft &data) {
LOG(("API Error: Got self left participant.")); LOG(("API Error: Got self left participant."));
finalize(-1, 0); finalize();
}); });
}); });
}).fail([=](const MTP::Error &error) { }).fail([=](const MTP::Error &error) {
@ -1668,7 +1675,7 @@ void ApiWrap::requestSelfParticipant(not_null<ChannelData*> channel) {
if (error.type() == qstr("CHANNEL_PRIVATE")) { if (error.type() == qstr("CHANNEL_PRIVATE")) {
channel->privateErrorReceived(); channel->privateErrorReceived();
} }
finalize(-1, 0); finalize();
}).afterDelay(kSmallDelayMs).send(); }).afterDelay(kSmallDelayMs).send();
} }

View file

@ -412,6 +412,7 @@ public:
// > 0 - user who invited me to channel, < 0 - not in channel. // > 0 - user who invited me to channel, < 0 - not in channel.
UserId inviter = 0; UserId inviter = 0;
TimeId inviteDate = 0; TimeId inviteDate = 0;
bool inviteViaRequest = false;
private: private:
struct InvitePeek { struct InvitePeek {

View file

@ -2879,16 +2879,17 @@ MsgRange History::rangeForDifferenceRequest() const {
} }
HistoryService *History::insertJoinedMessage() { HistoryService *History::insertJoinedMessage() {
if (!isChannel() const auto channel = peer->asChannel();
if (!channel
|| _joinedMessage || _joinedMessage
|| !peer->asChannel()->amIn() || !channel->amIn()
|| (peer->isMegagroup() || (peer->isMegagroup()
&& peer->asChannel()->mgInfo->joinedMessageFound)) { && channel->mgInfo->joinedMessageFound)) {
return _joinedMessage; return _joinedMessage;
} }
const auto inviter = peer->asChannel()->inviter const auto inviter = (channel->inviter.bare > 0)
? owner().userLoaded(peer->asChannel()->inviter) ? owner().userLoaded(channel->inviter)
: nullptr; : nullptr;
if (!inviter) { if (!inviter) {
return nullptr; return nullptr;
@ -2898,12 +2899,15 @@ HistoryService *History::insertJoinedMessage() {
&& peer->migrateFrom() && peer->migrateFrom()
&& !blocks.empty() && !blocks.empty()
&& blocks.front()->messages.front()->data()->id == 1) { && blocks.front()->messages.front()->data()->id == 1) {
peer->asChannel()->mgInfo->joinedMessageFound = true; channel->mgInfo->joinedMessageFound = true;
return nullptr; return nullptr;
} }
const auto inviteDate = peer->asChannel()->inviteDate; _joinedMessage = GenerateJoinedMessage(
_joinedMessage = GenerateJoinedMessage(this, inviteDate, inviter); this,
channel->inviteDate,
inviter,
channel->inviteViaRequest);
insertLocalMessage(_joinedMessage); insertLocalMessage(_joinedMessage);
return _joinedMessage; return _joinedMessage;
} }

View file

@ -1243,7 +1243,8 @@ HistoryService::~HistoryService() {
HistoryService::PreparedText GenerateJoinedText( HistoryService::PreparedText GenerateJoinedText(
not_null<History*> history, not_null<History*> history,
not_null<UserData*> inviter) { not_null<UserData*> inviter,
bool viaRequest) {
if (inviter->id != history->session().userPeerId()) { if (inviter->id != history->session().userPeerId()) {
auto result = HistoryService::PreparedText{}; auto result = HistoryService::PreparedText{};
result.links.push_back(inviter->createOpenLink()); result.links.push_back(inviter->createOpenLink());
@ -1255,6 +1256,9 @@ HistoryService::PreparedText GenerateJoinedText(
textcmdLink(1, inviter->name)); textcmdLink(1, inviter->name));
return result; return result;
} else if (history->isMegagroup()) { } else if (history->isMegagroup()) {
if (viaRequest) {
return { tr::lng_action_you_joined_by_request(tr::now) };
}
auto self = history->session().user(); auto self = history->session().user();
auto result = HistoryService::PreparedText{}; auto result = HistoryService::PreparedText{};
result.links.push_back(self->createOpenLink()); result.links.push_back(self->createOpenLink());
@ -1264,18 +1268,21 @@ HistoryService::PreparedText GenerateJoinedText(
textcmdLink(1, self->name)); textcmdLink(1, self->name));
return result; return result;
} }
return { tr::lng_action_you_joined(tr::now) }; return { viaRequest
? tr::lng_action_you_joined_by_request_channel(tr::now)
: tr::lng_action_you_joined(tr::now) };
} }
not_null<HistoryService*> GenerateJoinedMessage( not_null<HistoryService*> GenerateJoinedMessage(
not_null<History*> history, not_null<History*> history,
TimeId inviteDate, TimeId inviteDate,
not_null<UserData*> inviter) { not_null<UserData*> inviter,
bool viaRequest) {
return history->makeServiceMessage( return history->makeServiceMessage(
history->owner().nextLocalMessageId(), history->owner().nextLocalMessageId(),
MessageFlag::LocalHistoryEntry, MessageFlag::LocalHistoryEntry,
inviteDate, inviteDate,
GenerateJoinedText(history, inviter)); GenerateJoinedText(history, inviter, viaRequest));
} }
std::optional<bool> PeerHasThisCall( std::optional<bool> PeerHasThisCall(

View file

@ -175,7 +175,8 @@ private:
[[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage( [[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage(
not_null<History*> history, not_null<History*> history,
TimeId inviteDate, TimeId inviteDate,
not_null<UserData*> inviter); not_null<UserData*> inviter,
bool viaRequest);
[[nodiscard]] std::optional<bool> PeerHasThisCall( [[nodiscard]] std::optional<bool> PeerHasThisCall(
not_null<PeerData*> peer, not_null<PeerData*> peer,
CallId id); CallId id);