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