Skip to content

Commit

Permalink
Merge pull request #212 from jlewis13/attachment_names
Browse files Browse the repository at this point in the history
Attachment names
  • Loading branch information
jlewis13 authored Oct 17, 2017
2 parents f13bbff + 6ac3ae8 commit 7b29dbd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
22 changes: 18 additions & 4 deletions src/io/forsta/ccsm/api/model/ForstaMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Attachment>(), "", "", "");
}

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<Attachment> 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<Attachment> messageAttachments, String universalExpression, String threadTitle, String threadUid) {
JSONArray versions = new JSONArray();
JSONObject version1 = new JSONObject();
ContactDb contactDb = DbFactory.getContactDb(context);
Expand All @@ -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);
Expand Down Expand Up @@ -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<ForstaRecipient> forstaRecipients = contactDb.getRecipientsFromNumbers(recipientList);

for (ForstaRecipient r : forstaRecipients) {
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/io/forsta/securesms/mms/OutgoingMediaMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 0 additions & 4 deletions src/io/forsta/securesms/sms/OutgoingTextMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 7b29dbd

Please sign in to comment.