diff --git a/MatrixSDK/Background/MXBackgroundStore.swift b/MatrixSDK/Background/MXBackgroundStore.swift index 6c27fc5e5d..8fa0da0d71 100644 --- a/MatrixSDK/Background/MXBackgroundStore.swift +++ b/MatrixSDK/Background/MXBackgroundStore.swift @@ -200,13 +200,22 @@ class MXBackgroundStore: NSObject, MXStore { func deleteGroup(_ groupId: String) { } - + + @available(*, deprecated, message: "use storePartialAttributedTextMessage") func storePartialTextMessage(forRoom roomId: String, partialTextMessage: String) { } - + + @available(*, deprecated, message: "use partialAttributedTextMessage") func partialTextMessage(ofRoom roomId: String) -> String? { return nil } + + func storePartialAttributedTextMessage(forRoom roomId: String, partialAttributedTextMessage: NSAttributedString) { + } + + func partialAttributedTextMessage(ofRoom roomId: String) -> NSAttributedString? { + return nil + } func getEventReceipts(_ roomId: String, eventId: String, sorted sort: Bool, completion: @escaping ([MXReceiptData]) -> Void) { DispatchQueue.main.async { diff --git a/MatrixSDK/Data/MXRoom.h b/MatrixSDK/Data/MXRoom.h index bc8911d773..abc12cde89 100644 --- a/MatrixSDK/Data/MXRoom.h +++ b/MatrixSDK/Data/MXRoom.h @@ -158,13 +158,22 @@ FOUNDATION_EXPORT NSInteger const kMXRoomInvalidInviteSenderErrorCode; success:(void (^)(void))success failure:(void (^)(NSError *))failure NS_REFINED_FOR_SWIFT; +/** + The text message partially typed by the user but not yet sent. + The value is stored by the session store. Thus, it can be retrieved + when the application restarts. + + @deprecated use partialAttributedTextMessage + */ +@property (nonatomic) NSString *partialTextMessage __deprecated_msg("use partialAttributedTextMessage"); + /** The text message partially typed by the user but not yet sent. The value is stored by the session store. Thus, it can be retrieved when the application restarts. */ // @TODO(summary): Move to MXRoomSummary -@property (nonatomic) NSString *partialTextMessage; +@property (nonatomic) NSAttributedString *partialAttributedTextMessage; /** The list of ids of users currently typing in this room. diff --git a/MatrixSDK/Data/MXRoom.m b/MatrixSDK/Data/MXRoom.m index 067138ca68..85eec94fcd 100644 --- a/MatrixSDK/Data/MXRoom.m +++ b/MatrixSDK/Data/MXRoom.m @@ -390,6 +390,16 @@ - (NSString *)partialTextMessage return [mxSession.store partialTextMessageOfRoom:self.roomId]; } +- (void)setPartialAttributedTextMessage:(NSAttributedString *)partialAttributedTextMessage +{ + [mxSession.store storePartialAttributedTextMessageForRoom:self.roomId partialAttributedTextMessage:partialAttributedTextMessage]; +} + +- (NSAttributedString *)partialAttributedTextMessage +{ + return [mxSession.store partialAttributedTextMessageOfRoom:self.roomId]; +} + #pragma mark - Sync - (void)handleJoinedRoomSync:(MXRoomSync *)roomSync onComplete:(void (^)(void))onComplete diff --git a/MatrixSDK/Data/Store/MXFileStore/MXFileRoomStore.m b/MatrixSDK/Data/Store/MXFileStore/MXFileRoomStore.m index 1f5151c378..4ce33ed88a 100644 --- a/MatrixSDK/Data/Store/MXFileStore/MXFileRoomStore.m +++ b/MatrixSDK/Data/Store/MXFileStore/MXFileRoomStore.m @@ -34,6 +34,8 @@ - (id)initWithCoder:(NSCoder *)aDecoder self.partialTextMessage = [aDecoder decodeObjectForKey:@"partialTextMessage"]; + self.partialAttributedTextMessage = [aDecoder decodeObjectForKey:@"partialAttributedTextMessage"]; + // Rebuild the messagesByEventIds cache for (MXEvent *event in messages) { @@ -69,6 +71,10 @@ - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:self.partialTextMessage forKey:@"partialTextMessage"]; } + if (self.partialAttributedTextMessage) + { + [aCoder encodeObject:self.partialAttributedTextMessage forKey:@"partialAttributedTextMessage"]; + } } @end diff --git a/MatrixSDK/Data/Store/MXFileStore/MXFileStore.m b/MatrixSDK/Data/Store/MXFileStore/MXFileStore.m index 9c9755f3fa..2ddff9e428 100644 --- a/MatrixSDK/Data/Store/MXFileStore/MXFileStore.m +++ b/MatrixSDK/Data/Store/MXFileStore/MXFileStore.m @@ -450,6 +450,16 @@ - (void)storePartialTextMessageForRoom:(NSString *)roomId partialTextMessage:(NS } } +- (void)storePartialAttributedTextMessageForRoom:(NSString *)roomId partialAttributedTextMessage:(NSAttributedString *)partialAttributedTextMessage +{ + [super storePartialAttributedTextMessageForRoom:roomId partialAttributedTextMessage:partialAttributedTextMessage]; + + if (NSNotFound == [roomsToCommitForMessages indexOfObject:roomId]) + { + [roomsToCommitForMessages addObject:roomId]; + } +} + - (void)storeHasLoadedAllRoomMembersForRoom:(NSString *)roomId andValue:(BOOL)value { // XXX: To remove once https://github.com/vector-im/element-ios/issues/3807 is fixed diff --git a/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.h b/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.h index 744dd48b21..e4e738a74d 100644 --- a/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.h +++ b/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.h @@ -111,9 +111,16 @@ */ - (NSArray*)relationsForEvent:(NSString*)eventId relationType:(NSString*)relationType; +/** + The text message partially typed by the user but not yet sent in the room. + + @deprecated use partialAttributedTextMessage + */ +@property (nonatomic) NSString *partialTextMessage __deprecated_msg("use partialAttributedTextMessage"); + /** The text message partially typed by the user but not yet sent in the room. */ -@property (nonatomic) NSString *partialTextMessage; +@property (nonatomic) NSAttributedString *partialAttributedTextMessage; @end diff --git a/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryStore.m b/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryStore.m index 7b615405c9..b0d9f60398 100644 --- a/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryStore.m +++ b/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryStore.m @@ -183,6 +183,18 @@ - (NSString *)partialTextMessageOfRoom:(NSString *)roomId return roomStore.partialTextMessage; } +- (void)storePartialAttributedTextMessageForRoom:(NSString *)roomId partialAttributedTextMessage:(NSAttributedString *)partialAttributedTextMessage +{ + MXMemoryRoomStore *roomStore = [self getOrCreateRoomStore:roomId]; + roomStore.partialAttributedTextMessage = partialAttributedTextMessage; +} + +- (NSAttributedString *)partialAttributedTextMessageOfRoom:(NSString *)roomId +{ + MXMemoryRoomStore *roomStore = [self getOrCreateRoomStore:roomId]; + return roomStore.partialAttributedTextMessage; +} + - (void)loadReceiptsForRoom:(NSString *)roomId completion:(void (^)(void))completion { [self getOrCreateRoomReceiptsStore:roomId]; diff --git a/MatrixSDK/Data/Store/MXNoStore/MXNoStore.m b/MatrixSDK/Data/Store/MXNoStore/MXNoStore.m index d0b2102a94..77f338736d 100644 --- a/MatrixSDK/Data/Store/MXNoStore/MXNoStore.m +++ b/MatrixSDK/Data/Store/MXNoStore/MXNoStore.m @@ -42,6 +42,9 @@ @interface MXNoStore () // key: roomId, value: the text message the user typed NSMutableDictionary *partialTextMessages; + // key: roomId, value: the text message the user typed + NSMutableDictionary *partialAttributedTextMessages; + NSString *eventStreamToken; // All matrix users known by the user @@ -72,6 +75,7 @@ - (instancetype)init hasLoadedAllRoomMembersForRooms = [NSMutableDictionary dictionary]; lastMessages = [NSMutableDictionary dictionary]; partialTextMessages = [NSMutableDictionary dictionary]; + partialAttributedTextMessages = [NSMutableDictionary dictionary]; users = [NSMutableDictionary dictionary]; groups = [NSMutableDictionary dictionary]; roomSummaryStore = [[MXVoidRoomSummaryStore alloc] init]; @@ -168,6 +172,10 @@ - (void)deleteRoom:(NSString *)roomId { [partialTextMessages removeObjectForKey:roomId]; } + if (partialAttributedTextMessages[roomId]) + { + [partialAttributedTextMessages removeObjectForKey:roomId]; + } [roomSummaryStore removeSummaryOfRoom:roomId]; } @@ -180,6 +188,7 @@ - (void)deleteAllData [hasLoadedAllRoomMembersForRooms removeAllObjects]; [lastMessages removeAllObjects]; [partialTextMessages removeAllObjects]; + [partialAttributedTextMessages removeAllObjects]; [roomSummaryStore removeAllSummaries]; } @@ -384,6 +393,23 @@ - (NSString *)partialTextMessageOfRoom:(NSString *)roomId return partialTextMessages[roomId]; } +- (void)storePartialAttributedTextMessageForRoom:(NSString *)roomId partialAttributedTextMessage:(NSAttributedString *)partialAttributedTextMessage +{ + if (partialAttributedTextMessage) + { + partialAttributedTextMessages[roomId] = partialAttributedTextMessage; + } + else + { + [partialAttributedTextMessages removeObjectForKey:roomId]; + } +} + +- (NSAttributedString *)partialAttributedTextMessageOfRoom:(NSString *)roomId +{ + return partialAttributedTextMessages[roomId]; +} + - (BOOL)isPermanent { return NO; @@ -467,6 +493,7 @@ - (void)close [hasReachedHomeServerPaginations removeAllObjects]; [lastMessages removeAllObjects]; [partialTextMessages removeAllObjects]; + [partialAttributedTextMessages removeAllObjects]; [users removeAllObjects]; [groups removeAllObjects]; } diff --git a/MatrixSDK/Data/Store/MXStore.h b/MatrixSDK/Data/Store/MXStore.h index 4f3e1255cd..8c397438da 100644 --- a/MatrixSDK/Data/Store/MXStore.h +++ b/MatrixSDK/Data/Store/MXStore.h @@ -227,21 +227,41 @@ #pragma mark - /** Store the text message partially typed by the user but not yet sent. - + + @deprecated use storePartialAttributedTextMessageForRoom + @param roomId the id of the room. @param partialTextMessage the text to store. Nil to reset it. */ -// @TODO(summary): Move to MXRoomSummary -- (void)storePartialTextMessageForRoom:(nonnull NSString*)roomId partialTextMessage:(nonnull NSString*)partialTextMessage; +- (void)storePartialTextMessageForRoom:(nonnull NSString*)roomId + partialTextMessage:(nonnull NSString*)partialTextMessage __deprecated_msg("use storePartialAttributedTextMessageForRoom"); /** The text message typed by the user but not yet sent. + @deprecated use partialAttributedTextMessageOfRoom + @param roomId the id of the room. @return the text message. Can be nil. */ -- (NSString* _Nullable)partialTextMessageOfRoom:(nonnull NSString*)roomId; +- (NSString* _Nullable)partialTextMessageOfRoom:(nonnull NSString*)roomId __deprecated_msg("use partialAttributedTextMessageOfRoom"); + +/** + Store the text message partially typed by the user but not yet sent. + + @param roomId the id of the room. + @param partialAttributedTextMessage the text to store. Nil to reset it. + */ +// @TODO(summary): Move to MXRoomSummary +- (void)storePartialAttributedTextMessageForRoom:(nonnull NSString*)roomId partialAttributedTextMessage:(nonnull NSAttributedString*)partialAttributedTextMessage; +/** + The text message typed by the user but not yet sent. + + @param roomId the id of the room. + @return the text message. Can be nil. + */ +- (NSAttributedString* _Nullable)partialAttributedTextMessageOfRoom:(nonnull NSString*)roomId; /** Returns the receipts list for an event in a dedicated room. diff --git a/changelog.d/3526.change b/changelog.d/3526.change new file mode 100644 index 0000000000..aa9e37bf10 --- /dev/null +++ b/changelog.d/3526.change @@ -0,0 +1 @@ +Rooms: support for attributedPartialTextMessage storage