chatService.roomNeedsInvitation()

This commit is contained in:
2021-04-25 00:59:57 +02:00
parent dec3c88f82
commit 2cc48fa033
6 changed files with 17862 additions and 16 deletions

17854
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -23,7 +23,7 @@
"@angular/platform-browser": "~11.2.6",
"@angular/platform-browser-dynamic": "~11.2.6",
"@angular/router": "~11.2.6",
"angular-auth-oidc-client": "^11.6.4",
"angular-auth-oidc-client": "^11.6.6",
"matrix-js-sdk": "^9.9.0",
"moment": "^2.29.1",
"olm": "https://packages.matrix.org/npm/olm/olm-3.2.1.tgz",

View File

@@ -16,7 +16,7 @@ export class User {
return new User(
claims["sub"].toString(),
claims["preferred_username"].toString(),
'@' + claims["preferred_username"] + ':synapse',
'@' + claims["preferred_username"] + ':okupamicoche-synapse',
claims["name"].toString(),
claims["admin"] === true
);

View File

@@ -27,7 +27,7 @@ export class NewTravelComponent implements OnInit {
.subscribe(res => {
if (res.success) {
console.log('Travel created');
this.router.navigateByUrl('/');
this.router.navigateByUrl('/travel/' + travel.id);
}
else {
console.error('Error creating travel: ' + res.error.code + ' ' + res.error.msg);

View File

@@ -4,12 +4,15 @@ import * as matrix from 'matrix-js-sdk';
import { MatrixClient } from 'matrix-js-sdk/src/client';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { Room, RoomMember } from 'matrix-js-sdk/src/models/room';
import { SyncApi } from 'matrix-js-sdk/src/sync';
import * as olm from 'olm';
import { Observable } from 'rxjs';
import { MatrixLoginDto } from '../entities/matrix-login-dto';
import { ChatMessageHandler } from './chat-message-handler';
global.Olm = olm;
const FORWARDS = 'f';
@Injectable({
providedIn: 'root'
})
@@ -84,6 +87,18 @@ export class ChatService {
return this.matrixClient.leave(roomId);
}
roomNeedsInvitation = async (roomId: string): Promise<boolean> => {
let room: Room = this.matrixClient.getRoom(roomId) as Room;
if (room === null) {
try {
room = await this.matrixClient.peekInRoom(roomId);
}
catch (error) { return true; }
}
const joinRule = room.getLiveTimeline().getState(FORWARDS).getJoinRule();
return joinRule === 'invite';
}
private async loginWithToken(loginToken: string): Promise<MatrixClient> {
const matrixLogin = await this.http.post<MatrixLoginDto>(
'http://okupamicoche-synapse:8008/_matrix/client/r0/login',

View File

@@ -33,6 +33,9 @@ export class ChatComponent implements OnInit, AfterViewInit {
}
console.log('Is in room: ' + this.chatService.isInRoom(this.roomId));
console.log('Is invited to room: ' + this.chatService.isInvitedToRoom(this.roomId));
this.chatService.roomNeedsInvitation(this.roomId).then(needsInvitation => {
console.log('Room needs invitation: ' + needsInvitation);
});
}
ngAfterViewInit(): void {