Skip to content

Commit

Permalink
runfix: Only create a single system message for federation user remov…
Browse files Browse the repository at this point in the history
…al (#15967)
  • Loading branch information
atomrc authored Oct 11, 2023
1 parent 6715490 commit fbf72ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/script/conversation/ConversationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1754,9 +1754,9 @@ export class ConversationRepository {
*/
private async removeMembersLocally(conversation: Conversation, userIds: QualifiedId[]) {
const currentTimestamp = this.serverTimeHandler.toServerTimestamp();
const events = userIds.map(userId => EventBuilder.buildMemberLeave(conversation, userId, true, currentTimestamp));
const event = EventBuilder.buildMemberLeave(conversation, userIds, '', currentTimestamp);
// Injecting the event will trigger all the handlers that will then actually remove the users from the conversation
await this.eventRepository.injectEvents(events, EventRepository.SOURCE.INJECTED);
await this.eventRepository.injectEvent(event);
}

/**
Expand Down Expand Up @@ -1789,7 +1789,7 @@ export class ConversationRepository {
const currentTimestamp = this.serverTimeHandler.toServerTimestamp();
const event = hasResponse
? response.event
: EventBuilder.buildMemberLeave(conversationEntity, user, true, currentTimestamp);
: EventBuilder.buildMemberLeave(conversationEntity, [user], this.userState.self().id, currentTimestamp);

this.eventRepository.injectEvent(event, EventRepository.SOURCE.BACKEND_RESPONSE);
return event;
Expand Down
10 changes: 5 additions & 5 deletions src/script/conversation/EventBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,17 +476,17 @@ export const EventBuilder = {

buildMemberLeave(
conversationEntity: Conversation,
userId: QualifiedId,
removedBySelfUser: boolean,
userIds: QualifiedId[],
from: string,
currentTimestamp: number,
): MemberLeaveEvent {
return {
...buildQualifiedId(conversationEntity),
data: {
qualified_user_ids: [userId],
user_ids: [userId.id],
qualified_user_ids: userIds,
user_ids: userIds.map(({id}) => id),
},
from: removedBySelfUser ? conversationEntity.selfUser().id : userId.id,
from: from,
time: conversationEntity.getNextIsoDate(currentTimestamp),
type: CONVERSATION_EVENT.MEMBER_LEAVE,
};
Expand Down
2 changes: 1 addition & 1 deletion src/script/entity/message/MemberMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class MemberMessage extends SystemMessage {
}

const allUsers = this.generateNameString();
if (!this.user().isMe && !name) {
if (!this.user().id) {
return t('conversationMemberWereRemoved', allUsers);
}
return this.user().isMe
Expand Down

0 comments on commit fbf72ff

Please sign in to comment.