From 3f8c6af2927ca5532b64158517fb844ac3032e33 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 31 Jul 2006 20:16:45 +0000 Subject: [PATCH] Monotone-Parent: 0716f3b1177b2bc7db067cecbd503ead7fa1230c Monotone-Revision: 4f80f30dccff5569994ffab116a19516c7572247 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2006-07-31T20:16:45 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 9 +++++++ UI/MailerUI/UIxMailListView.m | 46 ++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 83f8aa4e2..d03708a3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2006-07-31 Wolfgang Sourdeau + * UI/MailerUI/UIxMailListView.m ([UIxMailListView + -defaultAction]): if the "pageforuid" parameter is passed in the + url, take its value and invoke [self firstMessageOfPageFor:] + consequently to deduce the first message to display. Otherwise, + set it to "idx", otherwise set it to 0. + ([UIxMailListView -firstMessageOfPageFor:]): new method + that determines the first message of the page where the message + passed as parameter is contained. + * UI/WebServerResources/UIxMailListView.js: removed this module, its code was put in MailerUI.js instead. diff --git a/UI/MailerUI/UIxMailListView.m b/UI/MailerUI/UIxMailListView.m index fb5dcaf6b..66adde3d9 100644 --- a/UI/MailerUI/UIxMailListView.m +++ b/UI/MailerUI/UIxMailListView.m @@ -26,6 +26,8 @@ object. */ +#define messagesPerPage 50 + #include "common.h" #include #include @@ -169,6 +171,7 @@ static int attachmentFlagSize = 8096; { return @"DATE"; } + - (NSString *) imap4SortKey { NSString *sort; @@ -203,8 +206,8 @@ static int attachmentFlagSize = 8096; - (NSRange) fetchRange { if (self->firstMessageNumber == 0) - return NSMakeRange(0, 50); - return NSMakeRange(self->firstMessageNumber - 1, 50); + return NSMakeRange(0, messagesPerPage); + return NSMakeRange(self->firstMessageNumber - 1, messagesPerPage); } - (NSArray *) sortedUIDs @@ -215,6 +218,7 @@ static int attachmentFlagSize = 8096; self->sortedUIDs = [[[self clientObject] fetchUIDsMatchingQualifier:[self qualifier] sortOrdering:[self imap4SortOrdering]] retain]; + return self->sortedUIDs; } @@ -255,10 +259,12 @@ static int attachmentFlagSize = 8096; r.length = len - r.location; return r; } + - (unsigned int) firstMessageNumber { return [self fetchBlock].location + 1; } + - (unsigned int) lastMessageNumber { NSRange r; @@ -266,10 +272,12 @@ static int attachmentFlagSize = 8096; r = [self fetchBlock]; return r.location + r.length; } + - (BOOL) hasPrevious { return [self fetchBlock].location == 0 ? NO : YES; } + - (BOOL) hasNext { NSRange r = [self fetchBlock]; @@ -280,6 +288,7 @@ static int attachmentFlagSize = 8096; { return [self firstMessageNumber] + [self fetchRange].length; } + - (unsigned int) prevFirstMessageNumber { NSRange r; @@ -457,10 +466,35 @@ static int attachmentFlagSize = 8096; return r; } +- (int) firstMessageOfPageFor: (int) messageNbr +{ + NSArray *messageNbrs; + int nbrInArray; + int firstMessage; + + messageNbrs = [self sortedUIDs]; + nbrInArray + = [messageNbrs indexOfObject: [NSNumber numberWithInt: messageNbr]]; + if (nbrInArray > -1) + firstMessage = ((int) (nbrInArray / messagesPerPage) + * messagesPerPage) + 1; + else + firstMessage = 1; + + return firstMessage; +} + - (id) defaultAction { - self->firstMessageNumber = - [[[[self context] request] formValueForKey:@"idx"] intValue]; + WORequest *request; + NSValue *specificMessage; + + request = [[self context] request]; + specificMessage = [request formValueForKey: @"pageforuid"]; + self->firstMessageNumber + = ((specificMessage) + ? [self firstMessageOfPageFor: [specificMessage intValue]] + : [[request formValueForKey:@"idx"] intValue]); return self; } @@ -502,7 +536,7 @@ static int attachmentFlagSize = 8096; { // TODO: we might want to flush the caches? id client; - + if ((client = [self clientObject]) == nil) { return [NSException exceptionWithHTTPStatus:404 /* Not Found */ reason:@"did not find mail folder"]; @@ -510,7 +544,7 @@ static int attachmentFlagSize = 8096; if (![client respondsToSelector:@selector(flushMailCaches) ]) { - return [NSException exceptionWithHTTPStatus:500 /* Server Error */ + return [NSException exceptionWithHTTPStatus: 500 /* Server Error */ reason: @"invalid client object (does not support flush)"]; }