Skip to content

Commit

Permalink
fixed post-import sorting
Browse files Browse the repository at this point in the history
Should fetch only current chat's messages. Lame.
  • Loading branch information
residentsummer committed Apr 9, 2017
1 parent 9a05ace commit 5cef4c6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions watoi/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ - (void) importMessages {
NSString *senderJID = [amsg objectForKey:@"remote_resource"];
NSManagedObject *member = [members objectForKey:senderJID];
if (member == nil) {
NSLog(@"\t not found sender %@", senderJID);
NSLog(@"\tmissing sender %@", senderJID);
member = [self addMissingMember:senderJID toChat:chatJID asAdmin:@NO];
}

Expand Down Expand Up @@ -475,9 +475,13 @@ - (void) importMessages {

// Fix sort fields for newly arrived messages
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"WAMessage"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"chatSession = %@", [chat objectID]];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"sort" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
// Newly created messages won't by fetched (as intended), see "setIncludesPendingChanges"
[fetchRequest setPredicate:predicate];
fetchRequest.includesPropertyValues = NO;
// Do not fetch unsaved messages (eg. ones we've just created)
fetchRequest.includesPendingChanges = NO;

NSError *error = nil;
NSArray *newMessages = [self.moc executeFetchRequest:fetchRequest error:&error];
Expand Down

0 comments on commit 5cef4c6

Please sign in to comment.