1- import firestore from '@react-native-firebase/firestore'
2- import * as React from 'react'
1+ import firestore from '@react-native-firebase/firestore' ;
2+ import * as React from 'react' ;
33
4- import { ROOMS_COLLECTION_NAME } from '.'
5- import { Room , User } from './types'
6- import { useFirebaseUser } from './useFirebaseUser'
7- import { fetchUser , processRoomsQuery } from './utils'
4+ import { ROOMS_COLLECTION_NAME } from '.' ;
5+ import { IRoom , IUser } from './types' ;
6+ import { useFirebaseUser } from './useFirebaseUser' ;
7+ import { fetchUser , processRoomsQuery } from './utils' ;
88
99/** Returns a stream of rooms from Firebase. Only rooms where current
1010 * logged in user exist are returned. `orderByUpdatedAt` is used in case
@@ -17,7 +17,7 @@ import { fetchUser, processRoomsQuery } from './utils'
1717 * is `rooms`, field indexed are `userIds` (type Arrays) and `updatedAt`
1818 * (type Descending), query scope is `Collection` */
1919export const useRooms = ( orderByUpdatedAt ?: boolean ) => {
20- const [ rooms , setRooms ] = React . useState < Room [ ] > ( [ ] )
20+ const [ rooms , setRooms ] = React . useState < IRoom [ ] > ( [ ] )
2121 const { firebaseUser } = useFirebaseUser ( )
2222
2323 React . useEffect ( ( ) => {
@@ -28,12 +28,12 @@ export const useRooms = (orderByUpdatedAt?: boolean) => {
2828
2929 const collection = orderByUpdatedAt
3030 ? firestore ( )
31- . collection ( ROOMS_COLLECTION_NAME )
32- . where ( 'userIds' , 'array-contains' , firebaseUser . uid )
33- . orderBy ( 'updatedAt' , 'desc' )
31+ . collection ( ROOMS_COLLECTION_NAME )
32+ . where ( 'userIds' , 'array-contains' , firebaseUser . uid )
33+ . orderBy ( 'updatedAt' , 'desc' )
3434 : firestore ( )
35- . collection ( ROOMS_COLLECTION_NAME )
36- . where ( 'userIds' , 'array-contains' , firebaseUser . uid )
35+ . collection ( ROOMS_COLLECTION_NAME )
36+ . where ( 'userIds' , 'array-contains' , firebaseUser . uid )
3737
3838 return collection . onSnapshot ( async ( query ) => {
3939 const newRooms = await processRoomsQuery ( { firebaseUser, query } )
@@ -55,7 +55,7 @@ export const useRooms = (orderByUpdatedAt?: boolean) => {
5555 imageUrl ?: string
5656 metadata ?: Record < string , any >
5757 name : string
58- users : User [ ]
58+ users : IUser [ ]
5959 } ) => {
6060 if ( ! firebaseUser ) return
6161
@@ -86,12 +86,12 @@ export const useRooms = (orderByUpdatedAt?: boolean) => {
8686 name,
8787 type : 'group' ,
8888 users : roomUsers ,
89- } as Room
89+ } as IRoom
9090 }
9191
9292 /** Creates a direct chat for 2 people. Add `metadata` for any additional custom data. */
9393 const createRoom = async (
94- otherUser : User ,
94+ otherUser : IUser ,
9595 metadata ?: Record < string , any >
9696 ) => {
9797 if ( ! firebaseUser ) return
@@ -138,7 +138,7 @@ export const useRooms = (orderByUpdatedAt?: boolean) => {
138138 metadata,
139139 type : 'direct' ,
140140 users,
141- } as Room
141+ } as IRoom
142142 }
143143
144144 return { createGroupRoom, createRoom, rooms }
0 commit comments