Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
sdk 1.1.0 (#1011)
Browse files Browse the repository at this point in the history
* Update npm module and ios pod install

* Code changs for new sdk

* Updated to latest rn sdk with fixes
  • Loading branch information
asutula authored Apr 3, 2019
1 parent 86cad69 commit bf52e50
Show file tree
Hide file tree
Showing 53 changed files with 1,116 additions and 459 deletions.
2 changes: 1 addition & 1 deletion App/Components/GroupCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const GroupCard = (props: ScreenProps) => {
<View style={styles.avatarContainer}>
{ members.slice(0, 8).map((mem: pb.IContact, i: number) => {
const imageStyle = cardImageStyle(members.length, i)
return (<Avatar key={mem.id} style={imageStyle} target={mem.avatar}/>)
return (<Avatar key={mem.address} style={imageStyle} target={mem.avatar}/>)
})}
</View>
</View>
Expand Down
2 changes: 1 addition & 1 deletion App/Containers/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Account extends Component<Props> {
}

const mapStateToProps = (state: RootState): StateProps => ({
username: state.account.profile.value ? state.account.profile.value.username || state.account.profile.value.id : 'unknown'
username: state.account.profile.value ? state.account.profile.value.name || state.account.profile.value.address : 'unknown'
})

export default connect(mapStateToProps, undefined)(Account)
6 changes: 3 additions & 3 deletions App/Containers/AddContact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class AddContact extends React.Component<Props> {
return (
<ListItem
leftItem={<Avatar style={{ width: 50 }} target={item.data.contact.avatar} />}
title={item.data.contact.username || item.data.contact.id}
subtitle={item.data.contact.id.substr(item.data.contact.id.length - 8, 8)}
title={item.data.contact.name || item.data.contact.address}
subtitle={item.data.contact.address.substr(item.data.contact.address.length - 8, 8)}
rightItems={[
<Button
key='add'
Expand Down Expand Up @@ -181,7 +181,7 @@ class AddContact extends React.Component<Props> {
}

onPressTextile = (contact: pb.IContact) => {
return () => this.props.navigation.navigate('Contact', { avatar: contact.avatar, username: contact.username, address: contact.address })
return () => this.props.navigation.navigate('Contact', { avatar: contact.avatar, username: contact.name, address: contact.address })
}

onAdd = (contact: pb.IContact) => {
Expand Down
12 changes: 6 additions & 6 deletions App/Containers/Contacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Contacts extends React.Component<Props, State> {
let data = allContacts
if (this.state.searchString !== undefined && this.state.searchString.length > 0) {
data = data.filter((contact) => {
const searchKey = (contact.username || contact.id).toLowerCase()
const searchKey = (contact.name || contact.address).toLowerCase()
const index = searchKey.indexOf(this.state.searchString!.toLowerCase())
return index > -1
})
Expand Down Expand Up @@ -112,15 +112,15 @@ class Contacts extends React.Component<Props, State> {
)
}

keyExtractor = (item: pb.IContact) => item.id
keyExtractor = (item: pb.IContact) => item.address

renderRow = (row: ListRenderItemInfo<pb.IContact>) => {
const { item } = row
const leftItem = <Avatar style={{ width: 50 }} target={item.avatar} />
const rightItems = [<Icon key='more' name='chevron-right' size={24} color={color.grey_4} />]
return (
<ListItem
title={item.username || item.id}
title={item.name || item.address}
leftItem={leftItem}
rightItems={rightItems}
onPress={this.onPress(item)}
Expand All @@ -136,7 +136,7 @@ class Contacts extends React.Component<Props, State> {

onPress = (contactInfo: pb.IContact) => {
return () => {
this.props.navigation.navigate('Contact', { avatar: contactInfo.avatar, username: contactInfo.username, address: contactInfo.address })
this.props.navigation.navigate('Contact', { avatar: contactInfo.avatar, username: contactInfo.name, address: contactInfo.address })
}
}

Expand All @@ -152,8 +152,8 @@ class Contacts extends React.Component<Props, State> {

const mapStateToProps = (state: RootState): StateProps => {
const contacts = state.contacts.contacts.slice().sort((a, b) => {
const aSortKey = a.username || a.id
const bSortKey = b.username || b.id
const aSortKey = a.name || a.address
const bSortKey = b.name || b.address
if (aSortKey < bSortKey) {
return -1
} else if (aSortKey > bSortKey) {
Expand Down
2 changes: 1 addition & 1 deletion App/Containers/OnboardingUsername.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class OnboardingUsername extends React.Component<Props, State> {

const mapStateToProps = (state: RootState): StateProps => ({
processing: state.account.profile.processing,
buttonText: state.account.profile.value && state.account.profile.value.username ? 'Success!' : 'Save'
buttonText: state.account.profile.value && state.account.profile.value.name ? 'Success!' : 'Save'
})

const mapDispatchToProps = (dispatch: Dispatch<RootAction>): DispatchProps => ({
Expand Down
2 changes: 1 addition & 1 deletion App/Redux/AccountSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getAddress (state: RootState): string | undefined {

export function getUsername (state: RootState): string | undefined {
return state.account.profile.value &&
state.account.profile.value.username
state.account.profile.value.name
}

export function bestSession(state: RootState): pb.ICafeSession | undefined {
Expand Down
4 changes: 2 additions & 2 deletions App/Redux/ThreadsRedux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const actions = {
return (id: string, name: string) => resolve({ id, name })
}),
addExternalInviteSuccess: createAction('ADD_EXTERNAL_INVITE_SUCCESS', (resolve) => {
return (id: string, name: string, invite: pb.INewInvite) => resolve({ id, name, invite })
return (id: string, name: string, invite: pb.IExternalInvite) => resolve({ id, name, invite })
}),
addExternalInviteError: createAction('ADD_EXTERNAL_INVITE_ERROR', (resolve) => {
return (id: string, error: Error) => resolve({ id, error })
Expand Down Expand Up @@ -54,7 +54,7 @@ export interface InviteQRCode {
export interface OutboundInvite {
readonly id: string
readonly name: string
readonly invite?: pb.INewInvite
readonly invite?: pb.IExternalInvite
readonly error?: Error
}

Expand Down
17 changes: 3 additions & 14 deletions App/Redux/__tests__/AccountRedux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,11 @@ import { pb } from '@textile/react-native-sdk'

const initialState = reducer(undefined, {} as any)
const profile: pb.IContact = {
id: 'id',
address: 'address',
username: 'username',
name: 'username',
avatar: 'avatar',
inboxes: [{
peer: 'peer',
address: 'address',
api: 'api',
protocol: 'protocol',
node: 'node',
url: 'url',
swarm: ['swarm']
}],
threads: [],
created: { seconds: 0, nanos: 0 },
updated: { seconds: 0, nanos: 0 }
peers: [],
threads: []
}
const peerId = 'peerId'
const error = 'error'
Expand Down
2 changes: 1 addition & 1 deletion App/Redux/__tests__/ThreadsRedux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const name: string = 'myThread' as any
const error = new Error('an error')
const inviteId: string = 'invite_id' as any
const inviteKey: string = 'a_key' as any
const invite: pb.INewInvite = {id: inviteId, inviter: 'tests' as any, key: inviteKey}
const invite: pb.IExternalInvite = {id: inviteId, inviter: 'tests' as any, key: inviteKey}

const initialState = reducer(undefined, {} as any)

Expand Down
2 changes: 1 addition & 1 deletion App/SB/components/ContactSelect/ContactSelectCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ContactSelectCard = (props) => {
select(item, item.included)
}}>
<Avatar style={styles.selectedContact} target={item.avatar} />
<Text style={styles.contactName}>{item.username || 'peer'}</Text>
<Text style={styles.contactName}>{item.name || 'peer'}</Text>
<View style={styles.contactSelectRadio}>
<RadioButton disabled={item.included} selected={selected} />
</View>
Expand Down
8 changes: 4 additions & 4 deletions App/SB/components/ContactSelect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const ContactSelect = (props) => {
return (<View />)
}

const selectState = !!selected[item.id] || item.included
const selectState = !!selected[item.address] || item.included

return (
<TouchableOpacity key={item.id} activeOpacity={0.6} style={styles.selectedContact} onPress={() => {
<TouchableOpacity key={item.address} activeOpacity={0.6} style={styles.selectedContact} onPress={() => {
select(item, item.included)
}}>
<Avatar style={styles.selectedContact} target={item.avatar} />
Expand Down Expand Up @@ -90,12 +90,12 @@ export class ContactSelectComponent extends React.Component {
return (
<FlatList
data={this.props.contacts}
keyExtractor={(item) => item.id}
keyExtractor={(item) => item.address}
extraData={this.props.selected}
ListHeaderComponent={this.renderHeader()}
renderItem={(contact) => {
const { item } = contact
const selectState = !!this.props.selected[item.id] || item.included
const selectState = !!this.props.selected[item.address] || item.included
return (
<ContactSelectCard item={item} select={this.props.onSelect} selected={selectState} />
)
Expand Down
24 changes: 12 additions & 12 deletions App/SB/views/ThreadsEditFriends/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class Component extends React.Component<Props> {
if (included) {
return // if the user is already part of the thread
}
const state = !this.state.selected[contact.id]
const state = !this.state.selected[contact.address]
this.setState({
selected: { ...this.state.selected, [contact.id]: state }
selected: { ...this.state.selected, [contact.address]: state }
})
}

Expand All @@ -76,23 +76,23 @@ class Component extends React.Component<Props> {
const selected = this.getSelected()

// grab the Pks from the user Ids
const ids: string[] = selected.map((id) => {
const existing = this.props.contacts.find((ctc) => ctc.id === id)
const addresses: string[] = selected.map((address) => {
const existing = this.props.contacts.find((ctc) => ctc.address === address)
if (existing) {
return existing.id
return existing.address
}
return ''
})
.filter((id) => id !== '')

if (ids.length === 0) {
if (addresses.length === 0) {
// @ts-ignore
this.refs.toast.show('No contacts selected.', 1500)
return
}
// @ts-ignore
this.refs.toast.show('Success! Your invite(s) were sent.', 2400)
this.props.addInternalInvites(this.props.threadId, ids)
this.props.addInternalInvites(this.props.threadId, addresses)
setTimeout(() => { this.props.cancel() }, 2400)
}

Expand Down Expand Up @@ -155,19 +155,19 @@ const mapStateToProps = (state: RootState, ownProps: ScreenProps): StateProps =
included: (contact.threads || []).indexOf(threadId) >= 0
}
})
.filter((contact) => contact.username !== '' && contact.username !== undefined)
.filter((contact) => contact.name !== '' && contact.name !== undefined)

const notInThread = contacts.filter((c) => !c.included)
const popularity = notInThread.sort((a, b) => (b.threads || []).length - (a.threads || []).length)
const topFive = popularity.slice(0, 5)
const sortedContacts = contacts.sort((a, b) => {
if (!a.username || a.username === '') {
if (!a.name || a.name === '') {
return 1
} else if (!b.username || b.username === '') {
} else if (!b.name || b.name === '') {
return -1
}
const A = a.username.toString().toUpperCase()
const B = b.username.toString().toUpperCase()
const A = a.name.toString().toUpperCase()
const B = b.name.toString().toUpperCase()
if (A === B) {
return 0
} else {
Expand Down
4 changes: 2 additions & 2 deletions App/Sagas/Account/AccountSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function * refreshProfile () {
while (true) {
try {
yield take(getType(AccountActions.refreshProfileRequest))
const profileResult: pb.IContact = yield call(API.profile.get)
const profileResult: pb.IContact = yield call(API.account.contact)
yield put(AccountActions.refreshProfileSuccess(profileResult))
} catch (error) {
yield call(logNewEvent, 'refreshProfile', error.message, true)
Expand Down Expand Up @@ -77,7 +77,7 @@ export function * setUsername () {
}
// Ideally this could move into the SDK directly so it can manage
// knowing its own online state
yield call(API.profile.setUsername, action.payload.username)
yield call(API.profile.setName, action.payload.username)
yield put(TextileEventsActions.updateProfile())
} catch (error) {
yield put(AccountActions.profileError(error))
Expand Down
4 changes: 2 additions & 2 deletions App/Sagas/ThreadsSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Config from 'react-native-config'
export function * addExternalInvite (action: ActionType<typeof ThreadsActions.addExternalInviteRequest>) {
const { id, name } = action.payload
try {
const invite: pb.INewInvite = yield call(API.invites.addExternal, id)
const invite: pb.IExternalInvite = yield call(API.invites.addExternal, id)
yield put(ThreadsActions.addExternalInviteSuccess(id, name, invite))
} catch (error) {
yield put(ThreadsActions.addExternalInviteError(id, error))
Expand All @@ -37,7 +37,7 @@ export function * addExternalInvite (action: ActionType<typeof ThreadsActions.ad
export function * displayThreadQRCode (action: ActionType<typeof ThreadsActions.threadQRCodeRequest>) {
const { id, name } = action.payload
try {
const invite: pb.INewInvite = yield call(API.invites.addExternal, id)
const invite: pb.IExternalInvite = yield call(API.invites.addExternal, id)
const link = DeepLink.createInviteLink(invite, name)
yield put(ThreadsActions.threadQRCodeSuccess(id, name, link))
// displayThreadQRCode
Expand Down
2 changes: 1 addition & 1 deletion App/Services/DeepLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function getData (href: string): DeepLinkData | undefined {
}
}

function createInviteLink (invite: pb.INewInvite, threadName: string): string {
function createInviteLink (invite: pb.IExternalInvite, threadName: string): string {
const hash: string[] = []
hash.push(`id=${encodeURIComponent(invite.id)}`)
hash.push(`key=${encodeURIComponent(invite.key)}`)
Expand Down
2 changes: 1 addition & 1 deletion App/Services/__tests__/DeepLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

const params = 'id=QmdNgTtH468cqZFzXCi4sVSWTbJMWQbhYb8cBVyikP9LzW&key=VsHHHz8bC8fu9k78RaX8ujQsUzGzaUxwKJyLFKKDacUZoWJaouGnzUQwgmh5&inviter=andrew-dev&name=TRT%20Dev&referral=SOMETHING'
const link = `www.textile.photos/invites/new#${params}`
const invite: pb.INewInvite = {
const invite: pb.IExternalInvite = {
id: 'QmdNgTtH468cqZFzXCi4sVSWTbJMWQbhYb8cBVyikP9LzW',
key: 'VsHHHz8bC8fu9k78RaX8ujQsUzGzaUxwKJyLFKKDacUZoWJaouGnzUQwgmh5',
inviter: 'andrew-dev'
Expand Down
6 changes: 3 additions & 3 deletions App/features/contacts/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ export default combineReducers<ContactsState, ContactsAction>({
case getType(actions.addContactRequest): {
return {
...state,
[action.payload.contact.id]: {}
[action.payload.contact.address]: {}
}
}
case getType(actions.addContactSuccess):
case getType(actions.clearAddContact): {
const { [action.payload.contact.id]: removed, ...addingContacts } = state
const { [action.payload.contact.address]: removed, ...addingContacts } = state
return {
addingContacts
}
Expand All @@ -128,7 +128,7 @@ export default combineReducers<ContactsState, ContactsAction>({
const message = error.message as string || error as string || 'unknown'
return {
...state,
[contact.id]: {
[contact.address]: {
error: message
}
}
Expand Down
4 changes: 2 additions & 2 deletions App/features/contacts/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ function executeTextileSearch(searchString: string) {
return eventChannel<pb.MobileQueryEvent>((emitter) => {
const query: pb.IContactQuery = {
username: searchString,
id: '',
address: ''
}
const options: pb.IQueryOptions = {
local: false,
localOnly: false,
remoteOnly: false,
limit: 20,
wait: 8,
filter: pb.QueryOptions.FilterType.NO_FILTER,
Expand Down
18 changes: 7 additions & 11 deletions App/features/contacts/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
AddressBookSearchResult
} from './models'

export const makeIsKnown = (id: string) => (state: ContactsState) => state.contacts.some((p) => p.id === id)
export const makeIsKnown = (address: string) => (state: ContactsState) => state.contacts.some((p) => p.address === address)

export const makeByThreadId = (id: string) => (state: ContactsState) => state.contacts.filter((contact) => (contact.threads || []).indexOf(id) > -1)

export const makeContactById = (id: string) => (state: ContactsState) => state.contacts.find((contact) => contact.id === id)
export const makeContactByAddress = (address: string) => (state: ContactsState) => state.contacts.find((contact) => contact.address === address)

export const searchResults = (state: ContactsState) => {
const sections: SearchResultsSection[] = []
Expand All @@ -21,18 +21,14 @@ export const searchResults = (state: ContactsState) => {
} else if (state.textileSearchResults.results && state.textileSearchResults.results.length > 0) {
textileData = state.textileSearchResults.results
.filter((current, index, arr) => {
const sames = arr.filter((el) => el.id === current.id)
if (sames.length === 1) {
return true
}
// If there is a newer entry, filter this one
return !(sames.find((el) => el.updated.seconds > current.updated.seconds || (el.updated.seconds === current.updated.seconds && el.updated.nanos > current.updated.nanos)))
const sames = arr.filter((el) => el.address === current.address)
return sames.length === 1
})
.map((result) => {
const selector = makeIsKnown(result.id)
const selector = makeIsKnown(result.address)
const isContact = selector(state)
const adding = Object.keys(state.addingContacts).indexOf(result.id) > -1
const textileResult: TextileSearchResult = { key: result.id, type: 'textile', data: { contact: result, isContact, adding } }
const adding = Object.keys(state.addingContacts).indexOf(result.address) > -1
const textileResult: TextileSearchResult = { key: result.address, type: 'textile', data: { contact: result, isContact, adding } }
return textileResult
})
} else if (state.textileSearchResults.results && state.textileSearchResults.results.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Loading

0 comments on commit bf52e50

Please sign in to comment.