Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log('Add Message', message.key);
const messages = {
...chats[groupId],
[message.key]: transformMessageForGiftedChat({ message, user }),
};
dispatch.chats.addMessages({
groupId,
messages,
});
// / UGH
const sortedMessages = Object.values(messages).sort((a, b) => a.timestamp < b.timestamp);
dispatch.messages.updateWithMessage({
groupId,
message: sortedMessages[0],
});
},
startChatting: async ({ uids, callback, groupId }, { chats }) => {
const idx = memberUids.indexOf(uid);
if (idx > -1) memberUids.splice(idx, 1);
// TODO: Evan: Promise.all([])
const { data } = await this.getLastMessageForChatGroup({ groupId });
const message = data[0] || {};
const group = memberUids;
// TODO: Evan: Handle groups yolo
const sender = group[0]; //message.uid ||
const user = await (new Promise(res => dispatch.users.ensureUserIsLoadedAsync({ uid: sender, callback: res }) ));
const previewMessage = this.formatMessageForPreview(message, groupId, user, group);
previewMessages[groupId] = previewMessage;
}
if (force) {
dispatch.messages.clear();
}
dispatch.messages.update(previewMessages);
return previewMessages;
};
// TODO: dont get all data for each user
updateWithMessage: ({ groupId, message }) => {
dispatch.messages.update({
[groupId]: Fire.shared.formatMessageForPreview(message, groupId),
});
},
},