diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index c4d31f3..ce6b061 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -730,15 +730,28 @@ TimelineView::removeEvent(const QString &event_id) auto removedItem = eventIds_[event_id]; // Find the next and the previous widgets in the timeline - auto prevItem = qobject_cast(relativeWidget(removedItem, -1)); - auto nextItem = qobject_cast(relativeWidget(removedItem, 1)); + auto prevWidget = relativeWidget(removedItem, -1); + auto nextWidget = relativeWidget(removedItem, 1); + + // See if they are timeline items + auto prevItem = qobject_cast(prevWidget); + auto nextItem = qobject_cast(nextWidget); + + // ... or a date separator + auto prevLabel = qobject_cast(prevWidget); // If it's a TimelineItem add an avatar. - if (prevItem) + if (prevItem) { prevItem->addAvatar(); + } - if (nextItem) + if (nextItem) { nextItem->addAvatar(); + } else if (prevLabel) { + // If there's no chat message after this, and we have a label before us, delete the + // label. + prevLabel->deleteLater(); + } // Finally remove the event. removedItem->deleteLater();