diff --git a/build.gradle b/build.gradle index 9b382ad31..42d638def 100644 --- a/build.gradle +++ b/build.gradle @@ -156,8 +156,8 @@ android { applicationId 'io.forsta.relay' minSdkVersion 14 targetSdkVersion 22 - versionName "0.1.60" - versionCode 160 + versionName "0.1.61" + versionCode 161 multiDexEnabled true buildConfigField "long", "BUILD_TIMESTAMP", getLastCommitTimestamp() + "L" resValue "string", "forsta_authorities", applicationId + '.provider.ccsm' diff --git a/src/io/forsta/ccsm/api/model/ForstaMessage.java b/src/io/forsta/ccsm/api/model/ForstaMessage.java index 46dc5e298..5713cdb26 100644 --- a/src/io/forsta/ccsm/api/model/ForstaMessage.java +++ b/src/io/forsta/ccsm/api/model/ForstaMessage.java @@ -27,6 +27,7 @@ import io.forsta.ccsm.database.model.ForstaUser; import io.forsta.ccsm.util.ForstaUtils; import io.forsta.ccsm.util.InvalidMessagePayloadException; +import io.forsta.securesms.attachments.Attachment; import io.forsta.securesms.database.DatabaseFactory; import io.forsta.securesms.database.GroupDatabase; import io.forsta.securesms.recipients.Recipients; @@ -159,14 +160,14 @@ public static JSONObject getVersion(int version, String body) { } public static String createForstaMessageBody(Context context, String richTextMessage, Recipients messageRecipients) { - return createForstaMessageBody(context, richTextMessage, messageRecipients, "", "", ""); + return createForstaMessageBody(context, richTextMessage, messageRecipients, new ArrayList(), "", "", ""); } - public static String createForstaMessageBody(Context context, String message, Recipients recipients, ForstaThread forstaThread) { - return createForstaMessageBody(context, message, recipients, forstaThread.distribution, forstaThread.title, forstaThread.uid); + public static String createForstaMessageBody(Context context, String message, Recipients recipients, List messageAttachments, ForstaThread forstaThread) { + return createForstaMessageBody(context, message, recipients, messageAttachments, forstaThread.distribution, forstaThread.title, forstaThread.uid); } - public static String createForstaMessageBody(Context context, String richTextMessage, Recipients messageRecipients, String universalExpression, String threadTitle, String threadUid) { + public static String createForstaMessageBody(Context context, String richTextMessage, Recipients messageRecipients, List messageAttachments, String universalExpression, String threadTitle, String threadUid) { JSONArray versions = new JSONArray(); JSONObject version1 = new JSONObject(); ContactDb contactDb = DbFactory.getContactDb(context); @@ -184,6 +185,8 @@ public static String createForstaMessageBody(Context context, String richTextMes JSONObject sender = new JSONObject(); JSONObject recipients = new JSONObject(); JSONArray userIds = new JSONArray(); + JSONArray attachments = new JSONArray(); + String threadId = !TextUtils.isEmpty(threadUid) ? threadUid : ""; ForstaUser user = ForstaUser.getLocalForstaUser(context); @@ -213,6 +216,16 @@ public static String createForstaMessageBody(Context context, String richTextMes } } + if (attachments != null) { + for (Attachment attachment : messageAttachments) { + JSONObject attachmentJson = new JSONObject(); + attachmentJson.put("name", attachment.getDataUri().getLastPathSegment()); + attachmentJson.put("size", attachment.getSize()); + attachmentJson.put("type", attachment.getContentType()); + attachments.put(attachmentJson); + } + } + List forstaRecipients = contactDb.getRecipientsFromNumbers(recipientList); for (ForstaRecipient r : forstaRecipients) { @@ -233,6 +246,7 @@ public static String createForstaMessageBody(Context context, String richTextMes body.put(bodyPlain); data.put("body", body); + data.put("attachments", attachments); version1.put("version", 1); version1.put("userAgent", System.getProperty("http.agent", "")); version1.put("messageId", UUID.randomUUID().toString()); diff --git a/src/io/forsta/securesms/mms/OutgoingMediaMessage.java b/src/io/forsta/securesms/mms/OutgoingMediaMessage.java index fd3cf183f..47e40aeff 100644 --- a/src/io/forsta/securesms/mms/OutgoingMediaMessage.java +++ b/src/io/forsta/securesms/mms/OutgoingMediaMessage.java @@ -107,6 +107,6 @@ private static String buildMessage(SlideDeck slideDeck, String message) { } public void setForstaJsonBody(Context context, ForstaThread forstaThread) { - this.body = ForstaMessage.createForstaMessageBody(context, this.body, recipients, forstaThread); + this.body = ForstaMessage.createForstaMessageBody(context, this.body, recipients, attachments, forstaThread); } } diff --git a/src/io/forsta/securesms/sms/OutgoingTextMessage.java b/src/io/forsta/securesms/sms/OutgoingTextMessage.java index 2dc47f9ff..a8f5491f0 100644 --- a/src/io/forsta/securesms/sms/OutgoingTextMessage.java +++ b/src/io/forsta/securesms/sms/OutgoingTextMessage.java @@ -81,8 +81,4 @@ public OutgoingTextMessage withBody(String body) { return new OutgoingTextMessage(this, body); } - public void setForstaJsonBody(Context context, ForstaThread forstaThread) { - this.message = ForstaMessage.createForstaMessageBody(context, this.message, recipients, forstaThread); - } - }