How to use the @rematch/core.dispatch.chats function in @rematch/core

To help you get started, we’ve selected a few @rematch/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EvanBacon / pro-chat / client / src / rematch / chats.js View on Github external
// 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 }) => {
github EvanBacon / pro-chat / client / src / screens / ChatScreen.js View on Github external
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 });
  }
github EvanBacon / pro-chat / client / src / rematch / chats.js View on Github external
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]) {
github EvanBacon / pro-chat / client / src / components / MessageRow.js View on Github external
onLongPress = () => {
    console.warn('TODO: MessageRow.onLongPress');
    dispatch.chats.deleteChannel(this.props.groupId);
  };
github EvanBacon / pro-chat / client / src / Fire.js View on Github external
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;
  };
github EvanBacon / pro-chat / client / src / Fire.js View on Github external
return ref.onSnapshot((snapshot) => {
      console.log('GOT MESSAGES', snapshot.docs.length);
      return dispatch.chats.receivedMessage({ groupId, snapshot });
    });
  };
github EvanBacon / pro-chat / client / src / screens / ChatScreen.js View on Github external
InteractionManager.runAfterInteractions(() => {
      dispatch.chats.updatedGifOpened({
        isOpened: false,
      });
      this._GiftedMessenger.setBottomOffset(this._GiftedMessenger.getKeyboardHeight());
    });
  };
github EvanBacon / pro-chat / client / src / screens / ChatScreen.js View on Github external
  onLoadEarlier = () => dispatch.chats.loadEarlier(this.props.channel);