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();
if (const auto channel = session().data().channelLoaded(d.vchannel_id())) {
channel->inviter = UserId(0);
channel->inviteViaRequest = false;
if (channel->amIn()) {
if (channel->isMegagroup()
&& !channel->amCreator()

View File

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

View File

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

View File

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

View File

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

View File

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