diff --git a/src/app/auth/auth-config.module.ts b/src/app/auth/auth-config.module.ts index b4c4639..66fbeb0 100644 --- a/src/app/auth/auth-config.module.ts +++ b/src/app/auth/auth-config.module.ts @@ -3,37 +3,50 @@ import { APP_INITIALIZER, NgModule } from '@angular/core'; import { AuthInterceptor, AuthModule, LogLevel, OidcConfigService } from 'angular-auth-oidc-client'; import { TRAVEL_API_URL, USER_API_URL } from '../app.config'; -export function configureAuth(oidcConfigService: OidcConfigService): () => Promise { - return () => - oidcConfigService.withConfig({ - stsServer: 'https://okupamicoche-keycloak:8443/auth/realms/okupamicoche', +// export function configureAuth(oidcConfigService: OidcConfigService): () => Promise { +// return () => +// oidcConfigService.withConfig({ +// stsServer: 'https://okupamicoche-keycloak:8443/auth/realms/okupamicoche', +// redirectUrl: window.location.origin, +// postLogoutRedirectUri: window.location.origin, +// clientId: 'okupamicoche-frontend-angular', +// scope: 'openid profile', +// responseType: 'code', +// silentRenew: true, +// useRefreshToken: true, +// renewTimeBeforeTokenExpiresInSeconds: 30, +// tokenRefreshInSeconds: 20, +// ignoreNonceAfterRefresh: true, // Keycloak's refresh token fails if Nonce is not ignored +// secureRoutes: [TRAVEL_API_URL, USER_API_URL], +// storage: localStorage, +// logLevel: LogLevel.Warn +// }); +// } + +@NgModule({ + imports: [AuthModule.forRoot({ + config: { + authority: 'https://okupamicoche-keycloak:8443/auth/realms/okupamicoche', redirectUrl: window.location.origin, postLogoutRedirectUri: window.location.origin, clientId: 'okupamicoche-frontend-angular', - scope: 'openid profile', + scope: 'openid profile email offline_access', responseType: 'code', silentRenew: true, useRefreshToken: true, - renewTimeBeforeTokenExpiresInSeconds: 30, - tokenRefreshInSeconds: 20, + logLevel: LogLevel.Debug, ignoreNonceAfterRefresh: true, // Keycloak's refresh token fails if Nonce is not ignored - secureRoutes: [TRAVEL_API_URL, USER_API_URL], - storage: localStorage, - logLevel: LogLevel.Warn - }); -} - -@NgModule({ - imports: [AuthModule.forRoot()], + }, + })], exports: [AuthModule], providers: [ OidcConfigService, - { - provide: APP_INITIALIZER, - useFactory: configureAuth, - deps: [OidcConfigService], - multi: true, - }, + // { + // provide: APP_INITIALIZER, + // useFactory: configureAuth, + // deps: [OidcConfigService], + // multi: true, + // }, { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index f1c1e60..5a3714c 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -40,9 +40,9 @@ export class AuthService { } async configureAndTryLogin(chatLoginToken: string): Promise { - this.oidcSecurityService.isAuthenticated$.subscribe((auth) => { - console.log('isAuthenticated', auth); - this.loggedSubject.next(auth); + this.oidcSecurityService.isAuthenticated$.subscribe((authenticatedResult) => { + console.log('isAuthenticated', authenticatedResult); + this.loggedSubject.next(authenticatedResult.isAuthenticated); }); this.oidcSecurityService.userData$.subscribe((claims) => { diff --git a/src/app/services/chat-message-handler.ts b/src/app/services/chat-message-handler.ts index b901e5d..3ed5f13 100644 --- a/src/app/services/chat-message-handler.ts +++ b/src/app/services/chat-message-handler.ts @@ -1,7 +1,4 @@ -import { MatrixClient } from 'matrix-js-sdk/src/client'; -import { MatrixEvent } from 'matrix-js-sdk/src/models/event'; -import { EventTimeline } from 'matrix-js-sdk/src/models/event-timeline'; -import { Room } from 'matrix-js-sdk/src/models/room'; +import { EventTimeline, MatrixClient, MatrixEvent, Room } from 'matrix-js-sdk'; import { Subject } from 'rxjs'; export class ChatMessageHandler { @@ -9,10 +6,11 @@ export class ChatMessageHandler { private matrixClientPromise: Promise, ) { } - getRoomMessages = (roomId: string): Subject => { - const subject = new Subject(); + getRoomMessages = (roomId: string): Subject => { + const subject = new Subject(); - this.publishRoomOldMessages(roomId, subject); + // TODO + // this.publishRoomOldMessages(roomId, subject); this.publishRoomNewMessages(roomId, subject); return subject; @@ -27,21 +25,22 @@ export class ChatMessageHandler { }); } - private publishRoomNewMessages(roomId: string, subject: Subject): void { + private publishRoomNewMessages(roomId: string, subject: Subject): void { this.matrixClientPromise.then(client => { - client.on('Room.timeline', (event: EventTimeline, room: Room, toStartOfTimeline: boolean) => { - if (room.roomId !== roomId) { - return; // only listen to specified room - } - if (toStartOfTimeline) { - return; // don't print paginated results - } - if (event.getType() !== 'm.room.message') { - return; // only print messages - } + // TODO + // client.on('Room.timeline', (event: EventTimeline, room: Room, toStartOfTimeline: boolean) => { + // if (room.roomId !== roomId) { + // return; // only listen to specified room + // } + // if (toStartOfTimeline) { + // return; // don't print paginated results + // } + // if (event.getType() !== 'm.room.message') { + // return; // only print messages + // } - subject.next(event); - }); + // subject.next(event); + // }); }); } } diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index 246f627..fb7c793 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -3,8 +3,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { MatrixLoginDto } from '../entities/matrix-login-dto'; import { ChatMessageHandler } from './chat-message-handler'; -import { MatrixEvent, MatrixClient, Room, RoomMember } from 'matrix-js-sdk'; -import { createClient, ICreateClientOpts } from '../../../node_modules/matrix-js-sdk'; +import { MatrixEvent, MatrixClient, Room, RoomMember, createClient, EventTimeline, CreateClientOption } from 'matrix-js-sdk'; const FORWARDS = 'f'; @@ -15,7 +14,7 @@ export class ChatService { private matrixClient: MatrixClient; private chatMessageHandler: ChatMessageHandler; - getRoomMessages: (roomId: string) => (Observable); + getRoomMessages: (roomId: string) => (Observable); constructor( private http: HttpClient @@ -90,7 +89,8 @@ export class ChatService { } catch (error) { return true; } } - const joinRule = room.currentState.getJoinRule(); + // const joinRule = room.currentState.getJoinRule(); + const joinRule = 'invite'; // TODO return joinRule === 'invite'; } @@ -105,7 +105,7 @@ export class ChatService { ).toPromise(); console.log('LOGGED TO CHAT'); console.log({ matrixLogin }); - const ops: ICreateClientOpts = { + const ops: CreateClientOption = { baseUrl: 'http://okupamicoche-synapse:8008', accessToken: matrixLogin.access_token, userId: matrixLogin.user_id @@ -114,13 +114,14 @@ export class ChatService { await this.matrixClient.startClient({ initialSyncLimit: 100 }); - this.matrixClient.once('sync', (state: string, prevState: string, _: any) => { - if (state === 'PREPARED') { - console.log('CHAT SYNC FINISHED'); - } else { - console.log('MATRIX CLIENT STATE CHANGED state=' + state); - } - }); + // TODO + // this.matrixClient.once('sync', (state: string, prevState: string, _: any) => { + // if (state === 'PREPARED') { + // console.log('CHAT SYNC FINISHED'); + // } else { + // console.log('MATRIX CLIENT STATE CHANGED state=' + state); + // } + // }); return this.matrixClient; } diff --git a/src/app/views/chat/chat.component.html b/src/app/views/chat/chat.component.html index 489ede2..aac93b9 100644 --- a/src/app/views/chat/chat.component.html +++ b/src/app/views/chat/chat.component.html @@ -3,15 +3,15 @@ - -

This chat is private, you need to join the travel to see it.

-
+ +

This chat is private, you need to join the travel to see it.

+
- - - + + + @@ -19,14 +19,15 @@ -

{{message.getSender()}}

+ +
- + @@ -34,15 +35,15 @@ - + - + -
+ \ No newline at end of file diff --git a/src/app/views/chat/chat.component.ts b/src/app/views/chat/chat.component.ts index 342cc35..cde354c 100644 --- a/src/app/views/chat/chat.component.ts +++ b/src/app/views/chat/chat.component.ts @@ -1,6 +1,6 @@ import { AfterViewInit, ChangeDetectorRef, Component, ElementRef, Input, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core'; +import { EventTimeline, RoomMember } from 'matrix-js-sdk'; import { ChatService } from 'src/app/services/chat.service'; -import { MatrixEvent, RoomMember } from 'matrix-js-sdk'; @Component({ selector: 'app-chat', @@ -11,7 +11,7 @@ export class ChatComponent implements OnInit, AfterViewInit { @Input() roomId: string; @ViewChild('messageList', { read: ElementRef }) messageList: ElementRef; @ViewChildren('messageItem', { read: ElementRef }) messageItems: QueryList; - messages: MatrixEvent[] = new Array(); + messages: EventTimeline[] = new Array(); messageInput: string; constructor( @@ -24,7 +24,7 @@ export class ChatComponent implements OnInit, AfterViewInit { const messages$ = this.chatService.getRoomMessages(this.roomId); messages$.subscribe({ - next: (event: MatrixEvent) => { + next: (event: EventTimeline) => { this.messages.push(event); this.changeDetection.detectChanges(); // TODO theoretically it is not needed }