2018-09-10 03:55:16 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
2019-02-26 05:38:15 +01:00
|
|
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
|
|
|
2018-09-11 07:54:23 +02:00
|
|
|
import { AccountWrapper } from '../models/account.models';
|
2019-07-08 00:58:56 +02:00
|
|
|
import { OpenMediaEvent, StatusWrapper } from '../models/common.model';
|
2018-09-10 03:55:16 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class NavigationService {
|
2018-09-22 06:22:51 +02:00
|
|
|
private accountToManage: AccountWrapper;
|
2019-07-04 01:55:33 +02:00
|
|
|
activatedPanelSubject = new BehaviorSubject<OpenLeftPanelEvent>(new OpenLeftPanelEvent(LeftPanelType.Closed));
|
2019-02-26 05:38:15 +01:00
|
|
|
activatedMediaSubject: Subject<OpenMediaEvent> = new Subject<OpenMediaEvent>();
|
|
|
|
columnSelectedSubject = new BehaviorSubject<number>(-1);
|
2018-09-10 03:55:16 +02:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
constructor() { }
|
2018-09-10 03:55:16 +02:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
openColumnEditor(acc: AccountWrapper) {
|
|
|
|
this.accountToManage = acc;
|
2019-07-04 01:55:33 +02:00
|
|
|
const newEvent = new OpenLeftPanelEvent(LeftPanelType.ManageAccount);
|
|
|
|
this.activatedPanelSubject.next(newEvent);
|
2018-09-22 06:22:51 +02:00
|
|
|
}
|
2018-09-12 04:47:56 +02:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
openPanel(type: LeftPanelType){
|
2019-07-04 01:55:33 +02:00
|
|
|
const newEvent = new OpenLeftPanelEvent(type);
|
|
|
|
this.activatedPanelSubject.next(newEvent);
|
2018-09-22 06:22:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
closePanel() {
|
2019-07-04 01:55:33 +02:00
|
|
|
const newEvent = new OpenLeftPanelEvent(LeftPanelType.Closed);
|
|
|
|
this.activatedPanelSubject.next(newEvent);
|
2018-09-22 06:22:51 +02:00
|
|
|
this.accountToManage = null;
|
|
|
|
}
|
|
|
|
|
2019-07-04 01:55:33 +02:00
|
|
|
replyToUser(userHandle: string, isDirectMessage: boolean = false) {
|
|
|
|
const action = isDirectMessage ? LeftPanelAction.DM : LeftPanelAction.Mention;
|
|
|
|
const newEvent = new OpenLeftPanelEvent(LeftPanelType.CreateNewStatus, action, userHandle);
|
|
|
|
this.activatedPanelSubject.next(newEvent);
|
|
|
|
}
|
|
|
|
|
2019-07-08 00:58:56 +02:00
|
|
|
redraft(status: StatusWrapper){
|
|
|
|
const newEvent = new OpenLeftPanelEvent(LeftPanelType.CreateNewStatus, LeftPanelAction.Redraft, null, status);// statusContent.replace(/<[^>]*>/g, ''));
|
2019-07-06 06:20:03 +02:00
|
|
|
this.activatedPanelSubject.next(newEvent);
|
|
|
|
}
|
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
columnSelected(index: number): void {
|
|
|
|
this.columnSelectedSubject.next(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
getAccountToManage(): AccountWrapper {
|
|
|
|
return this.accountToManage;
|
|
|
|
}
|
2019-02-26 05:38:15 +01:00
|
|
|
|
|
|
|
openMedia(openMediaEvent: OpenMediaEvent): void{
|
|
|
|
this.activatedMediaSubject.next(openMediaEvent);
|
|
|
|
}
|
2018-09-10 03:55:16 +02:00
|
|
|
}
|
2018-09-22 06:22:51 +02:00
|
|
|
|
2019-07-04 01:55:33 +02:00
|
|
|
export class OpenLeftPanelEvent {
|
|
|
|
constructor(
|
|
|
|
public type: LeftPanelType,
|
|
|
|
public action: LeftPanelAction = LeftPanelAction.None,
|
2019-07-06 06:20:03 +02:00
|
|
|
public userHandle: string = null,
|
2019-07-08 00:58:56 +02:00
|
|
|
public status: StatusWrapper = null) {
|
2019-07-04 01:55:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum LeftPanelAction {
|
|
|
|
None = 0,
|
|
|
|
DM = 1,
|
2019-07-06 06:20:03 +02:00
|
|
|
Mention = 2,
|
|
|
|
Redraft = 3,
|
2019-07-04 01:55:33 +02:00
|
|
|
}
|
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
export enum LeftPanelType {
|
|
|
|
Closed = 0,
|
|
|
|
ManageAccount = 1,
|
|
|
|
CreateNewStatus = 2,
|
|
|
|
Search = 3,
|
|
|
|
AddNewAccount = 4,
|
|
|
|
Settings = 5
|
|
|
|
}
|