Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Validate empty fields for Message template #25250

Merged
merged 8 commits into from
Apr 27, 2022
16 changes: 15 additions & 1 deletion apps/meteor/client/views/room/MessageList/hooks/useMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ const options = {
},
};

// 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 nullValuesList = ['editedBy', 'editedAt', 'emoji', 'avatar', 'alias', 'customFields', 'groupable', 'attachments', 'reactions'];

const removePossibleNullValues = (message: any): IMessage => {
gabriellsh marked this conversation as resolved.
Show resolved Hide resolved
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);
// const hideSettings = !!useSetting('Hide_System_Messages');
Expand All @@ -35,5 +49,5 @@ export const useMessages = ({ rid }: { rid: IRoom['_id'] }): IMessage[] => {
// query.t = { $nin: Array.from(hideMessagesOfType.values()) };
// }

return useReactiveValue<IMessage[]>(useCallback(() => ChatMessage.find(query, options).fetch(), [query]));
return useReactiveValue<IMessage[]>(useCallback(() => ChatMessage.find(query, options).fetch().map(removePossibleNullValues), [query]));
};