Skip to content

Commit

Permalink
#84 fixed unread count
Browse files Browse the repository at this point in the history
  • Loading branch information
devashishmamgain committed Nov 30, 2015
1 parent 9d60ebd commit 7d35a32
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ -(void) updateDeliveryReports:(NSMutableArray *) messages

-(void) updateDeliveryReport: (NSString *) key
{

NSLog(@"updating delivery report for: %@", key);
NSString * theUrlString = [NSString stringWithFormat:@"%@/rest/ws/message/delivered",KBASE_URL];
NSString *theParamString=[NSString stringWithFormat:@"userId=%@&key=%@",[ALUserDefaultsHandler getUserId],key];

Expand Down
13 changes: 7 additions & 6 deletions sample-with-framework/Applozic/Applozic/ALMessageDBService.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ - (NSManagedObject *)getMessageByKey:(NSString *) key value:(NSString*) value{

-(NSUInteger)markConversationAsRead:(NSString *) contactId
{
NSArray *messages = [self getUnreadMessages:contactId];
NSArray *messages = [self getUnreadMessages:contactId];

ALDBHandler * dbHandler = [ALDBHandler sharedInstance];

Expand All @@ -230,9 +230,8 @@ -(NSUInteger)markConversationAsRead:(NSString *) contactId

if ( [dbHandler.managedObjectContext save:&error])
{
NSLog(@"message found and maked as deliverd");
NSLog(@"message found and marked as read.");
}

}
return messages.count;
}
Expand All @@ -256,8 +255,10 @@ - (NSArray *)getUnreadMessages:(NSString *) contactId
[fetchRequest setPredicate:predicate];
NSError *fetchError = nil;
NSArray *result = [dbHandler.managedObjectContext executeFetchRequest:fetchRequest error:&fetchError];
//NSLog(@"the fetch request %@",fetchRequest);
// NSLog(@"COUNT VALUE: %lu", result.count);
if ([contactId isEqualToString:@"applozic"]) {
NSLog(@"the fetch request %@",fetchRequest);
NSLog(@"COUNT VALUE: %lu", result.count);
}
return result;
}

Expand Down Expand Up @@ -374,7 +375,7 @@ -(DB_Message *) createMessageEntityForDBInsertionWithMessage:(ALMessage *) theMe
theMessageEntity.contactId = theMessage.contactIds;
theMessageEntity.createdAt = [NSNumber numberWithInteger:theMessage.createdAtTime.integerValue];
theMessageEntity.deviceKey = theMessage.deviceKey;
theMessageEntity.isRead = [NSNumber numberWithBool:theMessage.read];
theMessageEntity.isRead = [NSNumber numberWithBool:([theMessageEntity.type isEqualToString:@"5"] ? TRUE : theMessage.read)];
theMessageEntity.isSent = [NSNumber numberWithBool:theMessage.sent];
theMessageEntity.isSentToDevice = [NSNumber numberWithBool:theMessage.sendToDevice];
theMessageEntity.isShared = [NSNumber numberWithBool:theMessage.shared];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ +(void) getMessagesListGroupByContactswithCompletion:(void(^)(NSMutableArray * m

NSString * theUrlString = [NSString stringWithFormat:@"%@/rest/ws/message/list",KBASE_URL];


NSString * theParamString = [NSString stringWithFormat:@"startIndex=%@",@"0"];

NSMutableURLRequest * theRequest = [ALRequestHandler createGETRequestWithUrlString:theUrlString paramString:theParamString];
Expand Down Expand Up @@ -121,7 +120,7 @@ +(void) sendMessages:(ALMessage *)alMessage withCompletion:(void(^)(NSString * m
dbMessage.createdAt =response.createdAt;
alMessage.key = dbMessage.key;
dbMessage.sentToServer=[NSNumber numberWithBool:YES];
dbMessage.isRead=[NSNumber numberWithBool:YES]; NSLog(@"dbMessage.isRead %@",dbMessage.isRead);
dbMessage.isRead=[NSNumber numberWithBool:YES];

alMessage.key = dbMessage.key;
alMessage.sentToServer= dbMessage.sentToServer.boolValue;
Expand Down Expand Up @@ -330,6 +329,7 @@ +(void)markConversationAsRead: (NSString *) contactId withCompletion:(void (^)(N
ALMessageDBService * dbService = [[ALMessageDBService alloc]init];

NSUInteger count = [dbService markConversationAsRead:contactId];
NSLog(@"Found %ld messages for marking as read.", count);

if(count == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ - (void)viewDidLoad {

-(void)processMarkRead{
[ALMessageService markConversationAsRead: self.contactIds withCompletion:^(NSString* string,NSError* error){
if(!error ){
NSLog(@"No Error");
if(!error) {
NSLog(@"Marked messages as read for %@", self.contactIds);
}
else{
NSLog(@"some error");
else {
NSLog(@"Error while marking messages as read.");
}
}];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ -(void)viewWillAppear:(BOOL)animated {
[self.navBar setLeftBarButtonItems:nil];
}

self.detailChatViewController.contactIds = nil;

[self.tabBarController.tabBar setHidden: [ALUserDefaultsHandler isBottomTabBarHidden]];

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
Expand Down Expand Up @@ -175,9 +177,9 @@ -(void)setUpView {

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1){
self.navColor = [self.navigationController.navigationBar tintColor];
} else{
} else {
self.navColor = [self.navigationController.navigationBar barTintColor];
}
}
self.colors=[[NSArray alloc] initWithObjects:@"#617D8A",@"#628B70",@"#8C8863",@"8B627D",@"8B6F62", nil];
}

Expand Down Expand Up @@ -251,6 +253,7 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS

ALMessageDBService* messageDBService = [[ALMessageDBService alloc]init];
self.unreadCount=[messageDBService getUnreadMessages:[alContact userId]];
NSLog(@"unread count for userId: %@ is %ld", [alContact userId], (unsigned long)self.unreadCount.count);

// NSLog(@"self.unreadCount Array of ||%@|| withCount ||%lu|| is %@",[alContact userId],(unsigned long)self.unreadCount.count,self.unreadCount);

Expand All @@ -262,9 +265,6 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
contactCell.mCountImageView.hidden=TRUE;
}




contactCell.mUserImageView.hidden=FALSE;
contactCell.mUserImageView.layer.cornerRadius=contactCell.mUserImageView.frame.size.width/2;
contactCell.mCountImageView.layer.cornerRadius=contactCell.mCountImageView.frame.size.width/2;
Expand Down

0 comments on commit 7d35a32

Please sign in to comment.