Skip to content

Commit

Permalink
Merge pull request #145 from xmtp/return-message-from-send
Browse files Browse the repository at this point in the history
Return message upon sending
  • Loading branch information
neekolas authored Aug 8, 2022
2 parents 0faa1e3 + d2daf8d commit 9bfd12a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export default class Client {
peerAddress: string,
content: any,
options?: SendOptions
): Promise<void> {
): Promise<Message> {
let topics: string[]
const recipient = await this.getUserContact(peerAddress)

Expand All @@ -312,14 +312,18 @@ export default class Client {
}
const timestamp = options?.timestamp || new Date()
const msg = await this.encodeMessage(recipient, timestamp, content, options)
const msgBytes = msg.toBytes()

await Promise.all(
topics.map(async (topic) => {
const wakuMsg = await WakuMessage.fromBytes(msg.toBytes(), topic, {
const wakuMsg = await WakuMessage.fromBytes(msgBytes, topic, {
timestamp,
})
return this.sendWakuMessage(wakuMsg)
})
)

return this.decodeMessage(msgBytes, topics[0])
}

private async sendWakuMessage(msg: WakuMessage): Promise<void> {
Expand Down
6 changes: 3 additions & 3 deletions src/conversations/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export default class Conversation {
/**
* Send a message into the conversation
*/
async send(
send(
message: any, // eslint-disable-line @typescript-eslint/no-explicit-any
options?: SendOptions
): Promise<void> {
await this.client.sendMessage(this.peerAddress, message, options)
): Promise<Message> {
return this.client.sendMessage(this.peerAddress, message, options)
}
}
5 changes: 4 additions & 1 deletion test/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ describe('Client', () => {
const aliceBob = await alice.streamConversationMessages(bob.address)

// alice sends intro
await alice.sendMessage(bob.address, 'hi bob!')
const sentMessage = await alice.sendMessage(bob.address, 'hi bob!')
assert.equal(sentMessage.content, 'hi bob!')
assert.ok(sentMessage.id)
assert.ok(sentMessage.sent)
let msg = await aliceIntros.next()
assert.equal(msg.value.content, 'hi bob!')

Expand Down

0 comments on commit 9bfd12a

Please sign in to comment.