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 833
Update status message in the member list and user info panel when it is changed #7338
Merged
t3chguy
merged 11 commits into
matrix-org:develop
from
SimonBrandner:feature/update-status
Dec 13, 2021
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f4aaa6a
Add useUserStatusMessage hook
SimonBrandner 0cd988e
Use useUserStatusMessage hook
SimonBrandner 14c6f98
Fix status message event string
SimonBrandner 839d9ee
Simplifie code
SimonBrandner 23a07b3
Merge remote-tracking branch 'upstream/develop' into feature/update-s…
SimonBrandner b89bdbf
Delint
SimonBrandner a6116de
Fix removeListener call
SimonBrandner 0575e5a
Use useContext
SimonBrandner a6b5bc9
Fix imports
SimonBrandner 1a9775d
Re-use type from UserInfo
SimonBrandner 68bdc9e
Handle feature enabling/disabling inside the useUserStatusMessage hook
SimonBrandner 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,38 @@ | ||
/* | ||
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com> | ||
|
||
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 { MatrixClient, RoomMember } from "matrix-js-sdk"; | ||
SimonBrandner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { User } from "matrix-js-sdk/src/models/user"; | ||
import { useContext } from "react"; | ||
|
||
import { GroupMember } from "../components/views/right_panel/UserInfo"; | ||
import MatrixClientContext from "../contexts/MatrixClientContext"; | ||
import { useEventEmitterState } from "./useEventEmitter"; | ||
|
||
type StatusMessageUser = User | RoomMember | GroupMember; | ||
SimonBrandner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const getUser = (cli: MatrixClient, user: StatusMessageUser): User => cli.getUser(user?.userId); | ||
const getStatusMessage = (cli: MatrixClient, user: StatusMessageUser): string => { | ||
return getUser(cli, user).unstable_statusMessage; | ||
}; | ||
|
||
// Hook to simplify handling Matrix User status | ||
export const useUserStatusMessage = (user?: StatusMessageUser): string => { | ||
const cli = useContext(MatrixClientContext); | ||
return useEventEmitterState(getUser(cli, user), "User.unstable_statusMessage", () => { | ||
return getStatusMessage(cli, user); | ||
}); | ||
}; |
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.
IMO the hook should watch
SettingsStore.getValue("feature_custom_status")
instead, handling even more de-duplication of code. Also means it can not set up event emitter handles when the feature is disabled (if you pass a falsey eventEmitter as the first arg into auseEventEmitter*
func it will no-op)Let me know if that needs a better explanation
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.
Would something like this be sufficient?
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.
Yup, thats what I had in mind, though would be worth a test :P
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.
Hmm, it seems to work though it doesn't hide the statuses from the right panel when I disable the feature, which I assumed it would... Should it do that?