Skip to content

Commit

Permalink
Show an unread count for private messages and room highligts in the t…
Browse files Browse the repository at this point in the history
…ab bar and Colloquies back button.

git-svn-id: http://source.colloquy.info/svn/trunk@3898 cc480944-b4dd-0310-b5e3-89908df9b951
  • Loading branch information
kijiro committed Dec 16, 2008
1 parent 188068c commit 43640ca
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Mobile/Controllers/CQChatController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
id <CQChatViewController> _nextController;
NSString *_nextRoomName;
MVChatConnection *_nextRoomConnection;
NSInteger _totalImportantUnreadCount;
BOOL _active;
}
+ (CQChatController *) defaultController;

@property (nonatomic, readonly) NSArray *chatViewControllers;

@property (nonatomic) NSInteger totalImportantUnreadCount;

- (void) showNewChatActionSheet;
- (void) showChatControllerWhenAvailableForRoomNamed:(NSString *) room andConnection:(MVChatConnection *) connection;
- (void) showChatController:(id <CQChatViewController>) controller animated:(BOOL) animated;
Expand Down
42 changes: 42 additions & 0 deletions Mobile/Controllers/CQChatController.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ - (void) viewDidLoad {
[self pushViewController:_chatListViewController animated:NO];
}

- (void) viewWillAppear:(BOOL) animated {
[super viewWillAppear:animated];

self.totalImportantUnreadCount = 0;

_active = YES;
}

- (void) viewWillDisappear:(BOOL) animated {
[super viewWillDisappear:animated];

_active = NO;
}

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
// This should support UIDeviceOrientationLandscapeLeft too, but convertPoint: returns bad results in that orientation.
return (interfaceOrientation == UIDeviceOrientationPortrait || interfaceOrientation == UIDeviceOrientationLandscapeRight);
Expand Down Expand Up @@ -150,6 +164,29 @@ - (void) _gotDirectChatMessage:(NSNotification *) notification {

#pragma mark -

- (NSInteger) totalImportantUnreadCount {
return _totalImportantUnreadCount;
}

- (void) setTotalImportantUnreadCount:(NSInteger) count {
if (_active && self.visibleViewController == _chatListViewController)
return;

if (count < 0) count = 0;

_totalImportantUnreadCount = count;

if (_totalImportantUnreadCount) {
_chatListViewController.navigationItem.title = [NSString stringWithFormat:NSLocalizedString(@"%@ (%u)", @"Unread count view title, uses the view's normal title with a number"), self.title, _totalImportantUnreadCount];
self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%u", _totalImportantUnreadCount];
} else {
_chatListViewController.navigationItem.title = self.title;
self.tabBarItem.badgeValue = nil;
}
}

#pragma mark -

- (void) showNewChatActionSheet {
UIActionSheet *sheet = [[UIActionSheet alloc] init];
sheet.delegate = self;
Expand Down Expand Up @@ -220,6 +257,11 @@ - (void) showNextChatController {
_nextController = nil;
}

- (void) navigationController:(UINavigationController *) navigationController willShowViewController:(UIViewController *) viewController animated:(BOOL) animated {
if (viewController == _chatListViewController)
self.totalImportantUnreadCount = 0;
}

- (void) navigationController:(UINavigationController *) navigationController didShowViewController:(UIViewController *) viewController animated:(BOOL) animated {
if (viewController == _chatListViewController && _nextController)
[self performSelector:@selector(showNextChatController) withObject:nil afterDelay:0.33];
Expand Down
15 changes: 13 additions & 2 deletions Mobile/Controllers/CQDirectChatController.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ - (void) viewDidAppear:(BOOL) animated {

[transcriptView flashScrollIndicators];

if (_unreadHighlightedMessages)
[CQChatController defaultController].totalImportantUnreadCount -= _unreadHighlightedMessages;

if (_unreadMessages && self.user)
[CQChatController defaultController].totalImportantUnreadCount -= _unreadMessages;

_unreadMessages = 0;
_unreadHighlightedMessages = 0;
_active = YES;
Expand Down Expand Up @@ -259,8 +265,10 @@ - (NSArray *) highlightWordsForTranscriptView:(CQChatTranscriptView *) transcrip
}

- (void) transcriptView:(CQChatTranscriptView *) transcriptView highlightedMessageWithWord:(NSString *) highlightWord {
if (!_active)
if (!_active) {
++_unreadHighlightedMessages;
++[CQChatController defaultController].totalImportantUnreadCount;
}
}

#pragma mark -
Expand Down Expand Up @@ -372,8 +380,11 @@ - (void) addMessage:(NSDictionary *) info {
MVChatUser *user = [info objectForKey:@"user"];

if (!user.localUser) {
if (!_active)
if (!_active) {
++_unreadMessages;
if (self.user)
++[CQChatController defaultController].totalImportantUnreadCount;
}

[_recentMessages addObject:info];
if (_recentMessages.count > 5)
Expand Down

0 comments on commit 43640ca

Please sign in to comment.