mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
When replying to a message, don't use an earlier timestamp.
This produces a saner user experience when devices have differing clocks.
This commit is contained in:
@@ -244,7 +244,8 @@ NoContactsDialog.Listener {
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
noContactsDialog.show(fm, "NoContactsDialog");
|
||||
} else {
|
||||
startActivity(new Intent(this, WritePrivateMessageActivity.class));
|
||||
startActivity(new Intent(this,
|
||||
WritePrivateMessageActivity.class));
|
||||
}
|
||||
} else if(view == shareButton) {
|
||||
String apkPath = getPackageCodePath();
|
||||
|
||||
@@ -60,6 +60,7 @@ implements OnClickListener {
|
||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||
@Inject private volatile LifecycleManager lifecycleManager;
|
||||
private volatile MessageId messageId = null;
|
||||
private volatile long timestamp = -1;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -79,7 +80,7 @@ implements OnClickListener {
|
||||
messageId = new MessageId(b);
|
||||
String contentType = i.getStringExtra("net.sf.briar.CONTENT_TYPE");
|
||||
if(contentType == null) throw new IllegalStateException();
|
||||
long timestamp = i.getLongExtra("net.sf.briar.TIMESTAMP", -1);
|
||||
timestamp = i.getLongExtra("net.sf.briar.TIMESTAMP", -1);
|
||||
if(timestamp == -1) throw new IllegalStateException();
|
||||
|
||||
if(state == null) {
|
||||
@@ -262,6 +263,7 @@ implements OnClickListener {
|
||||
Intent i = new Intent(this, WritePrivateMessageActivity.class);
|
||||
i.putExtra("net.sf.briar.CONTACT_ID", contactId.getInt());
|
||||
i.putExtra("net.sf.briar.PARENT_ID", messageId.getBytes());
|
||||
i.putExtra("net.sf.briar.TIMESTAMP", timestamp);
|
||||
startActivity(i);
|
||||
setResult(RESULT_REPLY);
|
||||
finish();
|
||||
|
||||
@@ -66,6 +66,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
private volatile LocalAuthor localAuthor = null;
|
||||
private volatile ContactId contactId = null;
|
||||
private volatile MessageId parentId = null;
|
||||
private volatile long timestamp = -1;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -76,6 +77,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
if(id != -1) contactId = new ContactId(id);
|
||||
byte[] b = i.getByteArrayExtra("net.sf.briar.PARENT_ID");
|
||||
if(b != null) parentId = new MessageId(b);
|
||||
timestamp = i.getLongExtra("net.sf.briar.TIMESTAMP", -1);
|
||||
|
||||
if(state != null) {
|
||||
id = state.getInt("net.sf.briar.CONTACT_ID", -1);
|
||||
@@ -262,8 +264,11 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
public void run() {
|
||||
try {
|
||||
lifecycleManager.waitForDatabase();
|
||||
// Don't use an earlier timestamp than the parent
|
||||
long time = System.currentTimeMillis();
|
||||
time = Math.max(time, timestamp + 1);
|
||||
Message m = messageFactory.createPrivateMessage(parentId,
|
||||
"text/plain", body);
|
||||
"text/plain", time, body);
|
||||
long now = System.currentTimeMillis();
|
||||
db.addLocalPrivateMessage(m, contactId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
|
||||
@@ -60,6 +60,7 @@ implements OnClickListener {
|
||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||
@Inject private volatile LifecycleManager lifecycleManager;
|
||||
private volatile MessageId messageId = null;
|
||||
private volatile long timestamp = -1;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -78,7 +79,7 @@ implements OnClickListener {
|
||||
String authorName = i.getStringExtra("net.sf.briar.AUTHOR_NAME");
|
||||
String contentType = i.getStringExtra("net.sf.briar.CONTENT_TYPE");
|
||||
if(contentType == null) throw new IllegalStateException();
|
||||
long timestamp = i.getLongExtra("net.sf.briar.TIMESTAMP", -1);
|
||||
timestamp = i.getLongExtra("net.sf.briar.TIMESTAMP", -1);
|
||||
if(timestamp == -1) throw new IllegalStateException();
|
||||
|
||||
if(state == null) {
|
||||
@@ -266,6 +267,7 @@ implements OnClickListener {
|
||||
Intent i = new Intent(this, WriteGroupPostActivity.class);
|
||||
i.putExtra("net.sf.briar.GROUP_ID", groupId.getBytes());
|
||||
i.putExtra("net.sf.briar.PARENT_ID", messageId.getBytes());
|
||||
i.putExtra("net.sf.briar.TIMESTAMP", timestamp);
|
||||
startActivity(i);
|
||||
setResult(RESULT_REPLY);
|
||||
finish();
|
||||
|
||||
@@ -74,6 +74,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
private volatile LocalAuthor localAuthor = null;
|
||||
private volatile Group group = null;
|
||||
private volatile MessageId parentId = null;
|
||||
private volatile long timestamp = -1;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -84,6 +85,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
if(b != null) groupId = new GroupId(b);
|
||||
b = i.getByteArrayExtra("net.sf.briar.PARENT_ID");
|
||||
if(b != null) parentId = new MessageId(b);
|
||||
timestamp = i.getLongExtra("net.sf.briar.TIMESTAMP", -1);
|
||||
|
||||
if(state != null) {
|
||||
b = state.getByteArray("net.sf.briar.LOCAL_AUTHOR_ID");
|
||||
@@ -318,15 +320,18 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
// FIXME: This should happen on a CryptoExecutor thread
|
||||
private Message createMessage(byte[] body) throws IOException,
|
||||
GeneralSecurityException {
|
||||
// Don't use an earlier timestamp than the parent
|
||||
long time = System.currentTimeMillis();
|
||||
time = Math.max(time, timestamp + 1);
|
||||
if(localAuthor == null) {
|
||||
return messageFactory.createAnonymousMessage(parentId, group,
|
||||
"text/plain", body);
|
||||
"text/plain", time, body);
|
||||
} else {
|
||||
KeyParser keyParser = crypto.getSignatureKeyParser();
|
||||
byte[] authorKeyBytes = localAuthor.getPrivateKey();
|
||||
PrivateKey authorKey = keyParser.parsePrivateKey(authorKeyBytes);
|
||||
return messageFactory.createPseudonymousMessage(parentId,
|
||||
group, localAuthor, authorKey, "text/plain", body);
|
||||
group, localAuthor, authorKey, "text/plain", time, body);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user