Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Apply code review fixes

Acho Arnold77cc1b387fa1
diff --git a/android/app/src/main/java/com/httpsms/Constants.kt b/android/app/src/main/java/com/httpsms/Constants.kt
index 7734055b..542f78d7 100644
--- a/android/app/src/main/java/com/httpsms/Constants.kt
+++ b/android/app/src/main/java/com/httpsms/Constants.kt
@@ -19,6 +19,6 @@ class Constants {
const val TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'000000'ZZZZZ"
- const val MAX_MMS_ATTACHMENT_SIZE = 1.5 * 1024 * 1024;
+ const val MAX_MMS_ATTACHMENT_SIZE: Long = (3L * 1024 * 1024) / 2
}
}
diff --git a/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt b/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt
index d501f7f6..4639b6c2 100644
--- a/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt
+++ b/android/app/src/main/java/com/httpsms/HttpSmsApiService.kt
@@ -185,7 +185,6 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
return bytesCopied
}
- // Downloads the attachment URL content locally
fun downloadAttachment(context: Context, urlString: String, messageId: String, attachmentIndex: Int): Pair<File?, MediaType?> {
val request = Request.Builder().url(urlString).build()
@@ -216,7 +215,7 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
}
}
- return Pair(tempFile, response.body.contentType())
+ return Pair(tempFile, body.contentType())
}
} catch (e: Exception) {
Timber.e(e, "Exception while downloading attachment")
@@ -253,7 +252,7 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
}
if (!response.isSuccessful) {
- Timber.e("error response [${response.body?.string()}] with code [${response.code}] while sending [${event}] event [${body}] for message with ID [${messageId}]")
+ Timber.e("error response [${response.body.string()}] with code [${response.code}] while sending [${event}] event [${body}] for message with ID [${messageId}]")
response.close()
return false
}
diff --git a/api/pkg/requests/bulk_message_request.go b/api/pkg/requests/bulk_message_request.go
index 84007176..77319997 100644
--- a/api/pkg/requests/bulk_message_request.go
+++ b/api/pkg/requests/bulk_message_request.go
@@ -50,6 +50,6 @@ func (input *BulkMessage) ToMessageSendParams(userID entities.UserID, requestID
RequestReceivedAt: time.Now().UTC(),
Contact: input.sanitizeAddress(input.ToPhoneNumber),
Content: input.Content,
- Attachments: strings.Split(input.AttachmentURLs, ","),
+ Attachments: input.removeEmptyStrings(strings.Split(input.AttachmentURLs, ",")),
}
}
diff --git a/api/pkg/requests/request.go b/api/pkg/requests/request.go
index 851137d1..1db27861 100644
--- a/api/pkg/requests/request.go
+++ b/api/pkg/requests/request.go
@@ -108,6 +108,18 @@ func (input *request) removeStringDuplicates(values []string) []string {
return result
}
+func (input *request) removeEmptyStrings(values []string) []string {
+ var result []string
+ for _, value := range values {
+ value = strings.TrimSpace(value)
+ if value != "" {
+ result = append(result, value)
+ }
+ }
+
+ return result
+}
+
func (input *request) sanitizeMessageID(value string) string {
id := strings.Builder{}
for _, char := range value {
diff --git a/api/pkg/validators/validator.go b/api/pkg/validators/validator.go
index 2645c450..1fcb716a 100644
--- a/api/pkg/validators/validator.go
+++ b/api/pkg/validators/validator.go
@@ -94,7 +94,7 @@ func init() {
govalidator.AddCustomRule(multipleAttachmentURLRule, func(field string, rule string, message string, value interface{}) error {
attachments, ok := value.([]string)
if !ok {
- return fmt.Errorf("The %s field must be an array of valid attachment URL's", field)
+ return fmt.Errorf("The %s field must be an array of valid attachment URLs", field)
}
for index, attachment := range attachments {
diff --git a/web/pages/threads/_id/index.vue b/web/pages/threads/_id/index.vue
index 09b6dfc2..81931b9a 100644
--- a/web/pages/threads/_id/index.vue
+++ b/web/pages/threads/_id/index.vue
@@ -173,14 +173,15 @@
>
</v-card-text>
</v-card>
- <v-card rounded v-if="message.attachments?.length">
+ <v-card v-if="message.attachments?.length">
<v-card-text class="pb-2">
<a
v-for="(attachment, index) in message.attachments"
+ :key="index"
target="_blank"
+ rel="noopener noreferrer"
:href="attachment"
class="text-decoration-none hover:text-decoration-underline body-2 mb-2 d-flex w-full"
- :key="index"
>
<v-icon x-small class="text--secondary mt-1">{{
mdiPaperclip