Changeset 759

Show
Ignore:
Timestamp:
07/25/08 10:01:39 (6 months ago)
Author:
kaz
Message:

Fixed #139

  • Added since parameter to timeline request
  • Rename database table name (timelines -> messages) then added created_at column
Location:
trunk/TwitterFon
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/TwitterFon/Classes/DB/DBConnection.m

    r725 r759  
    2727    "DELETE FROM images WHERE updated_at <= (SELECT updated_at FROM images order by updated_at LIMIT 1 OFFSET 1000)", 
    2828#if 1 
    29     "DELETE FROM timelines WHERE type = 0 and id <= (SELECT id FROM timelines WHERE type = 0 ORDER BY id DESC LIMIT 1 OFFSET 40)", 
    30     "DELETE FROM timelines WHERE type = 1 and id <= (SELECT id FROM timelines WHERE type = 1 ORDER BY id DESC LIMIT 1 OFFSET 40)", 
    31     "DELETE FROM timelines WHERE type = 2 and id <= (SELECT id FROM timelines WHERE type = 2 ORDER BY id DESC LIMIT 1 OFFSET 40)" 
     29    "DELETE FROM messages WHERE type = 0 and id <= (SELECT id FROM messages WHERE type = 0 ORDER BY id DESC LIMIT 1 OFFSET 40)", 
     30    "DELETE FROM messages WHERE type = 1 and id <= (SELECT id FROM messages WHERE type = 1 ORDER BY id DESC LIMIT 1 OFFSET 40)", 
     31    "DELETE FROM messages WHERE type = 2 and id <= (SELECT id FROM messages WHERE type = 2 ORDER BY id DESC LIMIT 1 OFFSET 40)" 
    3232#else 
    33     "DELETE FROM timelines WHERE type = 0 and id >= (SELECT id FROM timelines WHERE type = 0 ORDER BY id DESC LIMIT 1 OFFSET 5)", 
    34     "DELETE FROM timelines WHERE type = 1 and id >= (SELECT id FROM timelines WHERE type = 1 ORDER BY id DESC LIMIT 1 OFFSET 5)", 
    35     "DELETE FROM timelines WHERE type = 2 and id >= (SELECT id FROM timelines WHERE type = 2 ORDER BY id DESC LIMIT 1 OFFSET 5)", 
     33    "DELETE FROM messages WHERE type = 0 and id >= (SELECT id FROM messages WHERE type = 0 ORDER BY id DESC LIMIT 1 OFFSET 5)", 
     34    "DELETE FROM messages WHERE type = 1 and id >= (SELECT id FROM messages WHERE type = 1 ORDER BY id DESC LIMIT 1 OFFSET 5)", 
     35    "DELETE FROM messages WHERE type = 2 and id >= (SELECT id FROM messages WHERE type = 2 ORDER BY id DESC LIMIT 1 OFFSET 5)", 
    3636#endif 
    3737}; 
  • trunk/TwitterFon/Classes/Twitter/Message.h

    r758 r759  
    2121{ 
    2222        sqlite_int64    messageId; 
    23         NSString*   text; 
    24         User*       user; 
     23        User*           user; 
     24        NSString*       text; 
     25    NSString*       createdAt; 
    2526 
    26     BOOL        unread; 
    27     MessageType type; 
    28     BOOL        hasURL; 
    29     CGRect      textBounds; 
    30     CGFloat     cellHeight; 
     27    BOOL            unread; 
     28    MessageType     type; 
     29    CGRect          textBounds; 
     30    CGFloat         cellHeight; 
    3131     
    3232    UITableViewCellAccessoryType accessoryType; 
     
    3434 
    3535@property (nonatomic, assign) sqlite_int64  messageId; 
    36 @property (nonatomic, assign) User*     user; 
    37 @property (nonatomic, copy)   NSString* text; 
     36@property (nonatomic, assign) User*         user; 
     37@property (nonatomic, copy)   NSString*     text; 
     38@property (nonatomic, copy)   NSString*     createdAt; 
    3839 
    39 @property (nonatomic, assign) BOOL      unread; 
    40 @property (nonatomic, assign) BOOL      hasURL; 
    41 @property (nonatomic, assign) CGRect    textBounds; 
    42 @property (nonatomic, assign) CGFloat   cellHeight; 
     40@property (nonatomic, assign) BOOL          unread; 
     41@property (nonatomic, assign) CGRect        textBounds; 
     42@property (nonatomic, assign) CGFloat       cellHeight; 
    4343@property (nonatomic, assign) UITableViewCellAccessoryType accessoryType; 
    4444 
  • trunk/TwitterFon/Classes/Twitter/Message.m

    r758 r759  
    1414 
    1515@synthesize messageId; 
     16@synthesize user; 
    1617@synthesize text; 
    17 @synthesize user; 
     18@synthesize createdAt; 
     19 
    1820@synthesize unread; 
    1921@synthesize textBounds; 
    2022@synthesize cellHeight; 
    21 @synthesize hasURL; 
    2223@synthesize accessoryType; 
    2324 
     
    3738        messageId = [[dic objectForKey:@"id"] longValue]; 
    3839        text      = [[dic objectForKey:@"text"] copy]; 
     40    createdAt = [[dic objectForKey:@"created_at"] copy]; 
    3941         
    4042        NSDictionary* userDic = [dic objectForKey:@"user"]; 
     
    100102    m.user.profileImageUrl  = [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)]; 
    101103    m.text                  = [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 5)]; 
     104    m.createdAt             = [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 6)]; 
    102105    m.unread = false; 
    103106    [m updateAttribute]; 
     
    117120 
    118121    if (select_statement== nil) { 
    119         static char *sql = "SELECT id FROM timelines WHERE id=?"; 
     122        static char *sql = "SELECT id FROM messages WHERE id=?"; 
    120123        if (sqlite3_prepare_v2(database, sql, -1, &select_statement, NULL) != SQLITE_OK) { 
    121124            NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); 
     
    134137     
    135138    if (insert_statement == nil) { 
    136         static char *sql = "INSERT INTO timelines VALUES(?, ?, ?, ?, ?, ?)"; 
     139        static char *sql = "INSERT INTO messages VALUES(?, ?, ?, ?, ?, ?, ?)"; 
    137140        if (sqlite3_prepare_v2(database, sql, -1, &insert_statement, NULL) != SQLITE_OK) { 
    138141            NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); 
     
    145148    sqlite3_bind_text(insert_statement, 5, [user.profileImageUrl UTF8String], -1, SQLITE_TRANSIENT); 
    146149    sqlite3_bind_text(insert_statement, 6, [text UTF8String], -1, SQLITE_TRANSIENT); 
     150    sqlite3_bind_text(insert_statement, 7, [createdAt UTF8String], -1, SQLITE_TRANSIENT); 
    147151     
    148152    int success = sqlite3_step(insert_statement); 
  • trunk/TwitterFon/Classes/Twitter/Timeline.m

    r758 r759  
    5353        timelineConn = [[TimelineDownloader alloc] initWithDelegate:self]; 
    5454 
    55         long lastMessageId = 0; 
    56         if ([messages count] > 0) lastMessageId = ((Message*)[messages lastObject]).messageId;     
    57         [timelineConn get:type since_id:lastMessageId]; 
     55        NSString* lastMessageDate = nil; 
     56        if ([messages count] > 0) lastMessageDate = ((Message*)[messages lastObject]).createdAt;     
     57        [timelineConn get:type since:lastMessageDate]; 
    5858} 
    5959 
     
    6363 
    6464    if (select_statement== nil) { 
    65         static char *sql = "SELECT * FROM timelines WHERE type = ? order BY id limit 40"; 
     65        static char *sql = "SELECT * FROM messages WHERE type = ? order BY id limit 40"; 
    6666        if (sqlite3_prepare_v2(database, sql, -1, &select_statement, NULL) != SQLITE_OK) { 
    6767            NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); 
  • trunk/TwitterFon/Classes/Twitter/TimelineDownloader.h

    r726 r759  
    1111 
    1212- (id)initWithDelegate:(NSObject*)delegate; 
    13 - (void)get:(MessageType)type since_id:(long)since_id; 
     13- (void)get:(MessageType)type since:(NSString*)since; 
    1414 
    1515@end 
  • trunk/TwitterFon/Classes/Twitter/TimelineDownloader.m

    r748 r759  
    4848} 
    4949 
    50 - (void)get:(MessageType)aType since_id:(long)since_id 
     50- (void)get:(MessageType)aType since:(NSString*)since 
    5151{ 
    5252        [conn release]; 
     
    6969    type = aType; 
    7070     
    71     if (since_id <= 0) since_id = 1; 
    72  
    7371        NSString* url = [NSString stringWithFormat:@"https://%@:%@@twitter.com/%@.json", 
    7472                     username, 
    7573                     password, 
    76                      sMethods[type], 
    77                      since_id]; 
    78  
    79     NSLog(@"%@", url); 
     74                     sMethods[type]]; 
     75 
     76    // 
     77    // Convert MySQL date format to HTTP date 
     78    // 
     79    if (since) { 
     80        NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] 
     81                                           initWithDateFormat:@"%a %b %d %H:%M:%S %z %Y" 
     82                                           allowNaturalLanguage:NO] autorelease]; 
     83        NSDate *date = [dateFormatter dateFromString:since]; 
     84         
     85        NSTimeZone *tz = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; 
     86        NSString* since_param = [date descriptionWithCalendarFormat:@"%a, %d %b %Y %H:%M:%S GMT"  
     87                                                           timeZone:tz  
     88                                                             locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]; 
     89        url = [NSString stringWithFormat:@"%@?since=%@", url, since_param]; 
     90    } 
     91 
    8092#endif 
    8193 
    8294    NSString *cURL = (NSString*)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)url, (CFStringRef)@"%", NULL, kCFStringEncodingUTF8); 
    8395    [cURL autorelease]; 
     96    NSLog(@"%@", cURL); 
    8497        NSURLRequest* req = [NSURLRequest requestWithURL:[NSURL URLWithString:cURL] 
    8598                                      cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 
     
    170183         
    171184        NSObject* obj = [s JSONValue]; 
    172  
     185     
    173186    if ([obj isKindOfClass:[NSDictionary class]]) { 
    174187        NSLog(@"%@", s); 
     
    181194    else if ([obj isKindOfClass:[NSArray class]]) { 
    182195        NSArray *ary = (NSArray*)obj; 
     196        NSLog(@"received %d objects", [ary count]); 
    183197        if (delegate && [delegate respondsToSelector:@selector(timelineDownloaderDidSucceed:messages:)]) { 
    184198            [delegate timelineDownloaderDidSucceed:self messages:ary]; 
  • trunk/TwitterFon/TwitterFon.xcodeproj/project.pbxproj

    r754 r759  
    319319                        isa = PBXGroup; 
    320320                        children = ( 
     321                                6EED14260E33E59B00C71EA4 /* User.h */, 
     322                                6EED14270E33E59B00C71EA4 /* User.m */, 
    321323                                6EED141E0E33E59B00C71EA4 /* Message.h */, 
    322324                                6EED141F0E33E59B00C71EA4 /* Message.m */, 
    323                                 6EED14200E33E59B00C71EA4 /* PostTweet.h */, 
    324                                 6EED14210E33E59B00C71EA4 /* PostTweet.m */, 
    325325                                6EED14220E33E59B00C71EA4 /* Timeline.h */, 
    326326                                6EED14230E33E59B00C71EA4 /* Timeline.m */, 
    327327                                6EED14240E33E59B00C71EA4 /* TimelineDownloader.h */, 
    328328                                6EED14250E33E59B00C71EA4 /* TimelineDownloader.m */, 
    329                                 6EED14260E33E59B00C71EA4 /* User.h */, 
    330                                 6EED14270E33E59B00C71EA4 /* User.m */, 
     329                                6EED14200E33E59B00C71EA4 /* PostTweet.h */, 
     330                                6EED14210E33E59B00C71EA4 /* PostTweet.m */, 
    331331                        ); 
    332332                        path = Twitter; 
  • trunk/TwitterFon/create.sql

    r738 r759  
    1 CREATE TABLE timelines ( 
     1CREATE TABLE messages ( 
    22       'id'                     INTEGER PRIMARY KEY, 
    33       'type'                   INTEGER,