-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
444 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { Routes, RouterModule } from '@angular/router'; | ||
|
||
import { ChatViewPage } from './chat-view.page'; | ||
|
||
const routes: Routes = [ | ||
{ | ||
path: '', | ||
component: ChatViewPage | ||
} | ||
]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
exports: [RouterModule], | ||
}) | ||
export class ChatViewPageRoutingModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { FormsModule } from '@angular/forms'; | ||
|
||
import { IonicModule } from '@ionic/angular'; | ||
|
||
import { ChatViewPageRoutingModule } from './chat-view-routing.module'; | ||
|
||
import { ChatViewPage } from './chat-view.page'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
FormsModule, | ||
IonicModule, | ||
ChatViewPageRoutingModule | ||
], | ||
declarations: [ChatViewPage] | ||
}) | ||
export class ChatViewPageModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<ion-header> | ||
<ion-toolbar color="primary"> | ||
<ion-title>chat-app</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button (click)="sendPicture()"><ion-icon name="image" slot="end"></ion-icon>Send Image</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
|
||
<ion-content class="chat-view"> | ||
|
||
<ion-card> | ||
<ion-card-header> | ||
<ion-card-title color="success"> | ||
<em>Chat View</em> | ||
</ion-card-title> | ||
</ion-card-header> | ||
</ion-card> | ||
|
||
<div class="messages"> | ||
<ion-item lines="none" color="{{ uid === chat.from ? 'primary' : 'light'}}" class="message" [ngClass]="{'me': uid === chat.from}" *ngFor="let chat of chats"> | ||
<ion-avatar slot="start"> | ||
<img src="{{interlocutorUIDData.picture}}" title="{{interlocutorUIDData.name}}" *ngIf="uid !== chat.from"> | ||
<img src="{{uidData.picture}}" *ngIf="uid === chat.from"> | ||
</ion-avatar> | ||
<p>{{chat.message}}</p> | ||
<img *ngIf="chat.picture" src="{{chat.picture}}"> | ||
</ion-item> | ||
</div> | ||
|
||
</ion-content> | ||
|
||
<ion-footer> | ||
<ion-toolbar color="light"> | ||
<ion-row> | ||
<ion-col size="1"> | ||
<ion-spinner *ngIf="!(chats)"></ion-spinner> | ||
</ion-col> | ||
<ion-col size="7" [hidden]="!chats"> | ||
<ion-input type="text" [(ngModel)]="message" placeholder="Enter Message..."></ion-input> | ||
</ion-col> | ||
<ion-col size="4" [hidden]="!chats"> | ||
<ion-button color="dark" expand="block" (click)="sendMessage()"><ion-icon name="send"></ion-icon></ion-button> | ||
</ion-col> | ||
</ion-row> | ||
</ion-toolbar> | ||
</ion-footer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.messages { | ||
width: 100%; | ||
position: absolute; | ||
} | ||
.message { | ||
width: 65%; | ||
padding: 5px 10px; | ||
border-radius: 5px; | ||
margin: 5px; | ||
float: left | ||
} | ||
.message.me { | ||
float: right; | ||
text-align: right | ||
} | ||
ion-item { | ||
--border-radius: 20px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { IonicModule } from '@ionic/angular'; | ||
|
||
import { ChatViewPage } from './chat-view.page'; | ||
|
||
describe('ChatViewPage', () => { | ||
let component: ChatViewPage; | ||
let fixture: ComponentFixture<ChatViewPage>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ ChatViewPage ], | ||
imports: [IonicModule.forRoot()] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ChatViewPage); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Component, OnInit, ViewChild } from '@angular/core'; | ||
import { ChatsService } from '../services/chats/chats.service'; | ||
import { AngularFireDatabase, AngularFireList } from '@angular/fire/database'; | ||
import { CameraService } from '../services/camera/camera.service'; | ||
import { Chat } from '../models/chat'; | ||
import { User } from '../models/user'; | ||
import { UtilService } from '../services/util/util.service'; | ||
|
||
@Component({ | ||
selector: 'app-chat-view', | ||
templateUrl: './chat-view.page.html', | ||
styleUrls: ['./chat-view.page.scss'], | ||
}) | ||
export class ChatViewPage implements OnInit { | ||
|
||
message: string; | ||
uid : string = ''; | ||
interlocutorUID : string = ''; | ||
chats: Array<Chat>; | ||
chatsRef : AngularFireList<Chat>; | ||
|
||
uidData: User; | ||
interlocutorUIDData : User; | ||
|
||
constructor(private chatsService: ChatsService, private db : AngularFireDatabase, private utilService : UtilService, private camera: CameraService) { | ||
this.utilService.doLoading('Please Wait...'); | ||
// get uids | ||
this.uid = this.chatsService.chatter.uid | ||
this.interlocutorUID = this.chatsService.chatter.interlocutorUID; | ||
|
||
// get chat Reference | ||
chatsService.getChatRef(this.uid, this.interlocutorUID).then((chatRefPath : string) => { | ||
console.log('chatRef: uid, interlocutorUID', chatRefPath); | ||
this.chatsRef = this.db.list(chatRefPath); | ||
this.db.list(chatRefPath).valueChanges().subscribe((chats : Chat[]) => { console.log('chats', chats); this.chats = chats }) ; | ||
|
||
}); | ||
this.db.object(`/users/${this.uid}`).valueChanges().subscribe((user : User) => this.uidData = user); | ||
this.db.object(`/users/${this.interlocutorUID}`).valueChanges().subscribe((user : User) => { console.log('interlo', user); this.interlocutorUIDData = user }); | ||
} | ||
|
||
sendMessage() : void { | ||
if(this.message) { | ||
let chat : Chat = { | ||
from: this.uid, | ||
message : this.message, | ||
type: 'message', | ||
to: this.interlocutorUID, | ||
picture : null | ||
}; | ||
this.chatsRef.push(chat); | ||
this.message =""; | ||
} | ||
}; | ||
|
||
sendPicture() : void { | ||
|
||
this.camera.getPicture().then(imageData => { | ||
let chat: Chat = { | ||
from: this.uid, | ||
message: '', | ||
type: 'picture', | ||
picture: 'data:image/jpeg;base64,' + imageData, | ||
to: this.interlocutorUID, | ||
}; | ||
this.chatsRef.push(chat); | ||
}).catch(err => this.utilService.doAlert(`Error`, `This feature only works on Mobiles.`, 'OK')); | ||
} | ||
ngOnInit() { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class Chat { | ||
from : string; | ||
type: string; | ||
message: string; | ||
to: string; | ||
picture: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export class Chatter { | ||
uid : string; | ||
interlocutorUID : string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.