mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
WIP 4
This commit is contained in:
parent
0bb3cfcfad
commit
e1fbd1242e
@ -83,7 +83,7 @@ export class MemberDetailsViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async openDirectMessage() {
|
async openDirectMessage() {
|
||||||
const localId = await this._session.createRoom(RoomType.DirectMessage, undefined, undefined, undefined, [this.userId]);
|
const roomBeingCreated = await this._session.createRoom(RoomType.DirectMessage, undefined, undefined, undefined, [this.userId]);
|
||||||
this.navigation.push("room", localId);
|
this.navigation.push("room", roomBeingCreated.localId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -594,13 +594,13 @@ export class Session {
|
|||||||
|
|
||||||
createRoom(type, isEncrypted, explicitName, topic, invites, log = undefined) {
|
createRoom(type, isEncrypted, explicitName, topic, invites, log = undefined) {
|
||||||
return this._platform.logger.wrapOrRun(log, "create room", log => {
|
return this._platform.logger.wrapOrRun(log, "create room", log => {
|
||||||
const localId = `room-being-created-${this._platform.random()}`;
|
const localId = `local-${Math.round(this._platform.random() * Math.MAX_SAFE_INTEGER)}`;
|
||||||
const roomBeingCreated = new RoomBeingCreated(localId, type, isEncrypted, explicitName, topic, invites, this._roomsBeingCreatedUpdateCallback, this._mediaRepository, log);
|
const roomBeingCreated = new RoomBeingCreated(localId, type, isEncrypted, explicitName, topic, invites, this._roomsBeingCreatedUpdateCallback, this._mediaRepository, log);
|
||||||
this._roomsBeingCreated.set(localId, roomBeingCreated);
|
this._roomsBeingCreated.set(localId, roomBeingCreated);
|
||||||
log.wrapDetached("create room network", async log => {
|
log.wrapDetached("create room network", log => {
|
||||||
roomBeingCreated.start(this._hsApi, log);
|
return roomBeingCreated.start(this._hsApi, log);
|
||||||
});
|
});
|
||||||
return localId;
|
return roomBeingCreated;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,10 +691,9 @@ export class Session {
|
|||||||
if (roomBeingCreated.roomId === roomId) {
|
if (roomBeingCreated.roomId === roomId) {
|
||||||
const observableStatus = this._observedRoomStatus.get(roomBeingCreated.localId);
|
const observableStatus = this._observedRoomStatus.get(roomBeingCreated.localId);
|
||||||
if (observableStatus) {
|
if (observableStatus) {
|
||||||
this._platform.logger.wrapOrRun(log, `replacing room being created`, log => {
|
log.log(`replacing room being created`)
|
||||||
log.set("localId", roomBeingCreated.localId)
|
.set("localId", roomBeingCreated.localId)
|
||||||
.set("roomId", roomBeingCreated.roomId);
|
.set("roomId", roomBeingCreated.roomId);
|
||||||
});
|
|
||||||
observableStatus.set(observableStatus.get() | RoomStatus.Replaced);
|
observableStatus.set(observableStatus.get() | RoomStatus.Replaced);
|
||||||
}
|
}
|
||||||
this._roomsBeingCreated.remove(roomBeingCreated.localId);
|
this._roomsBeingCreated.remove(roomBeingCreated.localId);
|
||||||
@ -737,10 +736,12 @@ export class Session {
|
|||||||
for (const is of inviteStates) {
|
for (const is of inviteStates) {
|
||||||
const statusObservable = this._observedRoomStatus.get(is.id);
|
const statusObservable = this._observedRoomStatus.get(is.id);
|
||||||
if (statusObservable) {
|
if (statusObservable) {
|
||||||
|
const withInvited = statusObservable.get() | RoomStatus.Invited;
|
||||||
if (is.shouldAdd) {
|
if (is.shouldAdd) {
|
||||||
statusObservable.set(statusObservable.get().withInvited());
|
statusObservable.set(withInvited);
|
||||||
} else if (is.shouldRemove) {
|
} else if (is.shouldRemove) {
|
||||||
statusObservable.set(statusObservable.get().withoutInvited());
|
const withoutInvited = withInvited ^ RoomStatus.Invited;
|
||||||
|
statusObservable.set(withoutInvited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -750,7 +751,7 @@ export class Session {
|
|||||||
_forgetArchivedRoom(roomId) {
|
_forgetArchivedRoom(roomId) {
|
||||||
const statusObservable = this._observedRoomStatus.get(roomId);
|
const statusObservable = this._observedRoomStatus.get(roomId);
|
||||||
if (statusObservable) {
|
if (statusObservable) {
|
||||||
statusObservable.set(statusObservable.get() ^ RoomStatus.Archived);
|
statusObservable.set((statusObservable.get() | RoomStatus.Archived) ^ RoomStatus.Archived);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||||||
|
|
||||||
public readonly isEncrypted: boolean;
|
public readonly isEncrypted: boolean;
|
||||||
private _name: string;
|
private _name: string;
|
||||||
|
private _error?: Error;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly localId: string,
|
public readonly localId: string,
|
||||||
@ -115,12 +116,12 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||||||
if (this.isEncrypted) {
|
if (this.isEncrypted) {
|
||||||
options.initial_state = [createRoomEncryptionEvent()];
|
options.initial_state = [createRoomEncryptionEvent()];
|
||||||
}
|
}
|
||||||
console.log("going to create the room now");
|
try {
|
||||||
const response = await hsApi.createRoom(options, {log}).response();
|
const response = await hsApi.createRoom(options, {log}).response();
|
||||||
this._roomId = response["room_id"];
|
this._roomId = response["room_id"];
|
||||||
console.log("done creating the room now", this._roomId);
|
} catch (err) {
|
||||||
// TODO: somehow check in Session if we need to replace this with a joined room
|
this._error = err;
|
||||||
// in case the room appears first in sync, and this request returns later
|
}
|
||||||
this.emitChange(undefined, log);
|
this.emitChange(undefined, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,39 +129,30 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||||||
// only load profiles if we need it for the room name and avatar
|
// only load profiles if we need it for the room name and avatar
|
||||||
if (!this.explicitName && this.inviteUserIds) {
|
if (!this.explicitName && this.inviteUserIds) {
|
||||||
this.profiles = await loadProfiles(this.inviteUserIds, hsApi, log);
|
this.profiles = await loadProfiles(this.inviteUserIds, hsApi, log);
|
||||||
console.log("loaded the profiles", this.profiles);
|
|
||||||
const summaryData = {
|
const summaryData = {
|
||||||
joinCount: 1, // ourselves
|
joinCount: 1, // ourselves
|
||||||
inviteCount: this.inviteUserIds.length
|
inviteCount: this.inviteUserIds.length
|
||||||
};
|
};
|
||||||
this._name = calculateRoomName(this.profiles, summaryData, log);
|
this._name = calculateRoomName(this.profiles, summaryData, log);
|
||||||
console.log("loaded the profiles and the new name", this.name);
|
|
||||||
this.emitChange();
|
this.emitChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private emitChange(params?, log?) {
|
private emitChange(params?, log?: ILogItem) {
|
||||||
this.updateCallback(this, params, log);
|
this.updateCallback(this, params, log);
|
||||||
this.emit("change");
|
this.emit("change");
|
||||||
}
|
}
|
||||||
|
|
||||||
get avatarColorId(): string {
|
get avatarColorId(): string { return this.inviteUserIds?.[0] ?? this._roomId ?? this.localId; }
|
||||||
return this.inviteUserIds?.[0] ?? this._roomId ?? this.localId;
|
get avatarUrl(): string | undefined { return this.profiles[0]?.avatarUrl; }
|
||||||
}
|
get roomId(): string | undefined { return this._roomId; }
|
||||||
|
|
||||||
get avatarUrl(): string | undefined {
|
|
||||||
const result = this.profiles[0]?.avatarUrl;
|
|
||||||
console.log("RoomBeingCreated.avatarUrl", this.profiles, result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
get roomId(): string | undefined {
|
|
||||||
return this._roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
get name() { return this._name; }
|
get name() { return this._name; }
|
||||||
|
|
||||||
get isBeingCreated(): boolean { return true; }
|
get isBeingCreated(): boolean { return true; }
|
||||||
|
get error(): Error | undefined { return this._error; }
|
||||||
|
|
||||||
|
cancel() {
|
||||||
|
// remove from collection somehow
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadProfiles(userIds: string[], hsApi: HomeServerApi, log: ILogItem): Promise<Profile[]> {
|
export async function loadProfiles(userIds: string[], hsApi: HomeServerApi, log: ILogItem): Promise<Profile[]> {
|
||||||
@ -194,5 +186,4 @@ class UserIdProfile implements IProfile {
|
|||||||
get displayName() { return undefined; }
|
get displayName() { return undefined; }
|
||||||
get name() { return this.userId; }
|
get name() { return this.userId; }
|
||||||
get avatarUrl() { return undefined; }
|
get avatarUrl() { return undefined; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user