mirror of https://github.com/procxx/kepka.git
Fix localtime-related slowmode errors.
This commit is contained in:
parent
1a06714f3a
commit
e1fe373504
|
@ -561,8 +561,12 @@ void ApiWrap::sendMessageFail(
|
||||||
const auto left = error.type().mid(chop).toInt();
|
const auto left = error.type().mid(chop).toInt();
|
||||||
if (const auto channel = peer->asChannel()) {
|
if (const auto channel = peer->asChannel()) {
|
||||||
const auto seconds = channel->slowmodeSeconds();
|
const auto seconds = channel->slowmodeSeconds();
|
||||||
|
if (seconds >= left) {
|
||||||
channel->growSlowmodeLastMessage(
|
channel->growSlowmodeLastMessage(
|
||||||
base::unixtime::now() - (left - seconds));
|
base::unixtime::now() - (left - seconds));
|
||||||
|
} else {
|
||||||
|
requestFullPeer(peer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (const auto item = _session->data().message(itemId)) {
|
if (const auto item = _session->data().message(itemId)) {
|
||||||
|
|
|
@ -596,10 +596,15 @@ TimeId ChannelData::slowmodeLastMessage() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelData::growSlowmodeLastMessage(TimeId when) {
|
void ChannelData::growSlowmodeLastMessage(TimeId when) {
|
||||||
if (_slowmodeLastMessage >= when) {
|
const auto now = base::unixtime::now();
|
||||||
return;
|
accumulate_min(when, now);
|
||||||
}
|
if (_slowmodeLastMessage > now) {
|
||||||
_slowmodeLastMessage = when;
|
_slowmodeLastMessage = when;
|
||||||
|
} else if (_slowmodeLastMessage >= when) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
_slowmodeLastMessage = when;
|
||||||
|
}
|
||||||
Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelSlowmode);
|
Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelSlowmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,11 +660,10 @@ void ApplyChannelUpdate(
|
||||||
channel->setKickedCount(update.vkicked_count().value_or_empty());
|
channel->setKickedCount(update.vkicked_count().value_or_empty());
|
||||||
channel->setSlowmodeSeconds(update.vslowmode_seconds().value_or_empty());
|
channel->setSlowmodeSeconds(update.vslowmode_seconds().value_or_empty());
|
||||||
if (const auto next = update.vslowmode_next_send_date()) {
|
if (const auto next = update.vslowmode_next_send_date()) {
|
||||||
if (next->v > base::unixtime::now()) {
|
|
||||||
channel->growSlowmodeLastMessage(
|
channel->growSlowmodeLastMessage(
|
||||||
next->v - channel->slowmodeSeconds());
|
next->v - channel->slowmodeSeconds());
|
||||||
}
|
}
|
||||||
}
|
channel->checkSlowmodeLastMessage();
|
||||||
channel->setInviteLink(update.vexported_invite().match([&](
|
channel->setInviteLink(update.vexported_invite().match([&](
|
||||||
const MTPDchatInviteExported &data) {
|
const MTPDchatInviteExported &data) {
|
||||||
return qs(data.vlink());
|
return qs(data.vlink());
|
||||||
|
|
|
@ -713,12 +713,13 @@ bool PeerData::slowmodeApplied() const {
|
||||||
|
|
||||||
int PeerData::slowmodeSecondsLeft() const {
|
int PeerData::slowmodeSecondsLeft() const {
|
||||||
if (const auto channel = asChannel()) {
|
if (const auto channel = asChannel()) {
|
||||||
|
if (const auto seconds = channel->slowmodeSeconds()) {
|
||||||
if (const auto last = channel->slowmodeLastMessage()) {
|
if (const auto last = channel->slowmodeLastMessage()) {
|
||||||
const auto seconds = channel->slowmodeSeconds();
|
|
||||||
const auto now = base::unixtime::now();
|
const auto now = base::unixtime::now();
|
||||||
return std::max(seconds - (now - last), 0);
|
return std::max(seconds - (now - last), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1637,11 +1637,7 @@ bool Session::checkEntitiesAndViewsUpdate(const MTPDmessage &data) {
|
||||||
existing->updateForwardedInfo(data.vfwd_from());
|
existing->updateForwardedInfo(data.vfwd_from());
|
||||||
existing->setViewsCount(data.vviews().value_or(-1));
|
existing->setViewsCount(data.vviews().value_or(-1));
|
||||||
existing->indexAsNewItem();
|
existing->indexAsNewItem();
|
||||||
if (const auto channel = existing->history()->peer->asChannel()) {
|
existing->contributeToSlowmode(data.vdate().v);
|
||||||
if (existing->out()) {
|
|
||||||
channel->growSlowmodeLastMessage(data.vdate().v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
requestItemTextRefresh(existing);
|
requestItemTextRefresh(existing);
|
||||||
if (existing->mainView()) {
|
if (existing->mainView()) {
|
||||||
checkSavedGif(existing);
|
checkSavedGif(existing);
|
||||||
|
|
|
@ -1242,16 +1242,12 @@ void History::newItemAdded(not_null<HistoryItem*> item) {
|
||||||
}
|
}
|
||||||
from->madeAction(item->date());
|
from->madeAction(item->date());
|
||||||
}
|
}
|
||||||
|
item->contributeToSlowmode();
|
||||||
if (item->out()) {
|
if (item->out()) {
|
||||||
destroyUnreadBar();
|
destroyUnreadBar();
|
||||||
if (!item->unread()) {
|
if (!item->unread()) {
|
||||||
outboxRead(item);
|
outboxRead(item);
|
||||||
}
|
}
|
||||||
if (const auto channel = peer->asChannel()) {
|
|
||||||
if (IsServerMsgId(item->id)) {
|
|
||||||
channel->growSlowmodeLastMessage(item->date());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (item->unread()) {
|
} else if (item->unread()) {
|
||||||
if (!isChannel() || peer->asChannel()->amIn()) {
|
if (!isChannel() || peer->asChannel()->amIn()) {
|
||||||
_notifications.push_back(item);
|
_notifications.push_back(item);
|
||||||
|
|
|
@ -204,6 +204,8 @@ public:
|
||||||
}
|
}
|
||||||
virtual void updateForwardedInfo(const MTPMessageFwdHeader *fwd) {
|
virtual void updateForwardedInfo(const MTPMessageFwdHeader *fwd) {
|
||||||
}
|
}
|
||||||
|
virtual void contributeToSlowmode(TimeId realDate = 0) {
|
||||||
|
}
|
||||||
|
|
||||||
virtual void addToUnreadMentions(UnreadMentionType type);
|
virtual void addToUnreadMentions(UnreadMentionType type);
|
||||||
virtual void eraseFromUnreadMentions() {
|
virtual void eraseFromUnreadMentions() {
|
||||||
|
|
|
@ -1098,6 +1098,14 @@ void HistoryMessage::updateForwardedInfo(const MTPMessageFwdHeader *fwd) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HistoryMessage::contributeToSlowmode(TimeId realDate) {
|
||||||
|
if (const auto channel = history()->peer->asChannel()) {
|
||||||
|
if (out() && IsServerMsgId(id)) {
|
||||||
|
channel->growSlowmodeLastMessage(realDate ? realDate : date());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HistoryMessage::addToUnreadMentions(UnreadMentionType type) {
|
void HistoryMessage::addToUnreadMentions(UnreadMentionType type) {
|
||||||
if (IsServerMsgId(id) && isUnreadMention()) {
|
if (IsServerMsgId(id) && isUnreadMention()) {
|
||||||
if (history()->addToUnreadMentions(id, type)) {
|
if (history()->addToUnreadMentions(id, type)) {
|
||||||
|
|
|
@ -137,6 +137,7 @@ public:
|
||||||
setReplyMarkup(markup);
|
setReplyMarkup(markup);
|
||||||
}
|
}
|
||||||
void updateForwardedInfo(const MTPMessageFwdHeader *fwd) override;
|
void updateForwardedInfo(const MTPMessageFwdHeader *fwd) override;
|
||||||
|
void contributeToSlowmode(TimeId realDate = 0) override;
|
||||||
|
|
||||||
void addToUnreadMentions(UnreadMentionType type) override;
|
void addToUnreadMentions(UnreadMentionType type) override;
|
||||||
void eraseFromUnreadMentions() override;
|
void eraseFromUnreadMentions() override;
|
||||||
|
|
|
@ -3821,9 +3821,7 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||||
sent.text,
|
sent.text,
|
||||||
TextUtilities::EntitiesFromMTP(list.value_or_empty())
|
TextUtilities::EntitiesFromMTP(list.value_or_empty())
|
||||||
}, d.vmedia());
|
}, d.vmedia());
|
||||||
if (const auto channel = item->history()->peer->asChannel()) {
|
item->contributeToSlowmode(d.vdate().v);
|
||||||
channel->growSlowmodeLastMessage(d.vdate().v);
|
|
||||||
}
|
|
||||||
if (!wasAlready) {
|
if (!wasAlready) {
|
||||||
item->indexAsNewItem();
|
item->indexAsNewItem();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue