Skip to content

Commit d2735e7

Browse files
author
hannojg
committed
Adding upload content and get downloadable url to SDK, version bump to alpha 63
1 parent 856d320 commit d2735e7

File tree

6 files changed

+64
-3
lines changed

6 files changed

+64
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.0.0-alpha63
4+
5+
* Added `uploadContent` and `contentGetDownloadableUrl` to the SDK
6+
37
## 1.0.0-alpha60
48

59
* Upgraded android matrix SDK to 0.19.35

android/src/main/java/de/hannojg/MatrixSdkModule.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,21 @@ public void onUploadComplete(String uploadId, String contentUri) {
844844
}
845845
}
846846

847+
@ReactMethod
848+
public void contentGetDownloadableUrl(String matrixContentUri, Promise promise) {
849+
if (mxSession == null) {
850+
promise.reject(E_MATRIX_ERROR, "client is not connected yet");
851+
return;
852+
}
853+
854+
String url = mxSession.getContentManager().getDownloadableUrl(matrixContentUri, false);
855+
if (url != null) {
856+
promise.resolve(url);
857+
} else {
858+
promise.reject(E_MATRIX_ERROR, "Failed to resolve content url");
859+
}
860+
}
861+
847862
//* ******************************************
848863
//* PUSH NOTIFICATIONS
849864
//* ******************************************

ios/MatrixSdk.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ + (BOOL)requiresMainQueueSetup
8282

8383
RCT_EXTERN_METHOD(uploadContent:(NSString *)fileUri fileName:(NSString *)fileName mimeType:(NSString *)mimeType uploadId:(NSString *)uploadId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
8484

85+
RCT_EXTERN_METHOD(contentGetDownloadableUrl:(NSString *)matrixContentUri resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
86+
87+
RCT_EXTERN_METHOD(downloadContent:(NSString *)matrixContentUri mimeType:(NSString *)mimeType folder:(NSString *)folder resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
88+
8589
RCT_EXTERN_METHOD(sendTyping:(NSString *)roomId isTyping:(nonnull BOOL *)isTyping timeout:(nonnull NSNumber *)timeout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
8690

8791
RCT_EXTERN_METHOD(updatePresence:(nonnull BOOL *)isOnline resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)

ios/RNMatrixSDK.swift

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,10 +907,41 @@ class RNMatrixSDK: RCTEventEmitter {
907907
uploadId: url
908908
])
909909
}, failure: { (error) in
910-
910+
reject(nil, "Failed to upload", error)
911911
})
912912
}
913913

914+
@objc(contentGetDownloadableUrl:resolver:rejecter:)
915+
func contentGetDownloadableUrl(matrixContentUri: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
916+
if mxSession == nil {
917+
reject(E_MATRIX_ERROR, "client is not connected yet", nil)
918+
return
919+
}
920+
921+
let url = mxSession.mediaManager.url(ofContent: matrixContentUri)
922+
if ((url) != nil) {
923+
resolve(url)
924+
} else {
925+
reject(nil, "Failed to get content uri", nil)
926+
}
927+
}
928+
929+
@objc(downloadContent:mimeType:folder:resolver:rejecter:)
930+
func downloadContent(matrixContentUri: String, mimeType: String, folder: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
931+
if mxSession == nil {
932+
reject(E_MATRIX_ERROR, "client is not connected yet", nil)
933+
return
934+
}
935+
936+
let mediaLoader = mxSession.mediaManager.downloadMedia(fromMatrixContentURI: matrixContentUri, withType: mimeType, inFolder: folder, success: { (fileUri) in
937+
resolve(fileUri)
938+
}) { (e) in
939+
reject(nil, "Failed to download", e)
940+
}
941+
942+
print("[DOWNLOAD NATIVE IOS] download url: " + (mediaLoader?.downloadMediaURL ?? "NO DOWNLOAD URL"))
943+
}
944+
914945
@objc(sendTyping:isTyping:timeout:resolver:rejecter:)
915946
func sendTyping(roomId: String, isTyping: Bool, timeout: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
916947
if mxSession == nil {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-matrix-sdk",
33
"title": "React Native Matrix Sdk",
4-
"version": "1.0.0",
4+
"version": "1.0.0-alpha63",
55
"description": "React Native SDK for Matrix.org",
66
"main": "index.js",
77
"types": "./types/index.d.ts",

types/index.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,14 @@ declare module 'react-native-matrix-sdk' {
219219
setUserDisplayName(displayName: string): Promise<void>;
220220

221221
/**
222-
* Uploads content to the matrix content respository of the connected homeserver.
222+
* Returns for a matrix content uri (mxc://...) the downloadable
223+
* server url of the content. Currently doesn't support encryption.
224+
* @param matrixContentUrl The matrix content url to resolve
225+
*/
226+
contentGetDownloadableUrl(matrixContentUrl: String): Promise<string>
227+
228+
/**
229+
* Uploads content to the matrix content repository of the connected homeserver.
223230
* @return {@see #SuccessUploadResponse}
224231
* @param fileUri the absolute file path to the file to be uploaded
225232
* @param fileName the file name of the file

0 commit comments

Comments
 (0)