Handle use only latest profile live refreshes

This commit is contained in:
Arnaud Ringenbach 2022-03-02 15:51:01 +01:00 committed by aringenbach
parent 724eef1b83
commit b2ff450a6f
3 changed files with 45 additions and 0 deletions

View file

@ -107,6 +107,18 @@
bubbleComponents = nil;
}
- (void)refreshProfileWithRoomDataSource:(MXKRoomDataSource *)roomDataSource2
{
if (self.events.firstObject)
{
MXEvent* firstEvent = self.events.firstObject;
senderDisplayName = [roomDataSource.eventFormatter senderDisplayNameForEvent:firstEvent
withRoomState:roomDataSource2.roomState];
senderAvatarUrl = [roomDataSource.eventFormatter senderAvatarUrlForEvent:firstEvent
withRoomState:roomDataSource2.roomState];
}
}
- (NSUInteger)updateEvent:(NSString *)eventId withEvent:(MXEvent *)event
{
NSUInteger count = 0;

View file

@ -231,6 +231,13 @@
*/
- (instancetype)initWithEvent:(MXEvent*)event andRoomState:(MXRoomState*)roomState andRoomDataSource:(MXKRoomDataSource*)roomDataSource;
/**
Refreshes the avatar and display name if needed. Should be used only if `roomScreenUseOnlyLatestProfiles` is enabled.
@param roomDataSource the `MXKRoomDataSource` object that will use this instance.
*/
- (void)refreshProfileWithRoomDataSource:(MXKRoomDataSource*)roomDataSource;
/**
Update the event because its sent state changed or it is has been redacted.

View file

@ -34,6 +34,8 @@
#import "MXKSendReplyEventStringLocalizer.h"
#import "MXKSlashCommands.h"
#import "GeneratedInterface-Swift.h"
const BOOL USE_THREAD_TIMELINE = YES;
#pragma mark - Constant definitions
@ -1009,6 +1011,11 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
liveEventsListener = [_timeline listenToEventsOfTypes:liveEventTypesFilterForMessages onEvent:^(MXEvent *event, MXTimelineDirection direction, MXRoomState *roomState) {
MXStrongifyAndReturnIfNil(self);
if (RiotSettings.shared.roomScreenUseOnlyLatestProfiles && event.eventType == MXEventTypeRoomMember && event.isUserProfileChange)
{
[self refreshProfilesIfNeeded];
}
if (MXTimelineDirectionForwards == direction)
{
@ -4321,4 +4328,23 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
self.secondaryRoomId = [self.mxSession virtualRoomOf:self.roomId];
}
#pragma mark - Use Only Latest Profiles
/**
Refreshes the avatars and display names if needed. This has no effect
if `roomScreenUseOnlyLatestProfiles` is disabled.
*/
- (void)refreshProfilesIfNeeded
{
if (RiotSettings.shared.roomScreenUseOnlyLatestProfiles)
{
@synchronized (bubbles) {
for (id<MXKRoomBubbleCellDataStoring> bubble in bubbles)
{
[bubble refreshProfileWithRoomDataSource:self];
}
}
}
}
@end