mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Recents: Remove left rooms from recents list
This commit is contained in:
parent
a36de54e3f
commit
515a2aef30
1 changed files with 21 additions and 6 deletions
|
@ -190,25 +190,40 @@
|
||||||
|
|
||||||
// Register recent listener
|
// Register recent listener
|
||||||
recentsListener = [mxHandler.mxSession listenToEventsOfTypes:mxHandler.eventsFilterForMessages onEvent:^(MXEvent *event, MXEventDirection direction, id customObject) {
|
recentsListener = [mxHandler.mxSession listenToEventsOfTypes:mxHandler.eventsFilterForMessages onEvent:^(MXEvent *event, MXEventDirection direction, id customObject) {
|
||||||
// consider only live event
|
// Consider only live event
|
||||||
if (direction == MXEventDirectionForwards) {
|
if (direction == MXEventDirectionForwards) {
|
||||||
|
// Check user's membership (We will remove left rooms from recents)
|
||||||
|
BOOL isLeft = NO;
|
||||||
|
if ([customObject isKindOfClass:[MXRoomState class]]) {
|
||||||
|
MXRoomState *roomState = (MXRoomState*)customObject;
|
||||||
|
if (roomState.membership == MXMembershipLeave || roomState.membership == MXMembershipBan) {
|
||||||
|
isLeft = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Consider this new event as unread only if the sender is not the user and if the room is not visible
|
// Consider this new event as unread only if the sender is not the user and if the room is not visible
|
||||||
BOOL isUnread = (![event.userId isEqualToString:mxHandler.userId]
|
BOOL isUnread = (![event.userId isEqualToString:mxHandler.userId]
|
||||||
&& ![[AppDelegate theDelegate].masterTabBarController.visibleRoomId isEqualToString:event.roomId]);
|
&& ![[AppDelegate theDelegate].masterTabBarController.visibleRoomId isEqualToString:event.roomId]);
|
||||||
|
|
||||||
// Look for the room
|
// Look for the room
|
||||||
BOOL isFound = NO;
|
BOOL isFound = NO;
|
||||||
for (NSUInteger index = 0; index < recents.count; index++) {
|
for (NSUInteger index = 0; index < recents.count; index++) {
|
||||||
RecentRoom *recentRoom = [recents objectAtIndex:index];
|
RecentRoom *recentRoom = [recents objectAtIndex:index];
|
||||||
if ([event.roomId isEqualToString:recentRoom.roomId]) {
|
if ([event.roomId isEqualToString:recentRoom.roomId]) {
|
||||||
isFound = YES;
|
isFound = YES;
|
||||||
|
if (isLeft) {
|
||||||
|
// Remove left room
|
||||||
|
[recents removeObjectAtIndex:index];
|
||||||
|
} else {
|
||||||
[recentRoom updateWithLastEvent:event andMarkAsUnread:isUnread];
|
[recentRoom updateWithLastEvent:event andMarkAsUnread:isUnread];
|
||||||
// Move this room at first position
|
// Move this room at first position
|
||||||
[recents removeObjectAtIndex:index];
|
[recents removeObjectAtIndex:index];
|
||||||
[recents insertObject:recentRoom atIndex:0];
|
[recents insertObject:recentRoom atIndex:0];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isFound) {
|
if (!isFound && !isLeft) {
|
||||||
// Insert in first position this new room
|
// Insert in first position this new room
|
||||||
RecentRoom *recentRoom = [[RecentRoom alloc] initWithLastEvent:event andMarkAsUnread:isUnread];
|
RecentRoom *recentRoom = [[RecentRoom alloc] initWithLastEvent:event andMarkAsUnread:isUnread];
|
||||||
if (recentRoom) {
|
if (recentRoom) {
|
||||||
|
|
Loading…
Reference in a new issue