Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rooms: support for attributedPartialTextMessage storage #1457

Merged
merged 5 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions MatrixSDK/Background/MXBackgroundStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion MatrixSDK/Data/MXRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions MatrixSDK/Data/MXRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions MatrixSDK/Data/Store/MXFileStore/MXFileRoomStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -69,6 +71,10 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.partialTextMessage forKey:@"partialTextMessage"];
}
if (self.partialAttributedTextMessage)
{
[aCoder encodeObject:self.partialAttributedTextMessage forKey:@"partialAttributedTextMessage"];
}
}

@end
10 changes: 10 additions & 0 deletions MatrixSDK/Data/Store/MXFileStore/MXFileStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:/vector-im/element-ios/issues/3807 is fixed
Expand Down
9 changes: 8 additions & 1 deletion MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,16 @@
*/
- (NSArray<MXEvent*>*)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
12 changes: 12 additions & 0 deletions MatrixSDK/Data/Store/MXMemoryStore/MXMemoryStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
27 changes: 27 additions & 0 deletions MatrixSDK/Data/Store/MXNoStore/MXNoStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ @interface MXNoStore () <MXEventsEnumeratorDataSource>
// 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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -168,6 +172,10 @@ - (void)deleteRoom:(NSString *)roomId
{
[partialTextMessages removeObjectForKey:roomId];
}
if (partialAttributedTextMessages[roomId])
{
[partialAttributedTextMessages removeObjectForKey:roomId];
}
[roomSummaryStore removeSummaryOfRoom:roomId];
}

Expand All @@ -180,6 +188,7 @@ - (void)deleteAllData
[hasLoadedAllRoomMembersForRooms removeAllObjects];
[lastMessages removeAllObjects];
[partialTextMessages removeAllObjects];
[partialAttributedTextMessages removeAllObjects];
[roomSummaryStore removeAllSummaries];
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -467,6 +493,7 @@ - (void)close
[hasReachedHomeServerPaginations removeAllObjects];
[lastMessages removeAllObjects];
[partialTextMessages removeAllObjects];
[partialAttributedTextMessages removeAllObjects];
[users removeAllObjects];
[groups removeAllObjects];
}
Expand Down
28 changes: 24 additions & 4 deletions MatrixSDK/Data/Store/MXStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions changelog.d/3526.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rooms: support for attributedPartialTextMessage storage