Refactor datasharing service
parent
161c3f2afd
commit
42f4a737b2
@ -1,37 +1,47 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {BehaviorSubject} from 'rxjs';
|
import {BehaviorSubject} from 'rxjs';
|
||||||
import {User} from '../models/user';
|
import {User} from '../models/user';
|
||||||
|
import {FriendInfo} from '../models/friendinfo';
|
||||||
|
import {Group} from '../models/group';
|
||||||
|
import {GroupInfo} from '../models/groupinfo';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class DatasharingService {
|
export class DatasharingService {
|
||||||
|
|
||||||
private userInfoSource = new BehaviorSubject<User>(new User());
|
currentUser = new BehaviorSubject<User>(new User());
|
||||||
private chatIDsSource = new BehaviorSubject<number[]>(new Array<number>());
|
|
||||||
currentUserInfo = this.userInfoSource.asObservable();
|
|
||||||
currentChatIDs = this.chatIDsSource.asObservable();
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
changeUserInfo(pUserInfo: User) {
|
|
||||||
this.userInfoSource.next(pUserInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
addSentRequestUserID(id: number) {
|
addSentRequestUserID(id: number) {
|
||||||
const user: User = this.userInfoSource.getValue();
|
const user: User = this.currentUser.getValue();
|
||||||
user.sentRequestUserIDs.push(id);
|
user.sentRequestUserIDs.push(id);
|
||||||
this.changeUserInfo(user);
|
this.currentUser.next(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
addGroupToUser(group: GroupInfo) {
|
||||||
|
const user = this.currentUser.getValue();
|
||||||
|
user.groups.push(group);
|
||||||
|
user.groupCount++;
|
||||||
|
this.currentUser.next(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
addFriendToUser(friend: FriendInfo) {
|
||||||
|
const user = this.currentUser.getValue();
|
||||||
|
user.friends.push(friend);
|
||||||
|
user.friendCount++;
|
||||||
|
this.currentUser.next(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
setDarkMode(active: boolean) {
|
setDarkMode(active: boolean) {
|
||||||
const user: User = this.userInfoSource.getValue();
|
const user: User = this.currentUser.getValue();
|
||||||
user.darkmode = active;
|
user.darkmode = active;
|
||||||
this.changeUserInfo(user);
|
this.currentUser.next(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeChatIDs(pChatIDs: number[]) {
|
changeUserInfo(user: User) {
|
||||||
this.chatIDsSource.next(pChatIDs);
|
this.currentUser.next(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue