2019-02-11 06:56:52 +01:00
|
|
|
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';
|
2019-02-11 06:56:52 +01:00
|
|
|
|
|
|
|
@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>();
|
2019-07-06 05:41:03 +02:00
|
|
|
public deletedStatusStream = new Subject<StatusWrapper>();
|
2019-02-11 06:56:52 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2019-07-06 05:41:03 +02:00
|
|
|
|
|
|
|
public deleteStatus(status: StatusWrapper){
|
|
|
|
this.deletedStatusStream.next(status);
|
|
|
|
}
|
2019-02-11 06:56:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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){
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|