async subscribeToChats(callback) {
    const user = await getCurrentUser();
    if (user === null) {
      throw new ChatError('invalid-user-id');
    }
    const userId = user.uid;
    const userType = await this._getUserTypeInfo(userId);
    const userIdField = `${userType}.id`;

    return chatsCollection
      .where(userIdField, '==', userId)
      .orderBy('lastMessage.dateTime', 'desc')
      .limit(USER_CHATS_BATCH_SIZE)
      .onSnapshot((snapshot) => {
        snapshot.docChanges().forEach((change) => {
          if (change.type === 'added') {
            callback(ADDED, change.doc);
          }
          if (change.type === 'modified') {
            callback(MODIFIED, change.doc);
          }
        });
      });
  }
/**
   * Subscribe to chats belonging to the current logged in user. Does not include chat messages
   * @param {function(string, object): void} callback The function to call to handle the change in chats.
   * The callback will return a USER_CHATS_BATCH_SIZE of chats belonging to the user on the initial subscription
   * It is recommended to use this function to fetch the first batch of chats and use the getChatsForNPO / getChatsForDonor to get older chats
   *  The first argument is type. The type of change of the chat. Refer to the constant file `chatSubscriptionChange` to see which are the changed provided
   *  The second argument is doc. The firebase document that is changed
   * @throws {ChatError}
   * @throws {FirebaseError}
   * @return {function} The subscriber function. Needed to unsubscribe from the listener
   */
Subscribe to chats belonging to the current logged in user. Does not include chat messages
@param {function(string, object): void} callback The function to call to handle the change in chats.
The callback will return a USER_CHATS_BATCH_SIZE of chats belonging to the user on the initial subscription
It is recommended to use this function to fetch the first batch of chats and use the getChatsForNPO / getChatsForDonor to get older chats
The first argument is type. The type of change of the chat. Refer to the constant file `chatSubscriptionChange` to see which are the changed provided
The second argument is doc. The firebase document that is changed
@throws {ChatError}
@throws {FirebaseError}
@return {function} The subscriber function. Needed to unsubscribe from the listener
Subscribe to chats belonging to the current logged in user . Does not include chat messages @param { function ( string object ) : void } callback The function to call to handle the change in chats . The callback will return a USER_CHATS_BATCH_SIZE of chats belonging to the user on the initial subscription It is recommended to use this function to fetch the first batch of chats and use the getChatsForNPO / getChatsForDonor to get older chats The first argument is type . The type of change of the chat . Refer to the constant file ` chatSubscriptionChange ` to see which are the changed provided The second argument is doc . The firebase document that is changed @throws { ChatError } @throws { FirebaseError } @return { function } The subscriber function . Needed to unsubscribe from the listener
async subscribeToChats(callback) {
    const user = await getCurrentUser();
    if (user === null) {
      throw new ChatError('invalid-user-id');
    }
    const userId = user.uid;
    const userType = await this._getUserTypeInfo(userId);
    const userIdField = `${userType}.id`;
    return chatsCollection
      .where(userIdField, '==', userId)
      .orderBy('lastMessage.dateTime', 'desc')
      .limit(USER_CHATS_BATCH_SIZE)
      .onSnapshot((snapshot) => {
        snapshot.docChanges().forEach((change) => {
          if (change.type === 'added') {
            callback(ADDED, change.doc);
          }
          if (change.type === 'modified') {
            callback(MODIFIED, change.doc);
          }
        });
      });
  }
async subscribeToChats ( callback ) { const user = await getCurrentUser ( ) ; if ( user === null ) { throw new ChatError ( 'invalid-user-id' ) ; } const userId = user . uid ; const userType = await this . _getUserTypeInfo ( userId ) ; const userIdField = ` ${ userType } ` ; return chatsCollection . where ( userIdField , '==' , userId ) . orderBy ( 'lastMessage.dateTime' , 'desc' ) . limit ( USER_CHATS_BATCH_SIZE ) . onSnapshot ( ( snapshot ) => { snapshot . docChanges ( ) . forEach ( ( change ) => { if ( change . type === 'added' ) { callback ( ADDED , change . doc ) ; } if ( change . type === 'modified' ) { callback ( MODIFIED , change . doc ) ; } } ) ; } ) ; }
Subscribe to chats belonging to the current logged in user.
Subscribe to chats belonging to the current logged in user .