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

Switch between pinned messages in chat.

This commit is contained in:
John Preston
2020-10-09 19:23:53 +03:00
parent ec35e3f081
commit b9f40e35cd
12 changed files with 466 additions and 69 deletions

View File

@@ -1161,7 +1161,7 @@ void History::addEdgesToSharedMedia() {
{},
{ from, till }));
}
peer->addPinnedSlice({}, from, till);
peer->addPinnedSlice({}, { from, till }, std::nullopt);
}
void History::addOlderSlice(const QVector<MTPMessage> &slice) {
@@ -1358,7 +1358,7 @@ void History::addToSharedMedia(
{ from, till }));
}
}
peer->addPinnedSlice(std::move(pinned), from, till);
peer->addPinnedSlice(std::move(pinned), { from, till }, std::nullopt);
}
void History::calculateFirstUnreadMessage() {
@@ -1785,16 +1785,19 @@ TimeId History::adjustedChatListTimeId() const {
}
void History::countScrollState(int top) {
countScrollTopItem(top);
if (scrollTopItem) {
scrollTopOffset = (top - scrollTopItem->block()->y() - scrollTopItem->y());
}
std::tie(scrollTopItem, scrollTopOffset) = findItemAndOffset(top);
}
void History::countScrollTopItem(int top) {
auto History::findItemAndOffset(int top) const -> std::pair<Element*, int> {
if (const auto element = findScrollTopItem(top)) {
return { element, (top - element->block()->y() - element->y()) };
}
return {};
}
auto History::findScrollTopItem(int top) const -> Element* {
if (isEmpty()) {
forgetScrollState();
return;
return nullptr;
}
auto itemIndex = 0;
@@ -1813,8 +1816,7 @@ void History::countScrollTopItem(int top) {
const auto view = block->messages[itemIndex].get();
itemTop = block->y() + view->y();
if (itemTop <= top) {
scrollTopItem = view;
return;
return view;
}
}
if (--blockIndex >= 0) {
@@ -1824,27 +1826,24 @@ void History::countScrollTopItem(int top) {
}
} while (true);
scrollTopItem = blocks.front()->messages.front().get();
} else {
// go forward through history while we don't find the last item that starts above
for (auto blocksCount = int(blocks.size()); blockIndex < blocksCount; ++blockIndex) {
const auto &block = blocks[blockIndex];
for (auto itemsCount = int(block->messages.size()); itemIndex < itemsCount; ++itemIndex) {
itemTop = block->y() + block->messages[itemIndex]->y();
if (itemTop > top) {
Assert(itemIndex > 0 || blockIndex > 0);
if (itemIndex > 0) {
scrollTopItem = block->messages[itemIndex - 1].get();
} else {
scrollTopItem = blocks[blockIndex - 1]->messages.back().get();
}
return;
}
}
itemIndex = 0;
}
scrollTopItem = blocks.back()->messages.back().get();
return blocks.front()->messages.front().get();
}
// go forward through history while we don't find the last item that starts above
for (auto blocksCount = int(blocks.size()); blockIndex < blocksCount; ++blockIndex) {
const auto &block = blocks[blockIndex];
for (auto itemsCount = int(block->messages.size()); itemIndex < itemsCount; ++itemIndex) {
itemTop = block->y() + block->messages[itemIndex]->y();
if (itemTop > top) {
Assert(itemIndex > 0 || blockIndex > 0);
if (itemIndex > 0) {
return block->messages[itemIndex - 1].get();
}
return blocks[blockIndex - 1]->messages.back().get();
}
}
itemIndex = 0;
}
return blocks.back()->messages.back().get();
}
void History::getNextScrollTopItem(HistoryBlock *block, int32 i) {