forked from mystiq/hydrogen-web
Merge pull request #692 from ryushar/ryushar/typescriptify
Convert domain/avatar.js and domain/LogoutViewModel.js to Typescript
This commit is contained in:
commit
62ce111938
18 changed files with 41 additions and 31 deletions
|
@ -14,11 +14,18 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ViewModel} from "./ViewModel";
|
import {Options, ViewModel} from "./ViewModel";
|
||||||
import {Client} from "../matrix/Client.js";
|
import {Client} from "../matrix/Client.js";
|
||||||
|
|
||||||
export class LogoutViewModel extends ViewModel {
|
type LogoutOptions = { sessionId: string; } & Options;
|
||||||
constructor(options) {
|
|
||||||
|
export class LogoutViewModel extends ViewModel<LogoutOptions> {
|
||||||
|
private _sessionId: string;
|
||||||
|
private _busy: boolean;
|
||||||
|
private _showConfirm: boolean;
|
||||||
|
private _error?: Error;
|
||||||
|
|
||||||
|
constructor(options: LogoutOptions) {
|
||||||
super(options);
|
super(options);
|
||||||
this._sessionId = options.sessionId;
|
this._sessionId = options.sessionId;
|
||||||
this._busy = false;
|
this._busy = false;
|
||||||
|
@ -26,19 +33,19 @@ export class LogoutViewModel extends ViewModel {
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
get showConfirm() {
|
get showConfirm(): boolean {
|
||||||
return this._showConfirm;
|
return this._showConfirm;
|
||||||
}
|
}
|
||||||
|
|
||||||
get busy() {
|
get busy(): boolean {
|
||||||
return this._busy;
|
return this._busy;
|
||||||
}
|
}
|
||||||
|
|
||||||
get cancelUrl() {
|
get cancelUrl(): string {
|
||||||
return this.urlCreator.urlForSegment("session", true);
|
return this.urlCreator.urlForSegment("session", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async logout() {
|
async logout(): Promise<void> {
|
||||||
this._busy = true;
|
this._busy = true;
|
||||||
this._showConfirm = false;
|
this._showConfirm = false;
|
||||||
this.emitChange("busy");
|
this.emitChange("busy");
|
||||||
|
@ -53,7 +60,7 @@ export class LogoutViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get status() {
|
get status(): string {
|
||||||
if (this._error) {
|
if (this._error) {
|
||||||
return this.i18n`Could not log out of device: ${this._error.message}`;
|
return this.i18n`Could not log out of device: ${this._error.message}`;
|
||||||
} else {
|
} else {
|
|
@ -18,7 +18,7 @@ import {Client} from "../matrix/Client.js";
|
||||||
import {SessionViewModel} from "./session/SessionViewModel.js";
|
import {SessionViewModel} from "./session/SessionViewModel.js";
|
||||||
import {SessionLoadViewModel} from "./SessionLoadViewModel.js";
|
import {SessionLoadViewModel} from "./SessionLoadViewModel.js";
|
||||||
import {LoginViewModel} from "./login/LoginViewModel.js";
|
import {LoginViewModel} from "./login/LoginViewModel.js";
|
||||||
import {LogoutViewModel} from "./LogoutViewModel.js";
|
import {LogoutViewModel} from "./LogoutViewModel";
|
||||||
import {SessionPickerViewModel} from "./SessionPickerViewModel.js";
|
import {SessionPickerViewModel} from "./SessionPickerViewModel.js";
|
||||||
import {ViewModel} from "./ViewModel";
|
import {ViewModel} from "./ViewModel";
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import {SortedArray} from "../observable/index.js";
|
import {SortedArray} from "../observable/index.js";
|
||||||
import {ViewModel} from "./ViewModel";
|
import {ViewModel} from "./ViewModel";
|
||||||
import {avatarInitials, getIdentifierColorNumber} from "./avatar.js";
|
import {avatarInitials, getIdentifierColorNumber} from "./avatar";
|
||||||
|
|
||||||
class SessionItemViewModel extends ViewModel {
|
class SessionItemViewModel extends ViewModel {
|
||||||
constructor(options, pickerVM) {
|
constructor(options, pickerVM) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ import type {ILogger} from "../logging/types";
|
||||||
import type {Navigation} from "./navigation/Navigation";
|
import type {Navigation} from "./navigation/Navigation";
|
||||||
import type {URLRouter} from "./navigation/URLRouter";
|
import type {URLRouter} from "./navigation/URLRouter";
|
||||||
|
|
||||||
type Options = {
|
export type Options = {
|
||||||
platform: Platform
|
platform: Platform
|
||||||
logger: ILogger
|
logger: ILogger
|
||||||
urlCreator: URLRouter
|
urlCreator: URLRouter
|
||||||
|
@ -95,7 +95,7 @@ export class ViewModel<O extends Options = Options> extends EventEmitter<{change
|
||||||
//
|
//
|
||||||
// translated string should probably always be bindings, unless we're fine with a refresh when changing the language?
|
// translated string should probably always be bindings, unless we're fine with a refresh when changing the language?
|
||||||
// we probably are, if we're using routing with a url, we could just refresh.
|
// we probably are, if we're using routing with a url, we could just refresh.
|
||||||
i18n(parts: string[], ...expr: any[]) {
|
i18n(parts: TemplateStringsArray, ...expr: any[]) {
|
||||||
// just concat for now
|
// just concat for now
|
||||||
let result = "";
|
let result = "";
|
||||||
for (let i = 0; i < parts.length; ++i) {
|
for (let i = 0; i < parts.length; ++i) {
|
||||||
|
|
|
@ -14,7 +14,10 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
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);
|
let firstChar = name.charAt(0);
|
||||||
if (firstChar === "!" || firstChar === "@" || firstChar === "#") {
|
if (firstChar === "!" || firstChar === "@" || firstChar === "#") {
|
||||||
firstChar = name.charAt(1);
|
firstChar = name.charAt(1);
|
||||||
|
@ -29,10 +32,10 @@ export function avatarInitials(name) {
|
||||||
*
|
*
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
function hashCode(str) {
|
function hashCode(str: string): number {
|
||||||
let hash = 0;
|
let hash = 0;
|
||||||
let i;
|
let i: number;
|
||||||
let chr;
|
let chr: number;
|
||||||
if (str.length === 0) {
|
if (str.length === 0) {
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
@ -44,11 +47,11 @@ function hashCode(str) {
|
||||||
return Math.abs(hash);
|
return Math.abs(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getIdentifierColorNumber(id) {
|
export function getIdentifierColorNumber(id: string): number {
|
||||||
return (hashCode(id) % 8) + 1;
|
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) {
|
if (avatarUrl) {
|
||||||
const imageSize = cssSize * platform.devicePixelRatio;
|
const imageSize = cssSize * platform.devicePixelRatio;
|
||||||
return mediaRepository.mxcUrlThumbnail(avatarUrl, imageSize, imageSize, "crop");
|
return mediaRepository.mxcUrlThumbnail(avatarUrl, imageSize, imageSize, "crop");
|
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js";
|
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar";
|
||||||
import {ViewModel} from "../../ViewModel";
|
import {ViewModel} from "../../ViewModel";
|
||||||
|
|
||||||
const KIND_ORDER = ["roomBeingCreated", "invite", "room"];
|
const KIND_ORDER = ["roomBeingCreated", "invite", "room"];
|
||||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import {ViewModel} from "../../ViewModel";
|
import {ViewModel} from "../../ViewModel";
|
||||||
import {RoomType} from "../../../matrix/room/common";
|
import {RoomType} from "../../../matrix/room/common";
|
||||||
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js";
|
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar";
|
||||||
|
|
||||||
export class MemberDetailsViewModel extends ViewModel {
|
export class MemberDetailsViewModel extends ViewModel {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ViewModel} from "../../ViewModel";
|
import {ViewModel} from "../../ViewModel";
|
||||||
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js";
|
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar";
|
||||||
|
|
||||||
export class MemberTileViewModel extends ViewModel {
|
export class MemberTileViewModel extends ViewModel {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ViewModel} from "../../ViewModel";
|
import {ViewModel} from "../../ViewModel";
|
||||||
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js";
|
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar";
|
||||||
|
|
||||||
export class RoomDetailsViewModel extends ViewModel {
|
export class RoomDetailsViewModel extends ViewModel {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js";
|
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar";
|
||||||
import {ViewModel} from "../../ViewModel";
|
import {ViewModel} from "../../ViewModel";
|
||||||
|
|
||||||
export class InviteViewModel extends ViewModel {
|
export class InviteViewModel extends ViewModel {
|
||||||
|
|
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js";
|
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar";
|
||||||
import {ViewModel} from "../../ViewModel";
|
import {ViewModel} from "../../ViewModel";
|
||||||
|
|
||||||
export class RoomBeingCreatedViewModel extends ViewModel {
|
export class RoomBeingCreatedViewModel extends ViewModel {
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
|
|
||||||
import {TimelineViewModel} from "./timeline/TimelineViewModel.js";
|
import {TimelineViewModel} from "./timeline/TimelineViewModel.js";
|
||||||
import {ComposerViewModel} from "./ComposerViewModel.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 {tilesCreator} from "./timeline/tilesCreator.js";
|
||||||
import {ViewModel} from "../../ViewModel";
|
import {ViewModel} from "../../ViewModel";
|
||||||
import {imageToInfo} from "../common.js";
|
import {imageToInfo} from "../common.js";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { linkify } from "./linkify/linkify.js";
|
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.
|
* Parse text into parts such as newline, links and text.
|
||||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import {SimpleTile} from "./SimpleTile.js";
|
import {SimpleTile} from "./SimpleTile.js";
|
||||||
import {ReactionsViewModel} from "../ReactionsViewModel.js";
|
import {ReactionsViewModel} from "../ReactionsViewModel.js";
|
||||||
import {getIdentifierColorNumber, avatarInitials, getAvatarHttpUrl} from "../../../../avatar.js";
|
import {getIdentifierColorNumber, avatarInitials, getAvatarHttpUrl} from "../../../../avatar";
|
||||||
|
|
||||||
export class BaseMessageTile extends SimpleTile {
|
export class BaseMessageTile extends SimpleTile {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ import {hasReadPixelPermission, ImageHandle, VideoHandle} from "./dom/ImageHandl
|
||||||
import {downloadInIframe} from "./dom/download.js";
|
import {downloadInIframe} from "./dom/download.js";
|
||||||
import {Disposables} from "../../utils/Disposables";
|
import {Disposables} from "../../utils/Disposables";
|
||||||
import {parseHTML} from "./parsehtml.js";
|
import {parseHTML} from "./parsehtml.js";
|
||||||
import {handleAvatarError} from "./ui/avatar.js";
|
import {handleAvatarError} from "./ui/avatar";
|
||||||
|
|
||||||
function addScript(src) {
|
function addScript(src) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {BaseUpdateView} from "./general/BaseUpdateView";
|
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
|
optimization to not use a sub view when changing between img and text
|
||||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {TemplateView} from "../../general/TemplateView";
|
import {TemplateView} from "../../general/TemplateView";
|
||||||
import {renderStaticAvatar} from "../../avatar.js";
|
import {renderStaticAvatar} from "../../avatar";
|
||||||
|
|
||||||
export class InviteView extends TemplateView {
|
export class InviteView extends TemplateView {
|
||||||
render(t, vm) {
|
render(t, vm) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {renderStaticAvatar} from "../../../avatar.js";
|
import {renderStaticAvatar} from "../../../avatar";
|
||||||
import {tag} from "../../../general/html";
|
import {tag} from "../../../general/html";
|
||||||
import {mountView} from "../../../general/utils";
|
import {mountView} from "../../../general/utils";
|
||||||
import {TemplateView} from "../../../general/TemplateView";
|
import {TemplateView} from "../../../general/TemplateView";
|
||||||
|
|
Loading…
Reference in a new issue