Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… np/group-polish-consent
  • Loading branch information
nplasterer committed Apr 24, 2024
2 parents 6aae818 + 6551038 commit dbcce93
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 36 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.10.4"
implementation "org.xmtp:android:0.10.5"
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 @@ -66,6 +66,7 @@ import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import com.facebook.common.util.Hex
import org.xmtp.android.library.messages.MessageDeliveryStatus
import org.xmtp.android.library.messages.Topic
import org.xmtp.android.library.push.Service

Expand Down Expand Up @@ -527,7 +528,7 @@ class XMTPModule : Module() {
}
}

AsyncFunction("groupMessages") Coroutine { clientAddress: String, id: String, limit: Int?, before: Long?, after: Long?, direction: String? ->
AsyncFunction("groupMessages") Coroutine { clientAddress: String, id: String, limit: Int?, before: Long?, after: Long?, direction: String?, deliveryStatus: String? ->
withContext(Dispatchers.IO) {
logV("groupMessages")
val client = clients[clientAddress] ?: throw XMTPException("No client")
Expand All @@ -540,6 +541,9 @@ class XMTPModule : Module() {
after = afterDate,
direction = MessageApiOuterClass.SortDirection.valueOf(
direction ?: "SORT_DIRECTION_DESCENDING"
),
deliveryStatus = MessageDeliveryStatus.valueOf(
deliveryStatus ?: "ALL"
)
)?.map { DecodedMessageWrapper.encode(it) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class DecodedMessageWrapper {
"content" to ContentJson(model.encodedContent).toJsonMap(),
"senderAddress" to model.senderAddress,
"sent" to model.sentAt.time,
"fallback" to fallback
"fallback" to fallback,
"deliveryStatus" to model.deliveryStatus.toString()
)
}
}
Expand Down
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PODS:
- hermes-engine/Pre-built (= 0.71.14)
- hermes-engine/Pre-built (0.71.14)
- libevent (2.1.12)
- LibXMTP (0.4.4-beta2)
- LibXMTP (0.4.4-beta3)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.4):
Expand Down Expand Up @@ -449,16 +449,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.10.3):
- XMTP (0.10.5):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.4.4-beta2)
- LibXMTP (= 0.4.4-beta3)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.10.3)
- XMTP (= 0.10.5)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -711,7 +711,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: 0c073613451e3850bfcaaab5438b481fe887cd97
LibXMTP: 1422d36d715fe868b5800692f3d9b8a218a41e9d
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: ed58ad794b3f88c24d604a5b74f3fba17fcbaf74
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: bf00ef58d4fbcc8ab740145a6303591adf3fb355
XMTPReactNative: fae44562e5e457c66fde8e2613e1dfd3c1a71113
XMTP: ec7fa7f9a2bd3990a7142c2f454e04c5b83b834a
XMTPReactNative: 42d61df711ce3c094d9fac9e3f44671f5466e93e
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2
Expand Down
63 changes: 59 additions & 4 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
Group,
ConversationContainer,
ConversationVersion,
syncGroup,

Check warning on line 17 in example/src/tests/groupTests.ts

View workflow job for this annotation

GitHub Actions / lint

'syncGroup' is defined but never used
MessageDeliveryStatus,
} from '../../../src/index'

export const groupTests: Test[] = []
Expand Down Expand Up @@ -205,11 +207,62 @@ test('production MLS V3 client creation throws error', async () => {
)
})

test('group message delivery status', async () => {
const [alixClient, boClient] = await createClients(2)
const alixGroup = await alixClient.conversations.newGroup([boClient.address])

await alixGroup.send('hello, world')

const alixMessages: DecodedMessage[] = await alixGroup.messages(true)

assert(
alixMessages.length === 2,
`the messages length should be 2 but was ${alixMessages.length}`
)

const alexMessagesFiltered: DecodedMessage[] = await alixGroup.messages(
true,
{
deliveryStatus: MessageDeliveryStatus.UNPUBLISHED,
}
)

assert(
alexMessagesFiltered.length === 1,
`the messages length should be 1 but was ${alexMessagesFiltered.length}`
)

const alixMessages2: DecodedMessage[] = await alixGroup.messages(false)

assert(
alixMessages2.length === 2,
`the messages length should be 2 but was ${alixMessages.length}`
)

assert(
alixMessages2[0].deliveryStatus === 'PUBLISHED',
`the message should have a delivery status of PUBLISHED but was ${alixMessages2[0].deliveryStatus}`
)

const boGroup = (await boClient.conversations.listGroups())[0]
const boMessages: DecodedMessage[] = await boGroup.messages()

assert(
boMessages.length === 1,
`the messages length should be 1 but was ${boMessages.length}`
)

assert(
boMessages[0].deliveryStatus === 'PUBLISHED',
`the message should have a delivery status of PUBLISHED but was ${boMessages[0].deliveryStatus}`
)

return true
})

test('who added me to a group', async () => {
const [alixClient, boClient] = await createClients(2)
const alixGroup = await alixClient.conversations.newGroup([
boClient.address,
])
const alixGroup = await alixClient.conversations.newGroup([boClient.address])

Check warning on line 265 in example/src/tests/groupTests.ts

View workflow job for this annotation

GitHub Actions / lint

'alixGroup' is assigned a value but never used

const boGroup = (await boClient.conversations.listGroups())[0]
const addedByAddress = await boGroup.addedByAddress()
Expand Down Expand Up @@ -842,7 +895,9 @@ test('can paginate group messages', async () => {
}
await delayToPropogate()
// bo can read messages from alix
const boMessages: DecodedMessage[] = await boGroups[0].messages(false, 1)
const boMessages: DecodedMessage[] = await boGroups[0].messages(false, {
limit: 1,
})

if (boMessages.length !== 1) {
throw Error(`Should limit just 1 message but was ${boMessages.length}`)
Expand Down
1 change: 1 addition & 0 deletions ios/Wrappers/DecodedMessageWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct DecodedMessageWrapper {
"senderAddress": model.senderAddress,
"sent": UInt64(model.sentAt.timeIntervalSince1970 * 1000),
"fallback": fallback,
"deliveryStatus": model.deliveryStatus.rawValue.uppercased(),
]
}

Expand Down
8 changes: 6 additions & 2 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public class XMTPModule: Module {
}
}

AsyncFunction("groupMessages") { (clientAddress: String, id: String, limit: Int?, before: Double?, after: Double?, direction: String?) -> [String] in
AsyncFunction("groupMessages") { (clientAddress: String, id: String, limit: Int?, before: Double?, after: Double?, direction: String?, deliveryStatus: String?) -> [String] in
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
}
Expand All @@ -427,6 +427,8 @@ public class XMTPModule: Module {
let afterDate = after != nil ? Date(timeIntervalSince1970: TimeInterval(after!) / 1000) : nil

let sortDirection: Int = (direction != nil && direction == "SORT_DIRECTION_ASCENDING") ? 1 : 2

let status: String = (deliveryStatus != nil) ? deliveryStatus!.lowercased() : "all"

guard let group = try await findGroup(clientAddress: clientAddress, id: id) else {
throw Error.conversationNotFound("no group found for \(id)")
Expand All @@ -435,7 +437,9 @@ public class XMTPModule: Module {
before: beforeDate,
after: afterDate,
limit: limit,
direction: PagingInfoSortDirection(rawValue: sortDirection))
direction: PagingInfoSortDirection(rawValue: sortDirection),
deliveryStatus: MessageDeliveryStatus(rawValue: status)
)

return decryptedMessages.compactMap { msg in
do {
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Pod::Spec.new do |s|
s.source_files = "**/*.{h,m,swift}"
s.dependency 'secp256k1.swift'
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.10.3"
s.dependency "XMTP", "= 0.10.5"
end
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ConversationContainer,
ConversationVersion,
} from './lib/ConversationContainer'
import { DecodedMessage } from './lib/DecodedMessage'
import { DecodedMessage, MessageDeliveryStatus } from './lib/DecodedMessage'
import { Group } from './lib/Group'
import type { Query } from './lib/Query'
import { ConversationSendPayload } from './lib/types'
Expand Down Expand Up @@ -165,15 +165,17 @@ export async function groupMessages<
direction?:
| 'SORT_DIRECTION_ASCENDING'
| 'SORT_DIRECTION_DESCENDING'
| undefined
| undefined,
deliveryStatus?: MessageDeliveryStatus | undefined
): Promise<DecodedMessage<ContentTypes>[]> {
const messages = await XMTPModule.groupMessages(
client.address,
id,
limit,
before,
after,
direction
direction,
deliveryStatus
)
return messages.map((json: string) => {
return DecodedMessage.from(json, client)
Expand Down Expand Up @@ -754,5 +756,5 @@ export {
} from './lib/ConversationContainer'
export { Query } from './lib/Query'
export { XMTPPush } from './lib/XMTPPush'
export { ConsentListEntry, DecodedMessage }
export { ConsentListEntry, DecodedMessage, MessageDeliveryStatus }
export { Group } from './lib/Group'
19 changes: 16 additions & 3 deletions src/lib/DecodedMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ const allowEmptyProperties: (keyof NativeMessageContent)[] = [
'text',
'readReceipt',
]
export enum MessageDeliveryStatus {
UNPUBLISHED = 'UNPUBLISHED',
PUBLISHED = 'PUBLISHED',
FAILED = 'FAILED',
ALL = 'ALL',
}

export class DecodedMessage<
ContentTypes extends DefaultContentTypes = DefaultContentTypes,
> {
Expand All @@ -24,6 +31,7 @@ export class DecodedMessage<
sent: number // timestamp in milliseconds
nativeContent: NativeMessageContent
fallback: string | undefined
deliveryStatus: MessageDeliveryStatus = MessageDeliveryStatus.PUBLISHED

static from<ContentTypes extends DefaultContentTypes = DefaultContentTypes>(
json: string,
Expand All @@ -38,7 +46,8 @@ export class DecodedMessage<
decoded.senderAddress,
decoded.sent,
decoded.content,
decoded.fallback
decoded.fallback,
decoded.deliveryStatus
)
}

Expand All @@ -53,6 +62,7 @@ export class DecodedMessage<
sent: number // timestamp in milliseconds
content: any
fallback: string | undefined
deliveryStatus: MessageDeliveryStatus | undefined
},
client: Client<ContentTypes>
): DecodedMessage<ContentTypes> {
Expand All @@ -64,7 +74,8 @@ export class DecodedMessage<
object.senderAddress,
object.sent,
object.content,
object.fallback
object.fallback,
object.deliveryStatus
)
}

Expand All @@ -76,7 +87,8 @@ export class DecodedMessage<
senderAddress: string,
sent: number,
content: any,
fallback: string | undefined
fallback: string | undefined,
deliveryStatus: MessageDeliveryStatus = MessageDeliveryStatus.PUBLISHED
) {
this.client = client
this.id = id
Expand All @@ -87,6 +99,7 @@ export class DecodedMessage<
this.nativeContent = content
// undefined comes back as null when bridged, ensure undefined so integrators don't have to add a new check for null as well
this.fallback = fallback ?? undefined
this.deliveryStatus = deliveryStatus
}

content(): ExtractDecodedType<[...ContentTypes, TextCodec][number] | string> {
Expand Down
21 changes: 9 additions & 12 deletions src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import {
ConversationVersion,
ConversationContainer,
} from './ConversationContainer'
import { DecodedMessage } from './DecodedMessage'
import { DecodedMessage, MessageDeliveryStatus } from './DecodedMessage'
import { ConversationSendPayload } from './types/ConversationCodecs'
import { DefaultContentTypes } from './types/DefaultContentType'
import { EventTypes } from './types/EventTypes'
import { MessagesOptions } from './types/MessagesOptions'
import { SendOptions } from './types/SendOptions'
import * as XMTP from '../index'

Expand Down Expand Up @@ -111,24 +112,20 @@ export class Group<
*/
async messages(
skipSync: boolean = false,
limit?: number | undefined,
before?: number | Date | undefined,
after?: number | Date | undefined,
direction?:
| 'SORT_DIRECTION_ASCENDING'
| 'SORT_DIRECTION_DESCENDING'
| undefined
opts?: MessagesOptions
): Promise<DecodedMessage<ContentTypes>[]> {
if (!skipSync) {
await this.sync()
}

return await XMTP.groupMessages(
this.client,
this.id,
limit,
before,
after,
direction
opts?.limit,
opts?.before,
opts?.after,
opts?.direction,
opts?.deliveryStatus ?? MessageDeliveryStatus.ALL
)
}

Expand Down
12 changes: 12 additions & 0 deletions src/lib/types/MessagesOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MessageDeliveryStatus } from '../DecodedMessage'

export type MessagesOptions = {
limit?: number | undefined
before?: number | Date | undefined
after?: number | Date | undefined
direction?:
| 'SORT_DIRECTION_ASCENDING'
| 'SORT_DIRECTION_DESCENDING'
| undefined
deliveryStatus?: MessageDeliveryStatus | undefined
}
1 change: 1 addition & 0 deletions src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './ContentCodec'
export * from './SendOptions'
export * from './ExtractDecodedType'
export * from './ConversationCodecs'
export * from './MessagesOptions'

0 comments on commit dbcce93

Please sign in to comment.