Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release] Hotfix 2.24.2 => 2.24.3 (patch) #11356

Merged
merged 10 commits into from
Feb 8, 2024
Merged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"yarn": ">=999.0.0",
"npm": ">=999.0.0"
},
"version": "2.24.2",
"version": "2.24.3",
"private": true,
"license": "AGPL-3.0-or-later",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/initialization/plugin-host/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ __setSiteAdaptorContext__({
currentNextIDPlatform: undefined,
currentPersonaIdentifier: UNDEFINED,
getPostURL: () => null,
getProfileURL: () => null,
share: undefined,
connectPersona: reject,
getPostIdFromNewPostToast: undefined,
Expand Down
12 changes: 12 additions & 0 deletions packages/icons/brands/DarkLens.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/icons/icon-generated-as-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ export const DangerOutline = /*#__PURE__*/ __createIcon('DangerOutline', [
s: true,
},
])
export const DarkLens = /*#__PURE__*/ __createIcon('DarkLens', [
{
u: () => new URL('./brands/DarkLens.svg', import.meta.url).href,
},
])
export const Debank = /*#__PURE__*/ __createIcon('Debank', [
{
u: () => new URL('./brands/Debank.svg', import.meta.url).href,
Expand Down
1 change: 1 addition & 0 deletions packages/icons/icon-generated-as-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function cross_sync_url() { return new URL("./brands/CrossSync.svg", impo
export function cyber_connect_url() { return new URL("./brands/CyberConnect.svg", import.meta.url).href }
export function danger_url() { return new URL("./brands/Danger.svg", import.meta.url).href }
export function danger_outline_url() { return new URL("./brands/DangerOutline.svg", import.meta.url).href }
export function dark_lens_url() { return new URL("./brands/DarkLens.svg", import.meta.url).href }
export function debank_url() { return new URL("./brands/Debank.svg", import.meta.url).href }
export function discord_url() { return new URL("./brands/Discord.svg", import.meta.url).href }
export function discord_round_url() { return new URL("./brands/DiscordRound.svg", import.meta.url).href }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Services from '#services'
import { encodeByNetwork } from '@masknet/encryption'
import { PluginID, Sniffings, SOCIAL_MEDIA_NAME } from '@masknet/shared-base'
import { PluginID, PostIdentifier, Sniffings, SOCIAL_MEDIA_NAME } from '@masknet/shared-base'
import type { Meta } from '@masknet/typed-message'
import { Telemetry } from '@masknet/web3-telemetry'
import { EventID, EventType } from '@masknet/web3-telemetry/types'
Expand Down Expand Up @@ -58,7 +58,17 @@ export function useSubmit(onClose: () => void, reason: 'timeline' | 'popup' | 'r
reason,
},
)
if (postId) location.reload()
const postIdentifier =
lastRecognizedIdentity.identifier && postId ?
new PostIdentifier(lastRecognizedIdentity.identifier, postId)
: undefined

if (postIdentifier) {
const postUrl = activatedSiteAdaptorUI.utils.getPostURL?.(postIdentifier)
if (postUrl) location.assign(postUrl)
} else if (postId) {
location.reload()
}
} else {
if (encode === 'image') {
if (!mediaObject) throw new Error('Failed to create image payload.')
Expand Down
2 changes: 2 additions & 0 deletions packages/mask/content-script/site-adaptor-infra/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export async function activateSiteAdaptorUIInner(ui_deferred: SiteAdaptorUI.Defe
ui.injection.profileAvatar?.(signal)
ui.injection.tips?.(signal)
ui.injection.nameWidget?.(signal)
ui.injection.farcaster?.(signal)
ui.injection.lens?.(signal)

ui.injection.enhancedProfileNFTAvatar?.(signal)
Expand Down Expand Up @@ -147,6 +148,7 @@ export async function activateSiteAdaptorUIInner(ui_deferred: SiteAdaptorUI.Defe
currentNextIDPlatform: ui.configuration.nextIDConfig?.platform,
currentPersonaIdentifier: createSubscriptionFromValueRef(currentPersonaIdentifier, signal),
getPostURL: ui.utils.getPostURL || (() => null),
getProfileURL: ui.utils.getProfileURL || (() => null),
share: ui.utils.share,
getPostIdFromNewPostToast: ui.configuration.nextIDConfig?.getPostIdFromNewPostToast,
connectPersona,
Expand Down
18 changes: 15 additions & 3 deletions packages/mask/content-script/site-adaptors/facebook.com/shared.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import urlcat from 'urlcat'
import type { SiteAdaptor } from '@masknet/types'
import { facebookBase } from './base.js'
import { getPostUrlAtFacebook, isValidFacebookUsername } from './utils/parse-username.js'
import { type PostIdentifier } from '@masknet/shared-base'
import { type ProfileIdentifier, type PostIdentifier } from '@masknet/shared-base'
import { hasPayloadLike } from '../../utils/index.js'
import { createSiteAdaptorSpecializedPostContext } from '../../site-adaptor-infra/utils/create-post-context.js'
import { openWindow } from '@masknet/shared-base-ui'
import { FacebookAdaptor } from '../../../shared/site-adaptors/implementations/facebook.com.js'

function getPostURL(post: PostIdentifier): URL | null {
return new URL(getPostUrlAtFacebook(post))
}
function getProfileURL(profile: ProfileIdentifier): URL | null {
return new URL('https://www.facebook.com')
}
function getShareURL(text: string): URL | null {
return new URL(
urlcat('https://www.facebook.com/sharer/sharer.php', {
quote: text,
u: 'mask.io',
}),
)
}
export const facebookShared: SiteAdaptor.Shared & SiteAdaptor.Base = {
...facebookBase,
utils: {
isValidUsername: (v) => !!isValidFacebookUsername(v),
getPostURL,
getProfileURL,
share(message) {
openWindow(FacebookAdaptor.getShareLinkURL?.(message))
openWindow(getShareURL?.(message))
},
createPostContext: createSiteAdaptorSpecializedPostContext(facebookBase.networkIdentifier, {
hasPayloadLike,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ const facebookUI: SiteAdaptorUI.Definition = {
...facebookShared,
automation: {
redirect: {
profilePage(profile) {
gotoProfilePage(profile) {
// there is no PWA way on Facebook desktop.
// mobile not tested
location.assign(getProfilePageUrlAtFacebook(profile))
},
newsFeed() {
gotoNewsFeed() {
const homeLink = document.querySelector<HTMLAnchorElement>(
[
'[data-click="bluebar_logo"] a[href]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import { createSiteAdaptorSpecializedPostContext } from '../../site-adaptor-infr
import { hasPayloadLike } from '../../utils/index.js'
import { instagramBase } from './base.js'

function getProfileURL(): URL | null {
return new URL('https://www.instagram.com/')
}

export const instagramShared: SiteAdaptor.Shared & SiteAdaptor.Base = {
...instagramBase,
utils: {
getProfileURL,
createPostContext: createSiteAdaptorSpecializedPostContext(instagramBase.networkIdentifier, {
hasPayloadLike,
}),
Expand Down
20 changes: 17 additions & 3 deletions packages/mask/content-script/site-adaptors/minds.com/shared.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
import { type PostIdentifier } from '@masknet/shared-base'
import urlcat from 'urlcat'
import { type ProfileIdentifier, type PostIdentifier } from '@masknet/shared-base'
import { openWindow } from '@masknet/shared-base-ui'
import type { SiteAdaptor } from '@masknet/types'
import { createSiteAdaptorSpecializedPostContext } from '../../site-adaptor-infra/utils/create-post-context.js'
import { hasPayloadLike } from '../../utils/index.js'
import { mindsBase } from './base.js'
import { usernameValidator } from './utils/user.js'
import { MindsAdaptor } from '../../../shared/site-adaptors/implementations/minds.com.js'

function getPostURL(post: PostIdentifier): URL {
return new URL(`https://minds.com/newsfeed/${post.postId}`)
}

function getProfileURL(profile: ProfileIdentifier): URL | null {
return new URL('https://www.minds.com')
}

function getShareURL(text: string): URL | null {
return new URL(
urlcat('https://www.minds.com/newsfeed/subscriptions', {
intentUrl: text,
}),
)
}

export const mindsShared: SiteAdaptor.Shared & SiteAdaptor.Base = {
...mindsBase,
utils: {
isValidUsername: usernameValidator,
getPostURL,
getProfileURL,
share(message) {
openWindow(MindsAdaptor.getShareLinkURL?.(message))
openWindow(getShareURL(message))
},
createPostContext: createSiteAdaptorSpecializedPostContext(mindsBase.networkIdentifier, {
hasPayloadLike,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ const mindsUI: SiteAdaptorUI.Definition = {
attachImage: pasteImageToCompositionMinds(),
},
redirect: {
newsFeed: gotoNewsFeedPageMinds,
profilePage: gotoProfilePageMinds,
gotoNewsFeed: gotoNewsFeedPageMinds,
gotoProfilePage: gotoProfilePageMinds,
},
},
collecting: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ import { hasPayloadLike } from '../../utils/index.js'
import { mirrorBase } from './base.js'
import { getUserIdentity } from './utils/user.js'

function getProfileURL() {
return new URL('https://mirror.xyz/dashboard')
}
function getShareURL(text: string) {
return new URL('https://mirror.xyz')
}

export const mirrorShared: SiteAdaptor.Shared & SiteAdaptor.Base = {
...mirrorBase,
utils: {
getProfileURL,
getShareURL,
createPostContext: createSiteAdaptorSpecializedPostContext(mirrorBase.networkIdentifier, {
hasPayloadLike,
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { injectFarcasterOnConversation } from './injectFarcasterOnConversation.js'
import { injectFarcasterOnPost } from './injectFarcasterOnPost.js'
import { injectFarcasterOnProfile } from './injectFarcasterOnProfile.js'
import { injectFarcasterOnSpaceDock } from './injectFarcasterOnSpaceDock.js'
import { injectFarcasterOnUserCell } from './injectFarcasterOnUserCell.js'

export function injectFarcaster(signal: AbortSignal) {
injectFarcasterOnProfile(signal)
injectFarcasterOnPost(signal)
injectFarcasterOnUserCell(signal)
injectFarcasterOnConversation(signal)
injectFarcasterOnSpaceDock(signal)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { memo, useMemo, useState } from 'react'
import { MutationObserverWatcher } from '@dimensiondev/holoflows-kit'
import { createInjectHooksRenderer, Plugin, useActivatedPluginsSiteAdaptor } from '@masknet/plugin-infra/content-script'
import { EnhanceableSite, ProfileIdentifier } from '@masknet/shared-base'
import { makeStyles } from '@masknet/theme'
import { attachReactTreeWithContainer } from '../../../../utils/shadow-root/renderInShadowRoot.js'
import { querySelectorAll } from '../../utils/selector.js'
import { startWatch } from '../../../../utils/startWatch.js'

function selector() {
return querySelectorAll<HTMLElement>('[data-testid=conversation] div:not([tabindex]) div[dir] + div[dir]')
}

const useStyles = makeStyles()((theme) => ({
hide: {
display: 'none',
},
slot: {
position: 'relative',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 999,
marginLeft: theme.spacing(0.5),
verticalAlign: 'top',
},
}))

interface Props {
userId: string
}

function createRootElement() {
const span = document.createElement('span')
Object.assign(span.style, {
verticalAlign: 'bottom',
height: '21px',
alignItems: 'center',
justifyContent: 'center',
display: 'inline-flex',
} as CSSStyleDeclaration)
return span
}

const ConversationFarcasterSlot = memo(function ConversationFarcasterSlot({ userId }: Props) {
const [disabled, setDisabled] = useState(true)
const { classes, cx } = useStyles()

const component = useMemo(() => {
const Component = createInjectHooksRenderer(
useActivatedPluginsSiteAdaptor.visibility.useNotMinimalMode,
(plugin) => plugin.Farcaster?.UI?.Content,
undefined,
createRootElement,
)
const identifier = ProfileIdentifier.of(EnhanceableSite.Twitter, userId).unwrapOr(null)
if (!identifier) return null

return (
<Component
identity={identifier}
slot={Plugin.SiteAdaptor.FarcasterSlot.Sidebar}
onStatusUpdate={setDisabled}
/>
)
}, [userId])

if (!component) return null

return <span className={cx(classes.slot, disabled ? classes.hide : null)}>{component}</span>
})

/**
* Inject on conversation, including both DM drawer and message page (/messages/xxx)
*/
export function injectFarcasterOnConversation(signal: AbortSignal) {
const watcher = new MutationObserverWatcher(selector())
startWatch(watcher, signal)
watcher.useForeach((node, _, proxy) => {
const spans = node
.closest('[data-testid=conversation]')
?.querySelectorAll<HTMLElement>('[tabindex] [dir] span:not([data-testid=tweetText])')
if (!spans) return
const userId = [...spans].reduce((id, node) => {
if (id) return id
if (node.textContent?.match(/@\w/)) {
return node.textContent.trim().slice(1)
}
return ''
}, '')
if (!userId) return
attachReactTreeWithContainer(proxy.afterShadow, { signal, untilVisible: true }).render(
<ConversationFarcasterSlot userId={userId} />,
)
})
}