mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Skip old and currently-sending draft updates.
This commit is contained in:
@@ -51,6 +51,7 @@ constexpr auto kStatusShowClientsideChooseContact = 6000;
|
||||
constexpr auto kStatusShowClientsidePlayGame = 10000;
|
||||
constexpr auto kSetMyActionForMs = 10000;
|
||||
constexpr auto kNewBlockEachMessage = 50;
|
||||
constexpr auto kSkipCloudDraftsFor = TimeId(3);
|
||||
|
||||
void checkForSwitchInlineButton(HistoryItem *item) {
|
||||
if (item->out() || !item->hasSwitchInlineButton()) {
|
||||
@@ -405,6 +406,24 @@ Data::Draft *History::createCloudDraft(Data::Draft *fromDraft) {
|
||||
return cloudDraft();
|
||||
}
|
||||
|
||||
bool History::skipCloudDraft(const QString &text, TimeId date) const {
|
||||
if (_lastSentDraftText && *_lastSentDraftText == text) {
|
||||
return true;
|
||||
} else if (date <= _lastSentDraftTime + kSkipCloudDraftsFor) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void History::setSentDraftText(const QString &text) {
|
||||
_lastSentDraftText = text;
|
||||
}
|
||||
|
||||
void History::clearSentDraftText() {
|
||||
_lastSentDraftText = base::none;
|
||||
accumulate_max(_lastSentDraftTime, unixtime());
|
||||
}
|
||||
|
||||
void History::setEditDraft(std::unique_ptr<Data::Draft> &&draft) {
|
||||
_editDraft = std::move(draft);
|
||||
}
|
||||
|
@@ -304,6 +304,9 @@ public:
|
||||
void createLocalDraftFromCloud();
|
||||
void setCloudDraft(std::unique_ptr<Data::Draft> &&draft);
|
||||
Data::Draft *createCloudDraft(Data::Draft *fromDraft);
|
||||
bool skipCloudDraft(const QString &text, TimeId date) const;
|
||||
void setSentDraftText(const QString &text);
|
||||
void clearSentDraftText();
|
||||
void setEditDraft(std::unique_ptr<Data::Draft> &&draft);
|
||||
void clearLocalDraft();
|
||||
void clearCloudDraft();
|
||||
@@ -501,6 +504,8 @@ private:
|
||||
|
||||
std::unique_ptr<Data::Draft> _localDraft, _cloudDraft;
|
||||
std::unique_ptr<Data::Draft> _editDraft;
|
||||
base::optional<QString> _lastSentDraftText;
|
||||
TimeId _lastSentDraftTime = 0;
|
||||
MessageIdsList _forwardDraft;
|
||||
|
||||
using TypingUsers = QMap<UserData*, TimeMs>;
|
||||
|
@@ -91,6 +91,9 @@ constexpr auto kShowMembersDropdownTimeoutMs = 300;
|
||||
constexpr auto kDisplayEditTimeWarningMs = 300 * 1000;
|
||||
constexpr auto kFullDayInMs = 86400 * 1000;
|
||||
constexpr auto kCancelTypingActionTimeout = TimeMs(5000);
|
||||
constexpr auto kSaveDraftTimeout = 1000;
|
||||
constexpr auto kSaveDraftAnywayTimeout = 5000;
|
||||
constexpr auto kSaveCloudDraftIdleTimeout = 14000;
|
||||
|
||||
ApiWrap::RequestMessageDataCallback replyEditMessageDataCallback() {
|
||||
return [](ChannelData *channel, MsgId msgId) {
|
||||
@@ -1192,9 +1195,9 @@ void HistoryWidget::onDraftSave(bool delayed) {
|
||||
auto ms = getms();
|
||||
if (!_saveDraftStart) {
|
||||
_saveDraftStart = ms;
|
||||
return _saveDraftTimer.start(SaveDraftTimeout);
|
||||
} else if (ms - _saveDraftStart < SaveDraftAnywayTimeout) {
|
||||
return _saveDraftTimer.start(SaveDraftTimeout);
|
||||
return _saveDraftTimer.start(kSaveDraftTimeout);
|
||||
} else if (ms - _saveDraftStart < kSaveDraftAnywayTimeout) {
|
||||
return _saveDraftTimer.start(kSaveDraftTimeout);
|
||||
}
|
||||
}
|
||||
writeDrafts(nullptr, nullptr);
|
||||
@@ -1275,7 +1278,7 @@ void HistoryWidget::writeDrafts(Data::Draft **localDraft, Data::Draft **editDraf
|
||||
}
|
||||
|
||||
if (!_editMsgId && !_inlineBot) {
|
||||
_saveCloudDraftTimer.start(SaveCloudDraftIdleTimeout);
|
||||
_saveCloudDraftTimer.start(kSaveCloudDraftIdleTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user