Skip to content

Commit

Permalink
Merge pull request #250 from jlewis13/provisionrequest
Browse files Browse the repository at this point in the history
Provision request
  • Loading branch information
jlewis13 authored Jan 25, 2018
2 parents 8892cbd + 8f43114 commit fb1e61c
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 28 deletions.
7 changes: 5 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.87"
versionCode 187
versionName "0.1.88"
versionCode 188
multiDexEnabled true
buildConfigField "long", "BUILD_TIMESTAMP", getLastCommitTimestamp() + "L"
resValue "string", "forsta_authorities", applicationId + '.provider.ccsm'
Expand All @@ -167,19 +167,22 @@ android {
dev {
applicationIdSuffix '.dev'
buildConfigField "String", "FORSTA_API_URL", "\"https://atlas-dev.forsta.io\""
buildConfigField "String", "FORSTA_SYNC_NUMBER", "\"1e1116aa-31b3-4fb2-a4db-21e8136d4f3a\""
resValue "string", "forsta_authorities", defaultConfig.applicationId + applicationIdSuffix + '.provider.ccsm'
resValue "string", "forsta_account_type", defaultConfig.applicationId + applicationIdSuffix
buildConfigField "String", "FORSTA_PROVISION_SERVICE_TOKEN", dev_service_config
}
stage {
applicationIdSuffix '.stage'
buildConfigField "String", "FORSTA_API_URL", "\"https://atlas-stage.forsta.io\""
buildConfigField "String", "FORSTA_SYNC_NUMBER", "\"88e7165e-d2da-4c3f-a14a-bb802bb0cefb\""
resValue "string", "forsta_authorities", defaultConfig.applicationId + applicationIdSuffix + '.provider.ccsm'
resValue "string", "forsta_account_type", defaultConfig.applicationId + applicationIdSuffix
buildConfigField "String", "FORSTA_PROVISION_SERVICE_TOKEN", stage_service_config
}
prod {
buildConfigField "String", "FORSTA_API_URL", "\"https://atlas.forsta.io\""
buildConfigField "String", "FORSTA_SYNC_NUMBER", "\"cf40fca2-dfa8-4356-8ae7-45f56f7551ca\""
buildConfigField "String", "FORSTA_PROVISION_SERVICE_TOKEN", prod_service_config
}
}
Expand Down
34 changes: 32 additions & 2 deletions src/io/forsta/ccsm/api/model/ForstaMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ForstaMessage {
private String controlType = ControlTypes.NONE;
private String threadType = ThreadTypes.CONVERSATION;
private List<ForstaAttachment> attachments = new ArrayList<>();
private ForstaProvisionRequest provisionRequest;

public static class ControlTypes {
public static final String NONE = "none";
Expand Down Expand Up @@ -53,6 +54,10 @@ public ForstaMessage() {

}

public boolean isControlMessage() {
return messageType.equals(MessageTypes.CONTROL);
}

public boolean hasThreadUid() {
return !TextUtils.isEmpty(threadUid);
}
Expand Down Expand Up @@ -165,8 +170,15 @@ public List<ForstaAttachment> getAttachments() {
}

public void addAttachment(String name, String type, long size) {
ForstaAttachment attachment = new ForstaAttachment(name, type, size);
attachments.add(attachment);
attachments.add(new ForstaAttachment(name, type, size));
}

public void setProvisionRequest(String uuid, String key) {
this.provisionRequest = new ForstaProvisionRequest(uuid, key);
}

public ForstaProvisionRequest getProvisionRequest() {
return provisionRequest;
}

public class ForstaAttachment {
Expand All @@ -192,4 +204,22 @@ public long getSize() {
return size;
}
}

public class ForstaProvisionRequest {
private String uuid;
private String key;

public ForstaProvisionRequest(String uuid, String key) {
this.uuid = uuid;
this.key = key;
}

public String getUuid() {
return uuid;
}

public String getKey() {
return key;
}
}
}
29 changes: 21 additions & 8 deletions src/io/forsta/ccsm/messaging/ForstaMessageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ private static ForstaMessage parseMessageBody(JSONObject jsonBody) throws Invali
forstaMessage.setMessageType(jsonBody.getString("messageType"));
}

JSONObject distribution = jsonBody.getJSONObject("distribution");
forstaMessage.setUniversalExpression(distribution.getString("expression"));
if (TextUtils.isEmpty(forstaMessage.getUniversalExpression())) {
throw new InvalidMessagePayloadException("No universal expression");
}
JSONObject sender = jsonBody.getJSONObject("sender");
forstaMessage.setSenderId(sender.getString("userId"));
forstaMessage.setMessageId(jsonBody.getString("messageId"));

JSONObject distribution = jsonBody.getJSONObject("distribution");
if (distribution.has("expression")) {
forstaMessage.setUniversalExpression(distribution.getString("expression"));
}

if (jsonBody.has("data")) {
JSONObject data = jsonBody.getJSONObject("data");
if (data.has("body")) {
Expand Down Expand Up @@ -158,22 +159,34 @@ private static ForstaMessage parseMessageBody(JSONObject jsonBody) throws Invali

if (data.has("control")) {
forstaMessage.setControlType(data.getString("control"));
Log.w(TAG, "Control message: " + forstaMessage.getControlType());

switch (forstaMessage.getControlType()) {
case ForstaMessage.ControlTypes.THREAD_UPDATE:
Log.w(TAG, "Thread update: ");
if (TextUtils.isEmpty(forstaMessage.getUniversalExpression())) {
throw new InvalidMessagePayloadException("Thread update. No universal expression.");
}
JSONObject threadUpdates = data.getJSONObject("threadUpdates");
if (threadUpdates.has("threadTitle")) {
forstaMessage.setThreadTitle(threadUpdates.getString("threadTitle"));
Log.w(TAG, "New thread title: " + forstaMessage.getThreadTitle());
}
break;
case ForstaMessage.ControlTypes.PROVISION_REQUEST:
String uuid = data.getString("uuid");
String key = data.getString("key");
forstaMessage.setProvisionRequest(uuid, key);
break;
default:
Log.w(TAG, "Not a control message");
}
}
}

if (!forstaMessage.isControlMessage()) {
if (TextUtils.isEmpty(forstaMessage.getUniversalExpression())) {
throw new InvalidMessagePayloadException("Content message. No universal expression.");
}
}

} catch (JSONException e) {
Log.e(TAG, jsonBody.toString());
throw new InvalidMessagePayloadException(e.getMessage());
Expand Down
5 changes: 5 additions & 0 deletions src/io/forsta/securesms/ConversationListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
import org.apache.http.impl.execchain.ServiceUnavailableRetryExec;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

import io.forsta.ccsm.DrawerFragment;
import io.forsta.ccsm.ForstaPreferences;
import io.forsta.ccsm.LoginActivity;
Expand All @@ -60,6 +63,7 @@
import io.forsta.securesms.recipients.RecipientFactory;
import io.forsta.securesms.recipients.Recipients;
import io.forsta.securesms.service.KeyCachingService;
import io.forsta.securesms.util.DirectoryHelper;
import io.forsta.securesms.util.DynamicLanguage;
import io.forsta.securesms.util.DynamicTheme;
import io.forsta.securesms.util.ServiceUtil;
Expand Down Expand Up @@ -269,6 +273,7 @@ public class RefreshUserOrg extends AsyncTask<Void, Void, JSONObject> {
@Override
protected JSONObject doInBackground(Void... voids) {
CcsmApi.forstaRefreshToken(ConversationListActivity.this);
ApplicationContext.getInstance(getApplicationContext()).getJobManager().add(new DirectoryRefreshJob(getApplicationContext(), null, null));

JSONObject userResponse = CcsmApi.getForstaUser(ConversationListActivity.this);
if (userResponse.has("id")) {
Expand Down
39 changes: 37 additions & 2 deletions src/io/forsta/securesms/ConversationListItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.os.Handler;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.text.SpannableString;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
Expand Down Expand Up @@ -56,11 +57,15 @@
import io.forsta.securesms.database.ThreadPreferenceDatabase;
import io.forsta.securesms.database.model.ThreadRecord;
import io.forsta.securesms.recipients.Recipient;
import io.forsta.securesms.recipients.RecipientFactory;
import io.forsta.securesms.recipients.Recipients;
import io.forsta.securesms.util.DateUtils;
import io.forsta.securesms.util.ResUtil;
import io.forsta.securesms.util.TextSecurePreferences;
import io.forsta.securesms.util.ViewUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;

Expand All @@ -75,7 +80,7 @@
*/

public class ConversationListItem extends RelativeLayout
implements Recipients.RecipientsModifiedListener,
implements Recipients.RecipientsModifiedListener, Recipient.RecipientModifiedListener,
BindableConversationListItem, Unbindable
{
private final static String TAG = ConversationListItem.class.getSimpleName();
Expand All @@ -85,6 +90,7 @@ public class ConversationListItem extends RelativeLayout

private Set<Long> selectedThreads;
private Recipients recipients;
private Recipient sender;
private long threadId;
private TextView subjectView;
private FromTextView fromView;
Expand All @@ -104,6 +110,7 @@ public class ConversationListItem extends RelativeLayout
private int distributionType;
private MaterialColor threadColor;
private String threadTitle;
private SpannableString threadDisplayBody;
private boolean isAnnouncement = false;

public ConversationListItem(Context context) {
Expand Down Expand Up @@ -150,8 +157,16 @@ public void bind(@NonNull final MasterSecret masterSecret, @NonNull ThreadRecord

isAnnouncement = thread.getThreadType() == ThreadDatabase.ThreadTypes.ANNOUNCEMENT;
threadTitle = thread.getTitle();
threadDisplayBody = thread.getDisplayBody();
String senderAddress = thread.getSenderAddress();
sender = RecipientFactory.getRecipientsFromString(getContext(), senderAddress, true).getPrimaryRecipient();
if (sender != null) {
sender.addListener(this);
setSubjectView(recipients, sender, threadDisplayBody, read);
} else {
subjectView.setText(threadDisplayBody);
}

subjectView.setText(thread.getDisplayBody());
this.subjectView.setTypeface(read ? LIGHT_TYPEFACE : BOLD_TYPEFACE);

if (thread.getDate() > 0) {
Expand All @@ -178,6 +193,7 @@ public void bind(@NonNull final MasterSecret masterSecret, @NonNull ThreadRecord
@Override
public void unbind() {
if (this.recipients != null) this.recipients.removeListener(this);
if (this.sender != null) this.sender.removeListener(this);
}

private void setBatchState(boolean batch) {
Expand Down Expand Up @@ -297,6 +313,25 @@ private void setFromView(Recipients recipients, boolean read) {
}
}

private void setSubjectView(Recipients recipients, Recipient sender, SpannableString body, boolean read) {
String name = TextSecurePreferences.getLocalNumber(getContext()).equals(sender.getAddress()) ? "" : sender.getName();
if (!TextUtils.isEmpty(name) && recipients.getRecipientsList().size() > 1 && !read) {
subjectView.setText(name + ": " + body);
} else {
subjectView.setText(body);
}
}

@Override
public void onModified(final Recipient recipient) {
handler.post(new Runnable() {
@Override
public void run() {
setSubjectView(recipients, recipient, threadDisplayBody, read);
}
});
}

private static class ThumbnailPositioner implements Runnable {
private final View thumbnailView;
private final View archivedView;
Expand Down
10 changes: 10 additions & 0 deletions src/io/forsta/securesms/database/model/ThreadRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public SpannableString getDisplayBody() {
return new SpannableString(body);
}

public String getSenderAddress() {
try {
ForstaMessage forstaMessage = ForstaMessageManager.fromMessagBodyString(getBody().getBody());
return forstaMessage.getSenderId();
} catch (InvalidMessagePayloadException e) {
e.printStackTrace();
}
return "";
}

private SpannableString emphasisAdded(String sequence) {
return emphasisAdded(sequence, 0, sequence.length());
}
Expand Down
Loading

0 comments on commit fb1e61c

Please sign in to comment.