WIP 4
This commit is contained in:
parent
0bb3cfcfad
commit
e1fbd1242e
3 changed files with 30 additions and 38 deletions
|
@ -83,7 +83,7 @@ export class MemberDetailsViewModel extends ViewModel {
|
|||
}
|
||||
|
||||
async openDirectMessage() {
|
||||
const localId = await this._session.createRoom(RoomType.DirectMessage, undefined, undefined, undefined, [this.userId]);
|
||||
this.navigation.push("room", localId);
|
||||
const roomBeingCreated = await this._session.createRoom(RoomType.DirectMessage, undefined, undefined, undefined, [this.userId]);
|
||||
this.navigation.push("room", roomBeingCreated.localId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -594,13 +594,13 @@ export class Session {
|
|||
|
||||
createRoom(type, isEncrypted, explicitName, topic, invites, log = undefined) {
|
||||
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);
|
||||
this._roomsBeingCreated.set(localId, roomBeingCreated);
|
||||
log.wrapDetached("create room network", async log => {
|
||||
roomBeingCreated.start(this._hsApi, log);
|
||||
log.wrapDetached("create room network", log => {
|
||||
return roomBeingCreated.start(this._hsApi, log);
|
||||
});
|
||||
return localId;
|
||||
return roomBeingCreated;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -691,10 +691,9 @@ export class Session {
|
|||
if (roomBeingCreated.roomId === roomId) {
|
||||
const observableStatus = this._observedRoomStatus.get(roomBeingCreated.localId);
|
||||
if (observableStatus) {
|
||||
this._platform.logger.wrapOrRun(log, `replacing room being created`, log => {
|
||||
log.set("localId", roomBeingCreated.localId)
|
||||
.set("roomId", roomBeingCreated.roomId);
|
||||
});
|
||||
log.log(`replacing room being created`)
|
||||
.set("localId", roomBeingCreated.localId)
|
||||
.set("roomId", roomBeingCreated.roomId);
|
||||
observableStatus.set(observableStatus.get() | RoomStatus.Replaced);
|
||||
}
|
||||
this._roomsBeingCreated.remove(roomBeingCreated.localId);
|
||||
|
@ -737,10 +736,12 @@ export class Session {
|
|||
for (const is of inviteStates) {
|
||||
const statusObservable = this._observedRoomStatus.get(is.id);
|
||||
if (statusObservable) {
|
||||
const withInvited = statusObservable.get() | RoomStatus.Invited;
|
||||
if (is.shouldAdd) {
|
||||
statusObservable.set(statusObservable.get().withInvited());
|
||||
statusObservable.set(withInvited);
|
||||
} 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) {
|
||||
const statusObservable = this._observedRoomStatus.get(roomId);
|
||||
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;
|
||||
private _name: string;
|
||||
private _error?: Error;
|
||||
|
||||
constructor(
|
||||
public readonly localId: string,
|
||||
|
@ -115,12 +116,12 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
if (this.isEncrypted) {
|
||||
options.initial_state = [createRoomEncryptionEvent()];
|
||||
}
|
||||
console.log("going to create the room now");
|
||||
const response = await hsApi.createRoom(options, {log}).response();
|
||||
this._roomId = response["room_id"];
|
||||
console.log("done creating the room now", this._roomId);
|
||||
// TODO: somehow check in Session if we need to replace this with a joined room
|
||||
// in case the room appears first in sync, and this request returns later
|
||||
try {
|
||||
const response = await hsApi.createRoom(options, {log}).response();
|
||||
this._roomId = response["room_id"];
|
||||
} catch (err) {
|
||||
this._error = err;
|
||||
}
|
||||
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
|
||||
if (!this.explicitName && this.inviteUserIds) {
|
||||
this.profiles = await loadProfiles(this.inviteUserIds, hsApi, log);
|
||||
console.log("loaded the profiles", this.profiles);
|
||||
const summaryData = {
|
||||
joinCount: 1, // ourselves
|
||||
inviteCount: this.inviteUserIds.length
|
||||
};
|
||||
this._name = calculateRoomName(this.profiles, summaryData, log);
|
||||
console.log("loaded the profiles and the new name", this.name);
|
||||
this.emitChange();
|
||||
}
|
||||
}
|
||||
|
||||
private emitChange(params?, log?) {
|
||||
private emitChange(params?, log?: ILogItem) {
|
||||
this.updateCallback(this, params, log);
|
||||
this.emit("change");
|
||||
}
|
||||
|
||||
get avatarColorId(): string {
|
||||
return this.inviteUserIds?.[0] ?? this._roomId ?? this.localId;
|
||||
}
|
||||
|
||||
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 avatarColorId(): string { 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 name() { return this._name; }
|
||||
|
||||
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[]> {
|
||||
|
@ -194,5 +186,4 @@ class UserIdProfile implements IProfile {
|
|||
get displayName() { return undefined; }
|
||||
get name() { return this.userId; }
|
||||
get avatarUrl() { return undefined; }
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue