Skip to content

Commit

Permalink
Add Metadata to Room for easier extensibility (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Voidozzer authored and demchenkoalex committed Apr 22, 2021
1 parent 4fd621b commit 8a387a0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flyerhq/react-native-firebase-chat-core",
"version": "1.0.0",
"version": "1.0.1",
"description": "Actively maintained, community-driven Firebase BaaS for chat applications with an optional chat UI.",
"homepage": "https://flyer.chat",
"main": "lib/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface PreviewDataImage {
export interface Room {
id: string
imageUrl?: string
metadata?: Record<string, any>
name?: string
type: 'direct' | 'group'
users: User[]
Expand Down
11 changes: 10 additions & 1 deletion src/useRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ export const useRooms = () => {

const createGroupRoom = async ({
imageUrl,
metadata,
name,
users,
}: {
imageUrl?: string
metadata?: Record<string, any>
name: string
users: User[]
}) => {
Expand All @@ -44,6 +46,7 @@ export const useRooms = () => {
.collection('rooms')
.add({
imageUrl,
metadata,
name,
type: 'group',
userIds: roomUsers.map((u) => u.id),
Expand All @@ -52,13 +55,17 @@ export const useRooms = () => {
return {
id: room.id,
imageUrl,
metadata,
name,
type: 'group',
users: roomUsers,
} as Room
}

const createRoom = async (otherUser: User) => {
const createRoom = async (
otherUser: User,
metadata?: Record<string, any>
) => {
if (!firebaseUser) return

const query = await firestore()
Expand Down Expand Up @@ -89,13 +96,15 @@ export const useRooms = () => {
.collection('rooms')
.add({
imageUrl: undefined,
metadata,
name: undefined,
type: 'direct',
userIds: users.map((u) => u.id),
})

return {
id: room.id,
metadata,
type: 'direct',
users,
} as Room
Expand Down
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const processRoomsQuery = async ({
}) => {
const promises = query.docs.map(async (doc) => {
let imageUrl = (doc.get('imageUrl') as string | null) ?? undefined
let metadata =
(doc.get('metadata') as Record<string, any> | null) ?? undefined
let name = (doc.get('name') as string | null) ?? undefined
const type = doc.get('type') as Room['type']
const userIds = doc.get('userIds') as string[]
Expand All @@ -45,6 +47,7 @@ export const processRoomsQuery = async ({
const room: Room = {
id: doc.id,
imageUrl,
metadata,
name,
type,
users,
Expand Down

0 comments on commit 8a387a0

Please sign in to comment.