split up create code into separate files

This commit is contained in:
Bruno Windels 2022-02-10 16:39:54 +01:00
parent 15eecbb463
commit 8526461d3c
17 changed files with 82 additions and 77 deletions

View file

@ -16,7 +16,7 @@ limitations under the License.
import {ViewModel} from "../ViewModel.js";
import {imageToInfo} from "./common.js";
import {RoomType} from "../../matrix/room/create";
import {RoomType} from "../../matrix/room/common";
export class CreateRoomViewModel extends ViewModel {
constructor(options) {

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import {ObservableValue} from "../../observable/ObservableValue";
import {RoomStatus} from "../../matrix/room/RoomStatus";
import {RoomStatus} from "../../matrix/room/common";
/**
Depending on the status of a room (invited, joined, archived, or none),

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import {ViewModel} from "../../ViewModel.js";
import {RoomType} from "../../../matrix/room/create";
import {RoomType} from "../../../matrix/room/common";
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js";
export class MemberDetailsViewModel extends ViewModel {

View file

@ -17,8 +17,8 @@ limitations under the License.
import {Room} from "./room/Room.js";
import {ArchivedRoom} from "./room/ArchivedRoom.js";
import {RoomStatus} from "./room/RoomStatus";
import {RoomBeingCreated} from "./room/create";
import {RoomStatus} from "./room/common";
import {RoomBeingCreated} from "./room/RoomBeingCreated";
import {Invite} from "./room/Invite.js";
import {Pusher} from "./push/Pusher";
import { ObservableMap } from "../observable/index.js";

View file

@ -34,4 +34,4 @@ export function tests() {
assert(!isTxnId("$yS_n5n3cIO2aTtek0_2ZSlv-7g4YYR2zKrk2mFCW_rm"));
},
}
}
}

51
src/matrix/profile.ts Normal file
View file

@ -0,0 +1,51 @@
/*
Copyright 2020 Bruno Windels <bruno@windels.cloud>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import type {HomeServerApi} from "./net/HomeServerApi";
import type {ILogItem} from "../logging/types";
export async function loadProfiles(userIds: string[], hsApi: HomeServerApi, log: ILogItem): Promise<Profile[]> {
const profiles = await Promise.all(userIds.map(async userId => {
const response = await hsApi.profile(userId, {log}).response();
return new Profile(userId, response.displayname as string, response.avatar_url as string);
}));
profiles.sort((a, b) => a.name.localeCompare(b.name));
return profiles;
}
export interface IProfile {
get userId(): string;
get displayName(): string | undefined;
get avatarUrl(): string | undefined;
get name(): string;
}
export class Profile implements IProfile {
constructor(
public readonly userId: string,
public readonly displayName: string,
public readonly avatarUrl: string | undefined
) {}
get name() { return this.displayName || this.userId; }
}
export class UserIdProfile implements IProfile {
constructor(public readonly userId: string) {}
get displayName() { return undefined; }
get name() { return this.userId; }
get avatarUrl() { return undefined; }
}

View file

@ -19,6 +19,8 @@ import {createRoomEncryptionEvent} from "../e2ee/common";
import {MediaRepository} from "../net/MediaRepository";
import {EventEmitter} from "../../utils/EventEmitter";
import {AttachmentUpload} from "./AttachmentUpload";
import {loadProfiles, Profile, UserIdProfile} from "../profile";
import {RoomType} from "./common";
import type {HomeServerApi} from "../net/HomeServerApi";
import type {ILogItem} from "../../logging/types";
@ -60,12 +62,6 @@ type Options = {
alias?: string;
}
export enum RoomType {
DirectMessage,
Private,
Public
}
function defaultE2EEStatusForType(type: RoomType): boolean {
switch (type) {
case RoomType.DirectMessage:
@ -222,36 +218,3 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
}
}
}
export async function loadProfiles(userIds: string[], hsApi: HomeServerApi, log: ILogItem): Promise<Profile[]> {
const profiles = await Promise.all(userIds.map(async userId => {
const response = await hsApi.profile(userId, {log}).response();
return new Profile(userId, response.displayname as string, response.avatar_url as string);
}));
profiles.sort((a, b) => a.name.localeCompare(b.name));
return profiles;
}
interface IProfile {
get userId(): string;
get displayName(): string | undefined;
get avatarUrl(): string | undefined;
get name(): string;
}
export class Profile implements IProfile {
constructor(
public readonly userId: string,
public readonly displayName: string,
public readonly avatarUrl: string | undefined
) {}
get name() { return this.displayName || this.userId; }
}
class UserIdProfile implements IProfile {
constructor(public readonly userId: string) {}
get displayName() { return undefined; }
get name() { return this.userId; }
get avatarUrl() { return undefined; }
}

View file

@ -1,24 +0,0 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
export enum RoomStatus {
None = 1 << 0,
BeingCreated = 1 << 1,
Invited = 1 << 2,
Joined = 1 << 3,
Replaced = 1 << 4,
Archived = 1 << 5,
}

View file

@ -25,3 +25,18 @@ export const REDACTION_TYPE = "m.room.redaction";
export function isRedacted(event) {
return !!event?.unsigned?.redacted_because;
}
export enum RoomStatus {
None = 1 << 0,
BeingCreated = 1 << 1,
Invited = 1 << 2,
Joined = 1 << 3,
Replaced = 1 << 4,
Archived = 1 << 5,
}
export enum RoomType {
DirectMessage,
Private,
Public
}

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {getPrevContentFromStateEvent} from "../common.js";
import {getPrevContentFromStateEvent} from "../common";
export const EVENT_TYPE = "m.room.member";

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import {createEnum} from "../../../utils/enum";
import {AbortError} from "../../../utils/error";
import {REDACTION_TYPE} from "../common.js";
import {REDACTION_TYPE} from "../common";
import {getRelationFromContent, getRelationTarget, setRelationTarget} from "../timeline/relations.js";
export const SendStatus = createEnum(

View file

@ -18,7 +18,7 @@ import {SortedArray} from "../../../observable/list/SortedArray";
import {ConnectionError} from "../../error.js";
import {PendingEvent, SendStatus} from "./PendingEvent.js";
import {makeTxnId, isTxnId} from "../../common.js";
import {REDACTION_TYPE} from "../common.js";
import {REDACTION_TYPE} from "../common";
import {getRelationFromContent, getRelationTarget, setRelationTarget, REACTION_TYPE, ANNOTATION_RELATION_TYPE} from "../timeline/relations.js";
export class SendQueue {

View file

@ -22,7 +22,7 @@ import {TimelineReader} from "./persistence/TimelineReader.js";
import {PendingEventEntry} from "./entries/PendingEventEntry.js";
import {RoomMember} from "../members/RoomMember.js";
import {getRelation, ANNOTATION_RELATION_TYPE} from "./relations.js";
import {REDACTION_TYPE} from "../common.js";
import {REDACTION_TYPE} from "../common";
import {NonPersistedEventEntry} from "./entries/NonPersistedEventEntry.js";
import {DecryptionSource} from "../../e2ee/common.js";
import {EVENT_TYPE as MEMBER_EVENT_TYPE} from "../members/RoomMember.js";

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import {BaseEntry} from "./BaseEntry";
import {REDACTION_TYPE} from "../../common.js";
import {REDACTION_TYPE} from "../../common";
import {createAnnotation, ANNOTATION_RELATION_TYPE, getRelationFromContent} from "../relations.js";
import {PendingAnnotation} from "../PendingAnnotation.js";
import {createReplyContent} from "./reply.js"

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import {BaseEventEntry} from "./BaseEventEntry.js";
import {getPrevContentFromStateEvent, isRedacted} from "../../common.js";
import {getPrevContentFromStateEvent, isRedacted} from "../../common";
import {getRelationFromContent, getRelatedEventId} from "../relations.js";
export class EventEntry extends BaseEventEntry {

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import {EventEntry} from "../entries/EventEntry.js";
import {REDACTION_TYPE, isRedacted} from "../../common.js";
import {REDACTION_TYPE, isRedacted} from "../../common";
import {ANNOTATION_RELATION_TYPE, getRelation} from "../relations.js";
import {redactEvent} from "../common.js";

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {REDACTION_TYPE} from "../common.js";
import {REDACTION_TYPE} from "../common";
export const REACTION_TYPE = "m.reaction";
export const ANNOTATION_RELATION_TYPE = "m.annotation";