diff --git a/src/components/views/dialogs/AddressPickerDialog.tsx b/src/components/views/dialogs/AddressPickerDialog.tsx index 1802f8ced2..1bf5e7da2c 100644 --- a/src/components/views/dialogs/AddressPickerDialog.tsx +++ b/src/components/views/dialogs/AddressPickerDialog.tsx @@ -24,7 +24,7 @@ import { _t, _td } from '../../../languageHandler'; import * as sdk from '../../../index'; import { MatrixClientPeg } from '../../../MatrixClientPeg'; import dis from '../../../dispatcher/dispatcher'; -import { addressTypes, getAddressType } from '../../../UserAddress'; +import { AddressType, addressTypes, getAddressType, IUserAddress } from '../../../UserAddress'; import GroupStore from '../../../stores/GroupStore'; import * as Email from '../../../email'; import IdentityAuthClient from '../../../IdentityAuthClient'; @@ -54,8 +54,8 @@ interface IProps { roomId?: string; button?: string; focus?: boolean; - validAddressTypes?; // FIXME: UserAddressType should be an interface - onFinished: (success: boolean, list?) => void; // FIXME: UserAddressType should be an interface + validAddressTypes?: AddressType[]; + onFinished: (success: boolean, list?: IUserAddress[]) => void; groupId?: string; // The type of entity to search for. Default: 'user'. pickerType?: 'user' | 'room'; @@ -69,7 +69,7 @@ interface IState { invalidAddressError: boolean; // List of UserAddressType objects representing // the list of addresses we're going to invite - selectedList; // FIXME: UserAddressType should be an interface + selectedList: IUserAddress[]; // Whether a search is ongoing busy: boolean; // An error message generated during the user directory search @@ -80,10 +80,10 @@ interface IState { query: string; // List of UserAddressType objects representing the set of // auto-completion results for the current search query. - suggestedList; // FIXME: UserAddressType should be an interface + suggestedList: IUserAddress[]; // List of address types initialised from props, but may change while the // dialog is open and represents the supported list of address types at this time. - validAddressTypes; + validAddressTypes: AddressType[]; } @replaceableComponent("views.dialogs.AddressPickerDialog") @@ -106,8 +106,8 @@ export default class AddressPickerDialog extends React.Component let validAddressTypes = this.props.validAddressTypes; // Remove email from validAddressTypes if no IS is configured. It may be added at a later stage by the user - if (!MatrixClientPeg.get().getIdentityServerUrl() && validAddressTypes.includes("email")) { - validAddressTypes = validAddressTypes.filter(type => type !== "email"); + if (!MatrixClientPeg.get().getIdentityServerUrl() && validAddressTypes.includes(AddressType.Email)) { + validAddressTypes = validAddressTypes.filter(type => type !== AddressType.Email); } this.state = { @@ -488,14 +488,14 @@ export default class AddressPickerDialog extends React.Component }); } - private addAddressesToList(addressTexts): void { + private addAddressesToList(addressTexts): IUserAddress[] { const selectedList = this.state.selectedList.slice(); let hasError = false; addressTexts.forEach((addressText) => { addressText = addressText.trim(); const addrType = getAddressType(addressText); - const addrObj = { + const addrObj: IUserAddress = { addressType: addrType, address: addressText, isKnown: false, @@ -514,7 +514,6 @@ export default class AddressPickerDialog extends React.Component const room = MatrixClientPeg.get().getRoom(addrObj.address); if (room) { addrObj.displayName = room.name; - addrObj.avatarMxc = room.avatarUrl; addrObj.isKnown = true; } } @@ -580,7 +579,7 @@ export default class AddressPickerDialog extends React.Component } } - private getFilteredSuggestions() { // FIXME: UserAddressType should be an interface + private getFilteredSuggestions(): IUserAddress[] { // map addressType => set of addresses to avoid O(n*m) operation const selectedAddresses = {}; this.state.selectedList.forEach(({ address, addressType }) => { @@ -611,7 +610,7 @@ export default class AddressPickerDialog extends React.Component // Add email as a valid address type. const { validAddressTypes } = this.state; - validAddressTypes.push('email'); + validAddressTypes.push(AddressType.Email); this.setState({ validAddressTypes }); }; @@ -695,8 +694,8 @@ export default class AddressPickerDialog extends React.Component let identityServer; // If picker cannot currently accept e-mail but should be able to - if (this.props.pickerType === 'user' && !this.state.validAddressTypes.includes('email') - && this.props.validAddressTypes.includes('email')) { + if (this.props.pickerType === 'user' && !this.state.validAddressTypes.includes(AddressType.Email) + && this.props.validAddressTypes.includes(AddressType.Email)) { const defaultIdentityServerUrl = getDefaultIdentityServerUrl(); if (defaultIdentityServerUrl) { identityServer =
{ _t( diff --git a/src/components/views/elements/AddressSelector.tsx b/src/components/views/elements/AddressSelector.tsx index c55f6f22d2..d05f843570 100644 --- a/src/components/views/elements/AddressSelector.tsx +++ b/src/components/views/elements/AddressSelector.tsx @@ -19,12 +19,13 @@ import React, { createRef } from 'react'; import * as sdk from '../../../index'; import classNames from 'classnames'; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import { IUserAddress } from '../../../UserAddress'; interface IProps { onSelected: (index: number) => void; // List of the addresses to display - addressList; // FIXME: UserAddressType should be an interface + addressList: IUserAddress[]; // Whether to show the address on the address tiles showAddress?: boolean; truncateAt: number; diff --git a/src/components/views/elements/AddressTile.tsx b/src/components/views/elements/AddressTile.tsx index 9f147b6bd6..ec3e63c62d 100644 --- a/src/components/views/elements/AddressTile.tsx +++ b/src/components/views/elements/AddressTile.tsx @@ -21,9 +21,10 @@ import * as sdk from "../../../index"; import { _t } from '../../../languageHandler'; import { replaceableComponent } from "../../../utils/replaceableComponent"; import { mediaFromMxc } from "../../../customisations/Media"; +import { IUserAddress } from '../../../UserAddress'; interface IProps { - address; // FIXME: UserAddressType should be an interface + address: IUserAddress; canDismiss?: boolean; onDismissed?: () => void; justified?: boolean;