Fixed compile errors. Some parts were commented, need rewrite

This commit is contained in:
2021-12-27 16:21:14 +01:00
parent c26d71fd68
commit 8a5358deca
6 changed files with 85 additions and 71 deletions

View File

@@ -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<any> {
return () =>
oidcConfigService.withConfig({
stsServer: 'https://okupamicoche-keycloak:8443/auth/realms/okupamicoche',
// export function configureAuth(oidcConfigService: OidcConfigService): () => Promise<any> {
// 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,

View File

@@ -40,9 +40,9 @@ export class AuthService {
}
async configureAndTryLogin(chatLoginToken: string): Promise<AuthState> {
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) => {

View File

@@ -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<MatrixClient>,
) { }
getRoomMessages = (roomId: string): Subject<MatrixEvent> => {
const subject = new Subject<MatrixEvent>();
getRoomMessages = (roomId: string): Subject<EventTimeline> => {
const subject = new Subject<EventTimeline>();
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<MatrixEvent>): void {
private publishRoomNewMessages(roomId: string, subject: Subject<EventTimeline>): 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);
// });
});
}
}

View File

@@ -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<MatrixEvent>);
getRoomMessages: (roomId: string) => (Observable<EventTimeline>);
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;
}

View File

@@ -3,15 +3,15 @@
</ng-container>
<ng-template #elseIfNeedsInvitationBlock>
<ng-container *ngIf="needsInvitation | async;else elseIfNeedsToJoinBlock">
<p>This chat is private, you need to join the travel to see it.</p>
</ng-container>
<ng-container *ngIf="needsInvitation | async;else elseIfNeedsToJoinBlock">
<p>This chat is private, you need to join the travel to see it.</p>
</ng-container>
</ng-template>
<ng-template #elseIfNeedsToJoinBlock>
<ng-container *ngIf="!isInRoom;else elseBlock">
<button mat-raised-button class="btn btn-default" (click)="join()">Join chat</button>
</ng-container>
<ng-container *ngIf="!isInRoom;else elseBlock">
<button mat-raised-button class="btn btn-default" (click)="join()">Join chat</button>
</ng-container>
</ng-template>
<ng-template #elseBlock>
@@ -19,14 +19,15 @@
<mat-grid-tile colspan=4>
<mat-list #messageList class="chat-messages">
<mat-list-item #messageItem *ngFor="let message of messages; trackBy: getMessageId">
<h3 matLine> {{message.getSender()}} </h3>
<!-- TODO -->
<!-- <h3 matLine> {{message.getSender()}} </h3>
<p matLine>
{{message.getContent().body}}
</p>
</p> -->
</mat-list-item>
</mat-list>
</mat-grid-tile>
<mat-grid-tile>
<mat-list>
<mat-list-item *ngFor="let member of members">
@@ -34,15 +35,15 @@
</mat-list-item>
</mat-list>
</mat-grid-tile>
<mat-grid-tile colspan=4>
<mat-form-field class="send-message-input">
<input [(ngModel)]="messageInput" (keyup.enter)="sendMessage()" matInput placeholder="Type message here">
</mat-form-field>
</mat-grid-tile>
<mat-grid-tile colspan=1>
<button mat-raised-button class="btn btn-default" (click)="sendMessage()">Send</button>
</mat-grid-tile>
</mat-grid-list>
</ng-template>
</ng-template>

View File

@@ -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<ElementRef>;
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
}