-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Conversation.prepareMessage (#80)
This gives back a PreparedMessage that has a messageID on it. Clients can use this for optimistic sending purposes.
- Loading branch information
Showing
6 changed files
with
160 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// PreparedMessage.swift | ||
// | ||
// | ||
// Created by Pat Nakajima on 3/9/23. | ||
// | ||
|
||
import CryptoKit | ||
import Foundation | ||
|
||
public struct PreparedMessage { | ||
var messageEnvelope: Envelope | ||
var conversation: Conversation | ||
var onSend: () async throws -> Void | ||
|
||
public func decodedMessage() throws -> DecodedMessage { | ||
return try conversation.decode(messageEnvelope) | ||
} | ||
|
||
public func send() async throws { | ||
try await onSend() | ||
} | ||
|
||
var messageID: String { | ||
Data(SHA256.hash(data: messageEnvelope.message)).toHex | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters