From 1bff1adac9901601bc2ee563103edbc3c7ef7b0b Mon Sep 17 00:00:00 2001 From: St John Karp Date: Sun, 22 Apr 2018 20:39:59 -0700 Subject: [PATCH] Add semi-support for sending MMS messages Allow Matrix users to send MMS messages. Not entirely sure how to do this properly, so in the meantime just link the recipient to the URL of the file on the Matrix server. --- .../main/java/eu/droogers/smsmatrix/Matrix.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/droogers/smsmatrix/Matrix.java b/app/src/main/java/eu/droogers/smsmatrix/Matrix.java index d06ba3b..93481fc 100644 --- a/app/src/main/java/eu/droogers/smsmatrix/Matrix.java +++ b/app/src/main/java/eu/droogers/smsmatrix/Matrix.java @@ -1,11 +1,13 @@ package eu.droogers.smsmatrix; import android.content.Context; +import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract; import android.telephony.SmsManager; import android.util.Log; +import android.widget.Toast; import com.google.gson.JsonElement; @@ -250,10 +252,17 @@ public class Matrix { public void sendEvent(Event event) { if (event.sender.equals(realUserid)) { Room room = store.getRoom(event.roomId); - JsonElement json = event.getContent(); - String body = json.getAsJsonObject().get("body").getAsString(); SmsManager smsManager = SmsManager.getDefault(); - smsManager.sendTextMessage(room.getTopic(), null, body, null, null); + JsonObject json = event.getContent().getAsJsonObject(); + + if (json.get("msgtype").getAsString().equals(MESSAGE_TYPE_TEXT)) { + String body = json.get("body").getAsString(); + smsManager.sendTextMessage(room.getTopic(), null, body, null, null); + } else { + String url = session.getContentManager().getDownloadableUrl(json.get("url").getAsString()); + smsManager.sendTextMessage(room.getTopic(), null, url, null, null); + } + room.markAllAsRead(new SimpleApiCallback()); } }