notification

This commit is contained in:
Peter Maquiran
2022-01-26 17:28:55 +01:00
parent 58a32f45d4
commit 66098ae4e8
5 changed files with 87 additions and 15 deletions
+5 -1
View File
@@ -29,6 +29,7 @@ import { RouteService } from 'src/app/services/route.service';
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { environment } from 'src/environments/environment';
import { v4 as uuidv4 } from 'uuid'
import { NativeNotificationService } from 'src/app/services/native-notification.service';
@Component({
selector: 'app-home',
@@ -100,10 +101,13 @@ export class HomePage implements OnInit {
private screenOrientation: ScreenOrientation,
private sqliteservice: SqliteService,
private RouteService: RouteService,
private WsChatService: WsChatService) {
private WsChatService: WsChatService,
private NativeNotificationService: NativeNotificationService) {
/* this.webNotificationPopupService.askNotificationPermission() */
this.NativeNotificationService.askForPermission()
this.router.events.subscribe((val) => {
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
document.querySelectorAll('popover-viewport').forEach((e: any) => e.remove())
+18 -6
View File
@@ -1,13 +1,15 @@
import { Injectable } from '@angular/core'
import { Injectable } from '@angular/core';
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { MessageService } from 'src/app/services/chat/message.service'
import { ChatUserService } from 'src/app/services/chat/chat-user.service'
import { showDateDuration } from 'src/plugin/showDateDuration'
import { MessageService } from 'src/app/services/chat/message.service';
import { ChatUserService } from 'src/app/services/chat/chat-user.service';
import { showDateDuration } from 'src/plugin/showDateDuration';
import { ToastsService } from '../toast.service';
import { chatHistory, ChatMessage } from 'src/app/models/chatMethod'
import { chatHistory, ChatMessage } from 'src/app/models/chatMethod';
import { Storage } from '@ionic/storage';
import { Platform } from '@ionic/angular';
import { SqliteService } from 'src/app/services/sqlite.service';
import { NativeNotificationService } from 'src/app/services/native-notification.service';
import { SessionStore } from 'src/app/store/session.service';
@Injectable({
providedIn: 'root'
})
@@ -37,7 +39,10 @@ export class RoomService {
private storage: Storage,
private platform: Platform,
private sqlservice: SqliteService,
) { }
private NativeNotificationService: NativeNotificationService
) {
this.NativeNotificationService.askForPermission()
}
setData({ customFields, id, name, t, lastMessage, _updatedAt }) {
this.customFields = customFields
@@ -72,6 +77,13 @@ export class RoomService {
}, 100)
if(SessionStore.user.RochetChatUser != ChatMessage.u.username) {
this.NativeNotificationService.sendNotificationChat({
message: message.msg,
title: this.name
});
}
// save to ionic storage
this.storage.get('chatmsg' + this.id).then((messages: any) => {
const newListMessages = messages.push(ChatMessage)
@@ -8,14 +8,13 @@ import { Rooms, Update as room } from 'src/app/models/chatMethod';
import { Storage } from '@ionic/storage';
import { Platform } from '@ionic/angular';
import { SqliteService } from 'src/app/services/sqlite.service';
import { NativeNotificationService } from 'src/app/services/native-notification.service';
@Injectable({
providedIn: 'root'
})
export class WsChatMethodsService {
dm: {[key: string]: RoomService} = {}
group: {[key: string]: RoomService} = {}
@@ -29,6 +28,7 @@ export class WsChatMethodsService {
private storage: Storage,
private platform: Platform,
private sqlservice: SqliteService,
private NativeNotificationService: NativeNotificationService
) {
(async()=>{
await this.getAllRooms();
@@ -48,10 +48,7 @@ export class WsChatMethodsService {
rooms.result.update.forEach((roomData: room) => {
let room:RoomService;
//console.log(roomData);
room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice)
room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice, this.NativeNotificationService)
room.setData({
customFields: roomData.customFields,
id: this.getRoomId(roomData),
@@ -73,8 +70,6 @@ export class WsChatMethodsService {
this.groupCount++
}
});
this.loadingWholeList = false
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { NativeNotificationService } from './native-notification.service';
describe('NativeNotificationService', () => {
let service: NativeNotificationService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(NativeNotificationService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,45 @@
import { Injectable } from '@angular/core';
import { Platform } from '@ionic/angular';
import { CapacitorConfig } from '@capacitor/cli';
import { LocalNotifications } from '@capacitor/local-notifications';
@Injectable({
providedIn: 'root'
})
export class NativeNotificationService {
constructor(private platform: Platform,) {
this.askForPermission()
}
askForPermission() {
LocalNotifications.requestPermissions()
}
sendNotificationChat({title = 'User', icon = '', message = 'hello'}) {
LocalNotifications.schedule({
notifications:[
{
title : 'tile',
body : 'df',
id : 55
}
]
});
}
isDesktop() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
return true
} else {
return false
}
}
}