mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Try to make message-replacing more crash-resistant
This commit is contained in:
parent
635d4b2341
commit
7578743b74
|
@ -443,13 +443,21 @@ void ChannelView::setChannel(ChannelPtr newChannel)
|
|||
this->channelConnections_.push_back(
|
||||
newChannel->messageReplaced.connect([this](size_t index, MessagePtr replacement) {
|
||||
MessageLayoutPtr newItem(new MessageLayout(replacement));
|
||||
if (this->messages.getSnapshot()[index]->flags & MessageLayout::AlternateBackground) {
|
||||
auto snapshot = this->messages.getSnapshot();
|
||||
if (index >= snapshot.getLength()) {
|
||||
debug::Log("Tried to replace out of bounds message. Index: {}. Length: {}", index,
|
||||
snapshot.getLength());
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &message = snapshot[index];
|
||||
if (message->flags & MessageLayout::AlternateBackground) {
|
||||
newItem->flags |= MessageLayout::AlternateBackground;
|
||||
}
|
||||
|
||||
this->scrollBar.replaceHighlight(index, replacement->getScrollBarHighlight());
|
||||
|
||||
this->messages.replaceItem(this->messages.getSnapshot()[index], newItem);
|
||||
this->messages.replaceItem(message, newItem);
|
||||
this->layoutMessages();
|
||||
}));
|
||||
|
||||
|
|
Loading…
Reference in a new issue