From cd9397f279cf1719673072efe8cb6432f6af8fc9 Mon Sep 17 00:00:00 2001 From: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> Date: Mon, 13 Apr 2020 09:40:53 -0400 Subject: [PATCH] conversation: fix message sequensing Ensure that item is not typing indicator when computing message. Change-Id: I6fbcddfd7006d2a6bd18f1aeda1be15413b46b90 --- src/MessagesVC.mm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/MessagesVC.mm b/src/MessagesVC.mm index a88b8cf7..8a2232b8 100644 --- a/src/MessagesVC.mm +++ b/src/MessagesVC.mm @@ -793,9 +793,12 @@ typedef NS_ENUM(NSInteger, MessageSequencing) { } -(MessageSequencing) computeSequencingFor:(NSInteger) row { + if (row >= conversationView.numberOfRows - 1) { + return SINGLE_WITHOUT_TIME; + } auto* conv = [self getCurrentConversation]; if (conv == nil) - return SINGLE_WITHOUT_TIME; + return SINGLE_WITHOUT_TIME; auto it = conv->interactions.begin(); std::advance(it, row); if (it == conv->interactions.end()) { @@ -805,20 +808,24 @@ typedef NS_ENUM(NSInteger, MessageSequencing) { if (interaction.type != lrc::api::interaction::Type::TEXT) { return SINGLE_WITH_TIME; } + // first message in comversation if (row == 0) { if (it == conv->interactions.end()) { return SINGLE_WITH_TIME; } auto nextIt = it; nextIt++; + if (nextIt == conv->interactions.end()) { + return SINGLE_WITH_TIME; + } auto nextInteraction = nextIt->second; if ([self sequenceChangedFrom:interaction to: nextInteraction]) { return SINGLE_WITH_TIME; } return FIRST_WITH_TIME; } - - if (row == conversationView.numberOfRows - 1) { + // last message in comversation + if (row == conversationView.numberOfRows - 2) { if(it == conv->interactions.begin()) { return SINGLE_WITH_TIME; } @@ -835,14 +842,19 @@ typedef NS_ENUM(NSInteger, MessageSequencing) { } return SINGLE_WITH_TIME; } + // single message in comversation if(it == conv->interactions.begin() || it == conv->interactions.end()) { return SINGLE_WITH_TIME; } + // message in the middle of conversation auto previousIt = it; previousIt--; auto previousInteraction = previousIt->second; auto nextIt = it; nextIt++; + if (nextIt == conv->interactions.end()) { + return SINGLE_WITHOUT_TIME; + } auto nextInteraction = nextIt->second; bool timeChanged = [self sequenceTimeChangedFrom:interaction to:previousInteraction]; -- GitLab