Sengi-Windows-MacOS-Linux/src/app/services/notification.service.ts

62 lines
1.8 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
2019-02-12 04:28:15 +01:00
import { HttpErrorResponse } from '@angular/common/http';
2019-04-13 19:47:20 +02:00
import { StatusWrapper } from '../models/common.model';
2019-07-04 00:55:46 +02:00
import { Account } from './models/mastodon.interfaces';
@Injectable()
export class NotificationService {
public notifactionStream = new Subject<NotificatioData>();
2019-04-13 19:47:20 +02:00
public newRespondPostedStream = new Subject<NewReplyData>();
2019-07-04 00:55:46 +02:00
public hideAccountUrlStream = new Subject<string>();
public deletedStatusStream = new Subject<StatusWrapper>();
constructor() {
}
public notify(message: string, isError: boolean){
let newNotification = new NotificatioData(message, isError);
this.notifactionStream.next(newNotification);
}
2019-02-12 04:28:15 +01:00
2019-04-03 04:22:14 +02:00
public notifyHttpError(err: HttpErrorResponse){
let message = 'Oops, Unknown Error' ;
try{
message = `Oops, Error ${err.status}`;
console.error(err.message);
} catch(err){}
2019-02-12 04:28:15 +01:00
this.notify(message, true);
}
2019-04-13 19:47:20 +02:00
// public newStatusPosted(status: StatusWrapper){
public newStatusPosted(uiStatusRepliedToId: string, response: StatusWrapper){
const notification = new NewReplyData(uiStatusRepliedToId, response);
this.newRespondPostedStream.next(notification);
}
2019-07-04 00:55:46 +02:00
public hideAccount(account: Account){
this.hideAccountUrlStream.next(account.url);
}
public deleteStatus(status: StatusWrapper){
this.deletedStatusStream.next(status);
}
}
export class NotificatioData {
public id: string;
constructor(
public message: string,
public isError: boolean
) {
this.id = `${message}${new Date().getTime()}`;
}
}
2019-04-13 19:47:20 +02:00
export class NewReplyData {
constructor(public uiStatusId: string, public response: StatusWrapper){
}
}