diff --git a/matrixConsole/API/MatrixSDKHandler.h b/matrixConsole/API/MatrixSDKHandler.h
index 157cd6469..59fb83009 100644
--- a/matrixConsole/API/MatrixSDKHandler.h
+++ b/matrixConsole/API/MatrixSDKHandler.h
@@ -72,35 +72,33 @@ typedef enum : NSUInteger {
- (void)enableInAppNotifications:(BOOL)isEnabled;
-- (BOOL)isSupportedAttachment:(MXEvent*)event;
-- (BOOL)isEmote:(MXEvent*)event;
-
-// return a MatrixIDs list of 1:1 room members
-- (NSArray*)oneToOneRoomMemberMatrixIDs;
+// return a userIds list of 1:1 room members
+- (NSArray*)oneToOneRoomMemberIDs;
// Searches if a private OneToOne room has been started with this user
// Returns the room ID (nil if not found)
- (NSString*)privateOneToOneRoomIdWithUserId:(NSString*)userId;
-
// Reopens an existing private OneToOne room with this userId or creates a new one (if it doesn't exist)
- (void)startPrivateOneToOneRoomWithUserId:(NSString*)userId;
-// the pushes could have disabled for a dedicated room
-// reenable them
-- (void)allowRoomPushes:(NSString*)roomID;
+// Enables inApp notifications for a dedicated room if they were disabled
+- (void)restoreInAppNotificationsForRoomId:(NSString*)roomID;
-// Return the suitable url to display the content thumbnail into the provided view size
-// Note: the provided view size is supposed in points, this method will convert this size in pixels by considering screen scale
-- (NSString*)thumbnailURLForContent:(NSString*)contentURI inViewSize:(CGSize)viewSize withMethod:(MXThumbnailingMethod)thumbnailingMethod;
+// Stores the current text message partially typed in text input before leaving a room (use nil to reset the current value)
+- (void)storePartialTextMessage:(NSString*)textMessage forRoomId:(NSString*)roomId;
+// Returns the current partial message stored for this room (nil if none)
+- (NSString*)partialTextMessageForRoomId:(NSString*)roomId;
+// user power level in a dedicated room
+- (CGFloat)getPowerLevel:(MXRoomMember *)roomMember inRoom:(MXRoom *)room;
+
+- (BOOL)isSupportedAttachment:(MXEvent*)event;
+- (BOOL)isEmote:(MXEvent*)event;
// Note: the room state expected by the 3 following methods is the room state right before handling the event
- (NSString*)senderDisplayNameForEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState;
- (NSString*)senderAvatarUrlForEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState;
- (NSString*)displayTextForEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState inSubtitleMode:(BOOL)isSubtitle;
-// user power level in a dedicated room
-- (CGFloat)getPowerLevel:(MXRoomMember *)roomMember inRoom:(MXRoom *)room;
-
// return the presence ring color
// nil means there is no ring to display
- (UIColor*)getPresenceRingColor:(MXPresence)presence;
@@ -108,4 +106,8 @@ typedef enum : NSUInteger {
// return YES if the text contains a bing word
- (BOOL)containsBingWord:(NSString*)text;
+// Return the suitable url to display the content thumbnail into the provided view size
+// Note: the provided view size is supposed in points, this method will convert this size in pixels by considering screen scale
+- (NSString*)thumbnailURLForContent:(NSString*)contentURI inViewSize:(CGSize)viewSize withMethod:(MXThumbnailingMethod)thumbnailingMethod;
+
@end
diff --git a/matrixConsole/API/MatrixSDKHandler.m b/matrixConsole/API/MatrixSDKHandler.m
index 1dbbb56a2..219e9dca8 100644
--- a/matrixConsole/API/MatrixSDKHandler.m
+++ b/matrixConsole/API/MatrixSDKHandler.m
@@ -49,7 +49,9 @@ static MatrixSDKHandler *sharedHandler = nil;
@property (strong, nonatomic) MXCAlert *mxNotification;
@property (nonatomic) UIBackgroundTaskIdentifier bgTask;
-// when the user cancels a notification
+@property (strong, nonatomic) NSMutableDictionary *partialTextMsgByRoomId;
+
+// When the user cancels an inApp notification
// assume that any messagge room will be ignored
// until the next launch / debackground
@property (nonatomic,readwrite) NSMutableArray* unnotifiedRooms;
@@ -91,6 +93,7 @@ static MatrixSDKHandler *sharedHandler = nil;
}
_unnotifiedRooms = [[NSMutableArray alloc] init];
+ _partialTextMsgByRoomId = [[NSMutableDictionary alloc] init];
}
return self;
}
@@ -105,6 +108,10 @@ static MatrixSDKHandler *sharedHandler = nil;
_processingQueue = nil;
+ _unnotifiedRooms = nil;
+
+ _partialTextMsgByRoomId = nil;
+
[self closeSession];
self.mxSession = nil;
@@ -351,6 +358,7 @@ static MatrixSDKHandler *sharedHandler = nil;
self.homeServer = nil;
_unnotifiedRooms = [[NSMutableArray alloc] init];
+ _partialTextMsgByRoomId = [[NSMutableDictionary alloc] init];
// Keep userLogin, homeServerUrl
}
@@ -483,6 +491,8 @@ static MatrixSDKHandler *sharedHandler = nil;
_status = status;
}
+#pragma mark User's profile
+
- (NSString *)homeServerURL {
return [[NSUserDefaults standardUserDefaults] objectForKey:@"homeserverurl"];
}
@@ -593,6 +603,38 @@ static MatrixSDKHandler *sharedHandler = nil;
}
}
+#pragma mark Cache handling
+
+- (NSUInteger) MXCacheSize {
+
+ if (self.mxFileStore) {
+ return self.mxFileStore.diskUsage;
+ }
+
+ return 0;
+}
+
+- (NSUInteger) cachesSize {
+ return self.MXCacheSize + [MediaManager cacheSize];
+}
+
+- (NSUInteger) minCachesSize {
+ // add a 50MB margin to avoid cache file deletion
+ return self.MXCacheSize + [MediaManager minCacheSize] + 50 * 1024 * 1024;
+}
+
+- (NSUInteger) currentMaxCachesSize {
+ return self.MXCacheSize + [MediaManager currentMaxCacheSize];
+}
+
+- (void)setCurrentMaxCachesSize:(NSUInteger)maxCachesSize {
+ [MediaManager setCurrentMaxCacheSize:maxCachesSize - self.MXCacheSize];
+}
+
+- (NSUInteger) maxAllowedCachesSize {
+ return self.MXCacheSize + [MediaManager maxAllowedCacheSize];
+}
+
#pragma mark - Matrix user's settings
- (void)setUserPresence:(MXPresence)userPresence andStatusMessage:(NSString *)statusMessage completion:(void (^)(void))completion {
@@ -608,50 +650,10 @@ static MatrixSDKHandler *sharedHandler = nil;
}];
}
-#pragma mark - events handler
-
-// Checks whether the event is related to an attachment and if it is supported
-- (BOOL)isSupportedAttachment:(MXEvent*)event {
- BOOL isSupportedAttachment = NO;
-
- if (event.eventType == MXEventTypeRoomMessage) {
- NSString *msgtype = event.content[@"msgtype"];
- NSString *requiredField;
-
- if ([msgtype isEqualToString:kMXMessageTypeImage]) {
- requiredField = event.content[@"url"];
- if (requiredField.length) {
- isSupportedAttachment = YES;
- }
- } else if ([msgtype isEqualToString:kMXMessageTypeAudio]) {
- // Not supported yet
- } else if ([msgtype isEqualToString:kMXMessageTypeVideo]) {
- requiredField = event.content[@"url"];
- if (requiredField) {
- isSupportedAttachment = YES;
- }
- } else if ([msgtype isEqualToString:kMXMessageTypeLocation]) {
- // Not supported yet
- }
- }
- return isSupportedAttachment;
-}
-
-// Check whether the event is emote event
-- (BOOL)isEmote:(MXEvent*)event {
- if (event.eventType == MXEventTypeRoomMessage) {
- NSString *msgtype = event.content[@"msgtype"];
- if ([msgtype isEqualToString:kMXMessageTypeEmote]) {
- return YES;
- }
- }
- return NO;
-}
-
-#pragma mark -
+#pragma mark - Room handling
// return a MatrixIDs list of 1:1 room members
-- (NSArray*)oneToOneRoomMemberMatrixIDs {
+- (NSArray*)oneToOneRoomMemberIDs {
NSMutableArray* matrixIDs = [[NSMutableArray alloc] init];
MatrixSDKHandler *mxHandler = [MatrixSDKHandler sharedHandler];
@@ -760,30 +762,99 @@ static MatrixSDKHandler *sharedHandler = nil;
}
}
-// the pushes could have disabled for a dedicated room
-// reenable them
-- (void)allowRoomPushes:(NSString*)roomID {
+- (void)restoreInAppNotificationsForRoomId:(NSString*)roomID {
if (roomID) {
+ // Enable inApp notification for this room
[self.unnotifiedRooms removeObject:roomID];
}
}
-// Return the suitable url to display the content thumbnail into the provided view size
-// Note: the provided view size is supposed in points, this method will convert this size in pixels by considering screen scale
-- (NSString*)thumbnailURLForContent:(NSString*)contentURI inViewSize:(CGSize)viewSize withMethod:(MXThumbnailingMethod)thumbnailingMethod {
- // Suppose this url is a matrix content uri, we use SDK to get the well adapted thumbnail from server
- // Convert first the provided size in pixels
- CGFloat scale = [[UIScreen mainScreen] scale];
- CGSize sizeInPixels = CGSizeMake(viewSize.width * scale, viewSize.height * scale);
- NSString *thumbnailURL = [self.mxRestClient urlOfContentThumbnail:contentURI withSize:sizeInPixels andMethod:thumbnailingMethod];
- if (nil == thumbnailURL) {
- // Manage backward compatibility. The content URL used to be an absolute HTTP URL
- thumbnailURL = contentURI;
+- (void)storePartialTextMessage:(NSString*)textMessage forRoomId:(NSString*)roomId {
+ if (roomId) {
+ if (textMessage.length) {
+ [self.partialTextMsgByRoomId setObject:textMessage forKey:roomId];
+ } else {
+ [self.partialTextMsgByRoomId removeObjectForKey:roomId];
+ }
}
- return thumbnailURL;
}
-#pragma mark -
+- (NSString*)partialTextMessageForRoomId:(NSString*)roomId {
+ if (roomId) {
+ return [self.partialTextMsgByRoomId objectForKey:roomId];
+ }
+ return nil;
+}
+
+- (CGFloat)getPowerLevel:(MXRoomMember *)roomMember inRoom:(MXRoom *)room {
+ CGFloat powerLevel = 0;
+
+ // Customize banned and left (kicked) members
+ if (roomMember.membership == MXMembershipLeave || roomMember.membership == MXMembershipBan) {
+ powerLevel = 0;
+ } else {
+ // Handle power level display
+ //self.userPowerLevel.hidden = NO;
+ MXRoomPowerLevels *roomPowerLevels = room.state.powerLevels;
+
+ int maxLevel = 0;
+ for (NSString *powerLevel in roomPowerLevels.users.allValues) {
+ int level = [powerLevel intValue];
+ if (level > maxLevel) {
+ maxLevel = level;
+ }
+ }
+ NSUInteger userPowerLevel = [roomPowerLevels powerLevelOfUserWithUserID:roomMember.userId];
+ float userPowerLevelFloat = 0.0;
+ if (userPowerLevel) {
+ userPowerLevelFloat = userPowerLevel;
+ }
+
+ powerLevel = maxLevel ? userPowerLevelFloat / maxLevel : 1;
+ }
+
+ return powerLevel;
+}
+
+#pragma mark - Event handling
+
+// Checks whether the event is related to an attachment and if it is supported
+- (BOOL)isSupportedAttachment:(MXEvent*)event {
+ BOOL isSupportedAttachment = NO;
+
+ if (event.eventType == MXEventTypeRoomMessage) {
+ NSString *msgtype = event.content[@"msgtype"];
+ NSString *requiredField;
+
+ if ([msgtype isEqualToString:kMXMessageTypeImage]) {
+ requiredField = event.content[@"url"];
+ if (requiredField.length) {
+ isSupportedAttachment = YES;
+ }
+ } else if ([msgtype isEqualToString:kMXMessageTypeAudio]) {
+ // Not supported yet
+ } else if ([msgtype isEqualToString:kMXMessageTypeVideo]) {
+ requiredField = event.content[@"url"];
+ if (requiredField) {
+ isSupportedAttachment = YES;
+ }
+ } else if ([msgtype isEqualToString:kMXMessageTypeLocation]) {
+ // Not supported yet
+ }
+ }
+ return isSupportedAttachment;
+}
+
+// Check whether the event is emote event
+- (BOOL)isEmote:(MXEvent*)event {
+ if (event.eventType == MXEventTypeRoomMessage) {
+ NSString *msgtype = event.content[@"msgtype"];
+ if ([msgtype isEqualToString:kMXMessageTypeEmote]) {
+ return YES;
+ }
+ }
+ return NO;
+}
- (NSString*)senderDisplayNameForEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState {
// Consider first the current display name defined in provided room state (Note: this room state is supposed to not take the new event into account)
@@ -1149,66 +1220,7 @@ static MatrixSDKHandler *sharedHandler = nil;
return displayText;
}
-- (NSUInteger) MXCacheSize {
-
- if (self.mxFileStore) {
- return self.mxFileStore.diskUsage;
- }
-
- return 0;
-}
-
-- (NSUInteger) cachesSize {
- return self.MXCacheSize + [MediaManager cacheSize];
-}
-
-- (NSUInteger) minCachesSize {
- // add a 50MB margin to avoid cache file deletion
- return self.MXCacheSize + [MediaManager minCacheSize] + 50 * 1024 * 1024;
-}
-
-- (NSUInteger) currentMaxCachesSize {
- return self.MXCacheSize + [MediaManager currentMaxCacheSize];
-}
-
-- (void)setCurrentMaxCachesSize:(NSUInteger)maxCachesSize {
- [MediaManager setCurrentMaxCacheSize:maxCachesSize - self.MXCacheSize];
-}
-
-- (NSUInteger) maxAllowedCachesSize {
- return self.MXCacheSize + [MediaManager maxAllowedCacheSize];
-}
-
-- (CGFloat)getPowerLevel:(MXRoomMember *)roomMember inRoom:(MXRoom *)room {
- CGFloat powerLevel = 0;
-
- // Customize banned and left (kicked) members
- if (roomMember.membership == MXMembershipLeave || roomMember.membership == MXMembershipBan) {
- powerLevel = 0;
- } else {
- // Handle power level display
- //self.userPowerLevel.hidden = NO;
- MXRoomPowerLevels *roomPowerLevels = room.state.powerLevels;
-
- int maxLevel = 0;
- for (NSString *powerLevel in roomPowerLevels.users.allValues) {
- int level = [powerLevel intValue];
- if (level > maxLevel) {
- maxLevel = level;
- }
- }
- NSUInteger userPowerLevel = [roomPowerLevels powerLevelOfUserWithUserID:roomMember.userId];
- float userPowerLevelFloat = 0.0;
- if (userPowerLevel) {
- userPowerLevelFloat = userPowerLevel;
- }
-
- powerLevel = maxLevel ? userPowerLevelFloat / maxLevel : 1;
- }
-
- return powerLevel;
-}
-
+#pragma mark - Presence
// return the presence ring color
// nil means there is no ring to display
@@ -1228,6 +1240,8 @@ static MatrixSDKHandler *sharedHandler = nil;
}
}
+#pragma mark - Bing work
+
// return YES if the text contains a bing word
- (BOOL)containsBingWord:(NSString*)text {
MatrixSDKHandler *mxHandler = [MatrixSDKHandler sharedHandler];
@@ -1266,4 +1280,21 @@ static MatrixSDKHandler *sharedHandler = nil;
return NO;
}
+#pragma mark - Thumbnail
+
+// Return the suitable url to display the content thumbnail into the provided view size
+// Note: the provided view size is supposed in points, this method will convert this size in pixels by considering screen scale
+- (NSString*)thumbnailURLForContent:(NSString*)contentURI inViewSize:(CGSize)viewSize withMethod:(MXThumbnailingMethod)thumbnailingMethod {
+ // Suppose this url is a matrix content uri, we use SDK to get the well adapted thumbnail from server
+ // Convert first the provided size in pixels
+ CGFloat scale = [[UIScreen mainScreen] scale];
+ CGSize sizeInPixels = CGSizeMake(viewSize.width * scale, viewSize.height * scale);
+ NSString *thumbnailURL = [self.mxRestClient urlOfContentThumbnail:contentURI withSize:sizeInPixels andMethod:thumbnailingMethod];
+ if (nil == thumbnailURL) {
+ // Manage backward compatibility. The content URL used to be an absolute HTTP URL
+ thumbnailURL = contentURI;
+ }
+ return thumbnailURL;
+}
+
@end
diff --git a/matrixConsole/Base.lproj/Main.storyboard b/matrixConsole/Base.lproj/Main.storyboard
index 0ac92f5cf..b32860a73 100644
--- a/matrixConsole/Base.lproj/Main.storyboard
+++ b/matrixConsole/Base.lproj/Main.storyboard
@@ -311,10 +311,10 @@
-
+
-
+
@@ -581,6 +581,8 @@
+
+
diff --git a/matrixConsole/ViewController/ContactsViewController.m b/matrixConsole/ViewController/ContactsViewController.m
index dcfc0450d..2673f08b1 100644
--- a/matrixConsole/ViewController/ContactsViewController.m
+++ b/matrixConsole/ViewController/ContactsViewController.m
@@ -253,8 +253,7 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl
} else {
[self stopActivityIndicator];
- //NSArray* users = [mxHandler.mxSession users];
- NSArray* usersIDs = [mxHandler oneToOneRoomMemberMatrixIDs];
+ NSArray* usersIDs = [mxHandler oneToOneRoomMemberIDs];
// return a MatrixIDs list of 1:1 room members
NSMutableArray* knownUserIDs = [[matrixUserByMatrixID allKeys] mutableCopy];
diff --git a/matrixConsole/ViewController/MasterTabBarController.m b/matrixConsole/ViewController/MasterTabBarController.m
index 0adf2fd1f..ed36294be 100644
--- a/matrixConsole/ViewController/MasterTabBarController.m
+++ b/matrixConsole/ViewController/MasterTabBarController.m
@@ -143,7 +143,7 @@
}
- (void)setVisibleRoomId:(NSString *)aVisibleRoomId {
- [[MatrixSDKHandler sharedHandler] allowRoomPushes:aVisibleRoomId];
+ [[MatrixSDKHandler sharedHandler] restoreInAppNotificationsForRoomId:aVisibleRoomId];
_visibleRoomId = aVisibleRoomId;
}
diff --git a/matrixConsole/ViewController/RoomViewController.m b/matrixConsole/ViewController/RoomViewController.m
index d659a5719..56692d04c 100644
--- a/matrixConsole/ViewController/RoomViewController.m
+++ b/matrixConsole/ViewController/RoomViewController.m
@@ -126,6 +126,8 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
@property (weak, nonatomic) IBOutlet UIView *controlView;
@property (weak, nonatomic) IBOutlet UIButton *optionBtn;
@property (weak, nonatomic) IBOutlet MXCGrowingTextView *messageTextView;
+@property (weak, nonatomic) IBOutlet NSLayoutConstraint *messageTextViewTopConstraint;
+@property (weak, nonatomic) IBOutlet NSLayoutConstraint *messageTextViewBottomConstraint;
@property (weak, nonatomic) IBOutlet UIButton *sendBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *messagesTableViewBottomConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *controlViewBottomConstraint;
@@ -313,6 +315,8 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
}];
self.messageTextView.delegate = self;
+ // Retrieve the potential message partially typed during last room display
+ self.messageTextView.text = [mxHandler partialTextMessageForRoomId:self.roomId];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onKeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
@@ -322,6 +326,8 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
+ MatrixSDKHandler *mxHandler = [MatrixSDKHandler sharedHandler];
+
// hide action
if (self.actionMenu) {
[self.actionMenu dismiss:NO];
@@ -335,6 +341,8 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
[self hideRoomMembers];
self.messageTextView.delegate = nil;
+ // Store the potential message partially typed in text input
+ [mxHandler storePartialTextMessage:self.messageTextView.text forRoomId:self.roomId];
// slide to hide keyboard management
if (isKeyboardObserver) {
@@ -346,7 +354,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
[self dismissAttachmentImageViews];
if (membersListener) {
- MatrixSDKHandler *mxHandler = [MatrixSDKHandler sharedHandler];
[mxHandler.mxSession removeListener:membersListener];
membersListener = nil;
}
@@ -2168,18 +2175,18 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
- (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height {
// margins between _messageTextView and its superview (controlView)
- CGFloat controlViewHeight = height + self.controlView.frame.size.height - _messageTextView.frame.size.height;
+ CGFloat controlViewUpdatedHeight = height + _messageTextViewTopConstraint.constant + _messageTextViewBottomConstraint.constant;
// update the controlView height
- _controlViewHeightConstraint.constant = controlViewHeight;
+ _controlViewHeightConstraint.constant = controlViewUpdatedHeight;
UIEdgeInsets insets = self.messagesTableView.contentInset;
// if the keyboard is not displayed
if (!isKeyboardDisplayed) {
- insets.bottom = [AppDelegate theDelegate].masterTabBarController.tabBar.frame.size.height + controlViewHeight - defaultMessagesTableViewBottomConstraint;
+ insets.bottom = [AppDelegate theDelegate].masterTabBarController.tabBar.frame.size.height + controlViewUpdatedHeight - defaultMessagesTableViewBottomConstraint;
} else {
- insets.bottom = keyboardHeight + controlViewHeight - defaultMessagesTableViewBottomConstraint;
+ insets.bottom = keyboardHeight + controlViewUpdatedHeight - defaultMessagesTableViewBottomConstraint;
}
self.messagesTableView.contentInset = insets;