Changeset 759
- Timestamp:
- 07/25/08 10:01:39 (6 months ago)
- Location:
- trunk/TwitterFon
- Files:
-
- 9 modified
-
Classes/DB/DBConnection.m (modified) (1 diff)
-
Classes/Twitter/Message.h (modified) (2 diffs)
-
Classes/Twitter/Message.m (modified) (6 diffs)
-
Classes/Twitter/Timeline.m (modified) (2 diffs)
-
Classes/Twitter/TimelineDownloader.h (modified) (1 diff)
-
Classes/Twitter/TimelineDownloader.m (modified) (4 diffs)
-
TwitterFon.xcodeproj/project.pbxproj (modified) (1 diff)
-
create.sql (modified) (1 diff)
-
db.sql (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
trunk/TwitterFon/Classes/DB/DBConnection.m
r725 r759 27 27 "DELETE FROM images WHERE updated_at <= (SELECT updated_at FROM images order by updated_at LIMIT 1 OFFSET 1000)", 28 28 #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)" 32 32 #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)", 36 36 #endif 37 37 }; -
trunk/TwitterFon/Classes/Twitter/Message.h
r758 r759 21 21 { 22 22 sqlite_int64 messageId; 23 NSString* text; 24 User* user; 23 User* user; 24 NSString* text; 25 NSString* createdAt; 25 26 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; 31 31 32 32 UITableViewCellAccessoryType accessoryType; … … 34 34 35 35 @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; 38 39 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; 43 43 @property (nonatomic, assign) UITableViewCellAccessoryType accessoryType; 44 44 -
trunk/TwitterFon/Classes/Twitter/Message.m
r758 r759 14 14 15 15 @synthesize messageId; 16 @synthesize user; 16 17 @synthesize text; 17 @synthesize user; 18 @synthesize createdAt; 19 18 20 @synthesize unread; 19 21 @synthesize textBounds; 20 22 @synthesize cellHeight; 21 @synthesize hasURL;22 23 @synthesize accessoryType; 23 24 … … 37 38 messageId = [[dic objectForKey:@"id"] longValue]; 38 39 text = [[dic objectForKey:@"text"] copy]; 40 createdAt = [[dic objectForKey:@"created_at"] copy]; 39 41 40 42 NSDictionary* userDic = [dic objectForKey:@"user"]; … … 100 102 m.user.profileImageUrl = [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)]; 101 103 m.text = [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 5)]; 104 m.createdAt = [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 6)]; 102 105 m.unread = false; 103 106 [m updateAttribute]; … … 117 120 118 121 if (select_statement== nil) { 119 static char *sql = "SELECT id FROM timelines WHERE id=?";122 static char *sql = "SELECT id FROM messages WHERE id=?"; 120 123 if (sqlite3_prepare_v2(database, sql, -1, &select_statement, NULL) != SQLITE_OK) { 121 124 NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); … … 134 137 135 138 if (insert_statement == nil) { 136 static char *sql = "INSERT INTO timelines VALUES(?, ?, ?, ?, ?, ?)";139 static char *sql = "INSERT INTO messages VALUES(?, ?, ?, ?, ?, ?, ?)"; 137 140 if (sqlite3_prepare_v2(database, sql, -1, &insert_statement, NULL) != SQLITE_OK) { 138 141 NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); … … 145 148 sqlite3_bind_text(insert_statement, 5, [user.profileImageUrl UTF8String], -1, SQLITE_TRANSIENT); 146 149 sqlite3_bind_text(insert_statement, 6, [text UTF8String], -1, SQLITE_TRANSIENT); 150 sqlite3_bind_text(insert_statement, 7, [createdAt UTF8String], -1, SQLITE_TRANSIENT); 147 151 148 152 int success = sqlite3_step(insert_statement); -
trunk/TwitterFon/Classes/Twitter/Timeline.m
r758 r759 53 53 timelineConn = [[TimelineDownloader alloc] initWithDelegate:self]; 54 54 55 long lastMessageId = 0;56 if ([messages count] > 0) lastMessage Id = ((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]; 58 58 } 59 59 … … 63 63 64 64 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"; 66 66 if (sqlite3_prepare_v2(database, sql, -1, &select_statement, NULL) != SQLITE_OK) { 67 67 NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); -
trunk/TwitterFon/Classes/Twitter/TimelineDownloader.h
r726 r759 11 11 12 12 - (id)initWithDelegate:(NSObject*)delegate; 13 - (void)get:(MessageType)type since _id:(long)since_id;13 - (void)get:(MessageType)type since:(NSString*)since; 14 14 15 15 @end -
trunk/TwitterFon/Classes/Twitter/TimelineDownloader.m
r748 r759 48 48 } 49 49 50 - (void)get:(MessageType)aType since _id:(long)since_id50 - (void)get:(MessageType)aType since:(NSString*)since 51 51 { 52 52 [conn release]; … … 69 69 type = aType; 70 70 71 if (since_id <= 0) since_id = 1;72 73 71 NSString* url = [NSString stringWithFormat:@"https://%@:%@@twitter.com/%@.json", 74 72 username, 75 73 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 80 92 #endif 81 93 82 94 NSString *cURL = (NSString*)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)url, (CFStringRef)@"%", NULL, kCFStringEncodingUTF8); 83 95 [cURL autorelease]; 96 NSLog(@"%@", cURL); 84 97 NSURLRequest* req = [NSURLRequest requestWithURL:[NSURL URLWithString:cURL] 85 98 cachePolicy:NSURLRequestReloadIgnoringLocalCacheData … … 170 183 171 184 NSObject* obj = [s JSONValue]; 172 185 173 186 if ([obj isKindOfClass:[NSDictionary class]]) { 174 187 NSLog(@"%@", s); … … 181 194 else if ([obj isKindOfClass:[NSArray class]]) { 182 195 NSArray *ary = (NSArray*)obj; 196 NSLog(@"received %d objects", [ary count]); 183 197 if (delegate && [delegate respondsToSelector:@selector(timelineDownloaderDidSucceed:messages:)]) { 184 198 [delegate timelineDownloaderDidSucceed:self messages:ary]; -
trunk/TwitterFon/TwitterFon.xcodeproj/project.pbxproj
r754 r759 319 319 isa = PBXGroup; 320 320 children = ( 321 6EED14260E33E59B00C71EA4 /* User.h */, 322 6EED14270E33E59B00C71EA4 /* User.m */, 321 323 6EED141E0E33E59B00C71EA4 /* Message.h */, 322 324 6EED141F0E33E59B00C71EA4 /* Message.m */, 323 6EED14200E33E59B00C71EA4 /* PostTweet.h */,324 6EED14210E33E59B00C71EA4 /* PostTweet.m */,325 325 6EED14220E33E59B00C71EA4 /* Timeline.h */, 326 326 6EED14230E33E59B00C71EA4 /* Timeline.m */, 327 327 6EED14240E33E59B00C71EA4 /* TimelineDownloader.h */, 328 328 6EED14250E33E59B00C71EA4 /* TimelineDownloader.m */, 329 6EED142 60E33E59B00C71EA4 /* User.h */,330 6EED142 70E33E59B00C71EA4 /* User.m */,329 6EED14200E33E59B00C71EA4 /* PostTweet.h */, 330 6EED14210E33E59B00C71EA4 /* PostTweet.m */, 331 331 ); 332 332 path = Twitter; -
trunk/TwitterFon/create.sql
r738 r759 1 CREATE TABLE timelines (1 CREATE TABLE messages ( 2 2 'id' INTEGER PRIMARY KEY, 3 3 'type' INTEGER,
