This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 829
Communities v2 prototype: Override invite aesthetics for community-as-room invites #5143
Merged
+148
−8
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
Copyright 2020 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { AsyncStoreWithClient } from "./AsyncStoreWithClient"; | ||
import defaultDispatcher from "../dispatcher/dispatcher"; | ||
import { ActionPayload } from "../dispatcher/payloads"; | ||
import { Room } from "matrix-js-sdk/src/models/room"; | ||
import { EffectiveMembership, getEffectiveMembership } from "../utils/membership"; | ||
import SettingsStore from "../settings/SettingsStore"; | ||
import * as utils from "matrix-js-sdk/src/utils"; | ||
import { UPDATE_EVENT } from "./AsyncStore"; | ||
|
||
interface IState { | ||
// nothing of value - we use account data | ||
} | ||
|
||
export interface IRoomProfile { | ||
displayName: string; | ||
avatarMxc: string; | ||
} | ||
|
||
export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> { | ||
private static internalInstance = new CommunityPrototypeStore(); | ||
|
||
private constructor() { | ||
super(defaultDispatcher, {}); | ||
} | ||
|
||
public static get instance(): CommunityPrototypeStore { | ||
return CommunityPrototypeStore.internalInstance; | ||
} | ||
|
||
protected async onAction(payload: ActionPayload): Promise<any> { | ||
if (!this.matrixClient || !SettingsStore.getValue("feature_communities_v2_prototypes")) { | ||
return; | ||
} | ||
|
||
if (payload.action === "MatrixActions.Room.myMembership") { | ||
const room: Room = payload.room; | ||
const membership = getEffectiveMembership(payload.membership); | ||
const oldMembership = getEffectiveMembership(payload.oldMembership); | ||
if (membership === oldMembership) return; | ||
|
||
if (membership === EffectiveMembership.Invite) { | ||
try { | ||
const path = utils.encodeUri("/rooms/$roomId/group_info", {$roomId: room.roomId}); | ||
const profile = await this.matrixClient._http.authedRequest( | ||
undefined, "GET", path, | ||
undefined, undefined, | ||
{prefix: "/_matrix/client/unstable/im.vector.custom"}); | ||
// we use global account data because per-room account data on invites is unreliable | ||
await this.matrixClient.setAccountData("im.vector.group_info." + room.roomId, profile); | ||
} catch (e) { | ||
console.warn("Non-fatal error getting group information for invite:", e); | ||
} | ||
} | ||
} else if (payload.action === "MatrixActions.accountData") { | ||
if (payload.event_type.startsWith("im.vector.group_info.")) { | ||
this.emit(UPDATE_EVENT, payload.event_type.substring("im.vector.group_info.".length)); | ||
} | ||
} | ||
} | ||
|
||
public getInviteProfile(roomId: string): IRoomProfile { | ||
if (!this.matrixClient) return {displayName: null, avatarMxc: null}; | ||
const room = this.matrixClient.getRoom(roomId); | ||
if (SettingsStore.getValue("feature_communities_v2_prototypes")) { | ||
const data = this.matrixClient.getAccountData("im.vector.group_info." + roomId); | ||
if (data && data.getContent()) { | ||
return {displayName: data.getContent().name, avatarMxc: data.getContent().avatar_url}; | ||
} | ||
} | ||
return {displayName: room.name, avatarMxc: room.avatar_url}; | ||
} | ||
|
||
protected async onReady(): Promise<any> { | ||
for (const room of this.matrixClient.getRooms()) { | ||
const myMember = room.currentState.getMembers().find(m => m.userId === this.matrixClient.getUserId()); | ||
if (!myMember) continue; | ||
if (getEffectiveMembership(myMember.membership) === EffectiveMembership.Invite) { | ||
// Fake an update for anything that might have started listening before the invite | ||
// data was available (eg: RoomPreviewBar after a refresh) | ||
this.emit(UPDATE_EVENT, room.roomId); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular need to change anything now, but just pointing out that
im.vector
should probably be replaced withio.element
for new work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 will keep in mind for the next one (which should hopefully not need a generic
custom
namespace and instead can be associated to an MSC)