Fixes #1259 highlight not added when changing channel

This commit is contained in:
fourtf 2019-09-16 11:54:34 +02:00
parent 89fd3bfce9
commit cadff4c430

View file

@ -535,64 +535,64 @@ ChannelPtr ChannelView::channel()
return this->channel_; return this->channel_;
} }
void ChannelView::setChannel(ChannelPtr newChannel) void ChannelView::setChannel(ChannelPtr channel)
{ {
/// Clear connections from the last channel /// Clear connections from the last channel
this->channelConnections_.clear(); this->channelConnections_.clear();
this->clearMessages(); this->clearMessages();
this->scrollBar_->clearHighlights();
// on new message // on new message
this->channelConnections_.push_back(newChannel->messageAppended.connect( this->channelConnections_.push_back(channel->messageAppended.connect(
[this](MessagePtr &message, [this](MessagePtr &message,
boost::optional<MessageFlags> overridingFlags) { boost::optional<MessageFlags> overridingFlags) {
this->messageAppended(message, overridingFlags); this->messageAppended(message, overridingFlags);
})); }));
this->channelConnections_.push_back( this->channelConnections_.push_back(channel->messagesAddedAtStart.connect(
newChannel->messagesAddedAtStart.connect(
[this](std::vector<MessagePtr> &messages) { [this](std::vector<MessagePtr> &messages) {
this->messageAddedAtStart(messages); this->messageAddedAtStart(messages);
})); }));
// on message removed // on message removed
this->channelConnections_.push_back( this->channelConnections_.push_back(
newChannel->messageRemovedFromStart.connect( channel->messageRemovedFromStart.connect([this](MessagePtr &message) {
[this](MessagePtr &message) {
this->messageRemoveFromStart(message); this->messageRemoveFromStart(message);
})); }));
// on message replaced // on message replaced
this->channelConnections_.push_back(newChannel->messageReplaced.connect( this->channelConnections_.push_back(channel->messageReplaced.connect(
[this](size_t index, MessagePtr replacement) { [this](size_t index, MessagePtr replacement) {
this->messageReplaced(index, replacement); this->messageReplaced(index, replacement);
})); }));
auto snapshot = newChannel->getMessageSnapshot(); auto snapshot = channel->getMessageSnapshot();
for (size_t i = 0; i < snapshot.size(); i++) for (size_t i = 0; i < snapshot.size(); i++)
{ {
MessageLayoutPtr deleted; MessageLayoutPtr deleted;
auto messageRef = new MessageLayout(snapshot[i]); auto messageLayout = new MessageLayout(snapshot[i]);
if (this->lastMessageHasAlternateBackground_) if (this->lastMessageHasAlternateBackground_)
{ {
messageRef->flags.set(MessageLayoutFlag::AlternateBackground); messageLayout->flags.set(MessageLayoutFlag::AlternateBackground);
} }
this->lastMessageHasAlternateBackground_ = this->lastMessageHasAlternateBackground_ =
!this->lastMessageHasAlternateBackground_; !this->lastMessageHasAlternateBackground_;
this->messages_.pushBack(MessageLayoutPtr(messageRef), deleted); this->messages_.pushBack(MessageLayoutPtr(messageLayout), deleted);
this->scrollBar_->addHighlight(snapshot[i]->getScrollBarHighlight());
} }
this->channel_ = newChannel; this->channel_ = channel;
this->queueLayout(); this->queueLayout();
this->queueUpdate(); this->queueUpdate();
// Notifications // Notifications
if (auto tc = dynamic_cast<TwitchChannel *>(newChannel.get())) if (auto tc = dynamic_cast<TwitchChannel *>(channel.get()))
{ {
this->connections_.push_back(tc->liveStatusChanged.connect([this]() { this->connections_.push_back(tc->liveStatusChanged.connect([this]() {
this->liveStatusChanged.invoke(); // this->liveStatusChanged.invoke(); //