Skip to content

Commit

Permalink
runfix: do not group system messages with content messages (#16770)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc authored Feb 6, 2024
1 parent 1b4d674 commit e752bd3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/script/components/MessagesList/utils/messagesGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {TimeInMillis} from '@wireapp/commons/lib/util/TimeUtil';
import {EventMapper} from 'src/script/conversation/EventMapper';
import {Conversation} from 'src/script/entity/Conversation';
import {Message} from 'src/script/entity/message/Message';
import {createMessageAddEvent} from 'test/helper/EventGenerator';
import {createGroupCreationEvent, createMessageAddEvent} from 'test/helper/EventGenerator';
import {getRandomNumber} from 'Util/NumberUtil';
import {createUuid} from 'Util/uuid';

Expand Down Expand Up @@ -56,6 +56,19 @@ describe('MessagesGroup', () => {
expect(lastGroup.sender).toBe(sender);
});

it('does not group together system messages and content messages', () => {
const sender = createUuid();
const groupCreationMessage = createGroupCreationEvent({from: sender});
const contentMessage = createMessageAddEvent({overrides: {from: sender}});

const allMessages = [groupCreationMessage, contentMessage].map(
event => eventMapper.mapJsonEvent(event, conversation) as Message,
);

const groupedMessages = groupMessagesBySenderAndTime(allMessages, 0);
expect(groupedMessages).toHaveLength(2);
});

it('adds markers for unread messages', () => {
const nbReadMessages = getRandomNumber(1, 10);
const nbUnreadMessages = getRandomNumber(1, 10);
Expand Down
6 changes: 5 additions & 1 deletion src/script/components/MessagesList/utils/messagesGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,19 @@ export function groupMessagesBySenderAndTime(messages: Message[], lastReadTimest
return messages.reduce<Array<MessagesGroup | Marker>>((acc, message, index) => {
const lastItem = acc[acc.length - 1];
const lastGroupInfo = isMarker(lastItem) ? undefined : lastItem;
const previousMessage = messages[index - 1];

const marker = getMessageMarkerType(message, lastReadTimestamp, messages[index - 1]);
const marker = getMessageMarkerType(message, lastReadTimestamp, previousMessage);

if (marker) {
// if there is a marker to insert, we insert it before the current message
acc.push({type: marker, timestamp: message.timestamp()});
}

const areContentMessages = message.isContent() && previousMessage?.isContent();

if (
areContentMessages &&
lastGroupInfo &&
lastGroupInfo.sender === message.from &&
shouldGroupMessagesByTimestamp(
Expand Down
17 changes: 17 additions & 0 deletions test/helper/EventGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
AssetAddEvent,
DeleteEvent,
EventBuilder,
GroupCreationEvent,
MemberLeaveEvent,
MessageAddEvent,
ReactionEvent,
Expand Down Expand Up @@ -124,6 +125,22 @@ export function createAssetAddEvent(overrides: Partial<AssetAddEvent> = {}): Ass
};
}

export function createGroupCreationEvent(overrides: Partial<GroupCreationEvent>): GroupCreationEvent {
return {
conversation: createUuid(),
data: {
userIds: [],
allTeamMembers: false,
name: '',
},
from: createUuid(),
id: createUuid(),
time: new Date().toISOString(),
type: CONVERSATION.GROUP_CREATION,
...overrides,
};
}

/**
* will simulate en event that has been saved to the DB
* @param event
Expand Down

0 comments on commit e752bd3

Please sign in to comment.