From cccc019cc356ecc257add1f9579bc564f4ba1ec3 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 23 Mar 2021 13:36:14 +0000 Subject: [PATCH 1/2] Add ensure profile helper function --- src/components/intent.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/components/intent.ts b/src/components/intent.ts index 07ac3a52..67973483 100644 --- a/src/components/intent.ts +++ b/src/components/intent.ts @@ -625,6 +625,25 @@ export class Intent { return this.client.setAvatarUrl(url); } + /** + * Ensure that the user has the given profile information set. If it does not, + * set it. + * @param displayname The displayname to set. Leave undefined to ignore. + * @param avatarUrl The avatar to set. Leave undefined to ignore. + */ + public async ensureProfile(displayname?: string, avatarUrl?: string) { + if (!displayname && !avatarUrl) { + throw Error('At least one of displayname,avatarUrl must be defined'); + } + const profile = await this.getProfileInfo(this.userId, null, false); + if (displayname && profile.displayname !== displayname) { + await this.setDisplayName(displayname); + } + if (avatarUrl && profile.avatar_url !== avatarUrl) { + await this.setAvatarUrl(avatarUrl); + } + } + public async setRoomUserProfile(roomId: string, profile: UserProfile) { const userId = this.client.getUserId(); const currProfile = this.opts.backingStore.getMemberProfile(roomId, userId); From 4ec78dc7511be9d9cc571ba80a788a95a322eb40 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 23 Mar 2021 13:37:02 +0000 Subject: [PATCH 2/2] changelog --- changelog.d/318.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/318.feature diff --git a/changelog.d/318.feature b/changelog.d/318.feature new file mode 100644 index 00000000..52186ca4 --- /dev/null +++ b/changelog.d/318.feature @@ -0,0 +1 @@ +Add `intent.ensureProfile` function. \ No newline at end of file