Skip to content

Commit

Permalink
Bug Fix - Chat screen: missed discussions badge would go red only if …
Browse files Browse the repository at this point in the history
…the user missed a highlight

#563
  • Loading branch information
giomfo committed Sep 5, 2016
1 parent 850e5de commit 26caeca
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions Vector/ViewController/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ @interface RoomViewController ()

// Missed discussions badge
NSUInteger missedDiscussionsCount;
NSUInteger missedHighlightCount;
UIBarButtonItem *missedDiscussionsButton;
UILabel *missedDiscussionsBadgeLabel;
UIView *missedDiscussionsBadgeLabelBgView;
Expand Down Expand Up @@ -270,7 +271,6 @@ - (void)viewDidLoad
missedDiscussionsBarButtonCustomView.clipsToBounds = NO;

missedDiscussionsBadgeLabelBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 21, 21)];
missedDiscussionsBadgeLabelBgView.backgroundColor = kVectorColorPinkRed;
[missedDiscussionsBadgeLabelBgView.layer setCornerRadius:10];

[missedDiscussionsBarButtonCustomView addSubview:missedDiscussionsBadgeLabelBgView];
Expand Down Expand Up @@ -2712,21 +2712,33 @@ - (void)refreshMissedDiscussionsCount:(BOOL)force
return;
}

NSUInteger count = [MXKRoomDataSourceManager missedDiscussionsCount];

if (count && self.roomDataSource.notificationCount)
NSUInteger highlightCount = 0;
NSUInteger missedCount = [MXKRoomDataSourceManager missedDiscussionsCount];
if (missedCount && self.roomDataSource.notificationCount)
{
// Remove the current room from the missed discussion counter
count--;
missedCount--;
}

if (missedCount)
{
// Compute the missed highlight count
highlightCount = [MXKRoomDataSourceManager missedHighlightDiscussionsCount];
if (highlightCount && self.roomDataSource.highlightCount)
{
// Remove the current room from the missed highlight counter
highlightCount--;
}
}

if (force || missedDiscussionsCount != count)
if (force || missedDiscussionsCount != missedCount || missedHighlightCount != highlightCount)
{
missedDiscussionsCount = count;
missedDiscussionsCount = missedCount;
missedHighlightCount = highlightCount;

NSMutableArray *leftBarButtonItems = [NSMutableArray arrayWithArray: self.navigationItem.leftBarButtonItems];

if (count)
if (missedCount)
{
// Consider the main navigation controller if the current view controller is embedded inside a split view controller.
UINavigationController *mainNavigationController = self.navigationController;
Expand All @@ -2738,13 +2750,13 @@ - (void)refreshMissedDiscussionsCount:(BOOL)force
UIBarButtonItem *backButton = backItem.backBarButtonItem;

// Refresh missed discussions count label
if (count > 99)
if (missedCount > 99)
{
missedDiscussionsBadgeLabel.text = @"99+";
}
else
{
missedDiscussionsBadgeLabel.text = [NSString stringWithFormat:@"%tu", count];
missedDiscussionsBadgeLabel.text = [NSString stringWithFormat:@"%tu", missedCount];
}

[missedDiscussionsBadgeLabel sizeToFit];
Expand Down Expand Up @@ -2773,6 +2785,16 @@ - (void)refreshMissedDiscussionsCount:(BOOL)force
missedDiscussionsBarButtonCustomView.frame = bgFrame;
}

// Set the right background color
if (highlightCount)
{
missedDiscussionsBadgeLabelBgView.backgroundColor = kVectorColorPinkRed;
}
else
{
missedDiscussionsBadgeLabelBgView.backgroundColor = kVectorColorGreen;
}

if (!missedDiscussionsButton || [leftBarButtonItems indexOfObject:missedDiscussionsButton] == NSNotFound)
{
missedDiscussionsButton = [[UIBarButtonItem alloc] initWithCustomView:missedDiscussionsBarButtonCustomView];
Expand Down

0 comments on commit 26caeca

Please # to comment.