Skip to content

Commit

Permalink
Resolve some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Jun 20, 2019
1 parent 0f58569 commit a7c86a2
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 53 deletions.
3 changes: 3 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
"banner_title": {
"message": "Welcome to Maskbook"
},
"banner_collecting_identity": {
"message": "Maskbook is identifying how to setup your account..."
},
"banner_get_started": {
"message": "Get started"
},
Expand Down
3 changes: 3 additions & 0 deletions src/_locales/zh/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@
"banner_title": {
"message": "歡迎使用 Maskbook"
},
"banner_collecting_identity": {
"message": "Maskbook 正在準備向導過程……"
},
"banner_get_started": {
"message": "開始使用"
},
Expand Down
6 changes: 1 addition & 5 deletions src/components/InjectedComponents/AdditionalPostContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ interface Props {
children?: any
}
const useStyles = makeStyles({
upDivider: {
marginBottom: 6,
// TODO: ? is this useful?
marginBlock: 6,
},
upDivider: { marginBottom: 6 },
title: { display: 'flex' },
icon: { transform: 'translate(-1px, -1px)' },
content: {
Expand Down
5 changes: 1 addition & 4 deletions src/components/Welcomes/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ export function Banner(props: Props) {
<Toolbar className={classes.toolbar}>
<Box flex={1}>
<Typography variant="subtitle1" color="inherit">
{/* // TODO: i18n */}
{props.disabled
? "Sorry, you can't setup your maskbook account currently, please try again later"
: geti18nString('banner_title')}
{props.disabled ? geti18nString('banner_collecting_identity') : geti18nString('banner_title')}
</Typography>
</Box>
<Button
Expand Down
1 change: 0 additions & 1 deletion src/database/migrate/old.keystore.1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export default async function migrate() {
const wait = (await queryPeopleCryptoKey()).map(record => {
if (record.username === '$self')
return People.storeMyIdentityDB({
// TODO: Need to update later !
identifier: new PersonIdentifier('facebook.com', '$self'),
groups: [],
publicKey: record.publicKey,
Expand Down
5 changes: 3 additions & 2 deletions src/database/people.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import { PersonIdentifier, Identifier, GroupIdentifier } from './type'
import { openDB, DBSchema } from 'idb/with-async-ittr'
import { JsonWebKeyToCryptoKey, CryptoKeyToJsonWebKey } from '../utils/type-transform/CryptoKey-JsonWebKey'
import { sendNewPersonMessageDB } from '../utils/messages'

//#region Type and utils
/**
Expand Down Expand Up @@ -117,7 +118,7 @@ const db = openDB<PeopleDB>('maskbook-people-v2', 1, {
export async function storeNewPersonDB(record: PersonRecord): Promise<void> {
const t = (await db).transaction('people', 'readwrite')
await t.objectStore('people').put(await toDb(record))
// TODO: Send new person message
sendNewPersonMessageDB(record)
return
}
/**
Expand Down Expand Up @@ -163,8 +164,8 @@ export async function updatePersonDB(person: Partial<PersonRecord> & Pick<Person
const full = await t.objectStore('people').get(person.identifier.toText())
if (!full) throw new Error('Person is not in the db')
const o: PersonRecordInDatabase = { ...full, ...(await toDb(person as PersonRecord)) }
// TODO: Send new person message
await t.objectStore('people').put(o)
sendNewPersonMessageDB(await outDb(o))
}
/**
* Remove people from database
Expand Down
4 changes: 2 additions & 2 deletions src/extension/background-script/CryptoService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Alpha40 from '../../crypto/crypto-alpha-40'
import { OnlyRunInContext } from '@holoflows/kit/es'
import { addPersonPublicKey } from '../../key-management/people-gun'
import { publishPostAESKey as publishPostAESKey_Service, queryPostAESKey } from '../../key-management/posts-gun'

import { decodeText, encodeArrayBuffer, decodeArrayBuffer } from '../../utils/type-transform/String-ArrayBuffer'
Expand All @@ -10,7 +9,8 @@ import { toCompressSecp256k1Point, unCompressSecp256k1Point } from '../../utils/
import { Person, getMyPrivateKeyAtFacebook, queryPerson } from '../../database'
import { queryMyIdentityAtDB, storeNewPersonDB, queryPersonDB, queryLocalKeyDB } from '../../database/people'
import { PersonIdentifier } from '../../database/type'
import { gun } from '../../key-management/gun'
import { addPersonPublicKey } from '../../key-management/people-gun'
import { gun } from '../../network/gun/version.1'

OnlyRunInContext('background', 'EncryptService')
//#region Encrypt & Decrypt
Expand Down
31 changes: 0 additions & 31 deletions src/key-management/gun.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/key-management/people-gun.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { gun } from './gun'
import tasks from '../extension/content-script/tasks'
import { verifyOthersProve } from '../extension/background-script/CryptoService'
import { sleep } from '../utils/utils'
import { getProfilePageUrlAtFacebook, getPostUrlAtFacebook } from '../utils/type-transform/Username'
import { geti18nString } from '../utils/i18n'
import { PersonIdentifier, PostIdentifier, PersonUI } from '../database/type'
import { queryPerson } from '../database'
import { gun } from '../network/gun/version.1'

export async function queryPersonFromGun(username: string) {
return gun
Expand Down
2 changes: 1 addition & 1 deletion src/key-management/posts-gun.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gun } from './gun'
import { PublishedAESKey } from '../crypto/crypto-alpha-40'
import { OnlyRunInContext } from '@holoflows/kit/es'
import { gun } from '../network/gun/version.1'

OnlyRunInContext('background', 'gun')
/**
Expand Down
11 changes: 9 additions & 2 deletions src/network/gun/version.1.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Gun from 'gun'
import 'gun/lib/then'
import { OnlyRunInContext } from '@holoflows/kit/es'
import { PublishedAESKey } from '../../crypto/crypto-alpha-40'

export interface ApplicationStateInGunVersion1 {
Expand All @@ -11,10 +14,14 @@ export interface ApplicationStateInGunVersion1 {
posts: {
// Post id or salt
[postIdentifier: string]: {
// TODO: This will leak post targets. (But keys are safe
// TODO: Consider using hash(id+username) or something
// NON-TODO: This will leak post targets. (But keys are safe
// NON-TODO: Consider using hash(id+username) or something
// ? Resolved in version -40. But not implemented yet.
[receiversUsername: string]: PublishedAESKey
}
}
}
}
OnlyRunInContext('background', 'Gun')
interface State extends ApplicationStateInGunVersion1 {}
export const gun = new Gun<State>(['http://172.104.123.119:8765/gun']).get('maskbook')
1 change: 0 additions & 1 deletion src/utils/jss/ConstructableStyleSheetsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ export default class ConstructableStyleSheetsRenderer {

// When rules are inserted using `insertRule` API, after `sheet.detach().attach()`
// browsers remove those rules.
// TODO figure out if its a bug and if it is known.
// Workaround is to redeploy the sheet.
if (this.hasInsertedRules) {
this.hasInsertedRules = false
Expand Down
9 changes: 7 additions & 2 deletions src/utils/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MessageCenter as MC } from '@holoflows/kit/es'
import { Person } from '../database'
import { MessageCenter as MC, OnlyRunInContext } from '@holoflows/kit/es'
import { Person, personRecordToPerson } from '../database'
import { PersonRecord } from '../database/people'

interface UIEvent {}
interface KeyStoreEvent {
Expand All @@ -8,4 +9,8 @@ interface KeyStoreEvent {
interface TypedMessages extends UIEvent, KeyStoreEvent {}

export const MessageCenter = new MC<TypedMessages>('maskbook-events')
export async function sendNewPersonMessageDB(personRecord: PersonRecord) {
OnlyRunInContext(['background', 'debugging'], 'sendNewPersonDB')
MessageCenter.send('newPerson', await personRecordToPerson(personRecord))
}
MessageCenter.writeToConsole = true
1 change: 0 additions & 1 deletion src/utils/type-transform/Username.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export function getPostUrlAtFacebook(post: PostIdentifier<PersonIdentifier>) {
* Normalize profile url
*/
export function getProfilePageUrlAtFacebook(user: PersonIdentifier | GroupIdentifier) {
// TODO:
if (user instanceof GroupIdentifier) throw new Error('Not implemented')
if (user.network !== 'facebook.com') throw new Error('Not implemented')
const username = user.userId
Expand Down

0 comments on commit a7c86a2

Please sign in to comment.