Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh committed Apr 20, 2022
1 parent c153eef commit de6196a
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions apps/meteor/client/views/room/MessageList/hooks/useMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,19 @@ const options = {
},
};

// In a previous version of the app, some values were being set to null instead of undefined.
// In a previous version of the app, some values were being set to null.
// This is a workaround to remove those null values.
// A migration script should be created to remove this code.
const ifNullUndefined = <T extends any>(value: T): T | undefined => (value === null ? undefined : value);

const removePossibleNullValues = ({
editedBy,
editedAt,
emoji,
avatar,
alias,
customFields,
groupable,
attachments,
reactions,
...message
}: any): IMessage => ({
...message,
editedBy: ifNullUndefined(editedBy),
editedAt: ifNullUndefined(editedAt),
emoji: ifNullUndefined(emoji),
avatar: ifNullUndefined(avatar),
alias: ifNullUndefined(alias),
customFields: ifNullUndefined(customFields),
groupable: ifNullUndefined(groupable),
attachments: ifNullUndefined(attachments),
reactions: ifNullUndefined(reactions),
});
const nullValuesList = ['editedBy', 'editedAt', 'emoji', 'avatar', 'alias', 'customFields', 'groupable', 'attachments', 'reactions'];

const removePossibleNullValues = (message: any): IMessage => {
nullValuesList.forEach((key) => {
if (message[key] === null) {
delete message[key];
}
});
return message;
};

export const useMessages = ({ rid }: { rid: IRoom['_id'] }): IMessage[] => {
const showInMainThread = useUserPreference<boolean>('showMessageInMainThread', false);
Expand Down

0 comments on commit de6196a

Please sign in to comment.