Skip to content

Commit

Permalink
Merge branch 'fix/1.5.1' into released
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Jul 25, 2019
2 parents a0ad6a2 + ad8d9f7 commit 73e96d2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/components/DataSource/PeopleRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import { PersonIdentifier, GroupIdentifier } from '../../database/type'
import { useValueRef } from '../../utils/hooks/useValueRef'

const ref = new ValueRef<Person[]>([])
Services.People.queryPeople('facebook.com').then(p => (ref.value = p))
function hasFingerprint(x: Person) {
return !!x.fingerprint
}
Services.People.queryPeople('facebook.com').then(p => (ref.value = p.filter(hasFingerprint)))
MessageCenter.on('newPerson', person => {
person.groups.forEach(group => Object.setPrototypeOf(group, GroupIdentifier.prototype))
person.previousIdentifiers &&
person.previousIdentifiers.forEach(id => Object.setPrototypeOf(id, PersonIdentifier.prototype))
Object.setPrototypeOf(person.identifier, PersonIdentifier.prototype)
const old = ref.value.filter(x => !x.identifier.equals(person.identifier))
ref.value = [...old, person]
ref.value = [...old, person].filter(hasFingerprint)
})
export function usePeople() {
return useValueRef(ref)
Expand Down
5 changes: 4 additions & 1 deletion src/components/InjectedComponents/PostComments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ interface Props {
export function PostComment({ comment, postContent, postIV, needZip }: Props) {
return (
<AsyncComponent
promise={() => Services.Crypto.decryptComment(postIV, postContent, comment)}
promise={() => {
if (!postIV || !postContent) return Promise.resolve('')
return Services.Crypto.decryptComment(postIV, postContent, comment)
}}
dependencies={[postIV, postContent, comment]}
awaitingComponent={null}
completeComponent={result =>
Expand Down
4 changes: 2 additions & 2 deletions src/extension/content-script/injections/MyUsername.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function getPersonIdentifierAtFacebook(links: link[] | link, allowCollect
}
return PersonIdentifier.unknown
}
function getUserID(x: string) {
export function getUserID(x: string) {
if (!x) return null
const relative = !x.startsWith('https://') && !x.startsWith('http://')
const url = relative ? new URL(x, location.host) : new URL(x)
Expand All @@ -101,5 +101,5 @@ function getUserID(x: string) {
const search = new URLSearchParams(url.search)
return search.get('id')
}
return url.pathname.replace(/^\//, '')
return url.pathname.replace(/^\//, '').replace(/\/$/, '')
}
2 changes: 1 addition & 1 deletion src/extension/content-script/injections/Posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ new MutationObserverWatcher(posts)
selectElementContents(_root.querySelector('[contenteditable]')!)
dispatchCustomEvents('paste', encryptedComment)
await sleep(200)
if (_root.innerText.match(encryptedComment)) console.log('Okay')
if (_root.innerText.match(encryptedComment)) 'Okay'
else prompt('Please paste it into the comment box!', encryptedComment)
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function PostInspector(props: PostInspectorProps) {
encryptedPost: deconstructPayload(post),
provePost: post.match(/🔒(.+)🔒/)!,
}
if (type.provePost) Services.People.uploadProvePostUrl(new PostIdentifier(postBy, postId))
useAsync(() => {
if (!whoAmI.equals(postBy)) return Promise.resolve([])
if (!type.encryptedPost) return Promise.resolve([])
Expand Down Expand Up @@ -63,7 +64,6 @@ export function PostInspector(props: PostInspectorProps) {
</>
)
} else if (type.provePost) {
Services.People.uploadProvePostUrl(new PostIdentifier(postBy, postId))
return <AddToKeyStore postBy={postBy} provePost={post} />
}
return null
Expand Down
9 changes: 4 additions & 5 deletions src/extension/content-script/injections/ProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import Services from '../../service'
import { PersonIdentifier } from '../../../database/type'
import { LiveSelector, MutationObserverWatcher } from '@holoflows/kit/es'
import { getUserID } from './MyUsername'

//#region Find key from bio
{
const bio = new LiveSelector().querySelector<HTMLDivElement>('#profile_timeline_intro_card')
function tryFindBioKey(text: string) {
const a = document.querySelector<HTMLAnchorElement>('#fb-timeline-cover-name a')
if (!text || !a) return
const id = a.href.match(/profile\.php\?id=(.+)/)
const name = a.href.match(/^https:..\.facebook.com\/(.+)/)
if (!id && !name) return
const username = id ? id[1] : name![1]
Services.Crypto.verifyOthersProve(text, new PersonIdentifier('facebook.com', username))
const id = getUserID(a.href)
if (!id) return
Services.Crypto.verifyOthersProve(text, new PersonIdentifier('facebook.com', id))
}
new MutationObserverWatcher(bio)
.enableSingleMode()
Expand Down

0 comments on commit 73e96d2

Please sign in to comment.