-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6092 from mozilla/ecs-pin-permissions
Pinning/Unpinning interaction and media promotion checks for bitECS + entity state API
- Loading branch information
Showing
19 changed files
with
230 additions
and
125 deletions.
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
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
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
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
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,49 @@ | ||
import { HubsWorld } from "../app"; | ||
import { createEntityState, deleteEntityState } from "./entity-state-utils"; | ||
import HubChannel from "./hub-channel"; | ||
import { EntityID } from "./networking-types"; | ||
import { takeOwnership } from "./take-ownership"; | ||
import { createMessageDatas, isNetworkInstantiated, isPinned } from "../bit-systems/networking"; | ||
|
||
export const setPinned = async (hubChannel: HubChannel, world: HubsWorld, eid: EntityID, shouldPin: boolean) => { | ||
_signInAndPinOrUnpinElement(hubChannel, world, eid, shouldPin); | ||
}; | ||
|
||
const _pinElement = async (hubChannel: HubChannel, world: HubsWorld, eid: EntityID) => { | ||
try { | ||
await createEntityState(hubChannel, world, eid); | ||
takeOwnership(world, eid); | ||
} catch (e) { | ||
if (e.reason === "invalid_token") { | ||
// TODO: Sign out and sign in again | ||
console.log("PinningHelper: Pin failed due to invalid token, signing out and trying again", e); | ||
} else { | ||
console.warn("PinningHelper: Pin failed for unknown reason", e); | ||
} | ||
} | ||
}; | ||
|
||
const unpinElement = (hubChannel: HubChannel, world: HubsWorld, eid: EntityID) => { | ||
deleteEntityState(hubChannel, world, eid); | ||
}; | ||
|
||
const _signInAndPinOrUnpinElement = (hubChannel: HubChannel, world: HubsWorld, eid: EntityID, shouldPin: boolean) => { | ||
const action = shouldPin ? () => _pinElement(hubChannel, world, eid) : () => unpinElement(hubChannel, world, eid); | ||
// TODO: Perform conditional sign in | ||
action(); | ||
}; | ||
|
||
export const canPin = (hubChannel: HubChannel, world: HubsWorld, eid: EntityID): boolean => { | ||
const { | ||
initialData: { fileId } | ||
} = createMessageDatas.get(eid)!; | ||
const hasFile = !!fileId; | ||
const hasPromotableFile = | ||
hasFile && APP.store.state.uploadPromotionTokens.some((upload: any) => upload.fileId === fileId); | ||
return ( | ||
isNetworkInstantiated(eid) && | ||
!isPinned(eid) && | ||
hubChannel.can("pin_objects") && // TODO: Remove once conditional sign in is implemented | ||
(!hasFile || hasPromotableFile) | ||
); | ||
}; |
Oops, something went wrong.