2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Move sendMessage and sendInlineResult to ApiWrap.

This commit is contained in:
John Preston
2018-06-26 16:34:38 +01:00
parent ff53404d5b
commit 33095966af
14 changed files with 362 additions and 331 deletions

View File

@@ -4625,6 +4625,94 @@ void readRecentHashtagsAndBots() {
}
}
void incrementRecentHashtag(RecentHashtagPack &recent, const QString &tag) {
auto i = recent.begin(), e = recent.end();
for (; i != e; ++i) {
if (i->first == tag) {
++i->second;
if (qAbs(i->second) > 0x4000) {
for (auto j = recent.begin(); j != e; ++j) {
if (j->second > 1) {
j->second /= 2;
} else if (j->second > 0) {
j->second = 1;
}
}
}
for (; i != recent.begin(); --i) {
if (qAbs((i - 1)->second) > qAbs(i->second)) {
break;
}
qSwap(*i, *(i - 1));
}
break;
}
}
if (i == e) {
while (recent.size() >= 64) recent.pop_back();
recent.push_back(qMakePair(tag, 1));
for (i = recent.end() - 1; i != recent.begin(); --i) {
if ((i - 1)->second > i->second) {
break;
}
qSwap(*i, *(i - 1));
}
}
}
base::optional<RecentHashtagPack> saveRecentHashtags(
Fn<RecentHashtagPack()> getPack,
const QString &text) {
auto found = false;
auto m = QRegularExpressionMatch();
auto recent = getPack();
for (auto i = 0, next = 0; (m = TextUtilities::RegExpHashtag().match(text, i)).hasMatch(); i = next) {
i = m.capturedStart();
next = m.capturedEnd();
if (m.hasMatch()) {
if (!m.capturedRef(1).isEmpty()) {
++i;
}
if (!m.capturedRef(2).isEmpty()) {
--next;
}
}
const auto tag = text.mid(i + 1, next - i - 1);
if (TextUtilities::RegExpHashtagExclude().match(tag).hasMatch()) {
continue;
}
if (!found
&& cRecentWriteHashtags().isEmpty()
&& cRecentSearchHashtags().isEmpty()) {
Local::readRecentHashtagsAndBots();
recent = getPack();
}
found = true;
incrementRecentHashtag(recent, tag);
}
return found ? base::make_optional(recent) : base::none;
}
void saveRecentSentHashtags(const QString &text) {
const auto result = saveRecentHashtags(
[] { return cRecentWriteHashtags(); },
text);
if (result) {
cSetRecentWriteHashtags(*result);
Local::writeRecentHashtagsAndBots();
}
}
void saveRecentSearchHashtags(const QString &text) {
const auto result = saveRecentHashtags(
[] { return cRecentSearchHashtags(); },
text);
if (result) {
cSetRecentSearchHashtags(*result);
Local::writeRecentHashtagsAndBots();
}
}
void WriteExportSettings(const Export::Settings &settings) {
if (!_working()) return;

View File

@@ -165,6 +165,8 @@ void writeLangPack();
void writeRecentHashtagsAndBots();
void readRecentHashtagsAndBots();
void saveRecentSentHashtags(const QString &text);
void saveRecentSearchHashtags(const QString &text);
void WriteExportSettings(const Export::Settings &settings);
Export::Settings ReadExportSettings();