Skip to content

Commit 8550b76

Browse files
committed
Merge branch 'develop' into ismail/5840_thread_events_order
2 parents 4c5e0f0 + 63f7e74 commit 8550b76

File tree

14 files changed

+303
-59
lines changed

14 files changed

+303
-59
lines changed

MatrixSDK.xcodeproj/project.pbxproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,12 +1717,16 @@
17171717
ECF29BDF264195320053E6D6 /* MXAssertedIdentityModel.h in Headers */ = {isa = PBXBuildFile; fileRef = ECF29BDD264195320053E6D6 /* MXAssertedIdentityModel.h */; settings = {ATTRIBUTES = (Public, ); }; };
17181718
ECF29BE52641953C0053E6D6 /* MXAssertedIdentityModel.m in Sources */ = {isa = PBXBuildFile; fileRef = ECF29BE42641953C0053E6D6 /* MXAssertedIdentityModel.m */; };
17191719
ECF29BE62641953C0053E6D6 /* MXAssertedIdentityModel.m in Sources */ = {isa = PBXBuildFile; fileRef = ECF29BE42641953C0053E6D6 /* MXAssertedIdentityModel.m */; };
1720+
ED8943D427E34762000FC39C /* MXMemoryRoomStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED8943D327E34762000FC39C /* MXMemoryRoomStoreTests.swift */; };
1721+
ED8943D527E34762000FC39C /* MXMemoryRoomStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED8943D327E34762000FC39C /* MXMemoryRoomStoreTests.swift */; };
17201722
EDB4209227DF77390036AF39 /* MXEventsEnumeratorOnArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDB4209027DF77310036AF39 /* MXEventsEnumeratorOnArrayTests.swift */; };
17211723
EDB4209327DF77390036AF39 /* MXEventsEnumeratorOnArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDB4209027DF77310036AF39 /* MXEventsEnumeratorOnArrayTests.swift */; };
17221724
EDB4209527DF822B0036AF39 /* MXEventsByTypesEnumeratorOnArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDB4209427DF822B0036AF39 /* MXEventsByTypesEnumeratorOnArrayTests.swift */; };
17231725
EDB4209627DF822B0036AF39 /* MXEventsByTypesEnumeratorOnArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDB4209427DF822B0036AF39 /* MXEventsByTypesEnumeratorOnArrayTests.swift */; };
17241726
EDB4209927DF842F0036AF39 /* MXEventFixtures.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDB4209827DF842F0036AF39 /* MXEventFixtures.swift */; };
17251727
EDB4209A27DF842F0036AF39 /* MXEventFixtures.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDB4209827DF842F0036AF39 /* MXEventFixtures.swift */; };
1728+
EDF4678727E3331D00435913 /* EventsEnumeratorDataSourceStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDF4678627E3331D00435913 /* EventsEnumeratorDataSourceStub.swift */; };
1729+
EDF4678827E3331D00435913 /* EventsEnumeratorDataSourceStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDF4678627E3331D00435913 /* EventsEnumeratorDataSourceStub.swift */; };
17261730
F0173EAC1FCF0E8900B5F6A3 /* MXGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = F0173EAA1FCF0E8800B5F6A3 /* MXGroup.h */; settings = {ATTRIBUTES = (Public, ); }; };
17271731
F0173EAD1FCF0E8900B5F6A3 /* MXGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = F0173EAB1FCF0E8900B5F6A3 /* MXGroup.m */; };
17281732
F03EF4FE1DF014D9009DF592 /* MXMediaLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = F03EF4FA1DF014D9009DF592 /* MXMediaLoader.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -2683,10 +2687,12 @@
26832687
ECF29BDD264195320053E6D6 /* MXAssertedIdentityModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXAssertedIdentityModel.h; sourceTree = "<group>"; };
26842688
ECF29BE42641953C0053E6D6 /* MXAssertedIdentityModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXAssertedIdentityModel.m; sourceTree = "<group>"; };
26852689
ED2F344856EFFCA383E37B22 /* Pods-SDK-MatrixSDK.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SDK-MatrixSDK.release.xcconfig"; path = "Target Support Files/Pods-SDK-MatrixSDK/Pods-SDK-MatrixSDK.release.xcconfig"; sourceTree = "<group>"; };
2690+
ED8943D327E34762000FC39C /* MXMemoryRoomStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXMemoryRoomStoreTests.swift; sourceTree = "<group>"; };
26862691
EDB4209027DF77310036AF39 /* MXEventsEnumeratorOnArrayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXEventsEnumeratorOnArrayTests.swift; sourceTree = "<group>"; };
26872692
EDB4209427DF822B0036AF39 /* MXEventsByTypesEnumeratorOnArrayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXEventsByTypesEnumeratorOnArrayTests.swift; sourceTree = "<group>"; };
26882693
EDB4209827DF842F0036AF39 /* MXEventFixtures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXEventFixtures.swift; sourceTree = "<group>"; };
26892694
EDC74874AB2D86EFEE912B04 /* Pods-MatrixSDK-MatrixSDK-macOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MatrixSDK-MatrixSDK-macOS.debug.xcconfig"; path = "Target Support Files/Pods-MatrixSDK-MatrixSDK-macOS/Pods-MatrixSDK-MatrixSDK-macOS.debug.xcconfig"; sourceTree = "<group>"; };
2695+
EDF4678627E3331D00435913 /* EventsEnumeratorDataSourceStub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsEnumeratorDataSourceStub.swift; sourceTree = "<group>"; };
26902696
F0173EAA1FCF0E8800B5F6A3 /* MXGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXGroup.h; sourceTree = "<group>"; };
26912697
F0173EAB1FCF0E8900B5F6A3 /* MXGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXGroup.m; sourceTree = "<group>"; };
26922698
F03EF4FA1DF014D9009DF592 /* MXMediaLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXMediaLoader.h; sourceTree = "<group>"; };
@@ -4720,9 +4726,26 @@
47204726
path = Common;
47214727
sourceTree = "<group>";
47224728
};
4729+
ED8943D127E3474A000FC39C /* Store */ = {
4730+
isa = PBXGroup;
4731+
children = (
4732+
ED8943D227E34755000FC39C /* MXMemoryStore */,
4733+
);
4734+
path = Store;
4735+
sourceTree = "<group>";
4736+
};
4737+
ED8943D227E34755000FC39C /* MXMemoryStore */ = {
4738+
isa = PBXGroup;
4739+
children = (
4740+
ED8943D327E34762000FC39C /* MXMemoryRoomStoreTests.swift */,
4741+
);
4742+
path = MXMemoryStore;
4743+
sourceTree = "<group>";
4744+
};
47234745
EDB4208E27DF76C60036AF39 /* Data */ = {
47244746
isa = PBXGroup;
47254747
children = (
4748+
ED8943D127E3474A000FC39C /* Store */,
47264749
EDB4208F27DF77230036AF39 /* EventsEnumerator */,
47274750
);
47284751
path = Data;
@@ -4731,6 +4754,7 @@
47314754
EDB4208F27DF77230036AF39 /* EventsEnumerator */ = {
47324755
isa = PBXGroup;
47334756
children = (
4757+
EDF4678627E3331D00435913 /* EventsEnumeratorDataSourceStub.swift */,
47344758
EDB4209027DF77310036AF39 /* MXEventsEnumeratorOnArrayTests.swift */,
47354759
EDB4209427DF822B0036AF39 /* MXEventsByTypesEnumeratorOnArrayTests.swift */,
47364760
);
@@ -6228,6 +6252,7 @@
62286252
3A7B8D0E267FCF7200D9DD96 /* MXDehydrationTests.m in Sources */,
62296253
3281E8A019E2CC1200976E1A /* MXHTTPClientTests.m in Sources */,
62306254
321809B919EEBF3000377451 /* MXEventTests.m in Sources */,
6255+
EDF4678727E3331D00435913 /* EventsEnumeratorDataSourceStub.swift in Sources */,
62316256
EC746C59274E61EF002AD24C /* MXThreadingServiceTests.swift in Sources */,
62326257
32A31BC120D3F4C4005916C7 /* MXFilterTests.m in Sources */,
62336258
32B477842638133C00EA5800 /* MXAggregatedReferenceUnitTests.m in Sources */,
@@ -6243,6 +6268,7 @@
62436268
327137241A24BDDE00DB6757 /* MXUserTests.m in Sources */,
62446269
32B0E3E723A3864C0054FF1A /* MXEventReferenceUnitTests.swift in Sources */,
62456270
32720DA2222EB5650086FFF5 /* MXAutoDiscoveryTests.m in Sources */,
6271+
ED8943D427E34762000FC39C /* MXMemoryRoomStoreTests.swift in Sources */,
62466272
327E37B91A977810007F026F /* MXLoggerUnitTests.m in Sources */,
62476273
18937E7C273A5AE500902626 /* MXPollRelationTests.m in Sources */,
62486274
32792BE12296C64200F4FC9D /* MXAggregatedEditsTests.m in Sources */,
@@ -6746,6 +6772,7 @@
67466772
32D5D16423E400A600E3E37C /* MXRoomSummaryTrustTests.m in Sources */,
67476773
B1E09A1B2397FCE90057C069 /* MXAggregatedReactionTests.m in Sources */,
67486774
B1E09A3F2397FD820057C069 /* MXNotificationCenterTests.m in Sources */,
6775+
EDF4678827E3331D00435913 /* EventsEnumeratorDataSourceStub.swift in Sources */,
67496776
EC746C5A274E61EF002AD24C /* MXThreadingServiceTests.swift in Sources */,
67506777
B1E09A222397FCE90057C069 /* MXRoomSummaryTests.m in Sources */,
67516778
B1E09A3A2397FD820057C069 /* MXStoreTests.m in Sources */,
@@ -6761,6 +6788,7 @@
67616788
B1F939F626289F2600D0E525 /* MXSpaceChildContentTests.swift in Sources */,
67626789
B1E09A412397FD820057C069 /* MXAccountDataTests.m in Sources */,
67636790
B1E09A2D2397FD750057C069 /* MXRestClientNoAuthAPITests.m in Sources */,
6791+
ED8943D527E34762000FC39C /* MXMemoryRoomStoreTests.swift in Sources */,
67646792
B1E09A332397FD750057C069 /* MXRoomStateTests.m in Sources */,
67656793
18937E7D273A5AE500902626 /* MXPollRelationTests.m in Sources */,
67666794
B1E09A352397FD7D0057C069 /* MXEventTests.m in Sources */,

MatrixSDK/Background/MXBackgroundStore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ class MXBackgroundStore: NSObject, MXStore {
165165
}
166166

167167
func messagesEnumerator(forRoom roomId: String) -> MXEventsEnumerator {
168-
return MXEventsEnumeratorOnArray(messages: [])
168+
return MXEventsEnumeratorOnArray(eventIds: [], dataSource: nil)
169169
}
170170

171171
func messagesEnumerator(forRoom roomId: String, withTypeIn types: [Any]?) -> MXEventsEnumerator {
172-
return MXEventsEnumeratorOnArray(messages: [])
172+
return MXEventsEnumeratorOnArray(eventIds: [], dataSource: nil)
173173
}
174174

175175
func relations(forEvent eventId: String, inRoom roomId: String, relationType: String) -> [MXEvent] {

MatrixSDK/Data/EventsEnumerator/MXEventsByTypesEnumeratorOnArray.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,25 @@
1818
#import <Foundation/Foundation.h>
1919

2020
#import "MXEventsEnumerator.h"
21+
#import "MXEventsEnumeratorOnArray.h"
2122

2223
/**
23-
Generic events enumerator on an array of events with a filter on events types.
24+
Generic events enumerator on an array of event identifiers with a filter on events types.
2425
*/
2526
@interface MXEventsByTypesEnumeratorOnArray : NSObject <MXEventsEnumerator>
2627

2728
/**
28-
Construct an enumerator based on a events array.
29+
Construct an enumerator based on an array of event identifiers.
2930
3031
@param messages the list of messages to enumerate on.
3132
@param types an array of event types strings to use as a filter filter.
33+
@param dataSource object responsible for translating an event identifier into
34+
the most recent version of the event.
3235
3336
@return the newly created instance.
3437
*/
35-
- (instancetype)initWithMessages:(NSArray<MXEvent*> *)messages andTypesIn:(NSArray*)types;
38+
- (instancetype)initWithEventIds:(NSArray<NSString *> *)eventIds
39+
andTypesIn:(NSArray*)types
40+
dataSource:(id<MXEventsEnumeratorDataSource>)dataSource;
3641

3742
@end

MatrixSDK/Data/EventsEnumerator/MXEventsByTypesEnumeratorOnArray.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ @interface MXEventsByTypesEnumeratorOnArray ()
3434

3535
@implementation MXEventsByTypesEnumeratorOnArray
3636

37-
- (instancetype)initWithMessages:(NSArray<MXEvent *> *)messages andTypesIn:(NSArray *)theTypes
37+
- (instancetype)initWithEventIds:(NSArray<NSString *> *)eventIds
38+
andTypesIn:(NSArray*)theTypes
39+
dataSource:(id<MXEventsEnumeratorDataSource>)dataSource
3840
{
3941
self = [super init];
4042
if (self)
4143
{
4244
types = theTypes;
43-
allMessagesEnumerator = [[MXEventsEnumeratorOnArray alloc] initWithMessages:messages];
45+
allMessagesEnumerator = [[MXEventsEnumeratorOnArray alloc] initWithEventIds:eventIds dataSource:dataSource];
4446
}
4547

4648
return self;

MatrixSDK/Data/EventsEnumerator/MXEventsEnumerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
#import "MXEvent.h"
1818

1919
/**
20-
The `MXStoreEventsEnumerator` protocol defines an interface that must be implemented
20+
The `MXEventsEnumerator` protocol defines an interface that must be implemented
2121
in order to iterate on a list of events.
2222
2323
This interface is used in the MXStore to manage the results of requests on the store
2424
database.
2525
26-
The `MXStoreEventsEnumerator` implementation must start the iteration on the most recent
26+
The `MXEventsEnumerator` implementation must start the iteration on the most recent
2727
events of the list.
2828
*/
2929
@protocol MXEventsEnumerator <NSObject>

MatrixSDK/Data/EventsEnumerator/MXEventsEnumeratorOnArray.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,30 @@
1919
#import "MXEventsEnumerator.h"
2020

2121
/**
22-
Generic events enumerator on an array of events.
22+
Data source which provides the most up-to-date event to an enumerator
23+
based on the event identifier.
24+
*/
25+
@protocol MXEventsEnumeratorDataSource
26+
- (MXEvent *)eventWithEventId:(NSString *)eventId;
27+
@end
28+
29+
/**
30+
Generic events enumerator on an array of event identifiers that are
31+
translated to events on demand.
2332
*/
2433
@interface MXEventsEnumeratorOnArray : NSObject <MXEventsEnumerator>
2534

2635
/**
27-
Construct an enumerator based on a events array.
36+
Construct an enumerator based on an array of event identifiers.
37+
38+
@param eventIds the list of event identifiers to enumerate.
39+
The order is chronological where the first item is the oldest event
40+
@param dataSource object responsible for translating an event identifier into
41+
the most recent version of the event.
2842
29-
@param messages the list of messages to enumerate.
3043
@return the newly created instance.
3144
*/
32-
- (instancetype)initWithMessages:(NSArray<MXEvent*> *)messages;
45+
- (instancetype)initWithEventIds:(NSArray<NSString *> *)eventIds
46+
dataSource:(id<MXEventsEnumeratorDataSource>)dataSource;
3347

3448
@end

MatrixSDK/Data/EventsEnumerator/MXEventsEnumeratorOnArray.m

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,40 @@
1717
#import "MXEventsEnumeratorOnArray.h"
1818

1919
@interface MXEventsEnumeratorOnArray ()
20-
{
21-
// The list of events to enumerate on.
22-
// The order is chronological: the first item is the oldest message.
23-
NSArray<MXEvent*> *messages;
24-
25-
// This is the position from the end
26-
NSInteger paginationPosition;
27-
}
28-
20+
@property (nonatomic, strong) id<MXEventsEnumeratorDataSource> dataSource;
21+
@property (nonatomic, strong) NSArray<NSString *> *eventIds;
22+
@property (nonatomic) NSInteger paginationPosition;
2923
@end
3024

3125
@implementation MXEventsEnumeratorOnArray
3226

33-
- (instancetype)initWithMessages:(NSArray<MXEvent*> *)theMessages
27+
- (instancetype)initWithEventIds:(NSArray<NSString *> *)eventIds
28+
dataSource:(id<MXEventsEnumeratorDataSource>)dataSource;
3429
{
3530
self = [super init];
3631
if (self)
3732
{
38-
// Copy the array of events references to be protected against mutation of
39-
// theMessages.
40-
// No need of a deep copy as the events it contains are immutable.
41-
messages = [theMessages copy];
42-
paginationPosition = messages.count;
33+
_eventIds = eventIds;
34+
_dataSource = dataSource;
35+
_paginationPosition = _eventIds.count;
4336
}
4437
return self;
4538
}
4639

4740
- (NSArray *)nextEventsBatch:(NSUInteger)eventsCount threadId:(NSString *)threadId
4841
{
49-
if (paginationPosition <= 0)
42+
if (self.paginationPosition <= 0)
5043
{
5144
// there is not any events left
5245
return nil;
5346
}
5447

55-
if (paginationPosition <= eventsCount)
48+
if (self.paginationPosition <= eventsCount)
5649
{
5750
// there is not enough events, return them all
58-
NSArray *result = [messages subarrayWithRange:NSMakeRange(0, paginationPosition)];
59-
paginationPosition = 0;
60-
return result;
51+
NSArray *result = [self.eventIds subarrayWithRange:NSMakeRange(0, self.paginationPosition)];
52+
self.paginationPosition = 0;
53+
return [self eventsForEventIds:result];
6154
}
6255

6356
if (threadId)
@@ -95,18 +88,31 @@ - (MXEvent *)nextEvent
9588
{
9689
MXEvent *nextEvent = nil;
9790

98-
if (0 < paginationPosition)
91+
if (0 < self.paginationPosition)
9992
{
100-
nextEvent = messages[paginationPosition - 1];
101-
paginationPosition--;
93+
NSString *eventId = self.eventIds[self.paginationPosition - 1];
94+
nextEvent = [self.dataSource eventWithEventId:eventId];
95+
self.paginationPosition--;
10296
}
10397

10498
return nextEvent;
10599
}
106100

107101
- (NSUInteger)remaining
108102
{
109-
return paginationPosition;
103+
return self.paginationPosition;
104+
}
105+
106+
- (NSArray <MXEvent *>*)eventsForEventIds:(NSArray <NSString *>*)eventIds
107+
{
108+
NSMutableArray *events = [[NSMutableArray alloc] initWithCapacity:eventIds.count];
109+
for (NSString *eventId in eventIds) {
110+
MXEvent *event = [self.dataSource eventWithEventId:eventId];
111+
if (event) {
112+
[events addObject:event];
113+
}
114+
}
115+
return events.copy;
110116
}
111117

112118
@end

MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#import "MXEventsEnumeratorOnArray.h"
2121
#import "MXEventsByTypesEnumeratorOnArray.h"
2222

23-
@interface MXMemoryRoomStore ()
23+
@interface MXMemoryRoomStore () <MXEventsEnumeratorDataSource>
2424
{
2525
}
2626

@@ -85,14 +85,23 @@ - (void)removeAllMessages
8585
[messagesByEventIds removeAllObjects];
8686
}
8787

88+
- (NSArray <NSString *>*)allEventIds
89+
{
90+
NSMutableArray *eventIds = [[NSMutableArray alloc] initWithCapacity:messages.count];
91+
for (MXEvent *event in messages) {
92+
[eventIds addObject:event.eventId];
93+
}
94+
return eventIds.copy;
95+
}
96+
8897
- (id<MXEventsEnumerator>)messagesEnumerator
8998
{
90-
return [[MXEventsEnumeratorOnArray alloc] initWithMessages:messages];
99+
return [[MXEventsEnumeratorOnArray alloc] initWithEventIds:[self allEventIds] dataSource:self];
91100
}
92101

93102
- (id<MXEventsEnumerator>)enumeratorForMessagesWithTypeIn:(NSArray*)types
94103
{
95-
return [[MXEventsByTypesEnumeratorOnArray alloc] initWithMessages:messages andTypesIn:types];
104+
return [[MXEventsByTypesEnumeratorOnArray alloc] initWithEventIds:[self allEventIds] andTypesIn:types dataSource:self];
96105
}
97106

98107
- (NSArray<MXEvent*>*)eventsAfter:(NSString *)eventId threadId:(NSString *)threadId except:(NSString *)userId withTypeIn:(NSSet<MXEventTypeString>*)types

MatrixSDK/Data/Store/MXNoStore/MXNoStore.m

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#import "MXEventsEnumeratorOnArray.h"
2121
#import "MXVoidRoomSummaryStore.h"
2222

23-
@interface MXNoStore ()
23+
@interface MXNoStore () <MXEventsEnumeratorDataSource>
2424
{
2525
// key: roomId, value: the pagination token
2626
NSMutableDictionary<NSString*, NSString*> *paginationTokens;
@@ -239,15 +239,19 @@ - (BOOL)hasLoadedAllRoomMembersForRoom:(NSString *)roomId
239239
// of MXNoStore is to not store messages so that all paginations are made
240240
// via requests to the homeserver.
241241
// So, return an empty enumerator.
242-
return [[MXEventsEnumeratorOnArray alloc] initWithMessages:@[]];
242+
return [[MXEventsEnumeratorOnArray alloc] initWithEventIds:@[] dataSource:nil];
243243
}
244244

245245
- (id<MXEventsEnumerator>)messagesEnumeratorForRoom:(NSString *)roomId withTypeIn:(NSArray *)types
246246
{
247247
// [MXStore messagesEnumeratorForRoom: withTypeIn: ignoreMemberProfileChanges:] is used
248248
// to get the last message of the room which must not be nil.
249249
// So return an enumerator with the last message we have without caring of its type.
250-
return [[MXEventsEnumeratorOnArray alloc] initWithMessages:@[lastMessages[roomId]]];
250+
MXEvent *event = lastMessages[roomId];
251+
if (event) {
252+
return [[MXEventsEnumeratorOnArray alloc] initWithEventIds:@[event.eventId] dataSource:self];
253+
}
254+
return [[MXEventsEnumeratorOnArray alloc] initWithEventIds:@[] dataSource:nil];
251255
}
252256

253257
- (NSArray<MXEvent *> *)relationsForEvent:(NSString *)eventId inRoom:(NSString *)roomId relationType:(NSString *)relationType
@@ -462,4 +466,16 @@ - (void)close
462466
[groups removeAllObjects];
463467
}
464468

469+
#pragma mark - MXEventsEnumeratorDataSource
470+
471+
- (MXEvent *)eventWithEventId:(NSString *)eventId
472+
{
473+
for (MXEvent *event in lastMessages.allValues) {
474+
if ([event.eventId isEqualToString:eventId]) {
475+
return event;
476+
}
477+
}
478+
return nil;
479+
}
480+
465481
@end

0 commit comments

Comments
 (0)