Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// TODO: Nope...
const user = await new Promise(res =>
dispatch.users.ensureUserIsLoadedAsync({ uid, callback: res }));
console.log('_parseMessage: has user', !!user, uid);
// const user = await Fire.shared.getUserAsync({ uid });
if (user == null) {
throw new Error("Invalid User data found, can't parse message");
}
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 }) => {
async componentDidMount() {
const { otherUserId, groupId } = this.props;
// dispatch.chats.clear({ uid: groupId });
console.log("mounted chat", otherUserId);
dispatch.chats.startChatting({
groupId,
uids: otherUserId,
callback: (unsubscribe) => {
this.unsubscribe = unsubscribe;
},
})
dispatch.isTyping.observe({ groupId, uid: otherUserId }); // TODO: UNSUB
// dispatch.users.getProfileImage({ uid: otherUserId });
}
snapshot.docChanges().forEach(({ type, doc }) => {
console.log('Found message: parseMessagesSnapshot: ', type, doc.id);
if (type === 'added') {
const message = { key: doc.id, ...doc.data() };
dispatch.chats._parseMessage({ message, groupId });
} else if (type === 'removed') {
// removed
const messageKey = doc.id;
dispatch.chats.removeMessage({ messageKey, groupId });
// TODO: Maybe remove
} else {
console.warn('TODO: parseMessagesSnapshot: ', type);
}
});
if (!firstCursorCollection[groupId]) {
onLongPress = () => {
console.warn('TODO: MessageRow.onLongPress');
dispatch.chats.deleteChannel(this.props.groupId);
};
loadMoreFromChatGroup = async ({ groupId, startBefore }) => {
const PAGE_SIZE = 5;
const ref = this.getMessagesCollection(groupId)
.orderBy('timestamp', 'desc')
.limit(PAGE_SIZE)
.startBefore(startBefore);
const snapshot = await ref.get();
dispatch.chats.receivedMessage({ groupId, snapshot });
return snapshot;
};
return ref.onSnapshot((snapshot) => {
console.log('GOT MESSAGES', snapshot.docs.length);
return dispatch.chats.receivedMessage({ groupId, snapshot });
});
};
InteractionManager.runAfterInteractions(() => {
dispatch.chats.updatedGifOpened({
isOpened: false,
});
this._GiftedMessenger.setBottomOffset(this._GiftedMessenger.getKeyboardHeight());
});
};
onLoadEarlier = () => dispatch.chats.loadEarlier(this.props.channel);