Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3383997
D4393.id14470.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D4393.id14470.diff
View Options
diff --git a/native/ios/Comm/TemporaryMessageStorage/TemporaryMessageStorage.mm b/native/ios/Comm/TemporaryMessageStorage/TemporaryMessageStorage.mm
--- a/native/ios/Comm/TemporaryMessageStorage/TemporaryMessageStorage.mm
+++ b/native/ios/Comm/TemporaryMessageStorage/TemporaryMessageStorage.mm
@@ -46,6 +46,61 @@
return self;
}
+- (void)writeMessage:(NSString *)message {
+ NSArray<NSString *> *storageContent =
+ [NSFileManager.defaultManager contentsOfDirectoryAtPath:self.directoryPath
+ error:nil];
+ if (!storageContent) {
+ comm::Logger::log("Storage not existing yet. Skipping notification");
+ return;
+ }
+
+ NSString *currentFileName = nil;
+ if (storageContent.count) {
+ currentFileName =
+ [storageContent sortedArrayUsingSelector:@selector(compare:)]
+ .lastObject;
+ } else if (!(currentFileName = [self _createNewStorage])) {
+ comm::Logger::log(
+ "Failed to create new storage file. Details: " +
+ std::string(strerror(errno)));
+ }
+
+ NSString *currentFilePath = [self _getPath:currentFileName];
+ NSString *lockName = [self _getLockName:currentFileName];
+ NonBlockingLock *lock = [[NonBlockingLock alloc] initWithName:lockName];
+
+ NSError *lockError = nil;
+ NSError *writeError = nil;
+
+ @try {
+ if (![lock tryAcquireLock:&lockError]) {
+ NSString *randomPath =
+ [self.directoryURL
+ URLByAppendingPathComponent:[NSUUID UUID].UUIDString]
+ .path;
+ [EncryptedFileUtils writeData:message toFileAtPath:randomPath error:nil];
+ comm::Logger::log(
+ "Failed to acquire lock. Details: " +
+ std::string([lockError.localizedDescription UTF8String]) +
+ " Persisting notification at path: " +
+ std::string([randomPath UTF8String]));
+ return;
+ }
+ [EncryptedFileUtils appendData:message
+ toFileAtPath:currentFilePath
+ error:&writeError];
+ } @finally {
+ [lock releaseLock:&lockError];
+ }
+
+ if (writeError) {
+ comm::Logger::log(
+ "Failed to append message to storage. Details: " +
+ std::string([writeError.localizedDescription UTF8String]));
+ }
+}
+
- (NSString *)_createNewStorage {
int64_t timestamp = (int64_t)[NSDate date].timeIntervalSince1970;
NSString *newStorageName = [NSString stringWithFormat:@"msg_%lld", timestamp];
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 6:51 PM (21 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2597727
Default Alt Text
D4393.id14470.diff (2 KB)
Attached To
Mode
D4393: Implement write operation for flat-file based message storage
Attached
Detach File
Event Timeline
Log In to Comment