-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
997 additions
and
748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface DeletedMessagesManager : NSObject | ||
|
||
/// Singleton instance | ||
+ (instancetype)sharedManager; | ||
|
||
/// Save a message ID with the current date | ||
- (void)saveDeletedMessageWithID:(NSString *)messageID; | ||
|
||
/// Check if a message ID exists | ||
- (BOOL)messageExistsWithID:(NSString *)messageID; | ||
|
||
- (NSString *)dateForDeletedMessageWithID:(NSString *)messageID; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#import "DeletedMessagesManager.h" | ||
|
||
@implementation DeletedMessagesManager | ||
|
||
NSString *const plistFileName = @"deleted_messages.plist"; | ||
|
||
+ (instancetype)sharedManager { | ||
static DeletedMessagesManager *sharedInstance = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
sharedInstance = [[self alloc] init]; | ||
}); | ||
return sharedInstance; | ||
} | ||
|
||
- (NSString *)plistPath { | ||
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; | ||
return [documentsDirectory stringByAppendingPathComponent:plistFileName]; | ||
} | ||
|
||
- (NSMutableDictionary *)loadPlistData { | ||
NSString *path = [self plistPath]; | ||
NSMutableDictionary *data = [NSMutableDictionary dictionaryWithContentsOfFile:path]; | ||
if (!data) { | ||
data = [NSMutableDictionary dictionary]; | ||
} | ||
return data; | ||
} | ||
|
||
- (void)savePlistData:(NSDictionary *)data { | ||
NSString *path = [self plistPath]; | ||
[data writeToFile:path atomically:YES]; | ||
} | ||
|
||
- (void)saveDeletedMessageWithID:(NSString *)messageID { | ||
if (messageID.length == 0) { | ||
NSLog(@"Message ID cannot be empty."); | ||
return; | ||
} | ||
|
||
NSMutableDictionary *plistData = [self loadPlistData]; | ||
NSString *currentDate = [[NSDate date] description]; | ||
plistData[messageID] = currentDate; | ||
[self savePlistData:plistData]; | ||
|
||
NSLog(@"Saved message ID: %@ with date: %@", messageID, currentDate); | ||
} | ||
|
||
- (BOOL)messageExistsWithID:(NSString *)messageID { | ||
if (messageID.length == 0) { | ||
NSLog(@"Message ID cannot be empty."); | ||
return NO; | ||
} | ||
|
||
NSMutableDictionary *plistData = [self loadPlistData]; | ||
return plistData[messageID] != nil; | ||
} | ||
|
||
- (NSString *)dateForDeletedMessageWithID:(NSString *)messageID { | ||
if (messageID.length == 0) { | ||
NSLog(@"Message ID cannot be empty."); | ||
return nil; | ||
} | ||
|
||
NSMutableDictionary *plistData = [self loadPlistData]; | ||
return plistData[messageID]; | ||
} | ||
@end |
Oops, something went wrong.