Skip to content

Commit

Permalink
Merge pull request #4961 from vector-im/gil/4898_fix_performance_issu…
Browse files Browse the repository at this point in the history
…es_with_spaces

Fix performance issues with Spaces on very large accounts #4898
  • Loading branch information
gileluard authored Oct 7, 2021
2 parents a9950d1 + 9e33172 commit 5486d8e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Riot/Modules/Spaces/SpaceDetail/SpaceDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SpaceDetailViewModel: SpaceDetailViewModelType {
self.update(viewState: .loaded(parameters))

self.update(viewState: .loading)
space.room.state { state in
space.room?.state { state in
let joinRule = state?.joinRule
let membersCount = summary.membersCount.members

Expand Down
6 changes: 6 additions & 0 deletions Riot/Modules/Spaces/SpaceList/SpaceListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ final class SpaceListViewModel: SpaceListViewModelType {
self.userSessionsService = userSessionsService

NotificationCenter.default.addObserver(self, selector: #selector(self.sessionDidSync(notification:)), name: MXSpaceService.didBuildSpaceGraph, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(self.counterDidUpdateNotificationCount(notification:)), name: MXSpaceNotificationCounter.didUpdateNotificationCount, object: nil)

}

Expand Down Expand Up @@ -122,6 +124,10 @@ final class SpaceListViewModel: SpaceListViewModelType {
loadData()
}

@objc private func counterDidUpdateNotificationCount(notification: Notification) {
loadData()
}

private func loadData() {
guard let session = self.userSessionsService.mainUserSession?.matrixSession else {
return
Expand Down
6 changes: 3 additions & 3 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {
}

private func leaveSpace() {
guard let space = self.session.spaceService.getSpace(withId: self.spaceId), let displayName = space.summary?.displayname else {
guard let room = self.session.room(withRoomId: self.spaceId), let displayName = room.summary?.displayname else {
return
}

var isAdmin = false
if let roomState = space.room.dangerousSyncState, let powerLevels = roomState.powerLevels {
if let roomState = room.dangerousSyncState, let powerLevels = roomState.powerLevels {
let powerLevel = powerLevels.powerLevelOfUser(withUserID: self.session.myUserId)
let roomPowerLevel = RoomPowerLevelHelper.roomPowerLevel(from: powerLevel)
isAdmin = roomPowerLevel == .admin
Expand Down Expand Up @@ -156,7 +156,7 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {
}

private func leaveSpace(_ space: MXSpace) {
space.room.leave(completion: { [weak self] response in
space.room?.leave(completion: { [weak self] response in
guard let self = self else {
return
}
Expand Down
10 changes: 9 additions & 1 deletion Riot/Modules/TabBar/MasterTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ @interface MasterTabBarController () <AuthenticationViewControllerDelegate, UITa

// Custom title view of the navigation bar
MainTitleView *titleView;

id spaceNotificationCounterDidUpdateNotificationCountObserver;
}

@property(nonatomic,getter=isHidden) BOOL hidden;
Expand Down Expand Up @@ -122,7 +124,7 @@ - (void)viewDidLoad
childViewControllers = [NSMutableArray array];

MXWeakify(self);
[[NSNotificationCenter defaultCenter] addObserverForName:MXSpaceService.didBuildSpaceGraph object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
spaceNotificationCounterDidUpdateNotificationCountObserver = [[NSNotificationCenter defaultCenter] addObserverForName:MXSpaceNotificationCounter.didUpdateNotificationCount object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
MXStrongifyAndReturnIfNil(self);
[self updateSideMenuNotifcationIcon];
}];
Expand Down Expand Up @@ -272,6 +274,12 @@ - (void)dealloc
kThemeServiceDidChangeThemeNotificationObserver = nil;
}

if (spaceNotificationCounterDidUpdateNotificationCountObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:spaceNotificationCounterDidUpdateNotificationCountObserver];
spaceNotificationCounterDidUpdateNotificationCountObserver = nil;
}

childViewControllers = nil;
}

Expand Down
1 change: 1 addition & 0 deletions changelog.d/4898.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MasterTabBarController: Listen to `MXSpaceNotificationCounter` to update the notification badge

0 comments on commit 5486d8e

Please sign in to comment.