mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-30 22:16:14 +00:00
FullMsgId rely on PeerId instead of ChannelId.
This commit is contained in:
@@ -510,14 +510,14 @@ void ApiWrap::sendMessageFail(
|
||||
}
|
||||
|
||||
void ApiWrap::requestMessageData(
|
||||
ChannelData *channel,
|
||||
PeerData *peer,
|
||||
MsgId msgId,
|
||||
RequestMessageDataCallback callback) {
|
||||
auto &requests = channel
|
||||
? _channelMessageDataRequests[channel][msgId]
|
||||
Fn<void()> done) {
|
||||
auto &requests = (peer && peer->isChannel())
|
||||
? _channelMessageDataRequests[peer->asChannel()][msgId]
|
||||
: _messageDataRequests[msgId];
|
||||
if (callback) {
|
||||
requests.callbacks.push_back(callback);
|
||||
if (done) {
|
||||
requests.callbacks.push_back(std::move(done));
|
||||
}
|
||||
if (!requests.requestId) {
|
||||
_messageDataResolveDelayed.call();
|
||||
@@ -539,19 +539,19 @@ QVector<MTPInputMessage> ApiWrap::collectMessageIds(
|
||||
|
||||
auto ApiWrap::messageDataRequests(ChannelData *channel, bool onlyExisting)
|
||||
-> MessageDataRequests* {
|
||||
if (channel) {
|
||||
auto i = _channelMessageDataRequests.find(channel);
|
||||
if (i == end(_channelMessageDataRequests)) {
|
||||
if (onlyExisting) {
|
||||
return nullptr;
|
||||
}
|
||||
i = _channelMessageDataRequests.emplace(
|
||||
channel,
|
||||
MessageDataRequests()).first;
|
||||
}
|
||||
return &i->second;
|
||||
if (!channel) {
|
||||
return &_messageDataRequests;
|
||||
}
|
||||
return &_messageDataRequests;
|
||||
const auto i = _channelMessageDataRequests.find(channel);
|
||||
if (i != end(_channelMessageDataRequests)) {
|
||||
return &i->second;
|
||||
} else if (onlyExisting) {
|
||||
return nullptr;
|
||||
}
|
||||
return &_channelMessageDataRequests.emplace(
|
||||
channel,
|
||||
MessageDataRequests()
|
||||
).first->second;
|
||||
}
|
||||
|
||||
void ApiWrap::resolveMessageDatas() {
|
||||
@@ -614,20 +614,31 @@ void ApiWrap::finalizeMessageDataRequest(
|
||||
ChannelData *channel,
|
||||
mtpRequestId requestId) {
|
||||
auto requests = messageDataRequests(channel, true);
|
||||
if (requests) {
|
||||
for (auto i = requests->begin(); i != requests->cend();) {
|
||||
if (i->second.requestId == requestId) {
|
||||
for (const auto &callback : i->second.callbacks) {
|
||||
callback(channel, i->first);
|
||||
}
|
||||
i = requests->erase(i);
|
||||
if (!requests) {
|
||||
return;
|
||||
}
|
||||
auto callbacks = std::vector<Fn<void()>>();
|
||||
for (auto i = requests->begin(); i != requests->cend();) {
|
||||
if (i->second.requestId == requestId) {
|
||||
auto &list = i->second.callbacks;
|
||||
if (callbacks.empty()) {
|
||||
callbacks = std::move(list);
|
||||
} else {
|
||||
++i;
|
||||
callbacks.insert(
|
||||
end(callbacks),
|
||||
std::make_move_iterator(begin(list)),
|
||||
std::make_move_iterator(end(list)));
|
||||
}
|
||||
i = requests->erase(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
if (channel && requests->empty()) {
|
||||
_channelMessageDataRequests.remove(channel);
|
||||
}
|
||||
}
|
||||
if (channel && requests->empty()) {
|
||||
_channelMessageDataRequests.remove(channel);
|
||||
}
|
||||
for (const auto &callback : callbacks) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,7 +657,7 @@ QString ApiWrap::exportDirectMessageLink(
|
||||
if (inRepliesContext) {
|
||||
if (const auto rootId = item->replyToTop()) {
|
||||
const auto root = item->history()->owner().message(
|
||||
peerToChannel(channel->id),
|
||||
channel->id,
|
||||
rootId);
|
||||
const auto sender = root
|
||||
? root->discussionPostOriginalSender()
|
||||
@@ -1388,9 +1399,8 @@ void ApiWrap::deleteAllFromParticipant(
|
||||
const auto ids = history
|
||||
? history->collectMessagesFromParticipantToDelete(from)
|
||||
: std::vector<MsgId>();
|
||||
const auto channelId = peerToChannel(channel->id);
|
||||
for (const auto &msgId : ids) {
|
||||
if (const auto item = _session->data().message(channelId, msgId)) {
|
||||
if (const auto item = _session->data().message(channel->id, msgId)) {
|
||||
item->destroy();
|
||||
}
|
||||
}
|
||||
@@ -2225,11 +2235,7 @@ void ApiWrap::resolveWebPages() {
|
||||
if (i.key()->pendingTill <= t) {
|
||||
const auto item = _session->data().findWebPageItem(i.key());
|
||||
if (item) {
|
||||
if (item->channelId() == NoChannel) {
|
||||
ids.push_back(MTP_inputMessageID(MTP_int(item->id)));
|
||||
i.value() = -1;
|
||||
} else {
|
||||
auto channel = item->history()->peer->asChannel();
|
||||
if (const auto channel = item->history()->peer->asChannel()) {
|
||||
auto channelMap = idsByChannel.find(channel);
|
||||
if (channelMap == idsByChannel.cend()) {
|
||||
channelMap = idsByChannel.emplace(
|
||||
@@ -2244,6 +2250,9 @@ void ApiWrap::resolveWebPages() {
|
||||
MTP_inputMessageID(MTP_int(item->id)));
|
||||
}
|
||||
i.value() = -channelMap->second.first - 2;
|
||||
} else {
|
||||
ids.push_back(MTP_inputMessageID(MTP_int(item->id)));
|
||||
i.value() = -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -2927,14 +2936,13 @@ void ApiWrap::preloadEnoughUnreadMentions(not_null<History*> history) {
|
||||
void ApiWrap::checkForUnreadMentions(
|
||||
const base::flat_set<MsgId> &possiblyReadMentions,
|
||||
ChannelData *channel) {
|
||||
for (auto msgId : possiblyReadMentions) {
|
||||
requestMessageData(channel, msgId, [=](
|
||||
ChannelData *channel,
|
||||
MsgId msgId) {
|
||||
if (const auto item = _session->data().message(channel, msgId)) {
|
||||
if (item->mentionsMe()) {
|
||||
item->markMediaRead();
|
||||
}
|
||||
for (const auto msgId : possiblyReadMentions) {
|
||||
requestMessageData(channel, msgId, [=] {
|
||||
const auto item = channel
|
||||
? _session->data().message(channel->id, msgId)
|
||||
: _session->data().nonChannelMessage(msgId);
|
||||
if (item && item->mentionsMe()) {
|
||||
item->markMediaRead();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -3206,7 +3214,7 @@ void ApiWrap::forwardMessages(
|
||||
const auto randomId = base::RandomValue<uint64>();
|
||||
if (genClientSideMessage) {
|
||||
const auto newId = FullMsgId(
|
||||
peerToChannel(peer->id),
|
||||
peer->id,
|
||||
_session->data().nextLocalMessageId());
|
||||
const auto self = _session->user();
|
||||
const auto messageFromId = sendAs
|
||||
@@ -3279,7 +3287,7 @@ void ApiWrap::sendSharedContact(
|
||||
const auto peer = history->peer;
|
||||
|
||||
const auto newId = FullMsgId(
|
||||
history->channelId(),
|
||||
peer->id,
|
||||
_session->data().nextLocalMessageId());
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
|
||||
@@ -3505,7 +3513,7 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
||||
|
||||
while (TextUtilities::CutPart(sending, left, MaxMessageSize)) {
|
||||
auto newId = FullMsgId(
|
||||
peerToChannel(peer->id),
|
||||
peer->id,
|
||||
_session->data().nextLocalMessageId());
|
||||
auto randomId = base::RandomValue<uint64>();
|
||||
|
||||
@@ -3663,7 +3671,7 @@ void ApiWrap::sendInlineResult(
|
||||
const auto history = action.history;
|
||||
const auto peer = history->peer;
|
||||
const auto newId = FullMsgId(
|
||||
peerToChannel(peer->id),
|
||||
peer->id,
|
||||
_session->data().nextLocalMessageId());
|
||||
const auto randomId = base::RandomValue<uint64>();
|
||||
|
||||
|
Reference in New Issue
Block a user