Skip to content

Commit

Permalink
fix: add created at to the installation
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 26, 2024
1 parent a209215 commit 601bf7b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.15.10"
implementation "org.xmtp:android:0.15.11"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.xmtp.android.library.toHex
class GroupWrapper {

companion object {
fun encodeToObj(client: Client, group: Group): Map<String, Any> {
suspend fun encodeToObj(client: Client, group: Group): Map<String, Any> {
return mapOf(
"clientAddress" to client.address,
"id" to group.id,
Expand All @@ -26,7 +26,7 @@ class GroupWrapper {
)
}

fun encode(client: Client, group: Group): String {
suspend fun encode(client: Client, group: Group): String {
val gson = GsonBuilder().create()
val obj = encodeToObj(client, group)
return gson.toJson(obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ class InboxStateWrapper {
return mapOf(
"inboxId" to inboxState.inboxId,
"addresses" to inboxState.addresses,
"installationIds" to inboxState.installationIds,
"installations" to inboxState.installations.map {
mapOf(
"id" to it.installationId,
"createdAt" to it.createdAt?.time
)
},
"recoveryAddress" to inboxState.recoveryAddress
)
}
Expand Down
13 changes: 9 additions & 4 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,21 @@ test('can revoke all other installations', async () => {

const inboxState = await alix2.inboxState(true)
assert(
inboxState.installationIds.length === 2,
`installationIds length should be 2 but was ${inboxState.installationIds.length}`
inboxState.installations.length === 2,
`installations length should be 2 but was ${inboxState.installations.length}`
)

await alix2.revokeAllOtherInstallations(alixWallet)

const inboxState2 = await alix2.inboxState(true)
assert(
inboxState2.installationIds.length === 1,
`installationIds length should be 1 but was ${inboxState2.installationIds.length}`
inboxState2.installations.length === 1,
`installations length should be 1 but was ${inboxState2.installations.length}`
)

assert(
inboxState2.installations[0].createdAt !== undefined,
`installations createdAt should not be undefined`
)
return true
})
Expand Down
25 changes: 21 additions & 4 deletions src/lib/InboxState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { InboxId } from './Client'
export class InboxState {
inboxId: InboxId
addresses: string[]
installationIds: string[]
installations: Installation[]
recoveryAddress: string

constructor(
inboxId: InboxId,
addresses: string[],
installationIds: string[],
installations: Installation[],
recoveryAddress: string
) {
this.inboxId = inboxId
this.addresses = addresses
this.installationIds = installationIds
this.installations = installations
this.recoveryAddress = recoveryAddress
}

Expand All @@ -23,8 +23,25 @@ export class InboxState {
return new InboxState(
entry.inboxId,
entry.addresses,
entry.installationIds,
entry.installations.map((inst: string) => {
return Installation.from(inst)
}),
entry.recoveryAddress
)
}
}

export class Installation {
id: string
createdAt: number | undefined // timestamp in milliseconds

constructor(id: string, createdAt: number) {
this.id = id
this.createdAt = createdAt
}

static from(json: string): Installation {
const installation = JSON.parse(json)
return new Installation(installation.id, installation.createdAt)
}
}

0 comments on commit 601bf7b

Please sign in to comment.