From ea9c06c4381b296d5e26b5c565c1445373e5f428 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 17 Dec 2024 22:17:59 -0800 Subject: [PATCH] update all the places --- .../wrappers/ConversationWrapper.kt | 4 +-- .../wrappers/DecodedMessageWrapper.kt | 2 +- .../xmtpreactnativesdk/wrappers/DmWrapper.kt | 4 +-- .../wrappers/GroupWrapper.kt | 4 +-- example/dev/local/test/script.js | 6 ++-- example/src/ConversationScreen.tsx | 16 +++++----- example/src/GroupScreen.tsx | 16 +++++----- example/src/HomeScreen.tsx | 2 +- example/src/hooks.tsx | 32 +++++++++---------- ios/Wrappers/DecodedMessageWrapper.swift | 2 +- src/lib/DecodedMessage.ts | 27 ++++++++-------- 11 files changed, 58 insertions(+), 57 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConversationWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConversationWrapper.kt index 8d85ccb9b..1ea74caf4 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConversationWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConversationWrapper.kt @@ -7,7 +7,7 @@ import org.xmtp.android.library.Conversation class ConversationWrapper { companion object { - fun encodeToObj( + suspend fun encodeToObj( client: Client, conversation: Conversation, conversationParams: ConversationParamsWrapper = ConversationParamsWrapper(), @@ -25,7 +25,7 @@ class ConversationWrapper { } } - fun encode( + suspend fun encode( client: Client, conversation: Conversation, conversationParams: ConversationParamsWrapper = ConversationParamsWrapper(), diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt index 6d51552cd..ab5ac6835 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecodedMessageWrapper.kt @@ -22,7 +22,7 @@ class DecodedMessageWrapper { "topic" to model.topic, "contentTypeId" to model.encodedContent.type.description, "content" to ContentJson(model.encodedContent).toJsonMap(), - "senderAddress" to model.senderAddress, + "senderInboxId" to model.senderInboxId, "sentNs" to model.sentNs, "fallback" to fallback, "deliveryStatus" to model.deliveryStatus.toString() diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DmWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DmWrapper.kt index 9a690fbec..e41d2eaeb 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DmWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DmWrapper.kt @@ -6,7 +6,7 @@ import org.xmtp.android.library.Dm class DmWrapper { companion object { - fun encodeToObj( + suspend fun encodeToObj( client: Client, dm: Dm, dmParams: ConversationParamsWrapper = ConversationParamsWrapper(), @@ -30,7 +30,7 @@ class DmWrapper { } } - fun encode( + suspend fun encode( client: Client, dm: Dm, dmParams: ConversationParamsWrapper = ConversationParamsWrapper(), diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt index 6a0e14403..72a7bb36b 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt @@ -9,7 +9,7 @@ import org.xmtp.android.library.Group class GroupWrapper { companion object { - fun encodeToObj( + suspend fun encodeToObj( client: Client, group: Group, groupParams: ConversationParamsWrapper = ConversationParamsWrapper(), @@ -37,7 +37,7 @@ class GroupWrapper { } } - fun encode( + suspend fun encode( client: Client, group: Group, groupParams: ConversationParamsWrapper = ConversationParamsWrapper(), diff --git a/example/dev/local/test/script.js b/example/dev/local/test/script.js index 76c7ce342..1f1f7ecdc 100644 --- a/example/dev/local/test/script.js +++ b/example/dev/local/test/script.js @@ -19,14 +19,14 @@ async function checkAll() { try { for await (const message of await client.conversations.streamAllMessages()) { - if (message.senderAddress === wallet.address) { + if (message.senderInboxId === wallet.address) { continue } await message.conversation.send({ - text: 'HI ' + message.senderAddress, + text: 'HI ' + message.senderInboxId, }) - console.log(`Replied to ${message.senderAddress}`) + console.log(`Replied to ${message.senderInboxId}`) } } catch (e) { console.info(`Error:`, e) diff --git a/example/src/ConversationScreen.tsx b/example/src/ConversationScreen.tsx index 45304e7b9..64fa15036 100644 --- a/example/src/ConversationScreen.tsx +++ b/example/src/ConversationScreen.tsx @@ -178,8 +178,8 @@ export default function ConversationScreen({ showSender={ index === (filteredMessages || []).length - 1 || (index + 1 < (filteredMessages || []).length && - filteredMessages![index + 1].senderAddress !== - message.senderAddress) + filteredMessages![index + 1].senderInboxId !== + message.senderInboxId) } /> )} @@ -469,8 +469,8 @@ function ReplyInputHeader({ }} /> - {message?.senderAddress.slice(0, 6)}… - {message?.senderAddress.slice(-4)} + {message?.senderInboxId.slice(0, 6)}… + {message?.senderInboxId.slice(-4)} @@ -864,8 +864,8 @@ function ReplyMessageHeader({ }} /> - {message.senderAddress.slice(0, 6)}… - {message.senderAddress.slice(-4)} + {message.senderInboxId.slice(0, 6)}… + {message.senderInboxId.slice(-4)} {typeof content !== 'string' && 'text' in content && content.text ? ( - {message.senderAddress.slice(0, 6)}… - {message.senderAddress.slice(-4)} + {message.senderInboxId.slice(0, 6)}… + {message.senderInboxId.slice(-4)} {moment(message.sentNs / 1000000).fromNow()} diff --git a/example/src/GroupScreen.tsx b/example/src/GroupScreen.tsx index 43d856377..fd8fa355e 100644 --- a/example/src/GroupScreen.tsx +++ b/example/src/GroupScreen.tsx @@ -180,8 +180,8 @@ export default function GroupScreen({ showSender={ index === (filteredMessages || []).length - 1 || (index + 1 < (filteredMessages || []).length && - filteredMessages![index + 1].senderAddress !== - message.senderAddress) + filteredMessages![index + 1].senderInboxId !== + message.senderInboxId) } /> )} @@ -469,8 +469,8 @@ function ReplyInputHeader({ }} /> - {message?.senderAddress.slice(0, 6)}… - {message?.senderAddress.slice(-4)} + {message?.senderInboxId.slice(0, 6)}… + {message?.senderInboxId.slice(-4)} @@ -864,8 +864,8 @@ function ReplyMessageHeader({ }} /> - {message.senderAddress.slice(0, 6)}… - {message.senderAddress.slice(-4)} + {message.senderInboxId.slice(0, 6)}… + {message.senderInboxId.slice(-4)} {typeof content !== 'string' && 'text' in content && content.text ? ( - {message.senderAddress.slice(0, 6)}… - {message.senderAddress.slice(-4)} + {message.senderInboxId.slice(0, 6)}… + {message.senderInboxId.slice(-4)} {moment(message.sentNs / 1000000).fromNow()} diff --git a/example/src/HomeScreen.tsx b/example/src/HomeScreen.tsx index d45c57ed4..72f949582 100644 --- a/example/src/HomeScreen.tsx +++ b/example/src/HomeScreen.tsx @@ -150,7 +150,7 @@ function ConversationItem({ {lastMessage?.fallback} - {lastMessage?.senderAddress}: + {lastMessage?.senderInboxId}: {moment(lastMessage?.sentNs / 1000000).fromNow()} diff --git a/example/src/hooks.tsx b/example/src/hooks.tsx index addb8f99f..8a02b0d5c 100644 --- a/example/src/hooks.tsx +++ b/example/src/hooks.tsx @@ -171,7 +171,7 @@ export function useMessage({ console.log('Error refreshing messages', err) ) })) - const isSenderMe = message?.senderAddress === client?.address + const isSenderMe = message?.senderInboxId === client?.address return { message, performReaction, @@ -217,7 +217,7 @@ export function useGroupMessage({ console.log('Error refreshing messages', err) ) })) - const isSenderMe = message?.senderAddress === client?.address + const isSenderMe = message?.senderInboxId === client?.address return { message, performReaction, @@ -245,7 +245,7 @@ export function useConversationReactions({ topic }: { topic: string }) { }>( ['xmtp', 'reactions', client?.address, topic, reactions.length], () => { - // SELECT messageId, reaction, senderAddress FROM reactions GROUP BY messageId, reaction + // SELECT messageId, reaction, senderInboxId FROM reactions GROUP BY messageId, reaction const byId = {} as { [messageId: string]: { [reaction: string]: string[] } } @@ -254,23 +254,23 @@ export function useConversationReactions({ topic }: { topic: string }) { .slice() .reverse() .forEach((message) => { - const { senderAddress } = message + const { senderInboxId } = message const reaction = message.content() as ReactionContent const messageId = reaction!.reference const reactionText = reaction!.content const v = byId[messageId] || ({} as { [reaction: string]: string[] }) - // DELETE FROM reactions WHERE messageId = ? AND reaction = ? AND senderAddress = ? + // DELETE FROM reactions WHERE messageId = ? AND reaction = ? AND senderInboxId = ? let prior = (v[reactionText] || []) // This removes any prior instances of the sender using this reaction. - .filter((address) => address !== senderAddress) + .filter((address) => address !== senderInboxId) if (reaction!.action === 'added') { - // INSERT INTO reactions (messageId, reaction, senderAddress) VALUES (?, ?, ?) - prior = prior.concat([senderAddress]) + // INSERT INTO reactions (messageId, reaction, senderInboxId) VALUES (?, ?, ?) + prior = prior.concat([senderInboxId]) } v[reactionText] = prior byId[messageId] = v }) - // SELECT messageId, reaction, COUNT(*) AS count, COUNT(senderAddress = ?) AS includesMe + // SELECT messageId, reaction, COUNT(*) AS count, COUNT(senderInboxId = ?) AS includesMe // FROM reactions // GROUP BY messageId, reaction // ORDER BY count DESC @@ -318,7 +318,7 @@ export function useGroupReactions({ groupId }: { groupId: string }) { }>( ['xmtp', 'reactions', client?.address, groupId, reactions.length], () => { - // SELECT messageId, reaction, senderAddress FROM reactions GROUP BY messageId, reaction + // SELECT messageId, reaction, senderInboxId FROM reactions GROUP BY messageId, reaction const byId = {} as { [messageId: string]: { [reaction: string]: string[] } } @@ -327,23 +327,23 @@ export function useGroupReactions({ groupId }: { groupId: string }) { .slice() .reverse() .forEach((message) => { - const { senderAddress } = message + const { senderInboxId } = message const reaction = message.content() as ReactionContent const messageId = reaction!.reference const reactionText = reaction!.content const v = byId[messageId] || ({} as { [reaction: string]: string[] }) - // DELETE FROM reactions WHERE messageId = ? AND reaction = ? AND senderAddress = ? + // DELETE FROM reactions WHERE messageId = ? AND reaction = ? AND senderInboxId = ? let prior = (v[reactionText] || []) // This removes any prior instances of the sender using this reaction. - .filter((address) => address !== senderAddress) + .filter((address) => address !== senderInboxId) if (reaction!.action === 'added') { - // INSERT INTO reactions (messageId, reaction, senderAddress) VALUES (?, ?, ?) - prior = prior.concat([senderAddress]) + // INSERT INTO reactions (messageId, reaction, senderInboxId) VALUES (?, ?, ?) + prior = prior.concat([senderInboxId]) } v[reactionText] = prior byId[messageId] = v }) - // SELECT messageId, reaction, COUNT(*) AS count, COUNT(senderAddress = ?) AS includesMe + // SELECT messageId, reaction, COUNT(*) AS count, COUNT(senderInboxId = ?) AS includesMe // FROM reactions // GROUP BY messageId, reaction // ORDER BY count DESC diff --git a/ios/Wrappers/DecodedMessageWrapper.swift b/ios/Wrappers/DecodedMessageWrapper.swift index 21f3bf535..f9e51e3bd 100644 --- a/ios/Wrappers/DecodedMessageWrapper.swift +++ b/ios/Wrappers/DecodedMessageWrapper.swift @@ -13,7 +13,7 @@ struct DecodedMessageWrapper { "topic": model.topic, "contentTypeId": model.encodedContent.type.description, "content": try ContentJson.fromEncoded(model.encodedContent, client: client).toJsonMap() as Any, - "senderAddress": model.senderAddress, + "senderInboxId": model.senderInboxId, "sentNs": model.sentNs, "fallback": fallback, "deliveryStatus": model.deliveryStatus.rawValue.uppercased(), diff --git a/src/lib/DecodedMessage.ts b/src/lib/DecodedMessage.ts index f5dd48976..6915c5f84 100644 --- a/src/lib/DecodedMessage.ts +++ b/src/lib/DecodedMessage.ts @@ -1,11 +1,12 @@ import { Buffer } from 'buffer' -import { Client, ExtractDecodedType } from './Client' +import { Client, ExtractDecodedType, InboxId } from './Client' import { JSContentCodec, NativeContentCodec, NativeMessageContent, } from './ContentCodec' +import { ConversationTopic, MessageId } from './types' import { DecodedMessageUnion } from './types/DecodedMessageUnion' import { DefaultContentTypes } from './types/DefaultContentType' @@ -25,10 +26,10 @@ export class DecodedMessage< ContentTypes extends DefaultContentTypes = DefaultContentTypes, > { client: Client - id: string - topic: string + id: MessageId + topic: ConversationTopic contentTypeId: string - senderAddress: string + senderInboxId: InboxId sentNs: number // timestamp in nanoseconds nativeContent: NativeMessageContent fallback: string | undefined @@ -48,7 +49,7 @@ export class DecodedMessage< decoded.id, decoded.topic, decoded.contentTypeId, - decoded.senderAddress, + decoded.senderInboxId, decoded.sentNs, decoded.content, decoded.fallback, @@ -62,10 +63,10 @@ export class DecodedMessage< ContentTypes extends DefaultContentTypes = [ContentType], >( object: { - id: string - topic: string + id: MessageId + topic: ConversationTopic contentTypeId: string - senderAddress: string + senderInboxId: InboxId sentNs: number // timestamp in nanoseconds content: any fallback: string | undefined @@ -78,7 +79,7 @@ export class DecodedMessage< object.id, object.topic, object.contentTypeId, - object.senderAddress, + object.senderInboxId, object.sentNs, object.content, object.fallback, @@ -88,10 +89,10 @@ export class DecodedMessage< constructor( client: Client, - id: string, - topic: string, + id: MessageId, + topic: ConversationTopic, contentTypeId: string, - senderAddress: string, + senderInboxId: InboxId, sentNs: number, content: any, fallback: string | undefined, @@ -101,7 +102,7 @@ export class DecodedMessage< this.id = id this.topic = topic this.contentTypeId = contentTypeId - this.senderAddress = senderAddress + this.senderInboxId = senderInboxId this.sentNs = sentNs 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