From 1eaf6dd4ed260f64b993c6be82a261e466e79da6 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 15 Jul 2021 11:49:55 +0100 Subject: [PATCH] Improve TS in SenderProfile --- .../views/messages/SenderProfile.tsx | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/views/messages/SenderProfile.tsx b/src/components/views/messages/SenderProfile.tsx index bdae9cec4a..5198effb32 100644 --- a/src/components/views/messages/SenderProfile.tsx +++ b/src/components/views/messages/SenderProfile.tsx @@ -15,12 +15,14 @@ */ import React from 'react'; +import { MatrixEvent } from "matrix-js-sdk/src/models/event"; + import Flair from '../elements/Flair'; import FlairStore from '../../../stores/FlairStore'; import { getUserNameColorClass } from '../../../utils/FormattingUtils'; import MatrixClientContext from "../../../contexts/MatrixClientContext"; import { replaceableComponent } from "../../../utils/replaceableComponent"; -import { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { MsgType } from "matrix-js-sdk/lib/@types/event"; interface IProps { mxEvent: MatrixEvent; @@ -50,7 +52,7 @@ export default class SenderProfile extends React.Component { componentDidMount() { this.unmounted = false; - this._updateRelatedGroups(); + this.updateRelatedGroups(); if (this.state.userGroups.length === 0) { this.getPublicisedGroups(); @@ -64,7 +66,7 @@ export default class SenderProfile extends React.Component { this.context.removeListener('RoomState.events', this.onRoomStateEvents); } - async getPublicisedGroups() { + private async getPublicisedGroups() { if (!this.unmounted) { const userGroups = await FlairStore.getPublicisedGroupsCached( this.context, this.props.mxEvent.getSender(), @@ -73,15 +75,15 @@ export default class SenderProfile extends React.Component { } } - onRoomStateEvents = event => { + private onRoomStateEvents = (event: MatrixEvent) => { if (event.getType() === 'm.room.related_groups' && event.getRoomId() === this.props.mxEvent.getRoomId() ) { - this._updateRelatedGroups(); + this.updateRelatedGroups(); } }; - _updateRelatedGroups() { + private updateRelatedGroups() { if (this.unmounted) return; const room = this.context.getRoom(this.props.mxEvent.getRoomId()); if (!room) return; @@ -92,7 +94,7 @@ export default class SenderProfile extends React.Component { }); } - _getDisplayedGroups(userGroups, relatedGroups) { + private getDisplayedGroups(userGroups?: string[], relatedGroups?: string[]) { let displayedGroups = userGroups || []; if (relatedGroups && relatedGroups.length > 0) { displayedGroups = relatedGroups.filter((groupId) => { @@ -113,7 +115,7 @@ export default class SenderProfile extends React.Component { const displayName = mxEvent.sender?.rawDisplayName || mxEvent.getSender() || ""; const mxid = mxEvent.sender?.userId || mxEvent.getSender() || ""; - if (msgtype === 'm.emote') { + if (msgtype === MsgType.Emote) { return null; // emote message must include the name so don't duplicate it } @@ -128,7 +130,7 @@ export default class SenderProfile extends React.Component { let flair; if (this.props.enableFlair) { - const displayedGroups = this._getDisplayedGroups( + const displayedGroups = this.getDisplayedGroups( this.state.userGroups, this.state.relatedGroups, );