mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 16:22:39 +00:00
Room members list: refresh the member's last seen info (every 5 sec)
This commit is contained in:
parent
eee71e1672
commit
d87fda44b5
2 changed files with 105 additions and 36 deletions
|
@ -18,12 +18,26 @@
|
|||
#import "MatrixHandler.h"
|
||||
#import "MediaManager.h"
|
||||
|
||||
@interface RoomMemberTableCell () {
|
||||
NSString *roomMemberUserId;
|
||||
NSRange lastSeenRange;
|
||||
NSTimer* lastSeenTimer;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RoomMemberTableCell
|
||||
|
||||
- (void)dealloc {
|
||||
roomMemberUserId = nil;
|
||||
|
||||
[lastSeenTimer invalidate];
|
||||
lastSeenTimer = nil;
|
||||
}
|
||||
|
||||
// returns the presence color
|
||||
// nil if there is no valid one
|
||||
- (UIColor*) getUserPresenceColor:(MXUser*) user
|
||||
{
|
||||
- (UIColor*)getUserPresenceColor:(MXUser*)user {
|
||||
if (user) {
|
||||
switch (user.presence) {
|
||||
case MXPresenceOnline:
|
||||
|
@ -44,7 +58,6 @@
|
|||
}
|
||||
|
||||
- (NSString*)getLastPresenceText:(MXUser*)user {
|
||||
|
||||
NSString* presenceText = nil;
|
||||
|
||||
// Prepare last active ago string
|
||||
|
@ -80,8 +93,7 @@
|
|||
return presenceText;
|
||||
}
|
||||
|
||||
- (void) setPowerContainerValue:(CGFloat)progress
|
||||
{
|
||||
- (void)setPowerContainerValue:(CGFloat)progress {
|
||||
// no power level -> hide the pie
|
||||
if (0 == progress) {
|
||||
self.powerContainer.hidden = YES;
|
||||
|
@ -101,6 +113,11 @@
|
|||
}
|
||||
|
||||
- (void)setRoomMember:(MXRoomMember *)roomMember withRoom:(MXRoom *)room {
|
||||
if (lastSeenTimer) {
|
||||
[lastSeenTimer invalidate];
|
||||
lastSeenTimer = nil;
|
||||
}
|
||||
|
||||
if (room && roomMember) {
|
||||
// Set the user info
|
||||
self.userLabel.text = [room.state memberName:roomMember.userId];
|
||||
|
@ -149,14 +166,21 @@
|
|||
thumbnailBorderColor = [UIColor lightGrayColor];
|
||||
presenceText = @"invited";
|
||||
} else {
|
||||
roomMemberUserId = roomMember.userId;
|
||||
|
||||
// Get the user that corresponds to this member
|
||||
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
|
||||
MXUser *user = [mxHandler.mxSession userWithUserId:roomMember.userId];
|
||||
MXUser *user = [mxHandler.mxSession userWithUserId:roomMemberUserId];
|
||||
|
||||
// existing user ?
|
||||
if (user) {
|
||||
thumbnailBorderColor = [self getUserPresenceColor:user];
|
||||
presenceText = [self getLastPresenceText:user];
|
||||
if (presenceText) {
|
||||
// Trigger a timer to update last seen information
|
||||
lastSeenRange = NSMakeRange(self.userLabel.text.length + 2, presenceText.length);
|
||||
lastSeenTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(updateLastSeen:) userInfo:self repeats:NO];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,4 +224,31 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateLastSeen:(id)sender {
|
||||
[lastSeenTimer invalidate];
|
||||
lastSeenTimer = nil;
|
||||
|
||||
// Get the user that corresponds to this member
|
||||
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
|
||||
MXUser *user = [mxHandler.mxSession userWithUserId:roomMemberUserId];
|
||||
|
||||
// existing user ?
|
||||
if (user) {
|
||||
NSString *presenceText = [self getLastPresenceText:user];
|
||||
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithAttributedString:self.userLabel.attributedText];
|
||||
if (presenceText.length) {
|
||||
[attributedText replaceCharactersInRange:lastSeenRange withString:presenceText];
|
||||
// Trigger a timer to update last seen information
|
||||
lastSeenRange.length = presenceText.length;
|
||||
lastSeenTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(updateLastSeen:) userInfo:self repeats:NO];
|
||||
} else {
|
||||
// remove presence info
|
||||
lastSeenRange.location -= 1;
|
||||
lastSeenRange.length += 2;
|
||||
[attributedText deleteCharactersInRange:lastSeenRange];
|
||||
}
|
||||
[self.userLabel setAttributedText:attributedText];
|
||||
}
|
||||
}
|
||||
@end
|
|
@ -1105,6 +1105,8 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
- (void)hideRoomMembers {
|
||||
self.membersView.hidden = YES;
|
||||
members = nil;
|
||||
// Force a reload to release all table cells (and then stop running timer)
|
||||
[self.membersTableView reloadData];
|
||||
}
|
||||
|
||||
# pragma mark - Attachment handling
|
||||
|
@ -1569,7 +1571,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
}
|
||||
}
|
||||
|
||||
// Consider the specific case where the message is hidden (see outgoing messages temporarily hidden until our PUT is returned)
|
||||
// Sanity check
|
||||
if (!message) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -1631,19 +1633,15 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
message = [messages objectAtIndex:indexPath.row];
|
||||
}
|
||||
}
|
||||
// Consider the specific case where the message is hidden (see outgoing messages temporarily hidden until our PUT is returned)
|
||||
// Sanity check
|
||||
if (!message) {
|
||||
return [[UITableViewCell alloc] initWithFrame:CGRectZero];
|
||||
}
|
||||
// Else prepare the message cell
|
||||
RoomMessageTableCell *cell;
|
||||
BOOL isIncomingMsg = NO;
|
||||
|
||||
if ([message.senderId isEqualToString:mxHandler.userId]) {
|
||||
cell = [tableView dequeueReusableCellWithIdentifier:@"OutgoingMessageCell" forIndexPath:indexPath];
|
||||
OutgoingMessageTableCell* outgoingMsgCell = (OutgoingMessageTableCell*)cell;
|
||||
// Hide potential loading wheel
|
||||
[outgoingMsgCell stopAnimating];
|
||||
} else {
|
||||
cell = [tableView dequeueReusableCellWithIdentifier:@"IncomingMessageCell" forIndexPath:indexPath];
|
||||
isIncomingMsg = YES;
|
||||
|
@ -1656,22 +1654,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
cell.pictureView.mediaFolder = kMediaManagerThumbnailFolder;
|
||||
cell.attachmentView.mediaFolder = self.roomId;
|
||||
|
||||
// Remove all gesture recognizer
|
||||
while (cell.attachmentView.gestureRecognizers.count) {
|
||||
[cell.attachmentView removeGestureRecognizer:cell.attachmentView.gestureRecognizers[0]];
|
||||
}
|
||||
// Remove potential dateTime (or unsent) label(s)
|
||||
if (cell.dateTimeLabelContainer.subviews.count > 0) {
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(deactivateConstraints:)]) {
|
||||
[NSLayoutConstraint deactivateConstraints:cell.dateTimeLabelContainer.constraints];
|
||||
} else {
|
||||
[cell.dateTimeLabelContainer removeConstraints:cell.dateTimeLabelContainer.constraints];
|
||||
}
|
||||
for (UIView *view in cell.dateTimeLabelContainer.subviews) {
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether the previous message has been sent by the same user.
|
||||
// The user's picture and name are displayed only for the first message.
|
||||
BOOL shouldHideSenderInfo = NO;
|
||||
|
@ -1759,8 +1741,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
}
|
||||
}
|
||||
|
||||
[cell stopProgressUI];
|
||||
|
||||
// Set message content
|
||||
message.maxTextViewWidth = self.messagesTableView.frame.size.width - ROOM_MESSAGE_CELL_TEXTVIEW_LEADING_AND_TRAILING_CONSTRAINT_TO_SUPERVIEW;
|
||||
CGSize contentSize = message.contentSize;
|
||||
|
@ -1822,14 +1802,10 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
cell.messageTextView.attributedText = message.attributedTextMessage;
|
||||
}
|
||||
|
||||
// add a long tap gesture on the progressView
|
||||
// Add a long tap gesture on the progressView
|
||||
// manage it in the storyboard does not work properly
|
||||
// -> The gesture view is always the same i.e. the latest composed one.
|
||||
while (cell.progressView.gestureRecognizers.count) {
|
||||
[cell.progressView removeGestureRecognizer:cell.progressView.gestureRecognizers[0]];
|
||||
}
|
||||
|
||||
// only the download can be cancelled
|
||||
// Note: only the download can be cancelled
|
||||
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onProgressLongTap:)];
|
||||
[cell.progressView addGestureRecognizer:longPress];
|
||||
|
||||
|
@ -1912,6 +1888,48 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
}
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath {
|
||||
// Release here resources, and restore reusable cells
|
||||
|
||||
// Check table view members vs messages
|
||||
if (tableView == self.membersTableView) {
|
||||
RoomMemberTableCell *memberCell = (RoomMemberTableCell*)cell;
|
||||
// Stop potential timer used to refresh member's presence
|
||||
[memberCell setRoomMember:nil withRoom:nil];
|
||||
} else if (tableView == self.messagesTableView) {
|
||||
RoomMessageTableCell *msgCell = (RoomMessageTableCell*)cell;
|
||||
if ([cell isKindOfClass:[OutgoingMessageTableCell class]]) {
|
||||
OutgoingMessageTableCell *outgoingMsgCell = (OutgoingMessageTableCell*)cell;
|
||||
// Hide potential loading wheel
|
||||
[outgoingMsgCell stopAnimating];
|
||||
}
|
||||
msgCell.message = nil;
|
||||
|
||||
// Remove all gesture recognizer
|
||||
while (msgCell.attachmentView.gestureRecognizers.count) {
|
||||
[msgCell.attachmentView removeGestureRecognizer:msgCell.attachmentView.gestureRecognizers[0]];
|
||||
}
|
||||
// Remove potential dateTime (or unsent) label(s)
|
||||
if (msgCell.dateTimeLabelContainer.subviews.count > 0) {
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(deactivateConstraints:)]) {
|
||||
[NSLayoutConstraint deactivateConstraints:msgCell.dateTimeLabelContainer.constraints];
|
||||
} else {
|
||||
[msgCell.dateTimeLabelContainer removeConstraints:msgCell.dateTimeLabelContainer.constraints];
|
||||
}
|
||||
for (UIView *view in msgCell.dateTimeLabelContainer.subviews) {
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
}
|
||||
|
||||
[msgCell stopProgressUI];
|
||||
|
||||
// Remove long tap gesture on the progressView
|
||||
while (msgCell.progressView.gestureRecognizers.count) {
|
||||
[msgCell.progressView removeGestureRecognizer:msgCell.progressView.gestureRecognizers[0]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Detect vertical bounce at the top of the tableview to trigger pagination
|
||||
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
|
||||
if (scrollView == self.messagesTableView) {
|
||||
|
|
Loading…
Reference in a new issue