Skip to content

Commit

Permalink
refactor: rename sns to site (#10344)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Aug 10, 2023
1 parent fa70d26 commit 60ce5f0
Show file tree
Hide file tree
Showing 106 changed files with 418 additions and 1,193 deletions.
2 changes: 1 addition & 1 deletion packages/app/src/pages/ApplicationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface ApplicationsPageProps {}
export default function ApplicationsPage(props: ApplicationsPageProps) {
return (
<PageContainer title="Applications">
<ApplicationBoardForm allPersonas={[]} personaAgainstSNSConnectStatusLoading={false} />
<ApplicationBoardForm allPersonas={[]} personaPerSiteConnectStatusLoading={false} />
</PageContainer>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const PostHistoryRow = memo(({ post, network }: PostHistoryRowProps) => {
const pluginID = SUPPORT_PLUGIN[pluginName]?.pluginID

if (!pluginID) return null
const handler = () => Services.SiteAdaptor.openSNSAndActivatePlugin(`https://${identifier.network}`, pluginID)
const handler = () => Services.SiteAdaptor.openSiteAndActivatePlugin(`https://${identifier.network}`, pluginID)

return (
<Button color="secondary" variant="rounded" onClick={handler} sx={{ fontSize: 12 }}>
Expand Down
2 changes: 1 addition & 1 deletion packages/injected-script/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Injected scripts

This package is intended to be run inside the SNS Network to provide some extra functionality.
This package is intended to be run inside the website to provide some extra functionality.

This package has 3 project:

Expand Down
2 changes: 1 addition & 1 deletion packages/injected-script/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface InternalEvents {
* Simulate an image upload event.
*
* How to use:
* Call this event, then invoke the file selector (SNS). It will invoke click on some input, then let's replace with the result.
* Call this event, then invoke the file selector (for now it's instagram). It will invoke click on some input, then let's replace with the result.
*/
hookInputUploadOnce: [format: string, fileName: string, file: number[], triggerOnActiveElementNow: boolean]

Expand Down
6 changes: 3 additions & 3 deletions packages/mask-sdk/main/socialNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ let metadata: Mask.SocialNetwork['metadata'] = undefined
export class SocialNetwork extends EventTarget implements Mask.SocialNetwork {
constructor(init: InitInformation) {
super()
connected = init.SNSContext.connected
metadata = init.SNSContext.meta
connected = init.context.connected
metadata = init.context.meta
}
async appendComposition(message: string, metadata?: ReadonlyMap<string, unknown>) {
if (metadata) metadata = new Map(metadata)
contentScript.sns_appendComposition(message, metadata)
contentScript.site_appendComposition(message, metadata)
}
get connected() {
return !!connected
Expand Down
4 changes: 2 additions & 2 deletions packages/mask-sdk/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export interface BridgeAPI {
persona_sign_web3(message: string): Promise<string>
sns_appendComposition(message: string, metadata?: ReadonlyMap<string, unknown>): Promise<void>
site_appendComposition(message: string, metadata?: ReadonlyMap<string, unknown>): Promise<void>
}
export interface UserScriptAPI {
// When User script loaded, content script is not loaded. We must _be_ called to make sure CS has loaded.
request_init(init: InitInformation): Promise<void>
}
export interface InitInformation {
SNSContext: {
context: {
meta: Mask.SocialNetwork['metadata']
connected: boolean
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/background/database/persona/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export interface PersonaRecord {
hasLogout?: boolean
/**
* create a dummy persona which should hide to the user until
* connected at least one SNS identity
* connected at least one website
*/
uninitialized?: boolean
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace Version38Or39 {
if (x === EncryptPayloadNetwork.Minds) return 'minds-'
if (x === EncryptPayloadNetwork.Instagram) return 'instagram-'
if (x === EncryptPayloadNetwork.Unknown)
throw new TypeError('[@masknet/encryption] Current SNS network is not correctly configured.')
throw new TypeError('[@masknet/encryption] Current network is not correctly configured.')
unreachable(x)
}

Expand Down Expand Up @@ -343,7 +343,7 @@ namespace Version37 {
if (x === EncryptPayloadNetwork.Minds) return '37-minds'
if (x === EncryptPayloadNetwork.Instagram) return '37-ins'
if (x === EncryptPayloadNetwork.Unknown)
throw new TypeError('[@masknet/encryption] Current SNS network is not correctly configured.')
throw new TypeError('[@masknet/encryption] Current network is not correctly configured.')
unreachable(x)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/background/services/site-adaptors/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { getDesignatedAutoStartPluginID, openSNSAndActivatePlugin } from './open-with-plugin.js'
export { getDesignatedAutoStartPluginID, openSiteAndActivatePlugin } from './open-with-plugin.js'
export {
getSupportedSites,
getSupportedOrigins,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Storage } from 'webextension-polyfill'

const key = 'openSNSAndActivatePlugin'
const key = 'openSiteAndActivatePlugin'
// Note: sessionStorage is only available in MV2 or MV3 page mode.
const sessionStorage = (globalThis as any).sessionStorage
/**
* This function will open a new web page, then open the composition dialog and activate the composition entry of the given plugin.
* @param url URL to open
* @param pluginID Plugin to activate
*/
export async function openSNSAndActivatePlugin(url: string, pluginID: string): Promise<void> {
export async function openSiteAndActivatePlugin(url: string, pluginID: string): Promise<void> {
await browser.tabs.create({ active: true, url })
if (!('session' in browser.storage)) {
sessionStorage.setItem(key, pluginID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ThirdPartyPluginPermission,
} from '../../../shared/definitions/routes.js'
// TODO: those types are defined in the plugin/External
type MaskSDK_SNS_ContextIdentifier = string
type MaskSDK_Site_ContextIdentifier = string
type Manifest = any

export async function fetchManifest(addr: string): Promise<Manifest> {
Expand All @@ -20,13 +20,13 @@ export async function fetchManifest(addr: string): Promise<Manifest> {
.join('\n'),
)
}
const hostedMeta = new Map<MaskSDK_SNS_ContextIdentifier, [string, unknown]>()
export async function getHostedMeta(context: MaskSDK_SNS_ContextIdentifier) {
const hostedMeta = new Map<MaskSDK_Site_ContextIdentifier, [string, unknown]>()
export async function getHostedMeta(context: MaskSDK_Site_ContextIdentifier) {
return hostedMeta.get(context)
}
export async function openPluginPopup(
url: string,
meta?: [context: MaskSDK_SNS_ContextIdentifier, metaKey: string, meta: unknown],
meta?: [context: MaskSDK_Site_ContextIdentifier, metaKey: string, meta: unknown],
) {
new URL(url) // it must be a full qualified URL otherwise throws
if (meta) hostedMeta.set(meta[0], [meta[1], meta[2]])
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/shared-ui/TypedMessageRender/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export enum Order {
/**
* Message transformation order:
*
* sns_parsed_message
* parsed_message
* |> flatten
* |> parse links and tags (@user, #tag, $NAME)
* |> Mask Payload parser (installed in SNS Adaptor starts)
* |> Mask Payload parser (installed in Site Adaptor starts)
* |> plugins
*/
export const TypedMessageTransformers = composeTransformers()
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/src/ShadowRootAttachPointRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Suspense } from 'react'
import { useSNSThemeMode } from '@masknet/plugin-infra/content-script'
import { useSiteThemeMode } from '@masknet/plugin-infra/content-script'
import { SharedContextProvider } from '@masknet/shared'
import { CSSVariableInjector, MaskThemeProvider } from '@masknet/theme'
import { ErrorBoundary } from '@masknet/shared-base-ui'
Expand All @@ -14,7 +14,7 @@ export function ShadowRootAttachPointRoot(children: React.ReactNode) {
(children) => <ErrorBoundary children={children} />,
(children) =>
MaskThemeProvider({
useMaskIconPalette: useSNSThemeMode,
useMaskIconPalette: useSiteThemeMode,
useTheme: useMaskSiteAdaptorMixedTheme,
CustomSnackbarOffsetY: isFacebook(activatedSiteAdaptorUI) ? 80 : undefined,
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useCompositionClipboardRequest } from './useCompositionClipboardRequest
import { useRecipientsList } from './useRecipientsList.js'
import { useSubmit } from './useSubmit.js'
import { usePersonasFromDB } from '../DataSource/usePersonasFromDB.js'
import { useCurrentPersona } from '../DataSource/usePersonaConnectStatus.js'
import { useCurrentPersona } from '../DataSource/useCurrentPersona.js'
import { EncryptionMethodType } from './EncryptionMethodSelector.js'
import { useI18N } from '../../utils/index.js'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function useSubmit(onClose: () => void, reason: 'timeline' | 'popup' | 'r
lastRecognizedIdentity?.identifier ?? fallbackProfile,
activatedSiteAdaptorUI.encryptPayloadNetwork,
)
// Since we cannot directly send binary on the SNS, we need to encode it into a string.
// Since we cannot directly send binary in the composition box, we need to encode it into a string.
const encrypted = encodeByNetwork(activatedSiteAdaptorUI.encryptPayloadNetwork, rawEncrypted)

if (encode === 'image') {
Expand Down
20 changes: 20 additions & 0 deletions packages/mask/src/components/DataSource/useCurrentPersona.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useAsync } from 'react-use'
import { currentPersonaIdentifier } from '@masknet/shared-base'
import { useValueRef } from '@masknet/shared-base-ui'
import Services from '../../extension/service.js'

/**
* Get current setting persona
*/
export function useCurrentPersona() {
const currentIdentifier = useValueRef(currentPersonaIdentifier)

const { value } = useAsync(async () => {
const identifier = await Services.Settings.getCurrentPersonaIdentifier()

if (!identifier) return
return Services.Identity.queryPersona(identifier)
}, [currentIdentifier])

return value
}
103 changes: 0 additions & 103 deletions packages/mask/src/components/DataSource/useNextIDConnectStatus.ts

This file was deleted.

62 changes: 0 additions & 62 deletions packages/mask/src/components/DataSource/usePersonaConnectStatus.ts

This file was deleted.

0 comments on commit 60ce5f0

Please sign in to comment.