mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-26 00:12:25 +00:00
Better adjust shared media count.
This commit is contained in:
parent
2061248224
commit
751506d5b5
@ -31,18 +31,18 @@ void SparseIdsList::Slice::merge(
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Range>
|
template <typename Range>
|
||||||
int SparseIdsList::uniteAndAdd(
|
SparseIdsList::AddResult SparseIdsList::uniteAndAdd(
|
||||||
SparseIdsSliceUpdate &update,
|
SparseIdsSliceUpdate &update,
|
||||||
base::flat_set<Slice>::iterator uniteFrom,
|
base::flat_set<Slice>::iterator uniteFrom,
|
||||||
base::flat_set<Slice>::iterator uniteTill,
|
base::flat_set<Slice>::iterator uniteTill,
|
||||||
const Range &messages,
|
const Range &messages,
|
||||||
MsgRange noSkipRange) {
|
MsgRange noSkipRange) {
|
||||||
auto uniteFromIndex = uniteFrom - _slices.begin();
|
const auto uniteFromIndex = uniteFrom - _slices.begin();
|
||||||
auto was = uniteFrom->messages.size();
|
const auto was = int(uniteFrom->messages.size());
|
||||||
_slices.modify(uniteFrom, [&](Slice &slice) {
|
_slices.modify(uniteFrom, [&](Slice &slice) {
|
||||||
slice.merge(messages, noSkipRange);
|
slice.merge(messages, noSkipRange);
|
||||||
});
|
});
|
||||||
auto firstToErase = uniteFrom + 1;
|
const auto firstToErase = uniteFrom + 1;
|
||||||
if (firstToErase != uniteTill) {
|
if (firstToErase != uniteTill) {
|
||||||
for (auto it = firstToErase; it != uniteTill; ++it) {
|
for (auto it = firstToErase; it != uniteTill; ++it) {
|
||||||
_slices.modify(uniteFrom, [&](Slice &slice) {
|
_slices.modify(uniteFrom, [&](Slice &slice) {
|
||||||
@ -54,11 +54,12 @@ int SparseIdsList::uniteAndAdd(
|
|||||||
}
|
}
|
||||||
update.messages = &uniteFrom->messages;
|
update.messages = &uniteFrom->messages;
|
||||||
update.range = uniteFrom->range;
|
update.range = uniteFrom->range;
|
||||||
return uniteFrom->messages.size() - was;
|
const auto count = int(uniteFrom->messages.size());
|
||||||
|
return { count, count - was };
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Range>
|
template <typename Range>
|
||||||
int SparseIdsList::addRangeItemsAndCountNew(
|
SparseIdsList::AddResult SparseIdsList::addRangeItemsAndCountNew(
|
||||||
SparseIdsSliceUpdate &update,
|
SparseIdsSliceUpdate &update,
|
||||||
const Range &messages,
|
const Range &messages,
|
||||||
MsgRange noSkipRange) {
|
MsgRange noSkipRange) {
|
||||||
@ -86,7 +87,8 @@ int SparseIdsList::addRangeItemsAndCountNew(
|
|||||||
noSkipRange);
|
noSkipRange);
|
||||||
update.messages = &slice->messages;
|
update.messages = &slice->messages;
|
||||||
update.range = slice->range;
|
update.range = slice->range;
|
||||||
return slice->messages.size();
|
const auto count = int(slice->messages.size());
|
||||||
|
return { count, count };
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Range>
|
template <typename Range>
|
||||||
@ -97,22 +99,24 @@ void SparseIdsList::addRange(
|
|||||||
bool incrementCount) {
|
bool incrementCount) {
|
||||||
Expects(!count || !incrementCount);
|
Expects(!count || !incrementCount);
|
||||||
|
|
||||||
auto wasCount = _count;
|
|
||||||
auto update = SparseIdsSliceUpdate();
|
auto update = SparseIdsSliceUpdate();
|
||||||
auto result = addRangeItemsAndCountNew(
|
const auto result = addRangeItemsAndCountNew(
|
||||||
update,
|
update,
|
||||||
messages,
|
messages,
|
||||||
noSkipRange);
|
noSkipRange);
|
||||||
if (count) {
|
if (count) {
|
||||||
_count = count;
|
_count = count;
|
||||||
} else if (incrementCount && _count && result > 0) {
|
} else if (incrementCount && _count && result.added > 0) {
|
||||||
*_count += result;
|
*_count += result.added;
|
||||||
}
|
}
|
||||||
if (_slices.size() == 1) {
|
if (_slices.size() == 1) {
|
||||||
if (_slices.front().range == MsgRange { 0, ServerMaxMsgId }) {
|
if (_slices.front().range == MsgRange { 0, ServerMaxMsgId }) {
|
||||||
_count = _slices.front().messages.size();
|
_count = _slices.front().messages.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (_count) {
|
||||||
|
accumulate_max(*_count, result.inslice);
|
||||||
|
}
|
||||||
update.count = _count;
|
update.count = _count;
|
||||||
_sliceUpdated.fire(std::move(update));
|
_sliceUpdated.fire(std::move(update));
|
||||||
}
|
}
|
||||||
|
@ -68,15 +68,19 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AddResult {
|
||||||
|
int inslice = 0;
|
||||||
|
int added = 0;
|
||||||
|
};
|
||||||
template <typename Range>
|
template <typename Range>
|
||||||
int uniteAndAdd(
|
AddResult uniteAndAdd(
|
||||||
SparseIdsSliceUpdate &update,
|
SparseIdsSliceUpdate &update,
|
||||||
base::flat_set<Slice>::iterator uniteFrom,
|
base::flat_set<Slice>::iterator uniteFrom,
|
||||||
base::flat_set<Slice>::iterator uniteTill,
|
base::flat_set<Slice>::iterator uniteTill,
|
||||||
const Range &messages,
|
const Range &messages,
|
||||||
MsgRange noSkipRange);
|
MsgRange noSkipRange);
|
||||||
template <typename Range>
|
template <typename Range>
|
||||||
int addRangeItemsAndCountNew(
|
AddResult addRangeItemsAndCountNew(
|
||||||
SparseIdsSliceUpdate &update,
|
SparseIdsSliceUpdate &update,
|
||||||
const Range &messages,
|
const Range &messages,
|
||||||
MsgRange noSkipRange);
|
MsgRange noSkipRange);
|
||||||
|
Loading…
Reference in New Issue
Block a user