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
Live location share - handle insufficient permissions in location sharing (PSG-610) #9047
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ limitations under the License. | |
*/ | ||
|
||
import { MatrixClient } from "matrix-js-sdk/src/client"; | ||
import { MatrixError } from "matrix-js-sdk/src/http-api"; | ||
import { makeLocationContent, makeBeaconInfoContent } from "matrix-js-sdk/src/content-helpers"; | ||
import { logger } from "matrix-js-sdk/src/logger"; | ||
import { IEventRelation } from "matrix-js-sdk/src/models/event"; | ||
|
@@ -23,7 +24,7 @@ import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; | |
|
||
import { _t } from "../../../languageHandler"; | ||
import Modal from "../../../Modal"; | ||
import QuestionDialog from "../dialogs/QuestionDialog"; | ||
import QuestionDialog, { IQuestionDialogProps } from "../dialogs/QuestionDialog"; | ||
import SdkConfig from "../../../SdkConfig"; | ||
import { OwnBeaconStore } from "../../../stores/OwnBeaconStore"; | ||
|
||
|
@@ -44,12 +45,32 @@ const DEFAULT_LIVE_DURATION = 300000; | |
|
||
export type ShareLocationFn = (props: LocationShareProps) => Promise<void>; | ||
|
||
const handleShareError = (error: Error, openMenu: () => void, shareType: LocationShareType) => { | ||
const getPermissionsErrorParams = (shareType: LocationShareType): { | ||
errorMessage: string; | ||
modalParams: IQuestionDialogProps; | ||
} => { | ||
const errorMessage = shareType === LocationShareType.Live ? | ||
"Insufficient permissions to start sharing your live location" : | ||
"Insufficient permissions to send your location"; | ||
|
||
const modalParams = { | ||
title: _t("You don't have permission to share locations"), | ||
description: _t("You need to have the right permissions in order to share locations in this room."), | ||
button: _t("OK"), | ||
hasCancelButton: false, | ||
onFinished: () => {}, // NOOP | ||
}; | ||
return { modalParams, errorMessage }; | ||
}; | ||
|
||
const getDefaultErrorParams = (shareType: LocationShareType, openMenu: () => void): { | ||
errorMessage: string; | ||
modalParams: IQuestionDialogProps; | ||
} => { | ||
const errorMessage = shareType === LocationShareType.Live ? | ||
"We couldn't start sharing your live location" : | ||
"We couldn't send your location"; | ||
logger.error(errorMessage, error); | ||
const params = { | ||
const modalParams = { | ||
title: _t("We couldn't send your location"), | ||
description: _t("%(brand)s could not send your location. Please try again later.", { | ||
brand: SdkConfig.get().brand, | ||
|
@@ -62,7 +83,17 @@ const handleShareError = (error: Error, openMenu: () => void, shareType: Locatio | |
} | ||
}, | ||
}; | ||
Modal.createDialog(QuestionDialog, params); | ||
return { modalParams, errorMessage }; | ||
}; | ||
|
||
const handleShareError = (error: Error, openMenu: () => void, shareType: LocationShareType): void => { | ||
const { modalParams, errorMessage } = (error as MatrixError).errcode === 'M_FORBIDDEN' ? | ||
getPermissionsErrorParams(shareType) : | ||
getDefaultErrorParams(shareType, openMenu); | ||
Comment on lines
+90
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here with the ternary |
||
|
||
logger.error(errorMessage, error); | ||
|
||
Modal.createDialog(QuestionDialog, modalParams); | ||
}; | ||
|
||
export const shareLiveLocation = ( | ||
|
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
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.
According to our new code style ternaries should look like this: