Skip to content

Commit b51063a

Browse files
committed
Add multiple recipients support
1 parent 190180d commit b51063a

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

android/src/main/java/com/betomorrow/rnfilelogger/FileLoggerModule.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.facebook.react.bridge.ReactContextBaseJavaModule;
1212
import com.facebook.react.bridge.ReactMethod;
1313
import com.facebook.react.bridge.ReadableMap;
14+
import com.facebook.react.bridge.ReadableArray;
1415
import com.facebook.react.bridge.WritableArray;
1516

1617
import org.slf4j.Logger;
@@ -166,15 +167,15 @@ public void deleteLogFiles(Promise promise) {
166167
@ReactMethod
167168
public void sendLogFilesByEmail(ReadableMap options, Promise promise) {
168169
try {
169-
String to = options.hasKey("to") ? options.getString("to") : null;
170+
ReadableArray to = options.hasKey("to") ? options.getArray("to") : null;
170171
String subject = options.hasKey("subject") ? options.getString("subject") : null;
171172
String body = options.hasKey("body") ? options.getString("body") : null;
172173

173174
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE, Uri.parse("mailto:"));
174175
intent.setType("plain/text");
175176

176177
if (to != null) {
177-
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
178+
intent.putExtra(Intent.EXTRA_EMAIL, readableArrayToStringArray(to));
178179
}
179180
if (subject != null) {
180181
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
@@ -211,4 +212,13 @@ public boolean accept(File dir, String name) {
211212
}
212213
});
213214
}
215+
216+
private String[] readableArrayToStringArray(ReadableArray r) {
217+
int length = r.size();
218+
String[] strArray = new String[length];
219+
for (int i = 0; i < length; i++) {
220+
strArray[i] = r.getString(i);
221+
}
222+
return strArray;
223+
}
214224
}

ios/FileLogger.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ - (dispatch_queue_t)methodQueue {
7979
}
8080

8181
RCT_EXPORT_METHOD(sendLogFilesByEmail:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
82-
NSString* to = options[@"to"];
82+
NSArray<NSString*>* to = options[@"to"];
8383
NSString* subject = options[@"subject"];
8484
NSString* body = options[@"body"];
8585

@@ -91,7 +91,7 @@ - (dispatch_queue_t)methodQueue {
9191
MFMailComposeViewController* composeViewController = [[MFMailComposeViewController alloc] init];
9292
composeViewController.mailComposeDelegate = self;
9393
if (to) {
94-
[composeViewController setToRecipients:@[to]];
94+
[composeViewController setToRecipients:to];
9595
}
9696
if (subject) {
9797
[composeViewController setSubject:subject];

src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface ConfigureOptions {
2424
}
2525

2626
export interface SendByEmailOptions {
27-
to?: string;
27+
to?: string | string[];
2828
subject?: string;
2929
body?: string;
3030
}
@@ -86,7 +86,12 @@ class FileLoggerStatic {
8686
}
8787

8888
sendLogFilesByEmail(options: SendByEmailOptions = {}): Promise<void> {
89-
return RNFileLogger.sendLogFilesByEmail(options);
89+
if (options.to) {
90+
const to = Array.isArray(options.to) ? options.to : [options.to];
91+
return RNFileLogger.sendLogFilesByEmail({ ...options, to });
92+
} else {
93+
return RNFileLogger.sendLogFilesByEmail(options);
94+
}
9095
}
9196

9297
debug(msg: string) {

0 commit comments

Comments
 (0)