Compare commits
3 Commits
76405329f8
...
ca58ec78b6
| Author | SHA1 | Date | |
|---|---|---|---|
| ca58ec78b6 | |||
| aa126f7f45 | |||
| 7ff944dec4 |
@ -7,6 +7,7 @@ import {UserPublic} from "./UserPublic";
|
||||
import {Router} from "@angular/router";
|
||||
import {BehaviorSubject, Subscription} from "rxjs";
|
||||
import {AbstractSession} from "../Session/AbstractSession";
|
||||
import {StompService} from "@stomp/ng2-stompjs";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -22,8 +23,11 @@ export class UserService {
|
||||
constructor(
|
||||
protected readonly router: Router,
|
||||
protected readonly api: ApiService,
|
||||
protected readonly stompService: StompService,
|
||||
) {
|
||||
this.refresh();
|
||||
this.stompService.connected$.subscribe(() => {
|
||||
this.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
getCommonByUuid(uuid: string, next: Next<UserCommon>): void {
|
||||
@ -38,7 +42,10 @@ export class UserService {
|
||||
}
|
||||
|
||||
changeName(name: string, next?: Next<UserPrivate>) {
|
||||
this.api.postSingle(['User', 'changeName'], name, UserPrivate.fromJson, next);
|
||||
this.api.postSingle(['User', 'changeName'], name, UserPrivate.fromJson, user => {
|
||||
this.refresh();
|
||||
next && next(user);
|
||||
});
|
||||
}
|
||||
|
||||
goto(user: UserPublic) {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {NgForOf, NgIf} from "@angular/common";
|
||||
import {UserService} from "../../api/User/user.service";
|
||||
import {FormsModule} from "@angular/forms";
|
||||
@ -18,7 +18,7 @@ import {SessionListComponent} from "../tools/numbers/shared/session-list/session
|
||||
templateUrl: './profile.component.html',
|
||||
styleUrl: './profile.component.less'
|
||||
})
|
||||
export class ProfileComponent {
|
||||
export class ProfileComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
protected readonly userService: UserService,
|
||||
@ -26,4 +26,8 @@ export class ProfileComponent {
|
||||
// -
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userService.refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {UserService} from "../../../../api/User/user.service";
|
||||
import {DatePipe, NgForOf, NgIf} from "@angular/common";
|
||||
import {NumbersSessionService} from "../../../../api/tools/Numbers/Session/numbers-session.service";
|
||||
@ -16,7 +16,7 @@ import {SessionListComponent} from "../shared/session-list/session-list.componen
|
||||
templateUrl: './numbers-overview.component.html',
|
||||
styleUrl: './numbers-overview.component.less'
|
||||
})
|
||||
export class NumbersOverviewComponent {
|
||||
export class NumbersOverviewComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
protected readonly userService: UserService,
|
||||
@ -25,6 +25,10 @@ export class NumbersOverviewComponent {
|
||||
// -
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userService.refresh();
|
||||
}
|
||||
|
||||
create() {
|
||||
this.numberSessionService.create(session => this.numberSessionService.goto(session));
|
||||
}
|
||||
|
||||
@ -47,22 +47,18 @@ public abstract class AbstractSession implements IWebSocketMessage {
|
||||
|
||||
protected AbstractSession(@NonNull final User user) {
|
||||
this.owner = user;
|
||||
this.join(user);
|
||||
}
|
||||
|
||||
public void join(@NonNull final User user) {
|
||||
synchronized (uuid) {
|
||||
users.add(user);
|
||||
touch();
|
||||
user.join(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void leave(@NonNull final User user) {
|
||||
synchronized (uuid) {
|
||||
users.remove(user);
|
||||
touch();
|
||||
user.leave(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -39,9 +39,15 @@ public abstract class AbstractSessionController<SESSION extends AbstractSession>
|
||||
|
||||
@Scheduled(timeUnit = TimeUnit.MINUTES, initialDelay = 5, fixedRate = 5)
|
||||
public void cleanUp() {
|
||||
final ZonedDateTime deadline = ZonedDateTime.now().minusDays(1);
|
||||
final ZonedDateTime deadline = ZonedDateTime.now().minusDays(30);
|
||||
synchronized (sessions) {
|
||||
sessions.removeIf(session -> session.getLastAccess().isBefore(deadline));
|
||||
sessions.stream().filter(session -> session.getLastAccess().isBefore(deadline)).forEach(this::delete);
|
||||
}
|
||||
}
|
||||
|
||||
private void delete(@NonNull final SESSION session) {
|
||||
for (final User user : session.getUsers()) {
|
||||
user.leave(session);
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,9 +67,7 @@ public abstract class AbstractSessionController<SESSION extends AbstractSession>
|
||||
sessions.add(session);
|
||||
}
|
||||
|
||||
applicationEventPublisher.publishEvent(session);
|
||||
applicationEventPublisher.publishEvent(user);
|
||||
return toDto(session, user);
|
||||
return join(session, user);
|
||||
}
|
||||
|
||||
@PostMapping("canAccess")
|
||||
@ -89,7 +93,14 @@ public abstract class AbstractSessionController<SESSION extends AbstractSession>
|
||||
log.error("Wrong password: user={}, session={}", user, session);
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
return join(session, user);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private AbstractSessionDto join(@NonNull final SESSION session, @NonNull final User user) {
|
||||
session.join(user);
|
||||
user.join(session);
|
||||
log.info("User joined Session: user={}, session={}", user, session);
|
||||
applicationEventPublisher.publishEvent(session);
|
||||
applicationEventPublisher.publishEvent(user);
|
||||
return toDto(session, user);
|
||||
@ -124,6 +135,7 @@ public abstract class AbstractSessionController<SESSION extends AbstractSession>
|
||||
final User user = userService.getByPrivateUuidOrThrow(userUuid);
|
||||
final SESSION session = getSessionByUuid(sessionUuid);
|
||||
session.leave(user);
|
||||
user.leave(session);
|
||||
applicationEventPublisher.publishEvent(session);
|
||||
applicationEventPublisher.publishEvent(user);
|
||||
}
|
||||
|
||||
@ -48,9 +48,8 @@ public class User implements IWebSocketMessage {
|
||||
}
|
||||
|
||||
public void leave(@NonNull final AbstractSession session) {
|
||||
synchronized (privateUuid) {
|
||||
synchronized (sessions) {
|
||||
sessions.remove(session);
|
||||
touch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user