Skip to content

Commit

Permalink
update all the places
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Dec 18, 2024
1 parent 2209ff0 commit ea9c06c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -25,7 +25,7 @@ class ConversationWrapper {
}
}

fun encode(
suspend fun encode(
client: Client,
conversation: Conversation,
conversationParams: ConversationParamsWrapper = ConversationParamsWrapper(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -30,7 +30,7 @@ class DmWrapper {
}
}

fun encode(
suspend fun encode(
client: Client,
dm: Dm,
dmParams: ConversationParamsWrapper = ConversationParamsWrapper(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -37,7 +37,7 @@ class GroupWrapper {
}
}

fun encode(
suspend fun encode(
client: Client,
group: Group,
groupParams: ConversationParamsWrapper = ConversationParamsWrapper(),
Expand Down
6 changes: 3 additions & 3 deletions example/dev/local/test/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions example/src/ConversationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
/>
)}
Expand Down Expand Up @@ -469,8 +469,8 @@ function ReplyInputHeader({
}}
/>
<Text style={{ fontSize: 12, fontWeight: 'bold' }}>
{message?.senderAddress.slice(0, 6)}
{message?.senderAddress.slice(-4)}
{message?.senderInboxId.slice(0, 6)}
{message?.senderInboxId.slice(-4)}
</Text>
</View>
</TouchableHighlight>
Expand Down Expand Up @@ -864,8 +864,8 @@ function ReplyMessageHeader({
}}
/>
<Text style={{ fontSize: 12, fontWeight: 'bold' }}>
{message.senderAddress.slice(0, 6)}
{message.senderAddress.slice(-4)}
{message.senderInboxId.slice(0, 6)}
{message.senderInboxId.slice(-4)}
</Text>
{typeof content !== 'string' && 'text' in content && content.text ? (
<Text
Expand Down Expand Up @@ -955,8 +955,8 @@ function MessageItem({
}}
>
<Text style={{ fontWeight: 'bold' }}>
{message.senderAddress.slice(0, 6)}
{message.senderAddress.slice(-4)}
{message.senderInboxId.slice(0, 6)}
{message.senderInboxId.slice(-4)}
</Text>
<Text style={{ fontWeight: '300' }}>
{moment(message.sentNs / 1000000).fromNow()}
Expand Down
16 changes: 8 additions & 8 deletions example/src/GroupScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
/>
)}
Expand Down Expand Up @@ -469,8 +469,8 @@ function ReplyInputHeader({
}}
/>
<Text style={{ fontSize: 12, fontWeight: 'bold' }}>
{message?.senderAddress.slice(0, 6)}
{message?.senderAddress.slice(-4)}
{message?.senderInboxId.slice(0, 6)}
{message?.senderInboxId.slice(-4)}
</Text>
</View>
</TouchableHighlight>
Expand Down Expand Up @@ -864,8 +864,8 @@ function ReplyMessageHeader({
}}
/>
<Text style={{ fontSize: 12, fontWeight: 'bold' }}>
{message.senderAddress.slice(0, 6)}
{message.senderAddress.slice(-4)}
{message.senderInboxId.slice(0, 6)}
{message.senderInboxId.slice(-4)}
</Text>
{typeof content !== 'string' && 'text' in content && content.text ? (
<Text
Expand Down Expand Up @@ -955,8 +955,8 @@ function MessageItem({
}}
>
<Text style={{ fontWeight: 'bold' }}>
{message.senderAddress.slice(0, 6)}
{message.senderAddress.slice(-4)}
{message.senderInboxId.slice(0, 6)}
{message.senderInboxId.slice(-4)}
</Text>
<Text style={{ fontWeight: '300' }}>
{moment(message.sentNs / 1000000).fromNow()}
Expand Down
2 changes: 1 addition & 1 deletion example/src/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function ConversationItem({
<Text numberOfLines={1} ellipsizeMode="tail">
{lastMessage?.fallback}
</Text>
<Text>{lastMessage?.senderAddress}:</Text>
<Text>{lastMessage?.senderInboxId}:</Text>
<Text>{moment(lastMessage?.sentNs / 1000000).fromNow()}</Text>
</View>
</View>
Expand Down
32 changes: 16 additions & 16 deletions example/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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[] }
}
Expand All @@ -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
Expand Down Expand Up @@ -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[] }
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ios/Wrappers/DecodedMessageWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
27 changes: 14 additions & 13 deletions src/lib/DecodedMessage.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -25,10 +26,10 @@ export class DecodedMessage<
ContentTypes extends DefaultContentTypes = DefaultContentTypes,
> {
client: Client<ContentTypes>
id: string
topic: string
id: MessageId
topic: ConversationTopic
contentTypeId: string
senderAddress: string
senderInboxId: InboxId
sentNs: number // timestamp in nanoseconds
nativeContent: NativeMessageContent
fallback: string | undefined
Expand All @@ -48,7 +49,7 @@ export class DecodedMessage<
decoded.id,
decoded.topic,
decoded.contentTypeId,
decoded.senderAddress,
decoded.senderInboxId,
decoded.sentNs,
decoded.content,
decoded.fallback,
Expand All @@ -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
Expand All @@ -78,7 +79,7 @@ export class DecodedMessage<
object.id,
object.topic,
object.contentTypeId,
object.senderAddress,
object.senderInboxId,
object.sentNs,
object.content,
object.fallback,
Expand All @@ -88,10 +89,10 @@ export class DecodedMessage<

constructor(
client: Client<ContentTypes>,
id: string,
topic: string,
id: MessageId,
topic: ConversationTopic,
contentTypeId: string,
senderAddress: string,
senderInboxId: InboxId,
sentNs: number,
content: any,
fallback: string | undefined,
Expand All @@ -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
Expand Down

0 comments on commit ea9c06c

Please sign in to comment.