From 7055f02f168f0689c340e0b080129261015999a1 Mon Sep 17 00:00:00 2001 From: Tushar Date: Fri, 25 Feb 2022 15:52:54 +0530 Subject: [PATCH] typescriptify domain/avatar.js --- src/domain/SessionPickerViewModel.js | 2 +- src/domain/{avatar.js => avatar.ts} | 15 +++++++++------ src/domain/session/leftpanel/BaseTileViewModel.js | 2 +- .../session/rightpanel/MemberDetailsViewModel.js | 2 +- .../session/rightpanel/MemberTileViewModel.js | 2 +- .../session/rightpanel/RoomDetailsViewModel.js | 2 +- src/domain/session/room/InviteViewModel.js | 2 +- .../session/room/RoomBeingCreatedViewModel.js | 2 +- src/domain/session/room/RoomViewModel.js | 2 +- src/domain/session/room/timeline/MessageBody.js | 2 +- .../room/timeline/tiles/BaseMessageTile.js | 2 +- src/platform/web/Platform.js | 2 +- src/platform/web/ui/AvatarView.js | 2 +- src/platform/web/ui/session/room/InviteView.js | 2 +- .../ui/session/room/timeline/BaseMessageView.js | 2 +- 15 files changed, 23 insertions(+), 20 deletions(-) rename src/domain/{avatar.js => avatar.ts} (74%) diff --git a/src/domain/SessionPickerViewModel.js b/src/domain/SessionPickerViewModel.js index 6714e96f..e486c64f 100644 --- a/src/domain/SessionPickerViewModel.js +++ b/src/domain/SessionPickerViewModel.js @@ -16,7 +16,7 @@ limitations under the License. import {SortedArray} from "../observable/index.js"; import {ViewModel} from "./ViewModel"; -import {avatarInitials, getIdentifierColorNumber} from "./avatar.js"; +import {avatarInitials, getIdentifierColorNumber} from "./avatar"; class SessionItemViewModel extends ViewModel { constructor(options, pickerVM) { diff --git a/src/domain/avatar.js b/src/domain/avatar.ts similarity index 74% rename from src/domain/avatar.js rename to src/domain/avatar.ts index 5b32020b..6f1ef8b0 100644 --- a/src/domain/avatar.js +++ b/src/domain/avatar.ts @@ -14,7 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -export function avatarInitials(name) { +import { Platform } from "../platform/web/Platform"; +import { MediaRepository } from "../matrix/net/MediaRepository"; + +export function avatarInitials(name: string): string { let firstChar = name.charAt(0); if (firstChar === "!" || firstChar === "@" || firstChar === "#") { firstChar = name.charAt(1); @@ -29,10 +32,10 @@ export function avatarInitials(name) { * * @return {number} */ -function hashCode(str) { +function hashCode(str: string): number { let hash = 0; - let i; - let chr; + let i: number; + let chr: number; if (str.length === 0) { return hash; } @@ -44,11 +47,11 @@ function hashCode(str) { return Math.abs(hash); } -export function getIdentifierColorNumber(id) { +export function getIdentifierColorNumber(id: string): number { return (hashCode(id) % 8) + 1; } -export function getAvatarHttpUrl(avatarUrl, cssSize, platform, mediaRepository) { +export function getAvatarHttpUrl(avatarUrl: string, cssSize: number, platform: Platform, mediaRepository: MediaRepository): string | null { if (avatarUrl) { const imageSize = cssSize * platform.devicePixelRatio; return mediaRepository.mxcUrlThumbnail(avatarUrl, imageSize, imageSize, "crop"); diff --git a/src/domain/session/leftpanel/BaseTileViewModel.js b/src/domain/session/leftpanel/BaseTileViewModel.js index e1d6dfff..8f5106bf 100644 --- a/src/domain/session/leftpanel/BaseTileViewModel.js +++ b/src/domain/session/leftpanel/BaseTileViewModel.js @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js"; +import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar"; import {ViewModel} from "../../ViewModel"; const KIND_ORDER = ["roomBeingCreated", "invite", "room"]; diff --git a/src/domain/session/rightpanel/MemberDetailsViewModel.js b/src/domain/session/rightpanel/MemberDetailsViewModel.js index 8ee50030..b3c8278c 100644 --- a/src/domain/session/rightpanel/MemberDetailsViewModel.js +++ b/src/domain/session/rightpanel/MemberDetailsViewModel.js @@ -16,7 +16,7 @@ limitations under the License. import {ViewModel} from "../../ViewModel"; import {RoomType} from "../../../matrix/room/common"; -import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js"; +import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar"; export class MemberDetailsViewModel extends ViewModel { constructor(options) { diff --git a/src/domain/session/rightpanel/MemberTileViewModel.js b/src/domain/session/rightpanel/MemberTileViewModel.js index 9062ea7d..153c70c8 100644 --- a/src/domain/session/rightpanel/MemberTileViewModel.js +++ b/src/domain/session/rightpanel/MemberTileViewModel.js @@ -15,7 +15,7 @@ limitations under the License. */ import {ViewModel} from "../../ViewModel"; -import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js"; +import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar"; export class MemberTileViewModel extends ViewModel { constructor(options) { diff --git a/src/domain/session/rightpanel/RoomDetailsViewModel.js b/src/domain/session/rightpanel/RoomDetailsViewModel.js index 97e8588e..4e2735b1 100644 --- a/src/domain/session/rightpanel/RoomDetailsViewModel.js +++ b/src/domain/session/rightpanel/RoomDetailsViewModel.js @@ -15,7 +15,7 @@ limitations under the License. */ import {ViewModel} from "../../ViewModel"; -import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js"; +import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar"; export class RoomDetailsViewModel extends ViewModel { constructor(options) { diff --git a/src/domain/session/room/InviteViewModel.js b/src/domain/session/room/InviteViewModel.js index c2ff74e0..00697642 100644 --- a/src/domain/session/room/InviteViewModel.js +++ b/src/domain/session/room/InviteViewModel.js @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js"; +import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar"; import {ViewModel} from "../../ViewModel"; export class InviteViewModel extends ViewModel { diff --git a/src/domain/session/room/RoomBeingCreatedViewModel.js b/src/domain/session/room/RoomBeingCreatedViewModel.js index f5c5d3cd..b503af73 100644 --- a/src/domain/session/room/RoomBeingCreatedViewModel.js +++ b/src/domain/session/room/RoomBeingCreatedViewModel.js @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js"; +import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar"; import {ViewModel} from "../../ViewModel"; export class RoomBeingCreatedViewModel extends ViewModel { diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index b7af00ce..71060728 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -17,7 +17,7 @@ limitations under the License. import {TimelineViewModel} from "./timeline/TimelineViewModel.js"; import {ComposerViewModel} from "./ComposerViewModel.js" -import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js"; +import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar"; import {tilesCreator} from "./timeline/tilesCreator.js"; import {ViewModel} from "../../ViewModel"; import {imageToInfo} from "../common.js"; diff --git a/src/domain/session/room/timeline/MessageBody.js b/src/domain/session/room/timeline/MessageBody.js index a8bf2497..65b487a9 100644 --- a/src/domain/session/room/timeline/MessageBody.js +++ b/src/domain/session/room/timeline/MessageBody.js @@ -1,5 +1,5 @@ import { linkify } from "./linkify/linkify.js"; -import { getIdentifierColorNumber, avatarInitials } from "../../../avatar.js"; +import { getIdentifierColorNumber, avatarInitials } from "../../../avatar"; /** * Parse text into parts such as newline, links and text. diff --git a/src/domain/session/room/timeline/tiles/BaseMessageTile.js b/src/domain/session/room/timeline/tiles/BaseMessageTile.js index 6b0b4356..3385a587 100644 --- a/src/domain/session/room/timeline/tiles/BaseMessageTile.js +++ b/src/domain/session/room/timeline/tiles/BaseMessageTile.js @@ -16,7 +16,7 @@ limitations under the License. import {SimpleTile} from "./SimpleTile.js"; import {ReactionsViewModel} from "../ReactionsViewModel.js"; -import {getIdentifierColorNumber, avatarInitials, getAvatarHttpUrl} from "../../../../avatar.js"; +import {getIdentifierColorNumber, avatarInitials, getAvatarHttpUrl} from "../../../../avatar"; export class BaseMessageTile extends SimpleTile { constructor(options) { diff --git a/src/platform/web/Platform.js b/src/platform/web/Platform.js index 9de3d4ce..56cf4fc5 100644 --- a/src/platform/web/Platform.js +++ b/src/platform/web/Platform.js @@ -37,7 +37,7 @@ import {hasReadPixelPermission, ImageHandle, VideoHandle} from "./dom/ImageHandl import {downloadInIframe} from "./dom/download.js"; import {Disposables} from "../../utils/Disposables"; import {parseHTML} from "./parsehtml.js"; -import {handleAvatarError} from "./ui/avatar.js"; +import {handleAvatarError} from "./ui/avatar"; function addScript(src) { return new Promise(function (resolve, reject) { diff --git a/src/platform/web/ui/AvatarView.js b/src/platform/web/ui/AvatarView.js index f2d94e3b..551f7307 100644 --- a/src/platform/web/ui/AvatarView.js +++ b/src/platform/web/ui/AvatarView.js @@ -15,7 +15,7 @@ limitations under the License. */ import {BaseUpdateView} from "./general/BaseUpdateView"; -import {renderStaticAvatar, renderImg} from "./avatar.js"; +import {renderStaticAvatar, renderImg} from "./avatar"; /* optimization to not use a sub view when changing between img and text diff --git a/src/platform/web/ui/session/room/InviteView.js b/src/platform/web/ui/session/room/InviteView.js index 9d808abf..99345360 100644 --- a/src/platform/web/ui/session/room/InviteView.js +++ b/src/platform/web/ui/session/room/InviteView.js @@ -16,7 +16,7 @@ limitations under the License. */ import {TemplateView} from "../../general/TemplateView"; -import {renderStaticAvatar} from "../../avatar.js"; +import {renderStaticAvatar} from "../../avatar"; export class InviteView extends TemplateView { render(t, vm) { diff --git a/src/platform/web/ui/session/room/timeline/BaseMessageView.js b/src/platform/web/ui/session/room/timeline/BaseMessageView.js index a6fbb9be..9b583103 100644 --- a/src/platform/web/ui/session/room/timeline/BaseMessageView.js +++ b/src/platform/web/ui/session/room/timeline/BaseMessageView.js @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {renderStaticAvatar} from "../../../avatar.js"; +import {renderStaticAvatar} from "../../../avatar"; import {tag} from "../../../general/html"; import {mountView} from "../../../general/utils"; import {TemplateView} from "../../../general/TemplateView";