git » sdk » commit 2ab3316

Allow controlling encryption at caller

author Stephen Paul Weber
2026-07-21 17:29:24 UTC
committer Stephen Paul Weber
2026-07-21 17:29:24 UTC
parent 004690328c6bff6c6fedd8f53da238725c5d6274

Allow controlling encryption at caller

borogove/Client.hx +8 -3

diff --git a/borogove/Client.hx b/borogove/Client.hx
index 3569d54..6bdd87b 100644
--- a/borogove/Client.hx
+++ b/borogove/Client.hx
@@ -1173,9 +1173,10 @@ class Client extends EventEmitter {
 		Turn a file into a ChatAttachment for attaching to a ChatMessage
 
 		@param source The AttachmentSource to use
+		@param encrypt Should the data be encrypted with a fresh key?
 		@returns Promise resolving to a ChatAttachment
 	**/
-	public function prepareAttachment(source: AttachmentSource): Promise<ChatAttachment> {
+	public function prepareAttachment(source: AttachmentSource, encrypt: Bool = true): Promise<ChatAttachment> {
 		return persistence.findServicesWithFeature(accountId(), "urn:xmpp:http:upload:0").then((services) -> {
 			final sha256 = Hash.sha256incr();
 			final httpPut = (tsource: tink.io.Source.RealSource, size: Int) -> {
@@ -1195,8 +1196,12 @@ class Client extends EventEmitter {
 
 			// Giant attachments go unencrypted for now...
 			return thenshim.PromiseTools.all(([
-				if (source.size < 1000000000) {
-					XEP0454.put(tinkSource, httpPut).then(o -> new ChatAttachment(source.name, source.type, o.size, [o.uri], [sha256.digest()]));
+				if (encrypt) {
+					if (source.size < 1000000000) {
+						XEP0454.put(tinkSource, httpPut).then(o -> new ChatAttachment(source.name, source.type, o.size, [o.uri], [sha256.digest()]));
+					} else {
+						Promise.reject("Attachment is too big for current encryption options");
+					}
 				} else {
 					httpPut(tinkSource, source.size).then(uri -> new ChatAttachment(source.name, source.type, source.size, [uri], [sha256.digest()]));
 				},