Skip to content

Commit 0e73874

Browse files
committed
fix: bad state for event member creation
1 parent ffbf02f commit 0e73874

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/federation-sdk/src/services/state.service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ export class StateService {
114114
* Returns the state used to validate the event
115115
* This is the state prior to the event
116116
*/
117-
async findStateAtEvent(eventId: string): Promise<State> {
117+
async findStateAtEvent(
118+
eventId: string,
119+
include: 'always' | 'event' = 'event',
120+
): Promise<State> {
118121
this.logger.debug({ eventId }, 'finding state before event');
119122

120123
const event = await this.eventRepository.findById(eventId);
@@ -136,7 +139,10 @@ export class StateService {
136139

137140
// The fully resolved state for the room, prior to considering any state changes induced by the requested event. Includes the authorization chain for the events.
138141

139-
if (pdu.type === 'm.room.create') {
142+
const includeEvent =
143+
include === 'always' || (include === 'event' && !pdu.isState());
144+
145+
if (pdu.isCreateEvent() && !includeEvent) {
140146
return new Map();
141147
}
142148

@@ -157,8 +163,6 @@ export class StateService {
157163

158164
const state = new Map<StateMapKey, PersistentEventBase>();
159165

160-
const includeEvent = !pdu.isState();
161-
162166
/**
163167
* If the event is a state event, we don't include the event in the state, otherwise the state would be the new state
164168
* computed because of the event
@@ -621,7 +625,7 @@ export class StateService {
621625
lastState?._id?.toString(),
622626
);
623627

624-
const state = await this.findStateAtEvent(lastEvent._id);
628+
const state = await this.findStateAtEvent(lastEvent._id, 'always');
625629

626630
this.logState('state at last event seen:', state);
627631

0 commit comments

Comments
 (0)