Skip to content

Commit

Permalink
subscribe to user in chat service
Browse files Browse the repository at this point in the history
  • Loading branch information
jhuleatt committed May 11, 2024
1 parent 7626f5d commit e39ec81
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions angularfire-start/src/app/services/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getAuth,
User,
} from '@angular/fire/auth';
import { map, switchMap, firstValueFrom, filter, Observable } from 'rxjs';
import { map, switchMap, firstValueFrom, filter, Observable, Subscription } from 'rxjs';
import {
doc,
docData,
Expand All @@ -29,6 +29,7 @@ import {
limit,
onSnapshot,
DocumentData,
FieldValue,
} from '@angular/fire/firestore';
import {
Storage,
Expand All @@ -39,6 +40,16 @@ import {
import { getToken, Messaging, onMessage } from '@angular/fire/messaging';
import { Router } from '@angular/router';

type ChatMessage = {
name: string | null,
profilePicUrl: string | null,
timestamp: FieldValue,
uid: string | null,
text?: string,
imageUrl?: string
};


@Injectable({
providedIn: 'root',
})
Expand All @@ -51,8 +62,16 @@ export class ChatService {
private provider = new GoogleAuthProvider();
LOADING_IMAGE_URL = 'https://www.google.com/images/spin-32.gif?a';

// Observable user
// observable that is updated when the auth state changes
user$ = user(this.auth);
currentUser: User | null = this.auth.currentUser;
userSubscription: Subscription;

constructor() {
this.userSubscription = this.user$.subscribe((aUser: User | null) => {
this.currentUser = aUser;
});
}

// Login Friendly Chat.
login() {}
Expand Down

0 comments on commit e39ec81

Please sign in to comment.