mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Compare commits
142 Commits
lock-down-
...
integratio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c29c4fa5b | ||
|
|
34948fce13 | ||
|
|
f604320989 | ||
|
|
ea8c78bfef | ||
|
|
37d8a34c69 | ||
|
|
45e3c56eb8 | ||
|
|
647467a51a | ||
|
|
144bd7bf1d | ||
|
|
9d1c49c6b6 | ||
|
|
f5c2bed528 | ||
|
|
b4de1424ac | ||
|
|
f184bfe9ac | ||
|
|
d3204ab3ee | ||
|
|
163565e15c | ||
|
|
ef46f8ed64 | ||
|
|
f42a9a20d8 | ||
|
|
03c55311c7 | ||
|
|
ad67a0abd6 | ||
|
|
9bc3a2c73d | ||
|
|
af55d181e9 | ||
|
|
dde94baebd | ||
|
|
64e3940f77 | ||
|
|
012ab0310f | ||
|
|
63012d0a72 | ||
|
|
ebd233d005 | ||
|
|
f3b4440105 | ||
|
|
e36f275be7 | ||
|
|
3dc3d384d3 | ||
|
|
0c0c34696a | ||
|
|
7047f7d3d6 | ||
|
|
abc8c86eaa | ||
|
|
fa14448aa7 | ||
|
|
654603cfad | ||
|
|
112dace96c | ||
|
|
35bdb8075f | ||
|
|
f9d312a632 | ||
|
|
dd93c6852e | ||
|
|
5c4d971873 | ||
|
|
1d9acc7425 | ||
|
|
6738287a83 | ||
|
|
ea4f763a55 | ||
|
|
9d027fb250 | ||
|
|
b56a9beb1d | ||
|
|
1083507752 | ||
|
|
0d2137f0f8 | ||
|
|
f9ddb3a3a4 | ||
|
|
539198026d | ||
|
|
d84fb0e761 | ||
|
|
7bf07b3b84 | ||
|
|
e4da7968e3 | ||
|
|
f0e4e3c164 | ||
|
|
fac4132289 | ||
|
|
917da9ce36 | ||
|
|
e9249a9463 | ||
|
|
ec0a59db01 | ||
|
|
7e62d2aeff | ||
|
|
3d8826cef9 | ||
|
|
6113b4ebee | ||
|
|
00e3e64495 | ||
|
|
115724a0a4 | ||
|
|
0a92f0516f | ||
|
|
cc09a6deb2 | ||
|
|
5888775300 | ||
|
|
712f0f7cd9 | ||
|
|
0d3f531545 | ||
|
|
b02629bf34 | ||
|
|
b6693071f9 | ||
|
|
ff739e1982 | ||
|
|
47fa7ccc81 | ||
|
|
1cf1e8b617 | ||
|
|
b012f0991f | ||
|
|
1b7a1de881 | ||
|
|
8510fc80c9 | ||
|
|
5ae2a37d37 | ||
|
|
b032a84902 | ||
|
|
f6414b5ca1 | ||
|
|
c5669bece5 | ||
|
|
8c76db6216 | ||
|
|
370fe7601d | ||
|
|
55de9859e0 | ||
|
|
06a8086502 | ||
|
|
5522929b9b | ||
|
|
50d4f825c8 | ||
|
|
6cc225ec22 | ||
|
|
aaa03cd809 | ||
|
|
890c9837b5 | ||
|
|
6ac54af432 | ||
|
|
0ccbd57d1d | ||
|
|
66d3e8950e | ||
|
|
d291b7796e | ||
|
|
7af863160d | ||
|
|
c74e585668 | ||
|
|
0fd56b6c38 | ||
|
|
57264b0f04 | ||
|
|
70225c5380 | ||
|
|
f0a602a579 | ||
|
|
f9ab242f43 | ||
|
|
24efc29722 | ||
|
|
e72169ecee | ||
|
|
47db28a738 | ||
|
|
30261b0dcf | ||
|
|
10f9df4dc8 | ||
|
|
60dd260a5a | ||
|
|
579a72f54b | ||
|
|
e270910399 | ||
|
|
c1483ea61a | ||
|
|
35751ecef6 | ||
|
|
37d058a766 | ||
|
|
5a6846c972 | ||
|
|
b34e6ee2a7 | ||
|
|
2ae1e9631f | ||
|
|
76f2859a45 | ||
|
|
1c25b2da82 | ||
|
|
26fe2f804f | ||
|
|
c8d1ee878c | ||
|
|
7b16e78470 | ||
|
|
7fb71a6cb9 | ||
|
|
fc076954a3 | ||
|
|
6a1d2e65ba | ||
|
|
d67cbd40bd | ||
|
|
dba85debfa | ||
|
|
629cff20a3 | ||
|
|
6cfb70db95 | ||
|
|
737ecfb620 | ||
|
|
5a424b178e | ||
|
|
59f4e7c34a | ||
|
|
2480824d69 | ||
|
|
a6c2000d81 | ||
|
|
a38a3139d9 | ||
|
|
4c8adaa02b | ||
|
|
8a534b4503 | ||
|
|
e5b2275c82 | ||
|
|
5159593825 | ||
|
|
a546fecc01 | ||
|
|
3e7e37f5f6 | ||
|
|
d095ba0b15 | ||
|
|
7fab97d26c | ||
|
|
6fbc82ee27 | ||
|
|
885b03cfd7 | ||
|
|
f81bfcafeb | ||
|
|
fb2b4209cf | ||
|
|
e4a66615a7 |
1
.idea/dictionaries/briar.xml
generated
1
.idea/dictionaries/briar.xml
generated
@@ -7,6 +7,7 @@
|
|||||||
<w>encrypter</w>
|
<w>encrypter</w>
|
||||||
<w>identicon</w>
|
<w>identicon</w>
|
||||||
<w>introducee</w>
|
<w>introducee</w>
|
||||||
|
<w>introducees</w>
|
||||||
<w>introducer</w>
|
<w>introducer</w>
|
||||||
<w>onboarding</w>
|
<w>onboarding</w>
|
||||||
</words>
|
</words>
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 10214
|
versionCode 10216
|
||||||
versionName "1.2.14"
|
versionName "1.2.16"
|
||||||
consumerProguardFiles 'proguard-rules.txt'
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ public interface FeatureFlags {
|
|||||||
|
|
||||||
boolean shouldEnableProfilePictures();
|
boolean shouldEnableProfilePictures();
|
||||||
|
|
||||||
|
boolean shouldEnableDisappearingMessages();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.briarproject.bramble.api.cleanup;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for registering a hook with the {@link CleanupManager}
|
||||||
|
* that will be called when a message's cleanup deadline is reached.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface CleanupHook {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the cleanup deadlines of one or more messages are reached.
|
||||||
|
* <p>
|
||||||
|
* The callee is not required to delete the messages, but the hook won't be
|
||||||
|
* called again for these messages unless another cleanup timer is set (see
|
||||||
|
* {@link DatabaseComponent#setCleanupTimerDuration(Transaction, MessageId, long)}
|
||||||
|
* and {@link DatabaseComponent#startCleanupTimer(Transaction, MessageId)}).
|
||||||
|
*/
|
||||||
|
void deleteMessages(Transaction txn, GroupId g,
|
||||||
|
Collection<MessageId> messageIds) throws DbException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.briarproject.bramble.api.cleanup;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.cleanup.event.CleanupTimerStartedEvent;
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.ClientId;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The CleanupManager is responsible for tracking the cleanup deadlines of
|
||||||
|
* messages and passing them to their respective
|
||||||
|
* {@link CleanupHook CleanupHooks} when the deadlines are reached.
|
||||||
|
* <p>
|
||||||
|
* The CleanupManager responds to
|
||||||
|
* {@link CleanupTimerStartedEvent CleanupTimerStartedEvents} broadcast by the
|
||||||
|
* {@link DatabaseComponent}.
|
||||||
|
* <p>
|
||||||
|
* See {@link DatabaseComponent#setCleanupTimerDuration(Transaction, MessageId, long)},
|
||||||
|
* {@link DatabaseComponent#startCleanupTimer(Transaction, MessageId)},
|
||||||
|
* {@link DatabaseComponent#stopCleanupTimer(Transaction, MessageId)}.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface CleanupManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When scheduling a cleanup task we overshoot the deadline by this many
|
||||||
|
* milliseconds to reduce the number of tasks that need to be scheduled
|
||||||
|
* when messages have cleanup deadlines that are close together.
|
||||||
|
*/
|
||||||
|
long BATCH_DELAY_MS = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a hook to be called when messages are due for cleanup.
|
||||||
|
* This method should be called before
|
||||||
|
* {@link LifecycleManager#startServices(SecretKey)}.
|
||||||
|
*/
|
||||||
|
void registerCleanupHook(ClientId c, int majorVersion,
|
||||||
|
CleanupHook hook);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.briarproject.bramble.api.cleanup.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a message's cleanup timer is started.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class CleanupTimerStartedEvent extends Event {
|
||||||
|
|
||||||
|
private final MessageId messageId;
|
||||||
|
private final long cleanupDeadline;
|
||||||
|
|
||||||
|
public CleanupTimerStartedEvent(MessageId messageId,
|
||||||
|
long cleanupDeadline) {
|
||||||
|
this.messageId = messageId;
|
||||||
|
this.cleanupDeadline = cleanupDeadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageId getMessageId() {
|
||||||
|
return messageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCleanupDeadline() {
|
||||||
|
return cleanupDeadline;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.bramble.api.client;
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.crypto.PrivateKey;
|
import org.briarproject.bramble.api.crypto.PrivateKey;
|
||||||
import org.briarproject.bramble.api.crypto.PublicKey;
|
import org.briarproject.bramble.api.crypto.PublicKey;
|
||||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
@@ -16,6 +17,7 @@ import org.briarproject.bramble.api.sync.Message;
|
|||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -50,9 +52,11 @@ public interface ClientHelper {
|
|||||||
BdfDictionary getGroupMetadataAsDictionary(Transaction txn, GroupId g)
|
BdfDictionary getGroupMetadataAsDictionary(Transaction txn, GroupId g)
|
||||||
throws DbException, FormatException;
|
throws DbException, FormatException;
|
||||||
|
|
||||||
|
Collection<MessageId> getMessageIds(Transaction txn, GroupId g,
|
||||||
|
BdfDictionary query) throws DbException, FormatException;
|
||||||
|
|
||||||
BdfDictionary getMessageMetadataAsDictionary(MessageId m)
|
BdfDictionary getMessageMetadataAsDictionary(MessageId m)
|
||||||
throws DbException,
|
throws DbException, FormatException;
|
||||||
FormatException;
|
|
||||||
|
|
||||||
BdfDictionary getMessageMetadataAsDictionary(Transaction txn, MessageId m)
|
BdfDictionary getMessageMetadataAsDictionary(Transaction txn, MessageId m)
|
||||||
throws DbException, FormatException;
|
throws DbException, FormatException;
|
||||||
@@ -119,4 +123,17 @@ public interface ClientHelper {
|
|||||||
Map<TransportId, TransportProperties> parseAndValidateTransportPropertiesMap(
|
Map<TransportId, TransportProperties> parseAndValidateTransportPropertiesMap(
|
||||||
BdfDictionary properties) throws FormatException;
|
BdfDictionary properties) throws FormatException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the contact ID from the group metadata of the given contact
|
||||||
|
* group.
|
||||||
|
*/
|
||||||
|
ContactId getContactId(Transaction txn, GroupId contactGroupId)
|
||||||
|
throws DbException, FormatException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the given contact ID in the group metadata of the given contact
|
||||||
|
* group.
|
||||||
|
*/
|
||||||
|
void setContactId(Transaction txn, GroupId contactGroupId, ContactId c)
|
||||||
|
throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
|
public interface ContactGroupConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Group metadata key for associating a contact ID with a contact group.
|
||||||
|
*/
|
||||||
|
String GROUP_KEY_CONTACT_ID = "contactId";
|
||||||
|
}
|
||||||
@@ -41,6 +41,18 @@ import javax.annotation.Nullable;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface DatabaseComponent extends TransactionManager {
|
public interface DatabaseComponent extends TransactionManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return value for {@link #getNextCleanupDeadline(Transaction)} if
|
||||||
|
* no messages are scheduled to be deleted.
|
||||||
|
*/
|
||||||
|
long NO_CLEANUP_DEADLINE = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return value for {@link #startCleanupTimer(Transaction, MessageId)}
|
||||||
|
* if the cleanup timer was not started.
|
||||||
|
*/
|
||||||
|
long TIMER_NOT_STARTED = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the database and returns true if the database already existed.
|
* Opens the database and returns true if the database already existed.
|
||||||
*
|
*
|
||||||
@@ -288,6 +300,16 @@ public interface DatabaseComponent extends TransactionManager {
|
|||||||
Collection<MessageId> getMessageIds(Transaction txn, GroupId g)
|
Collection<MessageId> getMessageIds(Transaction txn, GroupId g)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the IDs of any delivered messages in the given group with
|
||||||
|
* metadata that matches all entries in the given query. If the query is
|
||||||
|
* empty, the IDs of all delivered messages are returned.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
Collection<MessageId> getMessageIds(Transaction txn, GroupId g,
|
||||||
|
Metadata query) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the IDs of any messages that need to be validated.
|
* Returns the IDs of any messages that need to be validated.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -314,6 +336,15 @@ public interface DatabaseComponent extends TransactionManager {
|
|||||||
Collection<MessageId> getMessagesToShare(Transaction txn)
|
Collection<MessageId> getMessagesToShare(Transaction txn)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the IDs of any messages of any messages that are due for
|
||||||
|
* deletion, along with their group IDs.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
Map<GroupId, Collection<MessageId>> getMessagesToDelete(Transaction txn)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the metadata for all delivered messages in the given group.
|
* Returns the metadata for all delivered messages in the given group.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -395,6 +426,15 @@ public interface DatabaseComponent extends TransactionManager {
|
|||||||
MessageStatus getMessageStatus(Transaction txn, ContactId c, MessageId m)
|
MessageStatus getMessageStatus(Transaction txn, ContactId c, MessageId m)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next time (in milliseconds since the Unix epoch) when a
|
||||||
|
* message is due to be deleted, or {@link #NO_CLEANUP_DEADLINE}
|
||||||
|
* if no messages are scheduled to be deleted.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
long getNextCleanupDeadline(Transaction txn) throws DbException;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the next time (in milliseconds since the Unix epoch) when a
|
* Returns the next time (in milliseconds since the Unix epoch) when a
|
||||||
* message is due to be sent to the given contact. The returned value may
|
* message is due to be sent to the given contact. The returned value may
|
||||||
@@ -535,6 +575,13 @@ public interface DatabaseComponent extends TransactionManager {
|
|||||||
void removeTransportKeys(Transaction txn, TransportId t, KeySetId k)
|
void removeTransportKeys(Transaction txn, TransportId t, KeySetId k)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cleanup timer duration for the given message. This does not
|
||||||
|
* start the message's cleanup timer.
|
||||||
|
*/
|
||||||
|
void setCleanupTimerDuration(Transaction txn, MessageId m, long duration)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given contact as verified.
|
* Marks the given contact as verified.
|
||||||
*/
|
*/
|
||||||
@@ -557,6 +604,12 @@ public interface DatabaseComponent extends TransactionManager {
|
|||||||
*/
|
*/
|
||||||
void setMessagePermanent(Transaction txn, MessageId m) throws DbException;
|
void setMessagePermanent(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the given message as not shared. This method is only meant for
|
||||||
|
* testing.
|
||||||
|
*/
|
||||||
|
void setMessageNotShared(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given message as shared.
|
* Marks the given message as shared.
|
||||||
*/
|
*/
|
||||||
@@ -599,6 +652,22 @@ public interface DatabaseComponent extends TransactionManager {
|
|||||||
void setTransportKeysActive(Transaction txn, TransportId t, KeySetId k)
|
void setTransportKeysActive(Transaction txn, TransportId t, KeySetId k)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the cleanup timer for the given message, if a timer duration
|
||||||
|
* has been set and the timer has not already been started.
|
||||||
|
*
|
||||||
|
* @return The cleanup deadline, or {@link #TIMER_NOT_STARTED} if no
|
||||||
|
* timer duration has been set for this message or its timer has already
|
||||||
|
* been started.
|
||||||
|
*/
|
||||||
|
long startCleanupTimer(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the cleanup timer for the given message, if the timer has been
|
||||||
|
* started.
|
||||||
|
*/
|
||||||
|
void stopCleanupTimer(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the given transport keys, deleting any keys they have replaced.
|
* Stores the given transport keys, deleting any keys they have replaced.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import org.briarproject.bramble.api.data.BdfList;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class ValidationUtils {
|
public class ValidationUtils {
|
||||||
|
|
||||||
@@ -64,4 +66,9 @@ public class ValidationUtils {
|
|||||||
if (dictionary != null && dictionary.size() != size)
|
if (dictionary != null && dictionary.size() != size)
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkRange(@Nullable Long l, long min, long max)
|
||||||
|
throws FormatException {
|
||||||
|
if (l != null && (l < min || l > max)) throw new FormatException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package org.briarproject.bramble.test;
|
||||||
|
|
||||||
|
public interface TimeTravel {
|
||||||
|
|
||||||
|
void setCurrentTimeMillis(long now) throws InterruptedException;
|
||||||
|
|
||||||
|
void addCurrentTimeMillis(long add) throws InterruptedException;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.bramble;
|
package org.briarproject.bramble;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.cleanup.CleanupModule;
|
||||||
import org.briarproject.bramble.contact.ContactModule;
|
import org.briarproject.bramble.contact.ContactModule;
|
||||||
import org.briarproject.bramble.crypto.CryptoExecutorModule;
|
import org.briarproject.bramble.crypto.CryptoExecutorModule;
|
||||||
import org.briarproject.bramble.db.DatabaseExecutorModule;
|
import org.briarproject.bramble.db.DatabaseExecutorModule;
|
||||||
@@ -14,6 +15,8 @@ import org.briarproject.bramble.versioning.VersioningModule;
|
|||||||
|
|
||||||
public interface BrambleCoreEagerSingletons {
|
public interface BrambleCoreEagerSingletons {
|
||||||
|
|
||||||
|
void inject(CleanupModule.EagerSingletons init);
|
||||||
|
|
||||||
void inject(ContactModule.EagerSingletons init);
|
void inject(ContactModule.EagerSingletons init);
|
||||||
|
|
||||||
void inject(CryptoExecutorModule.EagerSingletons init);
|
void inject(CryptoExecutorModule.EagerSingletons init);
|
||||||
@@ -39,6 +42,7 @@ public interface BrambleCoreEagerSingletons {
|
|||||||
class Helper {
|
class Helper {
|
||||||
|
|
||||||
public static void injectEagerSingletons(BrambleCoreEagerSingletons c) {
|
public static void injectEagerSingletons(BrambleCoreEagerSingletons c) {
|
||||||
|
c.inject(new CleanupModule.EagerSingletons());
|
||||||
c.inject(new ContactModule.EagerSingletons());
|
c.inject(new ContactModule.EagerSingletons());
|
||||||
c.inject(new CryptoExecutorModule.EagerSingletons());
|
c.inject(new CryptoExecutorModule.EagerSingletons());
|
||||||
c.inject(new DatabaseExecutorModule.EagerSingletons());
|
c.inject(new DatabaseExecutorModule.EagerSingletons());
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.bramble;
|
package org.briarproject.bramble;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.cleanup.CleanupModule;
|
||||||
import org.briarproject.bramble.client.ClientModule;
|
import org.briarproject.bramble.client.ClientModule;
|
||||||
import org.briarproject.bramble.connection.ConnectionModule;
|
import org.briarproject.bramble.connection.ConnectionModule;
|
||||||
import org.briarproject.bramble.contact.ContactModule;
|
import org.briarproject.bramble.contact.ContactModule;
|
||||||
@@ -21,15 +22,14 @@ import org.briarproject.bramble.rendezvous.RendezvousModule;
|
|||||||
import org.briarproject.bramble.settings.SettingsModule;
|
import org.briarproject.bramble.settings.SettingsModule;
|
||||||
import org.briarproject.bramble.sync.SyncModule;
|
import org.briarproject.bramble.sync.SyncModule;
|
||||||
import org.briarproject.bramble.sync.validation.ValidationModule;
|
import org.briarproject.bramble.sync.validation.ValidationModule;
|
||||||
import org.briarproject.bramble.system.ClockModule;
|
|
||||||
import org.briarproject.bramble.transport.TransportModule;
|
import org.briarproject.bramble.transport.TransportModule;
|
||||||
import org.briarproject.bramble.versioning.VersioningModule;
|
import org.briarproject.bramble.versioning.VersioningModule;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
|
|
||||||
@Module(includes = {
|
@Module(includes = {
|
||||||
|
CleanupModule.class,
|
||||||
ClientModule.class,
|
ClientModule.class,
|
||||||
ClockModule.class,
|
|
||||||
ConnectionModule.class,
|
ConnectionModule.class,
|
||||||
ContactModule.class,
|
ContactModule.class,
|
||||||
CryptoModule.class,
|
CryptoModule.class,
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
package org.briarproject.bramble.cleanup;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.cleanup.CleanupHook;
|
||||||
|
import org.briarproject.bramble.api.cleanup.CleanupManager;
|
||||||
|
import org.briarproject.bramble.api.cleanup.event.CleanupTimerStartedEvent;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.Service;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.ClientId;
|
||||||
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.versioning.ClientMajorVersion;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.GuardedBy;
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.Math.max;
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.api.db.DatabaseComponent.NO_CLEANUP_DEADLINE;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
|
@ThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
|
class CleanupManagerImpl implements CleanupManager, Service, EventListener {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
getLogger(CleanupManagerImpl.class.getName());
|
||||||
|
|
||||||
|
private final Executor dbExecutor;
|
||||||
|
private final DatabaseComponent db;
|
||||||
|
private final TaskScheduler taskScheduler;
|
||||||
|
private final Clock clock;
|
||||||
|
private final Map<ClientMajorVersion, CleanupHook> hooks =
|
||||||
|
new ConcurrentHashMap<>();
|
||||||
|
private final Object lock = new Object();
|
||||||
|
|
||||||
|
@GuardedBy("lock")
|
||||||
|
private final Set<CleanupTask> pending = new HashSet<>();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
CleanupManagerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
|
DatabaseComponent db, TaskScheduler taskScheduler, Clock clock) {
|
||||||
|
this.dbExecutor = dbExecutor;
|
||||||
|
this.db = db;
|
||||||
|
this.taskScheduler = taskScheduler;
|
||||||
|
this.clock = clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerCleanupHook(ClientId c, int majorVersion,
|
||||||
|
CleanupHook hook) {
|
||||||
|
hooks.put(new ClientMajorVersion(c, majorVersion), hook);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startService() {
|
||||||
|
maybeScheduleTask(clock.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopService() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void eventOccurred(Event e) {
|
||||||
|
if (e instanceof CleanupTimerStartedEvent) {
|
||||||
|
CleanupTimerStartedEvent a = (CleanupTimerStartedEvent) e;
|
||||||
|
maybeScheduleTask(a.getCleanupDeadline());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void maybeScheduleTask(long deadline) {
|
||||||
|
synchronized (lock) {
|
||||||
|
for (CleanupTask task : pending) {
|
||||||
|
if (task.deadline <= deadline) return;
|
||||||
|
}
|
||||||
|
CleanupTask task = new CleanupTask(deadline);
|
||||||
|
pending.add(task);
|
||||||
|
scheduleTask(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scheduleTask(CleanupTask task) {
|
||||||
|
long now = clock.currentTimeMillis();
|
||||||
|
long delay = max(0, task.deadline - now + BATCH_DELAY_MS);
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("Scheduling cleanup task in " + delay + " ms");
|
||||||
|
}
|
||||||
|
taskScheduler.schedule(() -> deleteMessagesAndScheduleNextTask(task),
|
||||||
|
dbExecutor, delay, MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteMessagesAndScheduleNextTask(CleanupTask task) {
|
||||||
|
try {
|
||||||
|
synchronized (lock) {
|
||||||
|
pending.remove(task);
|
||||||
|
}
|
||||||
|
long deadline = db.transactionWithResult(false, txn -> {
|
||||||
|
deleteMessages(txn);
|
||||||
|
return db.getNextCleanupDeadline(txn);
|
||||||
|
});
|
||||||
|
if (deadline != NO_CLEANUP_DEADLINE) {
|
||||||
|
maybeScheduleTask(deadline);
|
||||||
|
}
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteMessages(Transaction txn) throws DbException {
|
||||||
|
Map<GroupId, Collection<MessageId>> ids = db.getMessagesToDelete(txn);
|
||||||
|
for (Entry<GroupId, Collection<MessageId>> e : ids.entrySet()) {
|
||||||
|
GroupId groupId = e.getKey();
|
||||||
|
Collection<MessageId> messageIds = e.getValue();
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info(messageIds.size() + " messages to delete");
|
||||||
|
}
|
||||||
|
for (MessageId m : messageIds) db.stopCleanupTimer(txn, m);
|
||||||
|
Group group = db.getGroup(txn, groupId);
|
||||||
|
ClientMajorVersion cv = new ClientMajorVersion(group.getClientId(),
|
||||||
|
group.getMajorVersion());
|
||||||
|
CleanupHook hook = hooks.get(cv);
|
||||||
|
if (hook == null) {
|
||||||
|
throw new IllegalStateException("No cleanup hook for " + cv);
|
||||||
|
}
|
||||||
|
hook.deleteMessages(txn, groupId, messageIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CleanupTask {
|
||||||
|
|
||||||
|
private final long deadline;
|
||||||
|
|
||||||
|
private CleanupTask(long deadline) {
|
||||||
|
this.deadline = deadline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.briarproject.bramble.cleanup;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.cleanup.CleanupManager;
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class CleanupModule {
|
||||||
|
|
||||||
|
public static class EagerSingletons {
|
||||||
|
@Inject
|
||||||
|
CleanupManager cleanupManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
CleanupManager provideCleanupManager(LifecycleManager lifecycleManager,
|
||||||
|
EventBus eventBus, CleanupManagerImpl cleanupManager) {
|
||||||
|
lifecycleManager.registerService(cleanupManager);
|
||||||
|
eventBus.addListener(cleanupManager);
|
||||||
|
return cleanupManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,11 +2,13 @@ package org.briarproject.bramble.client;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.bramble.api.client.ClientHelper;
|
import org.briarproject.bramble.api.client.ClientHelper;
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.KeyParser;
|
import org.briarproject.bramble.api.crypto.KeyParser;
|
||||||
import org.briarproject.bramble.api.crypto.PrivateKey;
|
import org.briarproject.bramble.api.crypto.PrivateKey;
|
||||||
import org.briarproject.bramble.api.crypto.PublicKey;
|
import org.briarproject.bramble.api.crypto.PublicKey;
|
||||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
|
import org.briarproject.bramble.api.data.BdfEntry;
|
||||||
import org.briarproject.bramble.api.data.BdfList;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.bramble.api.data.BdfReader;
|
import org.briarproject.bramble.api.data.BdfReader;
|
||||||
import org.briarproject.bramble.api.data.BdfReaderFactory;
|
import org.briarproject.bramble.api.data.BdfReaderFactory;
|
||||||
@@ -32,6 +34,7 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -39,6 +42,7 @@ import java.util.Map.Entry;
|
|||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.client.ContactGroupConstants.GROUP_KEY_CONTACT_ID;
|
||||||
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
@@ -151,6 +155,12 @@ class ClientHelperImpl implements ClientHelper {
|
|||||||
return metadataParser.parse(metadata);
|
return metadataParser.parse(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<MessageId> getMessageIds(Transaction txn, GroupId g,
|
||||||
|
BdfDictionary query) throws DbException, FormatException {
|
||||||
|
return db.getMessageIds(txn, g, metadataEncoder.encode(query));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BdfDictionary getMessageMetadataAsDictionary(MessageId m)
|
public BdfDictionary getMessageMetadataAsDictionary(MessageId m)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
@@ -389,4 +399,27 @@ class ClientHelperImpl implements ClientHelper {
|
|||||||
return tpMap;
|
return tpMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContactId getContactId(Transaction txn, GroupId contactGroupId)
|
||||||
|
throws DbException {
|
||||||
|
try {
|
||||||
|
BdfDictionary meta =
|
||||||
|
getGroupMetadataAsDictionary(txn, contactGroupId);
|
||||||
|
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new DbException(e); // Invalid group metadata
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setContactId(Transaction txn, GroupId contactGroupId,
|
||||||
|
ContactId c) throws DbException {
|
||||||
|
BdfDictionary meta = BdfDictionary.of(
|
||||||
|
new BdfEntry(GROUP_KEY_CONTACT_ID, c.getInt()));
|
||||||
|
try {
|
||||||
|
mergeGroupMetadata(txn, contactGroupId, meta);
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -497,6 +497,25 @@ interface Database<T> {
|
|||||||
*/
|
*/
|
||||||
Collection<MessageId> getMessagesToShare(T txn) throws DbException;
|
Collection<MessageId> getMessagesToShare(T txn) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the IDs of any messages of any messages that are due for
|
||||||
|
* deletion, along with their group IDs.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
Map<GroupId, Collection<MessageId>> getMessagesToDelete(T txn)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next time (in milliseconds since the Unix epoch) when a
|
||||||
|
* message is due to be deleted, or
|
||||||
|
* {@link DatabaseComponent#NO_CLEANUP_DEADLINE} if no messages are
|
||||||
|
* scheduled to be deleted.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
long getNextCleanupDeadline(T txn) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next time (in milliseconds since the Unix epoch) when a
|
* Returns the next time (in milliseconds since the Unix epoch) when a
|
||||||
* message is due to be sent to the given contact. The returned value may
|
* message is due to be sent to the given contact. The returned value may
|
||||||
@@ -606,8 +625,10 @@ interface Database<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks a message as having been seen by the given contact.
|
* Marks a message as having been seen by the given contact.
|
||||||
|
*
|
||||||
|
* @return True if the message was not already marked as seen.
|
||||||
*/
|
*/
|
||||||
void raiseSeenFlag(T txn, ContactId c, MessageId m) throws DbException;
|
boolean raiseSeenFlag(T txn, ContactId c, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a contact from the database.
|
* Removes a contact from the database.
|
||||||
@@ -671,6 +692,13 @@ interface Database<T> {
|
|||||||
*/
|
*/
|
||||||
void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException;
|
void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cleanup timer duration for the given message. This does not
|
||||||
|
* start the message's cleanup timer.
|
||||||
|
*/
|
||||||
|
void setCleanupTimerDuration(T txn, MessageId m, long duration)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given contact as verified.
|
* Marks the given contact as verified.
|
||||||
*/
|
*/
|
||||||
@@ -701,9 +729,10 @@ interface Database<T> {
|
|||||||
void setMessagePermanent(T txn, MessageId m) throws DbException;
|
void setMessagePermanent(T txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given message as shared.
|
* Marks the given message as shared or not.
|
||||||
*/
|
*/
|
||||||
void setMessageShared(T txn, MessageId m) throws DbException;
|
void setMessageShared(T txn, MessageId m, boolean shared)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the validation and delivery state of the given message.
|
* Sets the validation and delivery state of the given message.
|
||||||
@@ -730,6 +759,22 @@ interface Database<T> {
|
|||||||
void setTransportKeysActive(T txn, TransportId t, KeySetId k)
|
void setTransportKeysActive(T txn, TransportId t, KeySetId k)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the cleanup timer for the given message, if a timer duration
|
||||||
|
* has been set and the timer has not already been started.
|
||||||
|
*
|
||||||
|
* @return The cleanup deadline, or
|
||||||
|
* {@link DatabaseComponent#TIMER_NOT_STARTED} if no timer duration has
|
||||||
|
* been set for this message or its timer has already been started.
|
||||||
|
*/
|
||||||
|
long startCleanupTimer(T txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the cleanup timer for the given message, if the timer has been
|
||||||
|
* started.
|
||||||
|
*/
|
||||||
|
void stopCleanupTimer(T txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the transmission count, expiry time and estimated time of arrival
|
* Updates the transmission count, expiry time and estimated time of arrival
|
||||||
* of the given message with respect to the given contact, using the latency
|
* of the given message with respect to the given contact, using the latency
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.bramble.db;
|
package org.briarproject.bramble.db;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.cleanup.event.CleanupTimerStartedEvent;
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.contact.PendingContact;
|
import org.briarproject.bramble.api.contact.PendingContact;
|
||||||
@@ -576,6 +577,15 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
return db.getMessageIds(txn, g);
|
return db.getMessageIds(txn, g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<MessageId> getMessageIds(Transaction transaction,
|
||||||
|
GroupId g, Metadata query) throws DbException {
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
if (!db.containsGroup(txn, g))
|
||||||
|
throw new NoSuchGroupException();
|
||||||
|
return db.getMessageIds(txn, g, query);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<MessageId> getMessagesToValidate(Transaction transaction)
|
public Collection<MessageId> getMessagesToValidate(Transaction transaction)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -597,6 +607,13 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
return db.getMessagesToShare(txn);
|
return db.getMessagesToShare(txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<GroupId, Collection<MessageId>> getMessagesToDelete(
|
||||||
|
Transaction transaction) throws DbException {
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
return db.getMessagesToDelete(txn);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<MessageId, Metadata> getMessageMetadata(Transaction transaction,
|
public Map<MessageId, Metadata> getMessageMetadata(Transaction transaction,
|
||||||
GroupId g) throws DbException {
|
GroupId g) throws DbException {
|
||||||
@@ -692,6 +709,13 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
return db.getMessageDependents(txn, m);
|
return db.getMessageDependents(txn, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getNextCleanupDeadline(Transaction transaction)
|
||||||
|
throws DbException {
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
return db.getNextCleanupDeadline(txn);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getNextSendTime(Transaction transaction, ContactId c)
|
public long getNextSendTime(Transaction transaction, ContactId c)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -795,8 +819,17 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
Collection<MessageId> acked = new ArrayList<>();
|
Collection<MessageId> acked = new ArrayList<>();
|
||||||
for (MessageId m : a.getMessageIds()) {
|
for (MessageId m : a.getMessageIds()) {
|
||||||
if (db.containsVisibleMessage(txn, c, m)) {
|
if (db.containsVisibleMessage(txn, c, m)) {
|
||||||
db.raiseSeenFlag(txn, c, m);
|
if (db.raiseSeenFlag(txn, c, m)) {
|
||||||
acked.add(m);
|
// This is the first time the message has been acked by
|
||||||
|
// this contact. Start the cleanup timer (a no-op unless
|
||||||
|
// a cleanup deadline has been set for this message)
|
||||||
|
long deadline = db.startCleanupTimer(txn, m);
|
||||||
|
if (deadline != TIMER_NOT_STARTED) {
|
||||||
|
transaction.attach(new CleanupTimerStartedEvent(m,
|
||||||
|
deadline));
|
||||||
|
}
|
||||||
|
acked.add(m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (acked.size() > 0) {
|
if (acked.size() > 0) {
|
||||||
@@ -952,6 +985,16 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
db.removeTransportKeys(txn, t, k);
|
db.removeTransportKeys(txn, t, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCleanupTimerDuration(Transaction transaction, MessageId m,
|
||||||
|
long duration) throws DbException {
|
||||||
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
if (!db.containsMessage(txn, m))
|
||||||
|
throw new NoSuchMessageException();
|
||||||
|
db.setCleanupTimerDuration(txn, m, duration);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContactVerified(Transaction transaction, ContactId c)
|
public void setContactVerified(Transaction transaction, ContactId c)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -1001,6 +1044,16 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
db.setMessagePermanent(txn, m);
|
db.setMessagePermanent(txn, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMessageNotShared(Transaction transaction, MessageId m)
|
||||||
|
throws DbException {
|
||||||
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
if (!db.containsMessage(txn, m))
|
||||||
|
throw new NoSuchMessageException();
|
||||||
|
db.setMessageShared(txn, m, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMessageShared(Transaction transaction, MessageId m)
|
public void setMessageShared(Transaction transaction, MessageId m)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -1010,7 +1063,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
throw new NoSuchMessageException();
|
throw new NoSuchMessageException();
|
||||||
if (db.getMessageState(txn, m) != DELIVERED)
|
if (db.getMessageState(txn, m) != DELIVERED)
|
||||||
throw new IllegalArgumentException("Shared undelivered message");
|
throw new IllegalArgumentException("Shared undelivered message");
|
||||||
db.setMessageShared(txn, m);
|
db.setMessageShared(txn, m, true);
|
||||||
transaction.attach(new MessageSharedEvent(m));
|
transaction.attach(new MessageSharedEvent(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1082,6 +1135,30 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
db.setTransportKeysActive(txn, t, k);
|
db.setTransportKeysActive(txn, t, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long startCleanupTimer(Transaction transaction, MessageId m)
|
||||||
|
throws DbException {
|
||||||
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
if (!db.containsMessage(txn, m))
|
||||||
|
throw new NoSuchMessageException();
|
||||||
|
long deadline = db.startCleanupTimer(txn, m);
|
||||||
|
if (deadline != TIMER_NOT_STARTED) {
|
||||||
|
transaction.attach(new CleanupTimerStartedEvent(m, deadline));
|
||||||
|
}
|
||||||
|
return deadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopCleanupTimer(Transaction transaction, MessageId m)
|
||||||
|
throws DbException {
|
||||||
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
if (!db.containsMessage(txn, m))
|
||||||
|
throw new NoSuchMessageException();
|
||||||
|
db.stopCleanupTimer(txn, m);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTransportKeys(Transaction transaction,
|
public void updateTransportKeys(Transaction transaction,
|
||||||
Collection<TransportKeySet> keys) throws DbException {
|
Collection<TransportKeySet> keys) throws DbException {
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ import static java.util.Arrays.asList;
|
|||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.api.db.DatabaseComponent.NO_CLEANUP_DEADLINE;
|
||||||
|
import static org.briarproject.bramble.api.db.DatabaseComponent.TIMER_NOT_STARTED;
|
||||||
import static org.briarproject.bramble.api.db.Metadata.REMOVE;
|
import static org.briarproject.bramble.api.db.Metadata.REMOVE;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
@@ -98,7 +100,7 @@ import static org.briarproject.bramble.util.LogUtils.now;
|
|||||||
abstract class JdbcDatabase implements Database<Connection> {
|
abstract class JdbcDatabase implements Database<Connection> {
|
||||||
|
|
||||||
// Package access for testing
|
// Package access for testing
|
||||||
static final int CODE_SCHEMA_VERSION = 47;
|
static final int CODE_SCHEMA_VERSION = 48;
|
||||||
|
|
||||||
// Time period offsets for incoming transport keys
|
// Time period offsets for incoming transport keys
|
||||||
private static final int OFFSET_PREV = -1;
|
private static final int OFFSET_PREV = -1;
|
||||||
@@ -180,6 +182,11 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " state INT NOT NULL,"
|
+ " state INT NOT NULL,"
|
||||||
+ " shared BOOLEAN NOT NULL,"
|
+ " shared BOOLEAN NOT NULL,"
|
||||||
+ " temporary BOOLEAN NOT NULL,"
|
+ " temporary BOOLEAN NOT NULL,"
|
||||||
|
// Null if no timer duration has been set
|
||||||
|
+ " cleanupTimerDuration BIGINT,"
|
||||||
|
// Null if no timer duration has been set or the timer
|
||||||
|
// hasn't started
|
||||||
|
+ " cleanupDeadline BIGINT,"
|
||||||
+ " length INT NOT NULL,"
|
+ " length INT NOT NULL,"
|
||||||
+ " raw BLOB," // Null if message has been deleted
|
+ " raw BLOB," // Null if message has been deleted
|
||||||
+ " PRIMARY KEY (messageId),"
|
+ " PRIMARY KEY (messageId),"
|
||||||
@@ -336,6 +343,10 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
"CREATE INDEX IF NOT EXISTS statusesByContactIdTimestamp"
|
"CREATE INDEX IF NOT EXISTS statusesByContactIdTimestamp"
|
||||||
+ " ON statuses (contactId, timestamp)";
|
+ " ON statuses (contactId, timestamp)";
|
||||||
|
|
||||||
|
private static final String INDEX_MESSAGES_BY_CLEANUP_DEADLINE =
|
||||||
|
"CREATE INDEX IF NOT EXISTS messagesByCleanupDeadline"
|
||||||
|
+ " ON messages (cleanupDeadline)";
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(JdbcDatabase.class.getName());
|
getLogger(JdbcDatabase.class.getName());
|
||||||
|
|
||||||
@@ -463,7 +474,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
new Migration43_44(dbTypes),
|
new Migration43_44(dbTypes),
|
||||||
new Migration44_45(),
|
new Migration44_45(),
|
||||||
new Migration45_46(),
|
new Migration45_46(),
|
||||||
new Migration46_47(dbTypes)
|
new Migration46_47(dbTypes),
|
||||||
|
new Migration47_48()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -531,6 +543,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
s.executeUpdate(INDEX_MESSAGE_DEPENDENCIES_BY_DEPENDENCY_ID);
|
s.executeUpdate(INDEX_MESSAGE_DEPENDENCIES_BY_DEPENDENCY_ID);
|
||||||
s.executeUpdate(INDEX_STATUSES_BY_CONTACT_ID_GROUP_ID);
|
s.executeUpdate(INDEX_STATUSES_BY_CONTACT_ID_GROUP_ID);
|
||||||
s.executeUpdate(INDEX_STATUSES_BY_CONTACT_ID_TIMESTAMP);
|
s.executeUpdate(INDEX_STATUSES_BY_CONTACT_ID_TIMESTAMP);
|
||||||
|
s.executeUpdate(INDEX_MESSAGES_BY_CLEANUP_DEADLINE);
|
||||||
s.close();
|
s.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
tryToClose(s, LOG, WARNING);
|
tryToClose(s, LOG, WARNING);
|
||||||
@@ -1290,7 +1303,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
public void deleteMessage(Connection txn, MessageId m) throws DbException {
|
public void deleteMessage(Connection txn, MessageId m) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
String sql = "UPDATE messages SET raw = NULL WHERE messageId = ?";
|
String sql = "UPDATE messages"
|
||||||
|
+ " SET raw = NULL, cleanupDeadline = NULL"
|
||||||
|
+ " WHERE messageId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setBytes(1, m.getBytes());
|
ps.setBytes(1, m.getBytes());
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
@@ -1769,7 +1784,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
// Return early if there are no matches
|
// Return early if there are no matches
|
||||||
if (intersection.isEmpty()) return Collections.emptySet();
|
if (intersection.isEmpty()) return Collections.emptySet();
|
||||||
}
|
}
|
||||||
if (intersection == null) throw new AssertionError();
|
|
||||||
return intersection;
|
return intersection;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
tryToClose(rs, LOG, WARNING);
|
tryToClose(rs, LOG, WARNING);
|
||||||
@@ -2226,6 +2240,39 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<GroupId, Collection<MessageId>> getMessagesToDelete(
|
||||||
|
Connection txn) throws DbException {
|
||||||
|
long now = clock.currentTimeMillis();
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
String sql = "SELECT messageId, groupId FROM messages"
|
||||||
|
+ " WHERE cleanupDeadline <= ?";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setLong(1, now);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
Map<GroupId, Collection<MessageId>> ids = new HashMap<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
MessageId m = new MessageId(rs.getBytes(1));
|
||||||
|
GroupId g = new GroupId(rs.getBytes(2));
|
||||||
|
Collection<MessageId> messageIds = ids.get(g);
|
||||||
|
if (messageIds == null) {
|
||||||
|
messageIds = new ArrayList<>();
|
||||||
|
ids.put(g, messageIds);
|
||||||
|
}
|
||||||
|
messageIds.add(m);
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
return ids;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(rs, LOG, WARNING);
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getNextSendTime(Connection txn, ContactId c)
|
public long getNextSendTime(Connection txn, ContactId c)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -2256,6 +2303,31 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getNextCleanupDeadline(Connection txn) throws DbException {
|
||||||
|
Statement s = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
String sql = "SELECT cleanupDeadline FROM messages"
|
||||||
|
+ " WHERE cleanupDeadline IS NOT NULL"
|
||||||
|
+ " ORDER BY cleanupDeadline LIMIT 1";
|
||||||
|
s = txn.createStatement();
|
||||||
|
rs = s.executeQuery(sql);
|
||||||
|
long nextDeadline = NO_CLEANUP_DEADLINE;
|
||||||
|
if (rs.next()) {
|
||||||
|
nextDeadline = rs.getLong(1);
|
||||||
|
if (rs.next()) throw new AssertionError();
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
s.close();
|
||||||
|
return nextDeadline;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(rs, LOG, WARNING);
|
||||||
|
tryToClose(s, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PendingContact getPendingContact(Connection txn, PendingContactId p)
|
public PendingContact getPendingContact(Connection txn, PendingContactId p)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -2776,7 +2848,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void raiseSeenFlag(Connection txn, ContactId c, MessageId m)
|
public boolean raiseSeenFlag(Connection txn, ContactId c, MessageId m)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
@@ -2788,6 +2860,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if (affected < 0 || affected > 1) throw new DbStateException();
|
if (affected < 0 || affected > 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
|
return affected == 1;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
tryToClose(ps, LOG, WARNING);
|
tryToClose(ps, LOG, WARNING);
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
@@ -3021,6 +3094,25 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCleanupTimerDuration(Connection txn, MessageId m,
|
||||||
|
long duration) throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
try {
|
||||||
|
String sql = "UPDATE messages SET cleanupTimerDuration = ?"
|
||||||
|
+ " WHERE messageId = ? AND cleanupTimerDuration IS NULL";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setLong(1, duration);
|
||||||
|
ps.setBytes(2, m.getBytes());
|
||||||
|
int affected = ps.executeUpdate();
|
||||||
|
if (affected < 0 || affected > 1) throw new DbStateException();
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContactVerified(Connection txn, ContactId c)
|
public void setContactVerified(Connection txn, ContactId c)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -3128,22 +3220,24 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMessageShared(Connection txn, MessageId m)
|
public void setMessageShared(Connection txn, MessageId m, boolean shared)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
String sql = "UPDATE messages SET shared = TRUE"
|
String sql = "UPDATE messages SET shared = ?"
|
||||||
+ " WHERE messageId = ?";
|
+ " WHERE messageId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setBytes(1, m.getBytes());
|
ps.setBoolean(1, shared);
|
||||||
|
ps.setBytes(2, m.getBytes());
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if (affected < 0 || affected > 1) throw new DbStateException();
|
if (affected < 0 || affected > 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
// Update denormalised column in statuses
|
// Update denormalised column in statuses
|
||||||
sql = "UPDATE statuses SET messageShared = TRUE"
|
sql = "UPDATE statuses SET messageShared = ?"
|
||||||
+ " WHERE messageId = ?";
|
+ " WHERE messageId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setBytes(1, m.getBytes());
|
ps.setBoolean(1, shared);
|
||||||
|
ps.setBytes(2, m.getBytes());
|
||||||
affected = ps.executeUpdate();
|
affected = ps.executeUpdate();
|
||||||
if (affected < 0) throw new DbStateException();
|
if (affected < 0) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -3272,6 +3366,60 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long startCleanupTimer(Connection txn, MessageId m)
|
||||||
|
throws DbException {
|
||||||
|
long now = clock.currentTimeMillis();
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
String sql = "UPDATE messages"
|
||||||
|
+ " SET cleanupDeadline = ? + cleanupTimerDuration"
|
||||||
|
+ " WHERE messageId = ?"
|
||||||
|
+ " AND cleanupTimerDuration IS NOT NULL"
|
||||||
|
+ " AND cleanupDeadline IS NULL";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setLong(1, now);
|
||||||
|
ps.setBytes(2, m.getBytes());
|
||||||
|
int affected = ps.executeUpdate();
|
||||||
|
if (affected < 0 || affected > 1) throw new DbStateException();
|
||||||
|
ps.close();
|
||||||
|
if (affected == 0) return TIMER_NOT_STARTED;
|
||||||
|
sql = "SELECT cleanupDeadline FROM messages WHERE messageId = ?";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setBytes(1, m.getBytes());
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
if (!rs.next()) throw new DbStateException();
|
||||||
|
long deadline = rs.getLong(1);
|
||||||
|
if (rs.next()) throw new DbStateException();
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
return deadline;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(rs, LOG, WARNING);
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopCleanupTimer(Connection txn, MessageId m)
|
||||||
|
throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
try {
|
||||||
|
String sql = "UPDATE messages SET cleanupDeadline = NULL"
|
||||||
|
+ " WHERE messageId = ?";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setBytes(1, m.getBytes());
|
||||||
|
int affected = ps.executeUpdate();
|
||||||
|
if (affected < 0 || affected > 1) throw new DbStateException();
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateExpiryTimeAndEta(Connection txn, ContactId c, MessageId m,
|
public void updateExpiryTimeAndEta(Connection txn, ContactId c, MessageId m,
|
||||||
int maxLatency) throws DbException {
|
int maxLatency) throws DbException {
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package org.briarproject.bramble.db;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.db.JdbcUtils.tryToClose;
|
||||||
|
|
||||||
|
class Migration47_48 implements Migration<Connection> {
|
||||||
|
|
||||||
|
private static final Logger LOG = getLogger(Migration47_48.class.getName());
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStartVersion() {
|
||||||
|
return 47;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getEndVersion() {
|
||||||
|
return 48;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void migrate(Connection txn) throws DbException {
|
||||||
|
Statement s = null;
|
||||||
|
try {
|
||||||
|
s = txn.createStatement();
|
||||||
|
// Null if no timer duration has been set
|
||||||
|
s.execute("ALTER TABLE messages"
|
||||||
|
+ " ADD COLUMN cleanupTimerDuration BIGINT");
|
||||||
|
// Null if no timer duration has been set or the timer
|
||||||
|
// hasn't started
|
||||||
|
s.execute("ALTER TABLE messages"
|
||||||
|
+ " ADD COLUMN cleanupDeadline BIGINT");
|
||||||
|
s.execute("CREATE INDEX IF NOT EXISTS messagesByCleanupDeadline"
|
||||||
|
+ " ON messages (cleanupDeadline)");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(s, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,5 @@ interface ClientVersioningConstants {
|
|||||||
// Metadata keys
|
// Metadata keys
|
||||||
String MSG_KEY_UPDATE_VERSION = "version";
|
String MSG_KEY_UPDATE_VERSION = "version";
|
||||||
String MSG_KEY_LOCAL = "local";
|
String MSG_KEY_LOCAL = "local";
|
||||||
String GROUP_KEY_CONTACT_ID = "contactId";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ import static java.util.Collections.emptyList;
|
|||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
||||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.GROUP_KEY_CONTACT_ID;
|
|
||||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
||||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
||||||
|
|
||||||
@@ -161,13 +160,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
|||||||
db.addGroup(txn, g);
|
db.addGroup(txn, g);
|
||||||
db.setGroupVisibility(txn, c.getId(), g.getId(), SHARED);
|
db.setGroupVisibility(txn, c.getId(), g.getId(), SHARED);
|
||||||
// Attach the contact ID to the group
|
// Attach the contact ID to the group
|
||||||
BdfDictionary meta = new BdfDictionary();
|
clientHelper.setContactId(txn, g.getId(), c.getId());
|
||||||
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
|
|
||||||
try {
|
|
||||||
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
|
|
||||||
} catch (FormatException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
// Create and store the first local update
|
// Create and store the first local update
|
||||||
List<ClientVersion> versions = new ArrayList<>(clients);
|
List<ClientVersion> versions = new ArrayList<>(clients);
|
||||||
Collections.sort(versions);
|
Collections.sort(versions);
|
||||||
@@ -229,7 +222,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
|||||||
Map<ClientMajorVersion, Visibility> after =
|
Map<ClientMajorVersion, Visibility> after =
|
||||||
getVisibilities(newLocalStates, newRemoteStates);
|
getVisibilities(newLocalStates, newRemoteStates);
|
||||||
// Call hooks for any visibilities that have changed
|
// Call hooks for any visibilities that have changed
|
||||||
ContactId c = getContactId(txn, m.getGroupId());
|
ContactId c = clientHelper.getContactId(txn, m.getGroupId());
|
||||||
if (!before.equals(after)) {
|
if (!before.equals(after)) {
|
||||||
Contact contact = db.getContact(txn, c);
|
Contact contact = db.getContact(txn, c);
|
||||||
callVisibilityHooks(txn, contact, before, after);
|
callVisibilityHooks(txn, contact, before, after);
|
||||||
@@ -521,17 +514,6 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
|||||||
storeUpdate(txn, g, states, 1);
|
storeUpdate(txn, g, states, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContactId getContactId(Transaction txn, GroupId g)
|
|
||||||
throws DbException {
|
|
||||||
try {
|
|
||||||
BdfDictionary meta =
|
|
||||||
clientHelper.getGroupMetadataAsDictionary(txn, g);
|
|
||||||
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
|
|
||||||
} catch (FormatException e) {
|
|
||||||
throw new DbException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ClientState> updateStatesFromRemoteStates(
|
private List<ClientState> updateStatesFromRemoteStates(
|
||||||
List<ClientState> oldLocalStates, List<ClientState> remoteStates) {
|
List<ClientState> oldLocalStates, List<ClientState> remoteStates) {
|
||||||
Set<ClientMajorVersion> remoteSet = new HashSet<>();
|
Set<ClientMajorVersion> remoteSet = new HashSet<>();
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
package org.briarproject.bramble;
|
package org.briarproject.bramble;
|
||||||
|
|
||||||
import org.briarproject.bramble.system.DefaultTaskSchedulerModule;
|
import org.briarproject.bramble.system.TimeTravelModule;
|
||||||
|
|
||||||
public interface BrambleCoreIntegrationTestEagerSingletons
|
public interface BrambleCoreIntegrationTestEagerSingletons
|
||||||
extends BrambleCoreEagerSingletons {
|
extends BrambleCoreEagerSingletons {
|
||||||
|
|
||||||
void inject(DefaultTaskSchedulerModule.EagerSingletons init);
|
void inject(TimeTravelModule.EagerSingletons init);
|
||||||
|
|
||||||
class Helper {
|
class Helper {
|
||||||
|
|
||||||
public static void injectEagerSingletons(
|
public static void injectEagerSingletons(
|
||||||
BrambleCoreIntegrationTestEagerSingletons c) {
|
BrambleCoreIntegrationTestEagerSingletons c) {
|
||||||
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(c);
|
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(c);
|
||||||
c.inject(new DefaultTaskSchedulerModule.EagerSingletons());
|
c.inject(new TimeTravelModule.EagerSingletons());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.bramble.db;
|
package org.briarproject.bramble.db;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.cleanup.event.CleanupTimerStartedEvent;
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.contact.PendingContactId;
|
import org.briarproject.bramble.api.contact.PendingContactId;
|
||||||
@@ -69,6 +70,8 @@ import static java.util.Arrays.asList;
|
|||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Collections.emptyMap;
|
import static java.util.Collections.emptyMap;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
import static java.util.concurrent.TimeUnit.HOURS;
|
||||||
|
import static org.briarproject.bramble.api.db.DatabaseComponent.TIMER_NOT_STARTED;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
||||||
@@ -510,11 +513,11 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Check whether the group is in the DB (which it's not)
|
// Check whether the group is in the DB (which it's not)
|
||||||
exactly(8).of(database).startTransaction();
|
exactly(10).of(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
exactly(8).of(database).containsGroup(txn, groupId);
|
exactly(10).of(database).containsGroup(txn, groupId);
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
exactly(8).of(database).abortTransaction(txn);
|
exactly(10).of(database).abortTransaction(txn);
|
||||||
// Allow other checks to pass
|
// Allow other checks to pass
|
||||||
allowing(database).containsContact(txn, contactId);
|
allowing(database).containsContact(txn, contactId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
@@ -523,7 +526,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
eventExecutor, shutdownManager);
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
db.getGroup(transaction, groupId));
|
db.getGroup(transaction, groupId));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchGroupException expected) {
|
} catch (NoSuchGroupException expected) {
|
||||||
@@ -531,7 +534,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
db.getGroupMetadata(transaction, groupId));
|
db.getGroupMetadata(transaction, groupId));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchGroupException expected) {
|
} catch (NoSuchGroupException expected) {
|
||||||
@@ -539,7 +542,23 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
|
db.getMessageIds(transaction, groupId));
|
||||||
|
fail();
|
||||||
|
} catch (NoSuchGroupException expected) {
|
||||||
|
// Expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
db.transaction(true, transaction ->
|
||||||
|
db.getMessageIds(transaction, groupId, new Metadata()));
|
||||||
|
fail();
|
||||||
|
} catch (NoSuchGroupException expected) {
|
||||||
|
// Expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
db.transaction(true, transaction ->
|
||||||
db.getMessageMetadata(transaction, groupId));
|
db.getMessageMetadata(transaction, groupId));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchGroupException expected) {
|
} catch (NoSuchGroupException expected) {
|
||||||
@@ -547,7 +566,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
db.getMessageMetadata(transaction, groupId,
|
db.getMessageMetadata(transaction, groupId,
|
||||||
new Metadata()));
|
new Metadata()));
|
||||||
fail();
|
fail();
|
||||||
@@ -556,7 +575,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
db.getMessageStatus(transaction, contactId, groupId));
|
db.getMessageStatus(transaction, contactId, groupId));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchGroupException expected) {
|
} catch (NoSuchGroupException expected) {
|
||||||
@@ -594,11 +613,11 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Check whether the message is in the DB (which it's not)
|
// Check whether the message is in the DB (which it's not)
|
||||||
exactly(12).of(database).startTransaction();
|
exactly(15).of(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
exactly(12).of(database).containsMessage(txn, messageId);
|
exactly(15).of(database).containsMessage(txn, messageId);
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
exactly(12).of(database).abortTransaction(txn);
|
exactly(15).of(database).abortTransaction(txn);
|
||||||
// Allow other checks to pass
|
// Allow other checks to pass
|
||||||
allowing(database).containsContact(txn, contactId);
|
allowing(database).containsContact(txn, contactId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
@@ -623,7 +642,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
db.getMessage(transaction, messageId));
|
db.getMessage(transaction, messageId));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchMessageException expected) {
|
} catch (NoSuchMessageException expected) {
|
||||||
@@ -631,7 +650,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
db.getMessageMetadata(transaction, messageId));
|
db.getMessageMetadata(transaction, messageId));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchMessageException expected) {
|
} catch (NoSuchMessageException expected) {
|
||||||
@@ -639,7 +658,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
db.getMessageState(transaction, messageId));
|
db.getMessageState(transaction, messageId));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchMessageException expected) {
|
} catch (NoSuchMessageException expected) {
|
||||||
@@ -647,7 +666,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
db.getMessageStatus(transaction, contactId, messageId));
|
db.getMessageStatus(transaction, contactId, messageId));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchMessageException expected) {
|
} catch (NoSuchMessageException expected) {
|
||||||
@@ -662,6 +681,15 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
db.transaction(false, transaction ->
|
||||||
|
db.setCleanupTimerDuration(transaction, message.getId(),
|
||||||
|
HOURS.toMillis(1)));
|
||||||
|
fail();
|
||||||
|
} catch (NoSuchMessageException expected) {
|
||||||
|
// Expected
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
db.setMessagePermanent(transaction, message.getId()));
|
db.setMessagePermanent(transaction, message.getId()));
|
||||||
@@ -687,7 +715,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
db.getMessageDependencies(transaction, messageId));
|
db.getMessageDependencies(transaction, messageId));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchMessageException expected) {
|
} catch (NoSuchMessageException expected) {
|
||||||
@@ -695,12 +723,28 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(true, transaction ->
|
||||||
db.getMessageDependents(transaction, messageId));
|
db.getMessageDependents(transaction, messageId));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchMessageException expected) {
|
} catch (NoSuchMessageException expected) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
db.transaction(false, transaction ->
|
||||||
|
db.startCleanupTimer(transaction, messageId));
|
||||||
|
fail();
|
||||||
|
} catch (NoSuchMessageException expected) {
|
||||||
|
// Expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
db.transaction(false, transaction ->
|
||||||
|
db.stopCleanupTimer(transaction, messageId));
|
||||||
|
fail();
|
||||||
|
} catch (NoSuchMessageException expected) {
|
||||||
|
// Expected
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -981,6 +1025,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(database).containsVisibleMessage(txn, contactId, messageId);
|
oneOf(database).containsVisibleMessage(txn, contactId, messageId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).raiseSeenFlag(txn, contactId, messageId);
|
oneOf(database).raiseSeenFlag(txn, contactId, messageId);
|
||||||
|
will(returnValue(true));
|
||||||
|
oneOf(database).startCleanupTimer(txn, messageId);
|
||||||
|
will(returnValue(TIMER_NOT_STARTED)); // No cleanup duration was set
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
oneOf(eventBus).broadcast(with(any(MessagesAckedEvent.class)));
|
oneOf(eventBus).broadcast(with(any(MessagesAckedEvent.class)));
|
||||||
}});
|
}});
|
||||||
@@ -993,6 +1040,56 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReceiveDuplicateAck() throws Exception {
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(database).startTransaction();
|
||||||
|
will(returnValue(txn));
|
||||||
|
oneOf(database).containsContact(txn, contactId);
|
||||||
|
will(returnValue(true));
|
||||||
|
oneOf(database).containsVisibleMessage(txn, contactId, messageId);
|
||||||
|
will(returnValue(true));
|
||||||
|
oneOf(database).raiseSeenFlag(txn, contactId, messageId);
|
||||||
|
will(returnValue(false)); // Already acked
|
||||||
|
oneOf(database).commitTransaction(txn);
|
||||||
|
}});
|
||||||
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
|
db.transaction(false, transaction -> {
|
||||||
|
Ack a = new Ack(singletonList(messageId));
|
||||||
|
db.receiveAck(transaction, contactId, a);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReceiveAckWithCleanupTimer() throws Exception {
|
||||||
|
long deadline = System.currentTimeMillis();
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(database).startTransaction();
|
||||||
|
will(returnValue(txn));
|
||||||
|
oneOf(database).containsContact(txn, contactId);
|
||||||
|
will(returnValue(true));
|
||||||
|
oneOf(database).containsVisibleMessage(txn, contactId, messageId);
|
||||||
|
will(returnValue(true));
|
||||||
|
oneOf(database).raiseSeenFlag(txn, contactId, messageId);
|
||||||
|
will(returnValue(true));
|
||||||
|
oneOf(database).startCleanupTimer(txn, messageId);
|
||||||
|
will(returnValue(deadline));
|
||||||
|
oneOf(database).commitTransaction(txn);
|
||||||
|
oneOf(eventBus).broadcast(with(any(
|
||||||
|
CleanupTimerStartedEvent.class)));
|
||||||
|
oneOf(eventBus).broadcast(with(any(MessagesAckedEvent.class)));
|
||||||
|
}});
|
||||||
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
|
eventExecutor, shutdownManager);
|
||||||
|
|
||||||
|
db.transaction(false, transaction -> {
|
||||||
|
Ack a = new Ack(singletonList(messageId));
|
||||||
|
db.receiveAck(transaction, contactId, a);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReceiveMessage() throws Exception {
|
public void testReceiveMessage() throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
|
|||||||
@@ -53,10 +53,11 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Collections.emptyMap;
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
import static org.briarproject.bramble.api.db.DatabaseComponent.NO_CLEANUP_DEADLINE;
|
||||||
|
import static org.briarproject.bramble.api.db.DatabaseComponent.TIMER_NOT_STARTED;
|
||||||
import static org.briarproject.bramble.api.db.Metadata.REMOVE;
|
import static org.briarproject.bramble.api.db.Metadata.REMOVE;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||||
@@ -351,7 +352,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
assertTrue(ids.isEmpty());
|
assertTrue(ids.isEmpty());
|
||||||
|
|
||||||
// Sharing the message should make it sendable
|
// Sharing the message should make it sendable
|
||||||
db.setMessageShared(txn, messageId);
|
db.setMessageShared(txn, messageId, true);
|
||||||
ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE, MAX_LATENCY);
|
ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE, MAX_LATENCY);
|
||||||
assertEquals(singletonList(messageId), ids);
|
assertEquals(singletonList(messageId), ids);
|
||||||
ids = db.getMessagesToOffer(txn, contactId, 100, MAX_LATENCY);
|
ids = db.getMessagesToOffer(txn, contactId, 100, MAX_LATENCY);
|
||||||
@@ -631,8 +632,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
|
|
||||||
// The group should not be visible to the contact
|
// The group should not be visible to the contact
|
||||||
assertEquals(INVISIBLE, db.getGroupVisibility(txn, contactId, groupId));
|
assertEquals(INVISIBLE, db.getGroupVisibility(txn, contactId, groupId));
|
||||||
assertEquals(emptyMap(),
|
assertTrue(db.getGroupVisibility(txn, groupId).isEmpty());
|
||||||
db.getGroupVisibility(txn, groupId));
|
|
||||||
|
|
||||||
// Make the group visible to the contact
|
// Make the group visible to the contact
|
||||||
db.addGroupVisibility(txn, contactId, groupId, false);
|
db.addGroupVisibility(txn, contactId, groupId, false);
|
||||||
@@ -655,8 +655,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
// Make the group invisible again
|
// Make the group invisible again
|
||||||
db.removeGroupVisibility(txn, contactId, groupId);
|
db.removeGroupVisibility(txn, contactId, groupId);
|
||||||
assertEquals(INVISIBLE, db.getGroupVisibility(txn, contactId, groupId));
|
assertEquals(INVISIBLE, db.getGroupVisibility(txn, contactId, groupId));
|
||||||
assertEquals(emptyMap(),
|
assertTrue(db.getGroupVisibility(txn, groupId).isEmpty());
|
||||||
db.getGroupVisibility(txn, groupId));
|
|
||||||
|
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
db.close();
|
db.close();
|
||||||
@@ -2040,7 +2039,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
assertEquals(Long.MAX_VALUE, db.getNextSendTime(txn, contactId));
|
assertEquals(Long.MAX_VALUE, db.getNextSendTime(txn, contactId));
|
||||||
|
|
||||||
// Share the message - now it should be sendable immediately
|
// Share the message - now it should be sendable immediately
|
||||||
db.setMessageShared(txn, messageId);
|
db.setMessageShared(txn, messageId, true);
|
||||||
assertEquals(0, db.getNextSendTime(txn, contactId));
|
assertEquals(0, db.getNextSendTime(txn, contactId));
|
||||||
|
|
||||||
// Mark the message as requested - it should still be sendable
|
// Mark the message as requested - it should still be sendable
|
||||||
@@ -2347,6 +2346,87 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCleanupTimer() throws Exception {
|
||||||
|
long duration = 60_000;
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
AtomicLong time = new AtomicLong(now);
|
||||||
|
Database<Connection> db =
|
||||||
|
open(false, new TestMessageFactory(), new SettableClock(time));
|
||||||
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
|
// No messages should be due or scheduled for deletion
|
||||||
|
assertTrue(db.getMessagesToDelete(txn).isEmpty());
|
||||||
|
assertEquals(NO_CLEANUP_DEADLINE, db.getNextCleanupDeadline(txn));
|
||||||
|
|
||||||
|
// Add a group and a message
|
||||||
|
db.addGroup(txn, group);
|
||||||
|
db.addMessage(txn, message, DELIVERED, false, false, null);
|
||||||
|
|
||||||
|
// No messages should be due or scheduled for deletion
|
||||||
|
assertTrue(db.getMessagesToDelete(txn).isEmpty());
|
||||||
|
assertEquals(NO_CLEANUP_DEADLINE, db.getNextCleanupDeadline(txn));
|
||||||
|
|
||||||
|
// Set the message's cleanup timer duration
|
||||||
|
db.setCleanupTimerDuration(txn, messageId, duration);
|
||||||
|
|
||||||
|
// No messages should be due or scheduled for deletion
|
||||||
|
assertTrue(db.getMessagesToDelete(txn).isEmpty());
|
||||||
|
assertEquals(NO_CLEANUP_DEADLINE, db.getNextCleanupDeadline(txn));
|
||||||
|
|
||||||
|
// Start the message's cleanup timer
|
||||||
|
assertEquals(now + duration, db.startCleanupTimer(txn, messageId));
|
||||||
|
|
||||||
|
// The timer can't be started again
|
||||||
|
assertEquals(TIMER_NOT_STARTED, db.startCleanupTimer(txn, messageId));
|
||||||
|
|
||||||
|
// No messages should be due for deletion, but the message should be
|
||||||
|
// scheduled for deletion
|
||||||
|
assertTrue(db.getMessagesToDelete(txn).isEmpty());
|
||||||
|
assertEquals(now + duration, db.getNextCleanupDeadline(txn));
|
||||||
|
|
||||||
|
// Stop the timer
|
||||||
|
db.stopCleanupTimer(txn, messageId);
|
||||||
|
|
||||||
|
// No messages should be due or scheduled for deletion
|
||||||
|
assertTrue(db.getMessagesToDelete(txn).isEmpty());
|
||||||
|
assertEquals(NO_CLEANUP_DEADLINE, db.getNextCleanupDeadline(txn));
|
||||||
|
|
||||||
|
// Start the timer again
|
||||||
|
assertEquals(now + duration, db.startCleanupTimer(txn, messageId));
|
||||||
|
|
||||||
|
// No messages should be due for deletion, but the message should be
|
||||||
|
// scheduled for deletion
|
||||||
|
assertTrue(db.getMessagesToDelete(txn).isEmpty());
|
||||||
|
assertEquals(now + duration, db.getNextCleanupDeadline(txn));
|
||||||
|
|
||||||
|
// 1 ms before the timer expires, no messages should be due for
|
||||||
|
// deletion but the message should be scheduled for deletion
|
||||||
|
time.set(now + duration - 1);
|
||||||
|
assertTrue(db.getMessagesToDelete(txn).isEmpty());
|
||||||
|
assertEquals(now + duration, db.getNextCleanupDeadline(txn));
|
||||||
|
|
||||||
|
// When the timer expires, the message should be due and scheduled for
|
||||||
|
// deletion
|
||||||
|
time.set(now + duration);
|
||||||
|
assertEquals(singletonMap(groupId, singletonList(messageId)),
|
||||||
|
db.getMessagesToDelete(txn));
|
||||||
|
assertEquals(now + duration, db.getNextCleanupDeadline(txn));
|
||||||
|
|
||||||
|
// 1 ms after the timer expires, the message should be due and
|
||||||
|
// scheduled for deletion
|
||||||
|
time.set(now + duration + 1);
|
||||||
|
assertEquals(singletonMap(groupId, singletonList(messageId)),
|
||||||
|
db.getMessagesToDelete(txn));
|
||||||
|
assertEquals(now + duration, db.getNextCleanupDeadline(txn));
|
||||||
|
|
||||||
|
// Once the message has been deleted, it should no longer be due
|
||||||
|
// or scheduled for deletion
|
||||||
|
db.deleteMessage(txn, messageId);
|
||||||
|
assertTrue(db.getMessagesToDelete(txn).isEmpty());
|
||||||
|
assertEquals(NO_CLEANUP_DEADLINE, db.getNextCleanupDeadline(txn));
|
||||||
|
}
|
||||||
|
|
||||||
private Database<Connection> open(boolean resume) throws Exception {
|
private Database<Connection> open(boolean resume) throws Exception {
|
||||||
return open(resume, new TestMessageFactory(), new SystemClock());
|
return open(resume, new TestMessageFactory(), new SystemClock());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.PriorityBlockingQueue;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link TaskScheduler} for use in tests. The scheduler keeps all scheduled
|
||||||
|
* tasks in a queue until {@link #runTasks()} is called.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
class TestTaskScheduler implements TaskScheduler {
|
||||||
|
|
||||||
|
private final Queue<Task> queue = new PriorityBlockingQueue<>();
|
||||||
|
private final Clock clock;
|
||||||
|
|
||||||
|
TestTaskScheduler(Clock clock) {
|
||||||
|
this.clock = clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cancellable schedule(Runnable task, Executor executor, long delay,
|
||||||
|
TimeUnit unit) {
|
||||||
|
AtomicBoolean cancelled = new AtomicBoolean(false);
|
||||||
|
return schedule(task, executor, delay, unit, cancelled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cancellable scheduleWithFixedDelay(Runnable task, Executor executor,
|
||||||
|
long delay, long interval, TimeUnit unit) {
|
||||||
|
AtomicBoolean cancelled = new AtomicBoolean(false);
|
||||||
|
return scheduleWithFixedDelay(task, executor, delay, interval, unit,
|
||||||
|
cancelled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Cancellable schedule(Runnable task, Executor executor, long delay,
|
||||||
|
TimeUnit unit, AtomicBoolean cancelled) {
|
||||||
|
long delayMillis = MILLISECONDS.convert(delay, unit);
|
||||||
|
long dueMillis = clock.currentTimeMillis() + delayMillis;
|
||||||
|
Task t = new Task(task, executor, dueMillis, cancelled);
|
||||||
|
queue.add(t);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Cancellable scheduleWithFixedDelay(Runnable task, Executor executor,
|
||||||
|
long delay, long interval, TimeUnit unit, AtomicBoolean cancelled) {
|
||||||
|
// All executions of this periodic task share a cancelled flag
|
||||||
|
Runnable wrapped = () -> {
|
||||||
|
task.run();
|
||||||
|
scheduleWithFixedDelay(task, executor, interval, interval, unit,
|
||||||
|
cancelled);
|
||||||
|
};
|
||||||
|
return schedule(wrapped, executor, delay, unit, cancelled);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs any scheduled tasks that are due.
|
||||||
|
*/
|
||||||
|
void runTasks() throws InterruptedException {
|
||||||
|
long now = clock.currentTimeMillis();
|
||||||
|
while (true) {
|
||||||
|
Task t = queue.peek();
|
||||||
|
if (t == null || t.dueMillis > now) return;
|
||||||
|
t = queue.poll();
|
||||||
|
// Submit the task to its executor and wait for it to finish
|
||||||
|
if (!t.run().await(1, MINUTES)) fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Task
|
||||||
|
implements Cancellable, Comparable<Task> {
|
||||||
|
|
||||||
|
private final Runnable task;
|
||||||
|
private final Executor executor;
|
||||||
|
private final long dueMillis;
|
||||||
|
private final AtomicBoolean cancelled;
|
||||||
|
|
||||||
|
private Task(Runnable task, Executor executor, long dueMillis,
|
||||||
|
AtomicBoolean cancelled) {
|
||||||
|
this.task = task;
|
||||||
|
this.executor = executor;
|
||||||
|
this.dueMillis = dueMillis;
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UseCompareMethod") // Animal Sniffer
|
||||||
|
@Override
|
||||||
|
public int compareTo(Task task) {
|
||||||
|
return Long.valueOf(dueMillis).compareTo(task.dueMillis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submits the task to its executor and returns a latch that will be
|
||||||
|
* released when the task finishes.
|
||||||
|
*/
|
||||||
|
public CountDownLatch run() {
|
||||||
|
if (cancelled.get()) return new CountDownLatch(0);
|
||||||
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
executor.execute(() -> {
|
||||||
|
task.run();
|
||||||
|
latch.countDown();
|
||||||
|
});
|
||||||
|
return latch;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancel() {
|
||||||
|
cancelled.set(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.test.SettableClock;
|
||||||
|
import org.briarproject.bramble.test.TimeTravel;
|
||||||
|
|
||||||
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class TimeTravelModule {
|
||||||
|
|
||||||
|
public static class EagerSingletons {
|
||||||
|
@Inject
|
||||||
|
TaskScheduler scheduler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ScheduledExecutorService scheduledExecutorService;
|
||||||
|
private final Clock clock;
|
||||||
|
private final TaskScheduler taskScheduler;
|
||||||
|
private final TimeTravel timeTravel;
|
||||||
|
|
||||||
|
public TimeTravelModule() {
|
||||||
|
this(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeTravelModule(boolean travel) {
|
||||||
|
// Discard tasks that are submitted during shutdown
|
||||||
|
RejectedExecutionHandler policy =
|
||||||
|
new ScheduledThreadPoolExecutor.DiscardPolicy();
|
||||||
|
scheduledExecutorService =
|
||||||
|
new ScheduledThreadPoolExecutor(1, policy);
|
||||||
|
if (travel) {
|
||||||
|
// Use a SettableClock and TestTaskScheduler to allow time travel
|
||||||
|
AtomicLong time = new AtomicLong(System.currentTimeMillis());
|
||||||
|
clock = new SettableClock(time);
|
||||||
|
TestTaskScheduler testTaskScheduler = new TestTaskScheduler(clock);
|
||||||
|
taskScheduler = testTaskScheduler;
|
||||||
|
timeTravel = new TimeTravel() {
|
||||||
|
@Override
|
||||||
|
public void setCurrentTimeMillis(long now)
|
||||||
|
throws InterruptedException {
|
||||||
|
time.set(now);
|
||||||
|
testTaskScheduler.runTasks();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCurrentTimeMillis(long add)
|
||||||
|
throws InterruptedException {
|
||||||
|
time.addAndGet(add);
|
||||||
|
testTaskScheduler.runTasks();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// Use the default clock and task scheduler
|
||||||
|
clock = new SystemClock();
|
||||||
|
taskScheduler = new TaskSchedulerImpl(scheduledExecutorService);
|
||||||
|
timeTravel = new TimeTravel() {
|
||||||
|
@Override
|
||||||
|
public void setCurrentTimeMillis(long now) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCurrentTimeMillis(long add) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
Clock provideClock() {
|
||||||
|
return clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
TaskScheduler provideTaskScheduler(LifecycleManager lifecycleManager) {
|
||||||
|
lifecycleManager.registerForShutdown(scheduledExecutorService);
|
||||||
|
return taskScheduler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
TimeTravel provideTimeTravel() {
|
||||||
|
return timeTravel;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,8 @@ package org.briarproject.bramble.test;
|
|||||||
import org.briarproject.bramble.api.FeatureFlags;
|
import org.briarproject.bramble.api.FeatureFlags;
|
||||||
import org.briarproject.bramble.battery.DefaultBatteryManagerModule;
|
import org.briarproject.bramble.battery.DefaultBatteryManagerModule;
|
||||||
import org.briarproject.bramble.event.DefaultEventExecutorModule;
|
import org.briarproject.bramble.event.DefaultEventExecutorModule;
|
||||||
import org.briarproject.bramble.system.DefaultTaskSchedulerModule;
|
|
||||||
import org.briarproject.bramble.system.DefaultWakefulIoExecutorModule;
|
import org.briarproject.bramble.system.DefaultWakefulIoExecutorModule;
|
||||||
|
import org.briarproject.bramble.system.TimeTravelModule;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
@@ -12,11 +12,11 @@ import dagger.Provides;
|
|||||||
@Module(includes = {
|
@Module(includes = {
|
||||||
DefaultBatteryManagerModule.class,
|
DefaultBatteryManagerModule.class,
|
||||||
DefaultEventExecutorModule.class,
|
DefaultEventExecutorModule.class,
|
||||||
DefaultTaskSchedulerModule.class,
|
|
||||||
DefaultWakefulIoExecutorModule.class,
|
DefaultWakefulIoExecutorModule.class,
|
||||||
TestDatabaseConfigModule.class,
|
TestDatabaseConfigModule.class,
|
||||||
TestPluginConfigModule.class,
|
TestPluginConfigModule.class,
|
||||||
TestSecureRandomModule.class
|
TestSecureRandomModule.class,
|
||||||
|
TimeTravelModule.class
|
||||||
})
|
})
|
||||||
public class BrambleCoreIntegrationTestModule {
|
public class BrambleCoreIntegrationTestModule {
|
||||||
|
|
||||||
@@ -33,6 +33,11 @@ public class BrambleCoreIntegrationTestModule {
|
|||||||
public boolean shouldEnableProfilePictures() {
|
public boolean shouldEnableProfilePictures() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldEnableDisappearingMessages() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import static org.briarproject.bramble.test.TestUtils.getContact;
|
|||||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.GROUP_KEY_CONTACT_ID;
|
|
||||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
||||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -60,8 +59,6 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final ClientId clientId = getClientId();
|
private final ClientId clientId = getClientId();
|
||||||
private final long now = System.currentTimeMillis();
|
private final long now = System.currentTimeMillis();
|
||||||
private final Transaction txn = new Transaction(null, false);
|
private final Transaction txn = new Transaction(null, false);
|
||||||
private final BdfDictionary groupMeta = BdfDictionary.of(
|
|
||||||
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
|
||||||
|
|
||||||
private ClientVersioningManagerImpl createInstance() {
|
private ClientVersioningManagerImpl createInstance() {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -123,8 +120,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(db).addGroup(txn, contactGroup);
|
oneOf(db).addGroup(txn, contactGroup);
|
||||||
oneOf(db).setGroupVisibility(txn, contact.getId(),
|
oneOf(db).setGroupVisibility(txn, contact.getId(),
|
||||||
contactGroup.getId(), SHARED);
|
contactGroup.getId(), SHARED);
|
||||||
oneOf(clientHelper).mergeGroupMetadata(txn, contactGroup.getId(),
|
oneOf(clientHelper).setContactId(txn, contactGroup.getId(),
|
||||||
groupMeta);
|
contact.getId());
|
||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(clientHelper).createMessage(contactGroup.getId(), now,
|
oneOf(clientHelper).createMessage(contactGroup.getId(), now,
|
||||||
@@ -460,9 +457,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(db).deleteMessage(txn, oldRemoteUpdateId);
|
oneOf(db).deleteMessage(txn, oldRemoteUpdateId);
|
||||||
oneOf(db).deleteMessageMetadata(txn, oldRemoteUpdateId);
|
oneOf(db).deleteMessageMetadata(txn, oldRemoteUpdateId);
|
||||||
// Get contact ID
|
// Get contact ID
|
||||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||||
contactGroup.getId());
|
will(returnValue(contact.getId()));
|
||||||
will(returnValue(groupMeta));
|
|
||||||
// No states or visibilities have changed
|
// No states or visibilities have changed
|
||||||
}});
|
}});
|
||||||
|
|
||||||
@@ -492,10 +488,9 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
// Load the latest local update
|
// Load the latest local update
|
||||||
oneOf(clientHelper).getMessageAsList(txn, oldLocalUpdateId);
|
oneOf(clientHelper).getMessageAsList(txn, oldLocalUpdateId);
|
||||||
will(returnValue(oldLocalUpdateBody));
|
will(returnValue(oldLocalUpdateBody));
|
||||||
// Get client ID
|
// Get contact ID
|
||||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||||
contactGroup.getId());
|
will(returnValue(contact.getId()));
|
||||||
will(returnValue(groupMeta));
|
|
||||||
// No states or visibilities have changed
|
// No states or visibilities have changed
|
||||||
}});
|
}});
|
||||||
|
|
||||||
@@ -546,8 +541,6 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
||||||
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
||||||
new BdfEntry(MSG_KEY_LOCAL, true));
|
new BdfEntry(MSG_KEY_LOCAL, true));
|
||||||
BdfDictionary groupMeta = BdfDictionary.of(
|
|
||||||
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(clientHelper).toList(newRemoteUpdate);
|
oneOf(clientHelper).toList(newRemoteUpdate);
|
||||||
@@ -577,9 +570,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
||||||
newLocalUpdateMeta, true, false);
|
newLocalUpdateMeta, true, false);
|
||||||
// The client's visibility has changed
|
// The client's visibility has changed
|
||||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||||
contactGroup.getId());
|
will(returnValue(contact.getId()));
|
||||||
will(returnValue(groupMeta));
|
|
||||||
oneOf(db).getContact(txn, contact.getId());
|
oneOf(db).getContact(txn, contact.getId());
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(hook).onClientVisibilityChanging(txn, contact, visibility);
|
oneOf(hook).onClientVisibilityChanging(txn, contact, visibility);
|
||||||
@@ -619,8 +611,6 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
||||||
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
||||||
new BdfEntry(MSG_KEY_LOCAL, true));
|
new BdfEntry(MSG_KEY_LOCAL, true));
|
||||||
BdfDictionary groupMeta = BdfDictionary.of(
|
|
||||||
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(clientHelper).toList(newRemoteUpdate);
|
oneOf(clientHelper).toList(newRemoteUpdate);
|
||||||
@@ -650,9 +640,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
||||||
newLocalUpdateMeta, true, false);
|
newLocalUpdateMeta, true, false);
|
||||||
// The client's visibility has changed
|
// The client's visibility has changed
|
||||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||||
contactGroup.getId());
|
will(returnValue(contact.getId()));
|
||||||
will(returnValue(groupMeta));
|
|
||||||
oneOf(db).getContact(txn, contact.getId());
|
oneOf(db).getContact(txn, contact.getId());
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(hook).onClientVisibilityChanging(txn, contact, INVISIBLE);
|
oneOf(hook).onClientVisibilityChanging(txn, contact, INVISIBLE);
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import org.briarproject.bramble.system.JavaSystemModule;
|
|||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
|
|
||||||
@Module(includes = {
|
@Module(includes = {
|
||||||
|
CircumventionModule.class,
|
||||||
JavaNetworkModule.class,
|
JavaNetworkModule.class,
|
||||||
JavaSystemModule.class,
|
JavaSystemModule.class,
|
||||||
CircumventionModule.class,
|
|
||||||
SocksModule.class
|
SocksModule.class
|
||||||
})
|
})
|
||||||
public class BrambleJavaModule {
|
public class BrambleJavaModule {
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 10214
|
versionCode 10216
|
||||||
versionName "1.2.14"
|
versionName "1.2.16"
|
||||||
applicationId "org.briarproject.briar.android"
|
applicationId "org.briarproject.briar.android"
|
||||||
|
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
@@ -95,6 +95,7 @@ dependencies {
|
|||||||
implementation project(path: ':bramble-core', configuration: 'default')
|
implementation project(path: ':bramble-core', configuration: 'default')
|
||||||
implementation project(':bramble-android')
|
implementation project(':bramble-android')
|
||||||
|
|
||||||
|
implementation 'androidx.fragment:fragment:1.3.0'
|
||||||
implementation 'androidx.preference:preference:1.1.1'
|
implementation 'androidx.preference:preference:1.1.1'
|
||||||
implementation 'androidx.exifinterface:exifinterface:1.3.1'
|
implementation 'androidx.exifinterface:exifinterface:1.3.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.android;
|
|||||||
import org.briarproject.bramble.BrambleAndroidModule;
|
import org.briarproject.bramble.BrambleAndroidModule;
|
||||||
import org.briarproject.bramble.BrambleCoreModule;
|
import org.briarproject.bramble.BrambleCoreModule;
|
||||||
import org.briarproject.bramble.account.BriarAccountModule;
|
import org.briarproject.bramble.account.BriarAccountModule;
|
||||||
|
import org.briarproject.bramble.system.ClockModule;
|
||||||
import org.briarproject.briar.BriarCoreModule;
|
import org.briarproject.briar.BriarCoreModule;
|
||||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||||
import org.briarproject.briar.android.attachment.media.MediaModule;
|
import org.briarproject.briar.android.attachment.media.MediaModule;
|
||||||
@@ -16,6 +17,7 @@ import dagger.Component;
|
|||||||
@Component(modules = {
|
@Component(modules = {
|
||||||
AppModule.class,
|
AppModule.class,
|
||||||
AttachmentModule.class,
|
AttachmentModule.class,
|
||||||
|
ClockModule.class,
|
||||||
MediaModule.class,
|
MediaModule.class,
|
||||||
BriarCoreModule.class,
|
BriarCoreModule.class,
|
||||||
BrambleAndroidModule.class,
|
BrambleAndroidModule.class,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.android;
|
|||||||
import org.briarproject.bramble.BrambleAndroidModule;
|
import org.briarproject.bramble.BrambleAndroidModule;
|
||||||
import org.briarproject.bramble.BrambleCoreModule;
|
import org.briarproject.bramble.BrambleCoreModule;
|
||||||
import org.briarproject.bramble.account.BriarAccountModule;
|
import org.briarproject.bramble.account.BriarAccountModule;
|
||||||
|
import org.briarproject.bramble.system.ClockModule;
|
||||||
import org.briarproject.briar.BriarCoreModule;
|
import org.briarproject.briar.BriarCoreModule;
|
||||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||||
import org.briarproject.briar.android.attachment.media.MediaModule;
|
import org.briarproject.briar.android.attachment.media.MediaModule;
|
||||||
@@ -17,6 +18,7 @@ import dagger.Component;
|
|||||||
@Component(modules = {
|
@Component(modules = {
|
||||||
AppModule.class,
|
AppModule.class,
|
||||||
AttachmentModule.class,
|
AttachmentModule.class,
|
||||||
|
ClockModule.class,
|
||||||
MediaModule.class,
|
MediaModule.class,
|
||||||
BriarCoreModule.class,
|
BriarCoreModule.class,
|
||||||
BrambleAndroidModule.class,
|
BrambleAndroidModule.class,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.briarproject.bramble.api.system.AndroidWakeLockManager;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
||||||
|
import org.briarproject.bramble.system.ClockModule;
|
||||||
import org.briarproject.briar.BriarCoreEagerSingletons;
|
import org.briarproject.briar.BriarCoreEagerSingletons;
|
||||||
import org.briarproject.briar.BriarCoreModule;
|
import org.briarproject.briar.BriarCoreModule;
|
||||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||||
@@ -42,6 +43,7 @@ import org.briarproject.briar.api.android.DozeWatchdog;
|
|||||||
import org.briarproject.briar.api.android.LockManager;
|
import org.briarproject.briar.api.android.LockManager;
|
||||||
import org.briarproject.briar.api.android.ScreenFilterMonitor;
|
import org.briarproject.briar.api.android.ScreenFilterMonitor;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentReader;
|
import org.briarproject.briar.api.attachment.AttachmentReader;
|
||||||
|
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
||||||
import org.briarproject.briar.api.blog.BlogManager;
|
import org.briarproject.briar.api.blog.BlogManager;
|
||||||
import org.briarproject.briar.api.blog.BlogPostFactory;
|
import org.briarproject.briar.api.blog.BlogPostFactory;
|
||||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||||
@@ -76,6 +78,7 @@ import dagger.Component;
|
|||||||
BriarAccountModule.class,
|
BriarAccountModule.class,
|
||||||
AppModule.class,
|
AppModule.class,
|
||||||
AttachmentModule.class,
|
AttachmentModule.class,
|
||||||
|
ClockModule.class,
|
||||||
MediaModule.class
|
MediaModule.class
|
||||||
})
|
})
|
||||||
public interface AndroidComponent
|
public interface AndroidComponent
|
||||||
@@ -184,6 +187,8 @@ public interface AndroidComponent
|
|||||||
|
|
||||||
Thread.UncaughtExceptionHandler exceptionHandler();
|
Thread.UncaughtExceptionHandler exceptionHandler();
|
||||||
|
|
||||||
|
AutoDeleteManager autoDeleteManager();
|
||||||
|
|
||||||
void inject(SignInReminderReceiver briarService);
|
void inject(SignInReminderReceiver briarService);
|
||||||
|
|
||||||
void inject(BriarService briarService);
|
void inject(BriarService briarService);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import org.briarproject.briar.android.splash.SplashScreenActivity;
|
|||||||
import org.briarproject.briar.android.util.BriarNotificationBuilder;
|
import org.briarproject.briar.android.util.BriarNotificationBuilder;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
|
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationResponse;
|
||||||
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
|
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
|
||||||
import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
|
import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
|
||||||
import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
|
import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
|
||||||
@@ -226,6 +227,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
} else if (e instanceof ConversationMessageReceivedEvent) {
|
} else if (e instanceof ConversationMessageReceivedEvent) {
|
||||||
ConversationMessageReceivedEvent<?> p =
|
ConversationMessageReceivedEvent<?> p =
|
||||||
(ConversationMessageReceivedEvent<?>) e;
|
(ConversationMessageReceivedEvent<?>) e;
|
||||||
|
if (p.getMessageHeader() instanceof ConversationResponse) {
|
||||||
|
ConversationResponse r =
|
||||||
|
(ConversationResponse) p.getMessageHeader();
|
||||||
|
// don't show notification for own auto-decline responses
|
||||||
|
if (r.isAutoDecline()) return;
|
||||||
|
}
|
||||||
showContactNotification(p.getContactId());
|
showContactNotification(p.getContactId());
|
||||||
} else if (e instanceof GroupMessageAddedEvent) {
|
} else if (e instanceof GroupMessageAddedEvent) {
|
||||||
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
||||||
|
|||||||
@@ -283,6 +283,11 @@ public class AppModule {
|
|||||||
public boolean shouldEnableProfilePictures() {
|
public boolean shouldEnableProfilePictures() {
|
||||||
return IS_DEBUG_BUILD;
|
return IS_DEBUG_BUILD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldEnableDisappearingMessages() {
|
||||||
|
return IS_DEBUG_BUILD;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import javax.inject.Inject;
|
|||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
|
|
||||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||||
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
||||||
import static android.content.Intent.ACTION_SHUTDOWN;
|
import static android.content.Intent.ACTION_SHUTDOWN;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
||||||
@@ -46,6 +46,7 @@ import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
|
|||||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
import static android.os.Process.myPid;
|
||||||
import static androidx.core.app.NotificationCompat.VISIBILITY_SECRET;
|
import static androidx.core.app.NotificationCompat.VISIBILITY_SECRET;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
@@ -56,8 +57,10 @@ import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
|||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID;
|
||||||
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_OLD_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_NOTIFICATION_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_NOTIFICATION_ID;
|
||||||
import static org.briarproject.briar.api.android.LockManager.ACTION_LOCK;
|
import static org.briarproject.briar.api.android.LockManager.ACTION_LOCK;
|
||||||
|
import static org.briarproject.briar.api.android.LockManager.EXTRA_PID;
|
||||||
|
|
||||||
public class BriarService extends Service {
|
public class BriarService extends Service {
|
||||||
|
|
||||||
@@ -120,11 +123,17 @@ public class BriarService extends Service {
|
|||||||
if (SDK_INT >= 26) {
|
if (SDK_INT >= 26) {
|
||||||
NotificationManager nm = (NotificationManager)
|
NotificationManager nm = (NotificationManager)
|
||||||
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
||||||
|
// Delete the old notification channel, which had
|
||||||
|
// IMPORTANCE_NONE and showed a badge
|
||||||
|
nm.deleteNotificationChannel(ONGOING_CHANNEL_OLD_ID);
|
||||||
|
// Use IMPORTANCE_LOW so the system doesn't show its own
|
||||||
|
// notification on API 26-27
|
||||||
NotificationChannel ongoingChannel = new NotificationChannel(
|
NotificationChannel ongoingChannel = new NotificationChannel(
|
||||||
ONGOING_CHANNEL_ID,
|
ONGOING_CHANNEL_ID,
|
||||||
getString(R.string.ongoing_notification_title),
|
getString(R.string.ongoing_notification_title),
|
||||||
IMPORTANCE_NONE);
|
IMPORTANCE_LOW);
|
||||||
ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||||
|
ongoingChannel.setShowBadge(false);
|
||||||
nm.createNotificationChannel(ongoingChannel);
|
nm.createNotificationChannel(ongoingChannel);
|
||||||
NotificationChannel failureChannel = new NotificationChannel(
|
NotificationChannel failureChannel = new NotificationChannel(
|
||||||
FAILURE_CHANNEL_ID,
|
FAILURE_CHANNEL_ID,
|
||||||
@@ -203,7 +212,12 @@ public class BriarService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (ACTION_LOCK.equals(intent.getAction())) {
|
if (ACTION_LOCK.equals(intent.getAction())) {
|
||||||
lockManager.setLocked(true);
|
int pid = intent.getIntExtra(EXTRA_PID, -1);
|
||||||
|
if (pid == myPid()) lockManager.setLocked(true);
|
||||||
|
else if (LOG.isLoggable(WARNING)) {
|
||||||
|
LOG.warning("Tried to lock process " + pid + " but this is " +
|
||||||
|
myPid());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return START_NOT_STICKY; // Don't restart automatically if killed
|
return START_NOT_STICKY; // Don't restart automatically if killed
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ import androidx.lifecycle.LiveData;
|
|||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import static android.app.AlarmManager.ELAPSED_REALTIME;
|
import static android.app.AlarmManager.ELAPSED_REALTIME;
|
||||||
|
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
||||||
import static android.app.PendingIntent.getService;
|
import static android.app.PendingIntent.getService;
|
||||||
import static android.content.Context.ALARM_SERVICE;
|
import static android.content.Context.ALARM_SERVICE;
|
||||||
|
import static android.os.Process.myPid;
|
||||||
import static android.os.SystemClock.elapsedRealtime;
|
import static android.os.SystemClock.elapsedRealtime;
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
@@ -75,23 +77,25 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
|||||||
LockManagerImpl(Application app, SettingsManager settingsManager,
|
LockManagerImpl(Application app, SettingsManager settingsManager,
|
||||||
AndroidNotificationManager notificationManager,
|
AndroidNotificationManager notificationManager,
|
||||||
@DatabaseExecutor Executor dbExecutor) {
|
@DatabaseExecutor Executor dbExecutor) {
|
||||||
this.appContext = app.getApplicationContext();
|
appContext = app.getApplicationContext();
|
||||||
this.settingsManager = settingsManager;
|
this.settingsManager = settingsManager;
|
||||||
this.notificationManager = notificationManager;
|
this.notificationManager = notificationManager;
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
this.alarmManager =
|
alarmManager =
|
||||||
(AlarmManager) appContext.getSystemService(ALARM_SERVICE);
|
(AlarmManager) appContext.getSystemService(ALARM_SERVICE);
|
||||||
Intent i =
|
Intent i =
|
||||||
new Intent(ACTION_LOCK, null, appContext, BriarService.class);
|
new Intent(ACTION_LOCK, null, appContext, BriarService.class);
|
||||||
this.lockIntent = getService(appContext, 0, i, 0);
|
i.putExtra(EXTRA_PID, myPid());
|
||||||
this.timeoutNever = Integer.valueOf(
|
// When not using FLAG_UPDATE_CURRENT, the intent might have no extras
|
||||||
|
lockIntent = getService(appContext, 0, i, FLAG_UPDATE_CURRENT);
|
||||||
|
timeoutNever = Integer.parseInt(
|
||||||
appContext.getString(R.string.pref_lock_timeout_value_never));
|
appContext.getString(R.string.pref_lock_timeout_value_never));
|
||||||
this.timeoutDefault = Integer.valueOf(
|
timeoutDefault = Integer.parseInt(
|
||||||
appContext.getString(R.string.pref_lock_timeout_value_default));
|
appContext.getString(R.string.pref_lock_timeout_value_default));
|
||||||
this.timeoutMinutes = timeoutNever;
|
timeoutMinutes = timeoutNever;
|
||||||
|
|
||||||
// setting this in the constructor makes #getValue() @NonNull
|
// setting this in the constructor makes #getValue() @NonNull
|
||||||
this.lockable.setValue(false);
|
lockable.setValue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -148,7 +152,7 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
|||||||
boolean oldValue = lockable.getValue();
|
boolean oldValue = lockable.getValue();
|
||||||
boolean newValue = hasScreenLock(appContext) && lockableSetting;
|
boolean newValue = hasScreenLock(appContext) && lockableSetting;
|
||||||
if (oldValue != newValue) {
|
if (oldValue != newValue) {
|
||||||
this.lockable.setValue(newValue);
|
lockable.setValue(newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class UnlockActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode,
|
protected void onActivityResult(int requestCode, int resultCode,
|
||||||
Intent data) {
|
@Nullable Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if (requestCode == REQUEST_KEYGUARD_UNLOCK) {
|
if (requestCode == REQUEST_KEYGUARD_UNLOCK) {
|
||||||
if (resultCode == RESULT_OK) unlock();
|
if (resultCode == RESULT_OK) unlock();
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.briarproject.briar.android.contact.add.remote.NicknameFragment;
|
|||||||
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
||||||
import org.briarproject.briar.android.conversation.AliasDialogFragment;
|
import org.briarproject.briar.android.conversation.AliasDialogFragment;
|
||||||
import org.briarproject.briar.android.conversation.ConversationActivity;
|
import org.briarproject.briar.android.conversation.ConversationActivity;
|
||||||
|
import org.briarproject.briar.android.conversation.ConversationSettingsDialog;
|
||||||
import org.briarproject.briar.android.conversation.ImageActivity;
|
import org.briarproject.briar.android.conversation.ImageActivity;
|
||||||
import org.briarproject.briar.android.conversation.ImageFragment;
|
import org.briarproject.briar.android.conversation.ImageFragment;
|
||||||
import org.briarproject.briar.android.forum.CreateForumActivity;
|
import org.briarproject.briar.android.forum.CreateForumActivity;
|
||||||
@@ -238,4 +239,6 @@ public interface ActivityComponent {
|
|||||||
|
|
||||||
void inject(ConfirmAvatarDialogFragment fragment);
|
void inject(ConfirmAvatarDialogFragment fragment);
|
||||||
|
|
||||||
|
void inject(ConversationSettingsDialog dialog);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
|||||||
import org.briarproject.briar.android.view.TextInputView;
|
import org.briarproject.briar.android.view.TextInputView;
|
||||||
import org.briarproject.briar.android.view.TextSendController;
|
import org.briarproject.briar.android.view.TextSendController;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
||||||
|
import org.briarproject.briar.android.view.TextSendController.SendState;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -27,6 +28,9 @@ import java.util.List;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import static android.view.View.FOCUS_DOWN;
|
import static android.view.View.FOCUS_DOWN;
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.INVISIBLE;
|
import static android.view.View.INVISIBLE;
|
||||||
@@ -34,6 +38,7 @@ import static android.view.View.VISIBLE;
|
|||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
||||||
import static org.briarproject.briar.android.blog.BasePostFragment.POST_ID;
|
import static org.briarproject.briar.android.blog.BasePostFragment.POST_ID;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -121,8 +126,8 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendClick(@Nullable String text,
|
public LiveData<SendState> onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers) {
|
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
||||||
ui.input.hideSoftKeyboard();
|
ui.input.hideSoftKeyboard();
|
||||||
feedController.repeatPost(item, text,
|
feedController.repeatPost(item, text,
|
||||||
new UiExceptionHandler<DbException>(this) {
|
new UiExceptionHandler<DbException>(this) {
|
||||||
@@ -132,6 +137,7 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
finish();
|
finish();
|
||||||
|
return new MutableLiveData<>(SENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showProgressBar() {
|
private void showProgressBar() {
|
||||||
|
|||||||
@@ -31,12 +31,16 @@ import java.util.logging.Logger;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -112,8 +116,8 @@ public class WriteBlogPostActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendClick(@Nullable String text,
|
public LiveData<SendState> onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers) {
|
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
||||||
if (isNullOrEmpty(text)) throw new AssertionError();
|
if (isNullOrEmpty(text)) throw new AssertionError();
|
||||||
|
|
||||||
// hide publish button, show progress bar
|
// hide publish button, show progress bar
|
||||||
@@ -122,6 +126,7 @@ public class WriteBlogPostActivity extends BriarActivity
|
|||||||
progressBar.setVisibility(VISIBLE);
|
progressBar.setVisibility(VISIBLE);
|
||||||
|
|
||||||
storePost(text);
|
storePost(text);
|
||||||
|
return new MutableLiveData<>(SENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storePost(String text) {
|
private void storePost(String text) {
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
|||||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDial.OnMenuItemClickListener;
|
import io.github.kobakei.materialfabspeeddial.FabSpeedDial.OnMenuItemClickListener;
|
||||||
|
|
||||||
import static com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_INDEFINITE;
|
import static com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_INDEFINITE;
|
||||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
|
||||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -102,7 +101,8 @@ public class ContactListFragment extends BaseFragment
|
|||||||
.observe(getViewLifecycleOwner(), result -> {
|
.observe(getViewLifecycleOwner(), result -> {
|
||||||
result.onError(this::handleException).onSuccess(items -> {
|
result.onError(this::handleException).onSuccess(items -> {
|
||||||
adapter.submitList(items);
|
adapter.submitList(items);
|
||||||
if (requireNonNull(items).size() == 0) list.showData();
|
// TODO remove when BriarRecyclerView was adapted
|
||||||
|
list.showData();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
viewModel.getHasPendingContacts()
|
viewModel.getHasPendingContacts()
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ import static org.briarproject.briar.android.util.UiUtils.showSoftKeyboard;
|
|||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
|
// TODO: we can probably switch to androidx DialogFragment here but need to
|
||||||
|
// test this properly
|
||||||
public class AliasDialogFragment extends AppCompatDialogFragment {
|
public class AliasDialogFragment extends AppCompatDialogFragment {
|
||||||
|
|
||||||
final static String TAG = AliasDialogFragment.class.getName();
|
final static String TAG = AliasDialogFragment.class.getName();
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import org.briarproject.briar.android.blog.BlogActivity;
|
|||||||
import org.briarproject.briar.android.conversation.ConversationVisitor.AttachmentCache;
|
import org.briarproject.briar.android.conversation.ConversationVisitor.AttachmentCache;
|
||||||
import org.briarproject.briar.android.conversation.ConversationVisitor.TextCache;
|
import org.briarproject.briar.android.conversation.ConversationVisitor.TextCache;
|
||||||
import org.briarproject.briar.android.forum.ForumActivity;
|
import org.briarproject.briar.android.forum.ForumActivity;
|
||||||
|
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||||
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
||||||
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
||||||
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
||||||
@@ -59,8 +60,10 @@ import org.briarproject.briar.android.view.TextAttachmentController;
|
|||||||
import org.briarproject.briar.android.view.TextAttachmentController.AttachmentListener;
|
import org.briarproject.briar.android.view.TextAttachmentController.AttachmentListener;
|
||||||
import org.briarproject.briar.android.view.TextInputView;
|
import org.briarproject.briar.android.view.TextInputView;
|
||||||
import org.briarproject.briar.android.view.TextSendController;
|
import org.briarproject.briar.android.view.TextSendController;
|
||||||
|
import org.briarproject.briar.android.view.TextSendController.SendState;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
|
import org.briarproject.briar.api.autodelete.event.ConversationMessagesDeletedEvent;
|
||||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
@@ -138,12 +141,14 @@ import static org.briarproject.briar.android.util.UiUtils.observeOnce;
|
|||||||
import static org.briarproject.briar.android.view.AuthorView.setAvatar;
|
import static org.briarproject.briar.android.view.AuthorView.setAvatar;
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
|
||||||
|
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_IMAGES_AUTO_DELETE;
|
||||||
|
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_ONLY;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class ConversationActivity extends BriarActivity
|
public class ConversationActivity extends BriarActivity
|
||||||
implements EventListener, ConversationListener, TextCache,
|
implements BaseFragmentListener, EventListener, ConversationListener,
|
||||||
AttachmentCache, AttachmentListener, ActionMode.Callback {
|
TextCache, AttachmentCache, AttachmentListener, ActionMode.Callback {
|
||||||
|
|
||||||
public static final String CONTACT_ID = "briar.CONTACT_ID";
|
public static final String CONTACT_ID = "briar.CONTACT_ID";
|
||||||
|
|
||||||
@@ -268,15 +273,11 @@ public class ConversationActivity extends BriarActivity
|
|||||||
ImagePreview imagePreview = findViewById(R.id.imagePreview);
|
ImagePreview imagePreview = findViewById(R.id.imagePreview);
|
||||||
sendController = new TextAttachmentController(textInputView,
|
sendController = new TextAttachmentController(textInputView,
|
||||||
imagePreview, this, viewModel);
|
imagePreview, this, viewModel);
|
||||||
viewModel.hasImageSupport().observe(this, new Observer<Boolean>() {
|
observeOnce(viewModel.getPrivateMessageFormat(), this, format -> {
|
||||||
@Override
|
if (format != TEXT_ONLY) {
|
||||||
public void onChanged(@Nullable Boolean hasSupport) {
|
// TODO: remove cast when removing feature flag
|
||||||
if (hasSupport != null && hasSupport) {
|
((TextAttachmentController) sendController)
|
||||||
// TODO: remove cast when removing feature flag
|
.setImagesSupported();
|
||||||
((TextAttachmentController) sendController)
|
|
||||||
.setImagesSupported();
|
|
||||||
viewModel.hasImageSupport().removeObserver(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -286,6 +287,9 @@ public class ConversationActivity extends BriarActivity
|
|||||||
textInputView.setMaxTextLength(MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
|
textInputView.setMaxTextLength(MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
|
||||||
textInputView.setReady(false);
|
textInputView.setReady(false);
|
||||||
textInputView.setOnKeyboardShownListener(this::scrollToBottom);
|
textInputView.setOnKeyboardShownListener(this::scrollToBottom);
|
||||||
|
|
||||||
|
viewModel.getAutoDeleteTimer().observe(this, timer ->
|
||||||
|
sendController.setAutoDeleteTimer(timer));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToBottom() {
|
private void scrollToBottom() {
|
||||||
@@ -369,6 +373,14 @@ public class ConversationActivity extends BriarActivity
|
|||||||
// enable alias action if available
|
// enable alias action if available
|
||||||
observeOnce(viewModel.getContactItem(), this, contact ->
|
observeOnce(viewModel.getContactItem(), this, contact ->
|
||||||
menu.findItem(R.id.action_set_alias).setEnabled(true));
|
menu.findItem(R.id.action_set_alias).setEnabled(true));
|
||||||
|
// Show auto-delete menu item if feature is enabled
|
||||||
|
if (featureFlags.shouldEnableDisappearingMessages()) {
|
||||||
|
MenuItem item = menu.findItem(R.id.action_conversation_settings);
|
||||||
|
item.setVisible(true);
|
||||||
|
// Enable menu item only if contact supports auto-delete
|
||||||
|
viewModel.getPrivateMessageFormat().observe(this, format ->
|
||||||
|
item.setEnabled(format == TEXT_IMAGES_AUTO_DELETE));
|
||||||
|
}
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
@@ -390,6 +402,10 @@ public class ConversationActivity extends BriarActivity
|
|||||||
AliasDialogFragment.newInstance().show(
|
AliasDialogFragment.newInstance().show(
|
||||||
getSupportFragmentManager(), AliasDialogFragment.TAG);
|
getSupportFragmentManager(), AliasDialogFragment.TAG);
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.action_conversation_settings:
|
||||||
|
if (contactId == null) return false;
|
||||||
|
onAutoDeleteTimerNoticeClicked();
|
||||||
|
return true;
|
||||||
case R.id.action_delete_all_messages:
|
case R.id.action_delete_all_messages:
|
||||||
askToDeleteAllMessages();
|
askToDeleteAllMessages();
|
||||||
return true;
|
return true;
|
||||||
@@ -559,7 +575,7 @@ public class ConversationActivity extends BriarActivity
|
|||||||
this::showImageOnboarding);
|
this::showImageOnboarding);
|
||||||
}
|
}
|
||||||
List<ConversationItem> items = createItems(headers);
|
List<ConversationItem> items = createItems(headers);
|
||||||
adapter.addAll(items);
|
adapter.replaceAll(items);
|
||||||
list.showData();
|
list.showData();
|
||||||
if (layoutManagerState == null) {
|
if (layoutManagerState == null) {
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
@@ -640,8 +656,8 @@ public class ConversationActivity extends BriarActivity
|
|||||||
supportFinishAfterTransition();
|
supportFinishAfterTransition();
|
||||||
}
|
}
|
||||||
} else if (e instanceof ConversationMessageReceivedEvent) {
|
} else if (e instanceof ConversationMessageReceivedEvent) {
|
||||||
ConversationMessageReceivedEvent p =
|
ConversationMessageReceivedEvent<?> p =
|
||||||
(ConversationMessageReceivedEvent) e;
|
(ConversationMessageReceivedEvent<?>) e;
|
||||||
if (p.getContactId().equals(contactId)) {
|
if (p.getContactId().equals(contactId)) {
|
||||||
LOG.info("Message received, adding");
|
LOG.info("Message received, adding");
|
||||||
onNewConversationMessage(p.getMessageHeader());
|
onNewConversationMessage(p.getMessageHeader());
|
||||||
@@ -658,6 +674,13 @@ public class ConversationActivity extends BriarActivity
|
|||||||
LOG.info("Messages acked");
|
LOG.info("Messages acked");
|
||||||
markMessages(m.getMessageIds(), true, true);
|
markMessages(m.getMessageIds(), true, true);
|
||||||
}
|
}
|
||||||
|
} else if (e instanceof ConversationMessagesDeletedEvent) {
|
||||||
|
ConversationMessagesDeletedEvent m =
|
||||||
|
(ConversationMessagesDeletedEvent) e;
|
||||||
|
if (m.getContactId().equals(contactId)) {
|
||||||
|
LOG.info("Messages auto-deleted");
|
||||||
|
onConversationMessagesDeleted(m.getMessageIds());
|
||||||
|
}
|
||||||
} else if (e instanceof ContactConnectedEvent) {
|
} else if (e instanceof ContactConnectedEvent) {
|
||||||
ContactConnectedEvent c = (ContactConnectedEvent) e;
|
ContactConnectedEvent c = (ContactConnectedEvent) e;
|
||||||
if (c.getContactId().equals(contactId)) {
|
if (c.getContactId().equals(contactId)) {
|
||||||
@@ -705,6 +728,13 @@ public class ConversationActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
private void onConversationMessagesDeleted(
|
||||||
|
Collection<MessageId> messageIds) {
|
||||||
|
adapter.incrementRevision();
|
||||||
|
adapter.removeItems(messageIds);
|
||||||
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private void markMessages(Collection<MessageId> messageIds, boolean sent,
|
private void markMessages(Collection<MessageId> messageIds, boolean sent,
|
||||||
boolean seen) {
|
boolean seen) {
|
||||||
@@ -735,20 +765,13 @@ public class ConversationActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendClick(@Nullable String text,
|
public LiveData<SendState> onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> attachmentHeaders) {
|
List<AttachmentHeader> attachmentHeaders,
|
||||||
|
long expectedAutoDeleteTimer) {
|
||||||
if (isNullOrEmpty(text) && attachmentHeaders.isEmpty())
|
if (isNullOrEmpty(text) && attachmentHeaders.isEmpty())
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
long timestamp = System.currentTimeMillis();
|
return viewModel
|
||||||
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
.sendMessage(text, attachmentHeaders, expectedAutoDeleteTimer);
|
||||||
viewModel.sendMessage(text, attachmentHeaders, timestamp);
|
|
||||||
textInputView.clearText();
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getMinTimestampForNewMessage() {
|
|
||||||
// Don't use an earlier timestamp than the newest message
|
|
||||||
ConversationItem item = adapter.getLastItem();
|
|
||||||
return item == null ? 0 : item.getTime() + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onAddedPrivateMessage(@Nullable PrivateMessageHeader h) {
|
private void onAddedPrivateMessage(@Nullable PrivateMessageHeader h) {
|
||||||
@@ -823,10 +846,6 @@ public class ConversationActivity extends BriarActivity
|
|||||||
fails.add(getString(
|
fails.add(getString(
|
||||||
R.string.dialog_message_not_deleted_ongoing_invitations));
|
R.string.dialog_message_not_deleted_ongoing_invitations));
|
||||||
}
|
}
|
||||||
if (result.hasNotFullyDownloaded()) {
|
|
||||||
fails.add(getString(
|
|
||||||
R.string.dialog_message_not_deleted_partly_downloaded));
|
|
||||||
}
|
|
||||||
// add problems the user can resolve
|
// add problems the user can resolve
|
||||||
if (result.hasNotAllIntroductionSelected() &&
|
if (result.hasNotAllIntroductionSelected() &&
|
||||||
result.hasNotAllInvitationSelected()) {
|
result.hasNotAllInvitationSelected()) {
|
||||||
@@ -958,13 +977,11 @@ public class ConversationActivity extends BriarActivity
|
|||||||
adapter.notifyItemChanged(position, item);
|
adapter.notifyItemChanged(position, item);
|
||||||
}
|
}
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
long timestamp = System.currentTimeMillis();
|
|
||||||
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
|
||||||
try {
|
try {
|
||||||
switch (item.getRequestType()) {
|
switch (item.getRequestType()) {
|
||||||
case INTRODUCTION:
|
case INTRODUCTION:
|
||||||
respondToIntroductionRequest(item.getSessionId(),
|
respondToIntroductionRequest(item.getSessionId(),
|
||||||
accept, timestamp);
|
accept);
|
||||||
break;
|
break;
|
||||||
case FORUM:
|
case FORUM:
|
||||||
respondToForumRequest(item.getSessionId(), accept);
|
respondToForumRequest(item.getSessionId(), accept);
|
||||||
@@ -1038,11 +1055,18 @@ public class ConversationActivity extends BriarActivity
|
|||||||
ActivityCompat.startActivity(this, i, options.toBundle());
|
ActivityCompat.startActivity(this, i, options.toBundle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAutoDeleteTimerNoticeClicked() {
|
||||||
|
ConversationSettingsDialog dialog =
|
||||||
|
ConversationSettingsDialog.newInstance(contactId);
|
||||||
|
dialog.show(getSupportFragmentManager(),
|
||||||
|
ConversationSettingsDialog.TAG);
|
||||||
|
}
|
||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
private void respondToIntroductionRequest(SessionId sessionId,
|
private void respondToIntroductionRequest(SessionId sessionId,
|
||||||
boolean accept, long time) throws DbException {
|
boolean accept) throws DbException {
|
||||||
introductionManager.respondToIntroduction(contactId, sessionId, time,
|
introductionManager.respondToIntroduction(contactId, sessionId, accept);
|
||||||
accept);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
|
|||||||
@@ -13,20 +13,26 @@ import org.briarproject.briar.R;
|
|||||||
import org.briarproject.briar.android.util.BriarAdapter;
|
import org.briarproject.briar.android.util.BriarAdapter;
|
||||||
import org.briarproject.briar.android.util.ItemReturningAdapter;
|
import org.briarproject.briar.android.util.ItemReturningAdapter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
import androidx.recyclerview.selection.SelectionTracker;
|
import androidx.recyclerview.selection.SelectionTracker;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView.RecycledViewPool;
|
import androidx.recyclerview.widget.RecyclerView.RecycledViewPool;
|
||||||
|
|
||||||
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||||
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class ConversationAdapter
|
class ConversationAdapter
|
||||||
extends BriarAdapter<ConversationItem, ConversationItemViewHolder>
|
extends BriarAdapter<ConversationItem, ConversationItemViewHolder>
|
||||||
implements ItemReturningAdapter<ConversationItem> {
|
implements ItemReturningAdapter<ConversationItem> {
|
||||||
|
|
||||||
private ConversationListener listener;
|
private final ConversationListener listener;
|
||||||
private final RecycledViewPool imageViewPool;
|
private final RecycledViewPool imageViewPool;
|
||||||
private final ImageItemDecoration imageItemDecoration;
|
private final ImageItemDecoration imageItemDecoration;
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -65,22 +71,20 @@ class ConversationAdapter
|
|||||||
@LayoutRes int type) {
|
@LayoutRes int type) {
|
||||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
View v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||||
type, viewGroup, false);
|
type, viewGroup, false);
|
||||||
switch (type) {
|
if (type == R.layout.list_item_conversation_msg_in) {
|
||||||
case R.layout.list_item_conversation_msg_in:
|
return new ConversationMessageViewHolder(v, listener, true,
|
||||||
return new ConversationMessageViewHolder(v, listener, true,
|
imageViewPool, imageItemDecoration);
|
||||||
imageViewPool, imageItemDecoration);
|
} else if (type == R.layout.list_item_conversation_msg_out) {
|
||||||
case R.layout.list_item_conversation_msg_out:
|
return new ConversationMessageViewHolder(v, listener, false,
|
||||||
return new ConversationMessageViewHolder(v, listener, false,
|
imageViewPool, imageItemDecoration);
|
||||||
imageViewPool, imageItemDecoration);
|
} else if (type == R.layout.list_item_conversation_notice_in) {
|
||||||
case R.layout.list_item_conversation_notice_in:
|
return new ConversationNoticeViewHolder(v, listener, true);
|
||||||
return new ConversationNoticeViewHolder(v, listener, true);
|
} else if (type == R.layout.list_item_conversation_notice_out) {
|
||||||
case R.layout.list_item_conversation_notice_out:
|
return new ConversationNoticeViewHolder(v, listener, false);
|
||||||
return new ConversationNoticeViewHolder(v, listener, false);
|
} else if (type == R.layout.list_item_conversation_request) {
|
||||||
case R.layout.list_item_conversation_request:
|
return new ConversationRequestViewHolder(v, listener, true);
|
||||||
return new ConversationRequestViewHolder(v, listener, true);
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Unknown ConversationItem");
|
|
||||||
}
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown ConversationItem");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -107,22 +111,65 @@ class ConversationAdapter
|
|||||||
return c1.equals(c2);
|
return c1.equals(c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(ConversationItem item) {
|
||||||
|
items.beginBatchedUpdates();
|
||||||
|
items.add(item);
|
||||||
|
updateTimersInBatch();
|
||||||
|
items.endBatchedUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void replaceAll(Collection<ConversationItem> itemsToReplace) {
|
||||||
|
items.beginBatchedUpdates();
|
||||||
|
// there can be items already in the adapter
|
||||||
|
// SortedList takes care of duplicates and detecting changed items
|
||||||
|
items.replaceAll(itemsToReplace);
|
||||||
|
updateTimersInBatch();
|
||||||
|
items.endBatchedUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void removeItems(Collection<MessageId> messageIds) {
|
||||||
|
// Collect all items to be deleted first
|
||||||
|
// and then delete them in one batched update.
|
||||||
|
// Deleting them right away would cause issues
|
||||||
|
// due to changing list positions.
|
||||||
|
List<ConversationItem> toRemove = new ArrayList<>(messageIds.size());
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
ConversationItem item = items.get(i);
|
||||||
|
if (messageIds.contains(item.getId())) toRemove.add(item);
|
||||||
|
}
|
||||||
|
items.beginBatchedUpdates();
|
||||||
|
for (ConversationItem item : toRemove) items.remove(item);
|
||||||
|
items.endBatchedUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTimersInBatch() {
|
||||||
|
long lastTimerIncoming = NO_AUTO_DELETE_TIMER;
|
||||||
|
long lastTimerOutgoing = NO_AUTO_DELETE_TIMER;
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
ConversationItem c = items.get(i);
|
||||||
|
boolean itemChanged;
|
||||||
|
boolean timerChanged;
|
||||||
|
if (c.isIncoming()) {
|
||||||
|
timerChanged = lastTimerIncoming != c.getAutoDeleteTimer();
|
||||||
|
lastTimerIncoming = c.getAutoDeleteTimer();
|
||||||
|
} else {
|
||||||
|
timerChanged = lastTimerOutgoing != c.getAutoDeleteTimer();
|
||||||
|
lastTimerOutgoing = c.getAutoDeleteTimer();
|
||||||
|
}
|
||||||
|
itemChanged = c.setTimerNoticeVisible(timerChanged);
|
||||||
|
if (itemChanged) items.updateItemAt(i, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setSelectionTracker(SelectionTracker<String> tracker) {
|
void setSelectionTracker(SelectionTracker<String> tracker) {
|
||||||
this.tracker = tracker;
|
this.tracker = tracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
ConversationItem getLastItem() {
|
|
||||||
if (items.size() > 0) {
|
|
||||||
return items.get(items.size() - 1);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SparseArray<ConversationItem> getOutgoingMessages() {
|
SparseArray<ConversationItem> getOutgoingMessages() {
|
||||||
SparseArray<ConversationItem> messages = new SparseArray<>();
|
SparseArray<ConversationItem> messages = new SparseArray<>();
|
||||||
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
ConversationItem item = items.get(i);
|
ConversationItem item = items.get(i);
|
||||||
if (!item.isIncoming()) {
|
if (!item.isIncoming()) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
||||||
|
|
||||||
@@ -22,20 +23,25 @@ abstract class ConversationItem {
|
|||||||
protected String text;
|
protected String text;
|
||||||
private final MessageId id;
|
private final MessageId id;
|
||||||
private final GroupId groupId;
|
private final GroupId groupId;
|
||||||
private final long time;
|
private final long time, autoDeleteTimer;
|
||||||
private final boolean isIncoming;
|
private final boolean isIncoming;
|
||||||
private boolean read, sent, seen;
|
private final LiveData<String> contactName;
|
||||||
|
private boolean read, sent, seen, showTimerNotice;
|
||||||
|
|
||||||
ConversationItem(@LayoutRes int layoutRes, ConversationMessageHeader h) {
|
ConversationItem(@LayoutRes int layoutRes, ConversationMessageHeader h,
|
||||||
|
LiveData<String> contactName) {
|
||||||
this.layoutRes = layoutRes;
|
this.layoutRes = layoutRes;
|
||||||
this.text = null;
|
this.text = null;
|
||||||
this.id = h.getId();
|
this.id = h.getId();
|
||||||
this.groupId = h.getGroupId();
|
this.groupId = h.getGroupId();
|
||||||
this.time = h.getTimestamp();
|
this.time = h.getTimestamp();
|
||||||
|
this.autoDeleteTimer = h.getAutoDeleteTimer();
|
||||||
this.read = h.isRead();
|
this.read = h.isRead();
|
||||||
this.sent = h.isSent();
|
this.sent = h.isSent();
|
||||||
this.seen = h.isSeen();
|
this.seen = h.isSeen();
|
||||||
this.isIncoming = !h.isLocal();
|
this.isIncoming = !h.isLocal();
|
||||||
|
this.contactName = contactName;
|
||||||
|
this.showTimerNotice = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LayoutRes
|
@LayoutRes
|
||||||
@@ -68,6 +74,10 @@ abstract class ConversationItem {
|
|||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getAutoDeleteTimer() {
|
||||||
|
return autoDeleteTimer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only useful for incoming messages.
|
* Only useful for incoming messages.
|
||||||
*/
|
*/
|
||||||
@@ -111,4 +121,25 @@ abstract class ConversationItem {
|
|||||||
return isIncoming;
|
return isIncoming;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<String> getContactName() {
|
||||||
|
return contactName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this to true when {@link #getAutoDeleteTimer()} has changed
|
||||||
|
* since the last message from the same peer.
|
||||||
|
*
|
||||||
|
* @return true if the value was set, false if it was already set.
|
||||||
|
*/
|
||||||
|
boolean setTimerNoticeVisible(boolean visible) {
|
||||||
|
if (this.showTimerNotice != visible) {
|
||||||
|
this.showTimerNotice = visible;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isTimerNoticeVisible() {
|
||||||
|
return showTimerNotice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package org.briarproject.briar.android.conversation;
|
package org.briarproject.briar.android.conversation;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
@@ -12,8 +14,12 @@ import androidx.annotation.UiThread;
|
|||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||||
|
|
||||||
|
import static android.view.View.GONE;
|
||||||
|
import static android.view.View.VISIBLE;
|
||||||
import static org.briarproject.bramble.util.StringUtils.trim;
|
import static org.briarproject.bramble.util.StringUtils.trim;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
||||||
|
import static org.briarproject.briar.android.util.UiUtils.formatDuration;
|
||||||
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -24,8 +30,9 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
|||||||
protected final ConstraintLayout layout;
|
protected final ConstraintLayout layout;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final OutItemViewHolder outViewHolder;
|
private final OutItemViewHolder outViewHolder;
|
||||||
private final TextView text;
|
private final TextView topNotice, text;
|
||||||
protected final TextView time;
|
protected final TextView time;
|
||||||
|
protected final ImageView bomb;
|
||||||
@Nullable
|
@Nullable
|
||||||
private String itemKey = null;
|
private String itemKey = null;
|
||||||
|
|
||||||
@@ -33,11 +40,13 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
|||||||
boolean isIncoming) {
|
boolean isIncoming) {
|
||||||
super(v);
|
super(v);
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.outViewHolder = isIncoming ? null : new OutItemViewHolder(v);
|
outViewHolder = isIncoming ? null : new OutItemViewHolder(v);
|
||||||
root = v;
|
root = v;
|
||||||
|
topNotice = v.findViewById(R.id.topNotice);
|
||||||
layout = v.findViewById(R.id.layout);
|
layout = v.findViewById(R.id.layout);
|
||||||
text = v.findViewById(R.id.text);
|
text = v.findViewById(R.id.text);
|
||||||
time = v.findViewById(R.id.time);
|
time = v.findViewById(R.id.time);
|
||||||
|
bomb = v.findViewById(R.id.bomb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@@ -45,6 +54,8 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
|||||||
itemKey = item.getKey();
|
itemKey = item.getKey();
|
||||||
root.setActivated(selected);
|
root.setActivated(selected);
|
||||||
|
|
||||||
|
setTopNotice(item);
|
||||||
|
|
||||||
if (item.getText() != null) {
|
if (item.getText() != null) {
|
||||||
text.setText(trim(item.getText()));
|
text.setText(trim(item.getText()));
|
||||||
}
|
}
|
||||||
@@ -52,6 +63,9 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
|||||||
long timestamp = item.getTime();
|
long timestamp = item.getTime();
|
||||||
time.setText(formatDate(time.getContext(), timestamp));
|
time.setText(formatDate(time.getContext(), timestamp));
|
||||||
|
|
||||||
|
boolean showBomb = item.getAutoDeleteTimer() != NO_AUTO_DELETE_TIMER;
|
||||||
|
bomb.setVisibility(showBomb ? VISIBLE : GONE);
|
||||||
|
|
||||||
if (outViewHolder != null) outViewHolder.bind(item);
|
if (outViewHolder != null) outViewHolder.bind(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,4 +78,35 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
|||||||
return itemKey;
|
return itemKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setTopNotice(ConversationItem item) {
|
||||||
|
if (item.isTimerNoticeVisible()) {
|
||||||
|
Context ctx = itemView.getContext();
|
||||||
|
topNotice.setVisibility(VISIBLE);
|
||||||
|
boolean enabled = item.getAutoDeleteTimer() != NO_AUTO_DELETE_TIMER;
|
||||||
|
String duration = enabled ?
|
||||||
|
formatDuration(ctx, item.getAutoDeleteTimer()) : "";
|
||||||
|
String tapToLearnMore = ctx.getString(R.string.tap_to_learn_more);
|
||||||
|
String text;
|
||||||
|
if (item.isIncoming()) {
|
||||||
|
String name = item.getContactName().getValue();
|
||||||
|
text = enabled ?
|
||||||
|
ctx.getString(R.string.auto_delete_msg_contact_enabled,
|
||||||
|
name, duration, tapToLearnMore) :
|
||||||
|
ctx.getString(R.string.auto_delete_msg_contact_disabled,
|
||||||
|
name, tapToLearnMore);
|
||||||
|
} else {
|
||||||
|
text = enabled ?
|
||||||
|
ctx.getString(R.string.auto_delete_msg_you_enabled,
|
||||||
|
duration, tapToLearnMore) :
|
||||||
|
ctx.getString(R.string.auto_delete_msg_you_disabled,
|
||||||
|
tapToLearnMore);
|
||||||
|
}
|
||||||
|
topNotice.setText(text);
|
||||||
|
topNotice.setOnClickListener(
|
||||||
|
v -> listener.onAutoDeleteTimerNoticeClicked());
|
||||||
|
} else {
|
||||||
|
topNotice.setVisibility(GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,4 +18,6 @@ interface ConversationListener {
|
|||||||
void onAttachmentClicked(View view, ConversationMessageItem messageItem,
|
void onAttachmentClicked(View view, ConversationMessageItem messageItem,
|
||||||
AttachmentItem attachmentItem);
|
AttachmentItem attachmentItem);
|
||||||
|
|
||||||
|
void onAutoDeleteTimerNoticeClicked();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import javax.annotation.concurrent.NotThreadSafe;
|
|||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -18,8 +19,8 @@ class ConversationMessageItem extends ConversationItem {
|
|||||||
private final List<AttachmentItem> attachments;
|
private final List<AttachmentItem> attachments;
|
||||||
|
|
||||||
ConversationMessageItem(@LayoutRes int layoutRes, PrivateMessageHeader h,
|
ConversationMessageItem(@LayoutRes int layoutRes, PrivateMessageHeader h,
|
||||||
List<AttachmentItem> attachments) {
|
LiveData<String> contactName, List<AttachmentItem> attachments) {
|
||||||
super(layoutRes, h);
|
super(layoutRes, h, contactName);
|
||||||
this.attachments = attachments;
|
this.attachments = attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.briar.android.conversation;
|
package org.briarproject.briar.android.conversation;
|
||||||
|
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ import androidx.recyclerview.widget.RecyclerView.RecycledViewPool;
|
|||||||
|
|
||||||
import static androidx.constraintlayout.widget.ConstraintSet.WRAP_CONTENT;
|
import static androidx.constraintlayout.widget.ConstraintSet.WRAP_CONTENT;
|
||||||
import static androidx.core.content.ContextCompat.getColor;
|
import static androidx.core.content.ContextCompat.getColor;
|
||||||
|
import static androidx.core.widget.ImageViewCompat.setImageTintList;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -84,6 +86,7 @@ class ConversationMessageViewHolder extends ConversationItemViewHolder {
|
|||||||
if (item.getText() == null) {
|
if (item.getText() == null) {
|
||||||
statusLayout.setBackgroundResource(R.drawable.msg_status_bubble);
|
statusLayout.setBackgroundResource(R.drawable.msg_status_bubble);
|
||||||
time.setTextColor(timeColorBubble);
|
time.setTextColor(timeColorBubble);
|
||||||
|
setImageTintList(bomb, ColorStateList.valueOf(timeColorBubble));
|
||||||
constraintSet = imageConstraints;
|
constraintSet = imageConstraints;
|
||||||
} else {
|
} else {
|
||||||
resetStatusLayoutForText();
|
resetStatusLayoutForText();
|
||||||
@@ -111,6 +114,7 @@ class ConversationMessageViewHolder extends ConversationItemViewHolder {
|
|||||||
// also reset padding (the background drawable defines some)
|
// also reset padding (the background drawable defines some)
|
||||||
statusLayout.setPadding(0, 0, 0, 0);
|
statusLayout.setPadding(0, 0, 0, 0);
|
||||||
time.setTextColor(timeColor);
|
time.setTextColor(timeColor);
|
||||||
|
setImageTintList(bomb, ColorStateList.valueOf(timeColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -17,15 +18,15 @@ class ConversationNoticeItem extends ConversationItem {
|
|||||||
private final String msgText;
|
private final String msgText;
|
||||||
|
|
||||||
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
||||||
ConversationRequest r) {
|
LiveData<String> contactName, ConversationRequest<?> r) {
|
||||||
super(layoutRes, r);
|
super(layoutRes, r, contactName);
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.msgText = r.getText();
|
this.msgText = r.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
||||||
ConversationResponse r) {
|
LiveData<String> contactName, ConversationResponse r) {
|
||||||
super(layoutRes, r);
|
super(layoutRes, r, contactName);
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.msgText = null;
|
this.msgText = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -26,14 +27,15 @@ class ConversationRequestItem extends ConversationNoticeItem {
|
|||||||
private boolean answered;
|
private boolean answered;
|
||||||
|
|
||||||
ConversationRequestItem(@LayoutRes int layoutRes, String text,
|
ConversationRequestItem(@LayoutRes int layoutRes, String text,
|
||||||
RequestType type, ConversationRequest r) {
|
LiveData<String> contactName, RequestType type,
|
||||||
super(layoutRes, text, r);
|
ConversationRequest<?> r) {
|
||||||
|
super(layoutRes, text, contactName, r);
|
||||||
this.requestType = type;
|
this.requestType = type;
|
||||||
this.sessionId = r.getSessionId();
|
this.sessionId = r.getSessionId();
|
||||||
this.answered = r.wasAnswered();
|
this.answered = r.wasAnswered();
|
||||||
if (r instanceof InvitationRequest) {
|
if (r instanceof InvitationRequest) {
|
||||||
this.requestedGroupId = ((Shareable) r.getNameable()).getId();
|
this.requestedGroupId = ((Shareable) r.getNameable()).getId();
|
||||||
this.canBeOpened = ((InvitationRequest) r).canBeOpened();
|
this.canBeOpened = ((InvitationRequest<?>) r).canBeOpened();
|
||||||
} else {
|
} else {
|
||||||
this.requestedGroupId = null;
|
this.requestedGroupId = null;
|
||||||
this.canBeOpened = false;
|
this.canBeOpened = false;
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package org.briarproject.briar.android.conversation;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
|
import org.briarproject.briar.android.widget.OnboardingFullDialogFragment;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
||||||
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class ConversationSettingsDialog extends DialogFragment {
|
||||||
|
|
||||||
|
final static String TAG = ConversationSettingsDialog.class.getName();
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(TAG);
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private ConversationViewModel viewModel;
|
||||||
|
|
||||||
|
static ConversationSettingsDialog newInstance(ContactId contactId) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putInt(CONTACT_ID, contactId.getInt());
|
||||||
|
ConversationSettingsDialog dialog = new ConversationSettingsDialog();
|
||||||
|
dialog.setArguments(args);
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
injectFragment(((BaseFragment.BaseFragmentListener) context)
|
||||||
|
.getActivityComponent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void injectFragment(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||||
|
.get(ConversationViewModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setStyle(DialogFragment.STYLE_NO_FRAME,
|
||||||
|
R.style.BriarFullScreenDialogTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.fragment_conversation_settings,
|
||||||
|
container, false);
|
||||||
|
|
||||||
|
Bundle args = requireArguments();
|
||||||
|
int id = args.getInt(CONTACT_ID, -1);
|
||||||
|
if (id == -1) throw new IllegalStateException();
|
||||||
|
ContactId contactId = new ContactId(id);
|
||||||
|
|
||||||
|
FragmentActivity activity = requireActivity();
|
||||||
|
viewModel = new ViewModelProvider(activity, viewModelFactory)
|
||||||
|
.get(ConversationViewModel.class);
|
||||||
|
viewModel.setContactId(contactId);
|
||||||
|
|
||||||
|
Toolbar toolbar = view.findViewById(R.id.toolbar);
|
||||||
|
toolbar.setNavigationOnClickListener(v -> dismiss());
|
||||||
|
|
||||||
|
SwitchCompat switchDisappearingMessages = view.findViewById(
|
||||||
|
R.id.switchDisappearingMessages);
|
||||||
|
switchDisappearingMessages.setOnCheckedChangeListener(
|
||||||
|
(button, value) -> viewModel.setAutoDeleteTimerEnabled(value));
|
||||||
|
|
||||||
|
Button buttonLearnMore =
|
||||||
|
view.findViewById(R.id.buttonLearnMore);
|
||||||
|
buttonLearnMore.setOnClickListener(e -> showLearnMoreDialog());
|
||||||
|
|
||||||
|
viewModel.getAutoDeleteTimer()
|
||||||
|
.observe(getViewLifecycleOwner(), timer -> {
|
||||||
|
LOG.info("Received auto delete timer: " + timer);
|
||||||
|
boolean disappearingMessages =
|
||||||
|
timer != NO_AUTO_DELETE_TIMER;
|
||||||
|
switchDisappearingMessages
|
||||||
|
.setChecked(disappearingMessages);
|
||||||
|
switchDisappearingMessages.setEnabled(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showLearnMoreDialog() {
|
||||||
|
OnboardingFullDialogFragment.newInstance(
|
||||||
|
R.string.disappearing_messages_title,
|
||||||
|
R.string.disappearing_messages_explanation_long
|
||||||
|
).show(getChildFragmentManager(), OnboardingFullDialogFragment.TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import org.briarproject.bramble.api.contact.ContactManager;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.NoSuchContactException;
|
import org.briarproject.bramble.api.db.NoSuchContactException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
@@ -28,16 +29,22 @@ import org.briarproject.briar.android.attachment.AttachmentResult;
|
|||||||
import org.briarproject.briar.android.attachment.AttachmentRetriever;
|
import org.briarproject.briar.android.attachment.AttachmentRetriever;
|
||||||
import org.briarproject.briar.android.contact.ContactItem;
|
import org.briarproject.briar.android.contact.ContactItem;
|
||||||
import org.briarproject.briar.android.util.UiUtils;
|
import org.briarproject.briar.android.util.UiUtils;
|
||||||
|
import org.briarproject.briar.android.view.TextSendController.SendState;
|
||||||
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
|
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
||||||
|
import org.briarproject.briar.api.autodelete.UnexpectedTimerException;
|
||||||
|
import org.briarproject.briar.api.autodelete.event.AutoDeleteTimerMirroredEvent;
|
||||||
import org.briarproject.briar.api.avatar.event.AvatarUpdatedEvent;
|
import org.briarproject.briar.api.avatar.event.AvatarUpdatedEvent;
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
import org.briarproject.briar.api.messaging.MessagingManager;
|
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessage;
|
import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||||
|
import org.briarproject.briar.api.messaging.PrivateMessageFormat;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||||
import org.briarproject.briar.api.messaging.event.AttachmentReceivedEvent;
|
import org.briarproject.briar.api.messaging.event.AttachmentReceivedEvent;
|
||||||
|
|
||||||
@@ -55,6 +62,7 @@ import androidx.lifecycle.MutableLiveData;
|
|||||||
|
|
||||||
import static androidx.lifecycle.Transformations.map;
|
import static androidx.lifecycle.Transformations.map;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
@@ -62,6 +70,13 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
|||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.observeForeverOnce;
|
import static org.briarproject.briar.android.util.UiUtils.observeForeverOnce;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.ERROR;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.UNEXPECTED_TIMER;
|
||||||
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||||
|
import static org.briarproject.briar.api.autodelete.AutoDeleteManager.DEFAULT_TIMER_DURATION;
|
||||||
|
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_IMAGES;
|
||||||
|
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_ONLY;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class ConversationViewModel extends DbViewModel
|
public class ConversationViewModel extends DbViewModel
|
||||||
@@ -84,6 +99,8 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
private final PrivateMessageFactory privateMessageFactory;
|
private final PrivateMessageFactory privateMessageFactory;
|
||||||
private final AttachmentRetriever attachmentRetriever;
|
private final AttachmentRetriever attachmentRetriever;
|
||||||
private final AttachmentCreator attachmentCreator;
|
private final AttachmentCreator attachmentCreator;
|
||||||
|
private final AutoDeleteManager autoDeleteManager;
|
||||||
|
private final ConversationManager conversationManager;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private ContactId contactId = null;
|
private ContactId contactId = null;
|
||||||
@@ -92,7 +109,7 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
private final LiveData<String> contactName = map(contactItem, c ->
|
private final LiveData<String> contactName = map(contactItem, c ->
|
||||||
UiUtils.getContactDisplayName(c.getContact()));
|
UiUtils.getContactDisplayName(c.getContact()));
|
||||||
private final LiveData<GroupId> messagingGroupId;
|
private final LiveData<GroupId> messagingGroupId;
|
||||||
private final MutableLiveData<Boolean> imageSupport =
|
private final MutableLiveData<PrivateMessageFormat> privateMessageFormat =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
private final MutableLiveEvent<Boolean> showImageOnboarding =
|
private final MutableLiveEvent<Boolean> showImageOnboarding =
|
||||||
new MutableLiveEvent<>();
|
new MutableLiveEvent<>();
|
||||||
@@ -100,8 +117,10 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
new MutableLiveEvent<>();
|
new MutableLiveEvent<>();
|
||||||
private final MutableLiveData<Boolean> showIntroductionAction =
|
private final MutableLiveData<Boolean> showIntroductionAction =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
private final MutableLiveData<Boolean> contactDeleted =
|
private final MutableLiveData<Long> autoDeleteTimer =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
|
private final MutableLiveData<Boolean> contactDeleted =
|
||||||
|
new MutableLiveData<>(false);
|
||||||
private final MutableLiveEvent<PrivateMessageHeader> addedHeader =
|
private final MutableLiveEvent<PrivateMessageHeader> addedHeader =
|
||||||
new MutableLiveEvent<>();
|
new MutableLiveEvent<>();
|
||||||
|
|
||||||
@@ -118,7 +137,9 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
SettingsManager settingsManager,
|
SettingsManager settingsManager,
|
||||||
PrivateMessageFactory privateMessageFactory,
|
PrivateMessageFactory privateMessageFactory,
|
||||||
AttachmentRetriever attachmentRetriever,
|
AttachmentRetriever attachmentRetriever,
|
||||||
AttachmentCreator attachmentCreator) {
|
AttachmentCreator attachmentCreator,
|
||||||
|
AutoDeleteManager autoDeleteManager,
|
||||||
|
ConversationManager conversationManager) {
|
||||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
@@ -129,10 +150,10 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
this.privateMessageFactory = privateMessageFactory;
|
this.privateMessageFactory = privateMessageFactory;
|
||||||
this.attachmentRetriever = attachmentRetriever;
|
this.attachmentRetriever = attachmentRetriever;
|
||||||
this.attachmentCreator = attachmentCreator;
|
this.attachmentCreator = attachmentCreator;
|
||||||
|
this.autoDeleteManager = autoDeleteManager;
|
||||||
|
this.conversationManager = conversationManager;
|
||||||
messagingGroupId = map(contactItem, c ->
|
messagingGroupId = map(contactItem, c ->
|
||||||
messagingManager.getContactGroup(c.getContact()).getId());
|
messagingManager.getContactGroup(c.getContact()).getId());
|
||||||
contactDeleted.setValue(false);
|
|
||||||
|
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +173,11 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
runOnDbThread(() -> attachmentRetriever
|
runOnDbThread(() -> attachmentRetriever
|
||||||
.loadAttachmentItem(a.getMessageId()));
|
.loadAttachmentItem(a.getMessageId()));
|
||||||
}
|
}
|
||||||
|
} else if (e instanceof AutoDeleteTimerMirroredEvent) {
|
||||||
|
AutoDeleteTimerMirroredEvent a = (AutoDeleteTimerMirroredEvent) e;
|
||||||
|
if (a.getContactId().equals(contactId)) {
|
||||||
|
autoDeleteTimer.postValue(a.getNewTimer());
|
||||||
|
}
|
||||||
} else if (e instanceof AvatarUpdatedEvent) {
|
} else if (e instanceof AvatarUpdatedEvent) {
|
||||||
AvatarUpdatedEvent a = (AvatarUpdatedEvent) e;
|
AvatarUpdatedEvent a = (AvatarUpdatedEvent) e;
|
||||||
if (a.getContactId().equals(contactId)) {
|
if (a.getContactId().equals(contactId)) {
|
||||||
@@ -201,6 +227,11 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
contactItem.postValue(new ContactItem(c, authorInfo));
|
contactItem.postValue(new ContactItem(c, authorInfo));
|
||||||
logDuration(LOG, "Loading contact", start);
|
logDuration(LOG, "Loading contact", start);
|
||||||
start = now();
|
start = now();
|
||||||
|
long timer = db.transactionWithResult(true, txn ->
|
||||||
|
autoDeleteManager.getAutoDeleteTimer(txn, contactId));
|
||||||
|
autoDeleteTimer.postValue(timer);
|
||||||
|
logDuration(LOG, "Getting auto-delete timer", start);
|
||||||
|
start = now();
|
||||||
checkFeaturesAndOnboarding(contactId);
|
checkFeaturesAndOnboarding(contactId);
|
||||||
logDuration(LOG, "Checking for image support", start);
|
logDuration(LOG, "Checking for image support", start);
|
||||||
} catch (NoSuchContactException e) {
|
} catch (NoSuchContactException e) {
|
||||||
@@ -235,20 +266,6 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void sendMessage(@Nullable String text,
|
|
||||||
List<AttachmentHeader> headers, long timestamp) {
|
|
||||||
// messagingGroupId is loaded with the contact
|
|
||||||
observeForeverOnce(messagingGroupId, groupId -> {
|
|
||||||
requireNonNull(groupId);
|
|
||||||
observeForeverOnce(imageSupport, hasImageSupport -> {
|
|
||||||
requireNonNull(hasImageSupport);
|
|
||||||
createMessage(groupId, text, headers, timestamp,
|
|
||||||
hasImageSupport);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@UiThread
|
@UiThread
|
||||||
public LiveData<AttachmentResult> storeAttachments(Collection<Uri> uris,
|
public LiveData<AttachmentResult> storeAttachments(Collection<Uri> uris,
|
||||||
@@ -275,10 +292,12 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
private void checkFeaturesAndOnboarding(ContactId c) throws DbException {
|
private void checkFeaturesAndOnboarding(ContactId c) throws DbException {
|
||||||
// check if images are supported
|
// check if images and auto-deletion are supported
|
||||||
boolean imagesSupported = db.transactionWithResult(true, txn ->
|
PrivateMessageFormat format = db.transactionWithResult(true, txn ->
|
||||||
messagingManager.contactSupportsImages(txn, c));
|
messagingManager.getContactMessageFormat(txn, c));
|
||||||
imageSupport.postValue(imagesSupported);
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("PrivateMessageFormat loaded: " + format.name());
|
||||||
|
privateMessageFormat.postValue(format);
|
||||||
|
|
||||||
// check if introductions are supported
|
// check if introductions are supported
|
||||||
Collection<Contact> contacts = contactManager.getContacts();
|
Collection<Contact> contacts = contactManager.getContacts();
|
||||||
@@ -287,7 +306,7 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
|
|
||||||
// we only show one onboarding dialog at a time
|
// we only show one onboarding dialog at a time
|
||||||
Settings settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
Settings settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||||
if (imagesSupported &&
|
if (format != TEXT_ONLY &&
|
||||||
settings.getBoolean(SHOW_ONBOARDING_IMAGE, true)) {
|
settings.getBoolean(SHOW_ONBOARDING_IMAGE, true)) {
|
||||||
onOnboardingShown(SHOW_ONBOARDING_IMAGE);
|
onOnboardingShown(SHOW_ONBOARDING_IMAGE);
|
||||||
showImageOnboarding.postEvent(true);
|
showImageOnboarding.postEvent(true);
|
||||||
@@ -306,39 +325,82 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private void createMessage(GroupId groupId, @Nullable String text,
|
LiveData<SendState> sendMessage(@Nullable String text,
|
||||||
List<AttachmentHeader> headers, long timestamp,
|
List<AttachmentHeader> headers, long expectedTimer) {
|
||||||
boolean hasImageSupport) {
|
MutableLiveData<SendState> liveData = new MutableLiveData<>();
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
db.transaction(false, txn -> {
|
||||||
|
long start = now();
|
||||||
|
PrivateMessage m = createMessage(txn, text, headers,
|
||||||
|
expectedTimer);
|
||||||
|
messagingManager.addLocalMessage(txn, m);
|
||||||
|
logDuration(LOG, "Storing message", start);
|
||||||
|
Message message = m.getMessage();
|
||||||
|
PrivateMessageHeader h = new PrivateMessageHeader(
|
||||||
|
message.getId(), message.getGroupId(),
|
||||||
|
message.getTimestamp(), true, true, false, false,
|
||||||
|
m.hasText(), m.getAttachmentHeaders(),
|
||||||
|
m.getAutoDeleteTimer());
|
||||||
|
// TODO add text to cache when available here
|
||||||
|
MessageId id = message.getId();
|
||||||
|
txn.attach(() -> {
|
||||||
|
attachmentCreator.onAttachmentsSent(id);
|
||||||
|
liveData.setValue(SENT);
|
||||||
|
addedHeader.setEvent(h);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (UnexpectedTimerException e) {
|
||||||
|
liveData.postValue(UNEXPECTED_TIMER);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
liveData.postValue(ERROR);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return liveData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PrivateMessage createMessage(Transaction txn, @Nullable String text,
|
||||||
|
List<AttachmentHeader> headers, long expectedTimer)
|
||||||
|
throws DbException {
|
||||||
|
// Sending is only possible (setReady(true)) after loading all messages
|
||||||
|
// which happens after the contact has been loaded.
|
||||||
|
// privateMessageFormat is loaded together with contact
|
||||||
|
Contact contact = requireNonNull(contactItem.getValue()).getContact();
|
||||||
|
GroupId groupId = messagingManager.getContactGroup(contact).getId();
|
||||||
|
PrivateMessageFormat format =
|
||||||
|
requireNonNull(privateMessageFormat.getValue());
|
||||||
|
long timestamp = conversationManager
|
||||||
|
.getTimestampForOutgoingMessage(txn, requireNonNull(contactId));
|
||||||
try {
|
try {
|
||||||
PrivateMessage pm;
|
if (format == TEXT_ONLY) {
|
||||||
if (hasImageSupport) {
|
return privateMessageFactory.createLegacyPrivateMessage(
|
||||||
pm = privateMessageFactory.createPrivateMessage(groupId,
|
groupId, timestamp, requireNonNull(text));
|
||||||
|
} else if (format == TEXT_IMAGES) {
|
||||||
|
return privateMessageFactory.createPrivateMessage(groupId,
|
||||||
timestamp, text, headers);
|
timestamp, text, headers);
|
||||||
} else {
|
} else {
|
||||||
pm = privateMessageFactory.createLegacyPrivateMessage(
|
long timer = autoDeleteManager
|
||||||
groupId, timestamp, requireNonNull(text));
|
.getAutoDeleteTimer(txn, contactId, timestamp);
|
||||||
|
if (timer != expectedTimer)
|
||||||
|
throw new UnexpectedTimerException();
|
||||||
|
return privateMessageFactory.createPrivateMessage(groupId,
|
||||||
|
timestamp, text, headers, timer);
|
||||||
}
|
}
|
||||||
storeMessage(pm);
|
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
void setAutoDeleteTimerEnabled(boolean enabled) {
|
||||||
private void storeMessage(PrivateMessage m) {
|
long timer = enabled ? DEFAULT_TIMER_DURATION : NO_AUTO_DELETE_TIMER;
|
||||||
attachmentCreator.onAttachmentsSent(m.getMessage().getId());
|
// ContactId is set before menu gets inflated and UI interaction
|
||||||
|
final ContactId c = requireNonNull(contactId);
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
long start = now();
|
db.transaction(false, txn ->
|
||||||
messagingManager.addLocalMessage(m);
|
autoDeleteManager.setAutoDeleteTimer(txn, c, timer));
|
||||||
logDuration(LOG, "Storing message", start);
|
autoDeleteTimer.postValue(timer);
|
||||||
Message message = m.getMessage();
|
|
||||||
PrivateMessageHeader h = new PrivateMessageHeader(
|
|
||||||
message.getId(), message.getGroupId(),
|
|
||||||
message.getTimestamp(), true, true, false, false,
|
|
||||||
m.hasText(), m.getAttachmentHeaders());
|
|
||||||
// TODO add text to cache when available here
|
|
||||||
addedHeader.postEvent(h);
|
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
}
|
}
|
||||||
@@ -357,8 +419,8 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
return contactName;
|
return contactName;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveData<Boolean> hasImageSupport() {
|
LiveData<PrivateMessageFormat> getPrivateMessageFormat() {
|
||||||
return imageSupport;
|
return privateMessageFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveEvent<Boolean> showImageOnboarding() {
|
LiveEvent<Boolean> showImageOnboarding() {
|
||||||
@@ -373,6 +435,10 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
return showIntroductionAction;
|
return showIntroductionAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LiveData<Long> getAutoDeleteTimer() {
|
||||||
|
return autoDeleteTimer;
|
||||||
|
}
|
||||||
|
|
||||||
LiveData<Boolean> isContactDeleted() {
|
LiveData<Boolean> isContactDeleted() {
|
||||||
return contactDeleted;
|
return contactDeleted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,10 +60,12 @@ class ConversationVisitor implements
|
|||||||
}
|
}
|
||||||
if (h.isLocal()) {
|
if (h.isLocal()) {
|
||||||
item = new ConversationMessageItem(
|
item = new ConversationMessageItem(
|
||||||
R.layout.list_item_conversation_msg_out, h, attachments);
|
R.layout.list_item_conversation_msg_out, h, contactName,
|
||||||
|
attachments);
|
||||||
} else {
|
} else {
|
||||||
item = new ConversationMessageItem(
|
item = new ConversationMessageItem(
|
||||||
R.layout.list_item_conversation_msg_in, h, attachments);
|
R.layout.list_item_conversation_msg_in, h, contactName,
|
||||||
|
attachments);
|
||||||
}
|
}
|
||||||
if (h.hasText()) {
|
if (h.hasText()) {
|
||||||
String text = textCache.getText(h.getId());
|
String text = textCache.getText(h.getId());
|
||||||
@@ -79,13 +81,15 @@ class ConversationVisitor implements
|
|||||||
String text = ctx.getString(R.string.blogs_sharing_invitation_sent,
|
String text = ctx.getString(R.string.blogs_sharing_invitation_sent,
|
||||||
r.getName(), contactName.getValue());
|
r.getName(), contactName.getValue());
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text, r);
|
R.layout.list_item_conversation_notice_out, text,
|
||||||
|
contactName, r);
|
||||||
} else {
|
} else {
|
||||||
String text = ctx.getString(
|
String text = ctx.getString(
|
||||||
R.string.blogs_sharing_invitation_received,
|
R.string.blogs_sharing_invitation_received,
|
||||||
contactName.getValue(), r.getName());
|
contactName.getValue(), r.getName());
|
||||||
return new ConversationRequestItem(
|
return new ConversationRequestItem(
|
||||||
R.layout.list_item_conversation_request, text, BLOG, r);
|
R.layout.list_item_conversation_request, text, contactName,
|
||||||
|
BLOG, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,13 +102,18 @@ class ConversationVisitor implements
|
|||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.blogs_sharing_response_accepted_sent,
|
R.string.blogs_sharing_response_accepted_sent,
|
||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
|
} else if (r.isAutoDecline()) {
|
||||||
|
text = ctx.getString(
|
||||||
|
R.string.blogs_sharing_response_declined_auto,
|
||||||
|
contactName.getValue());
|
||||||
} else {
|
} else {
|
||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.blogs_sharing_response_declined_sent,
|
R.string.blogs_sharing_response_declined_sent,
|
||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text, r);
|
R.layout.list_item_conversation_notice_out, text,
|
||||||
|
contactName, r);
|
||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
if (r.wasAccepted()) {
|
if (r.wasAccepted()) {
|
||||||
@@ -117,7 +126,8 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_in, text, r);
|
R.layout.list_item_conversation_notice_in, text,
|
||||||
|
contactName, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,13 +138,15 @@ class ConversationVisitor implements
|
|||||||
String text = ctx.getString(R.string.forum_invitation_sent,
|
String text = ctx.getString(R.string.forum_invitation_sent,
|
||||||
r.getName(), contactName.getValue());
|
r.getName(), contactName.getValue());
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text, r);
|
R.layout.list_item_conversation_notice_out, text,
|
||||||
|
contactName, r);
|
||||||
} else {
|
} else {
|
||||||
String text = ctx.getString(
|
String text = ctx.getString(
|
||||||
R.string.forum_invitation_received,
|
R.string.forum_invitation_received,
|
||||||
contactName.getValue(), r.getName());
|
contactName.getValue(), r.getName());
|
||||||
return new ConversationRequestItem(
|
return new ConversationRequestItem(
|
||||||
R.layout.list_item_conversation_request, text, FORUM, r);
|
R.layout.list_item_conversation_request, text, contactName,
|
||||||
|
FORUM, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,13 +159,18 @@ class ConversationVisitor implements
|
|||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.forum_invitation_response_accepted_sent,
|
R.string.forum_invitation_response_accepted_sent,
|
||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
|
} else if (r.isAutoDecline()) {
|
||||||
|
text = ctx.getString(
|
||||||
|
R.string.forum_invitation_response_declined_auto,
|
||||||
|
contactName.getValue());
|
||||||
} else {
|
} else {
|
||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.forum_invitation_response_declined_sent,
|
R.string.forum_invitation_response_declined_sent,
|
||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text, r);
|
R.layout.list_item_conversation_notice_out, text,
|
||||||
|
contactName, r);
|
||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
if (r.wasAccepted()) {
|
if (r.wasAccepted()) {
|
||||||
@@ -166,7 +183,8 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_in, text, r);
|
R.layout.list_item_conversation_notice_in, text,
|
||||||
|
contactName, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,13 +196,15 @@ class ConversationVisitor implements
|
|||||||
R.string.groups_invitations_invitation_sent,
|
R.string.groups_invitations_invitation_sent,
|
||||||
contactName.getValue(), r.getName());
|
contactName.getValue(), r.getName());
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text, r);
|
R.layout.list_item_conversation_notice_out, text,
|
||||||
|
contactName, r);
|
||||||
} else {
|
} else {
|
||||||
String text = ctx.getString(
|
String text = ctx.getString(
|
||||||
R.string.groups_invitations_invitation_received,
|
R.string.groups_invitations_invitation_received,
|
||||||
contactName.getValue(), r.getName());
|
contactName.getValue(), r.getName());
|
||||||
return new ConversationRequestItem(
|
return new ConversationRequestItem(
|
||||||
R.layout.list_item_conversation_request, text, GROUP, r);
|
R.layout.list_item_conversation_request, text, contactName,
|
||||||
|
GROUP, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,13 +217,18 @@ class ConversationVisitor implements
|
|||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.groups_invitations_response_accepted_sent,
|
R.string.groups_invitations_response_accepted_sent,
|
||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
|
} else if (r.isAutoDecline()) {
|
||||||
|
text = ctx.getString(
|
||||||
|
R.string.groups_invitations_response_declined_auto,
|
||||||
|
contactName.getValue());
|
||||||
} else {
|
} else {
|
||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.groups_invitations_response_declined_sent,
|
R.string.groups_invitations_response_declined_sent,
|
||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text, r);
|
R.layout.list_item_conversation_notice_out, text,
|
||||||
|
contactName, r);
|
||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
if (r.wasAccepted()) {
|
if (r.wasAccepted()) {
|
||||||
@@ -216,7 +241,8 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_in, text, r);
|
R.layout.list_item_conversation_notice_in, text,
|
||||||
|
contactName, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +253,8 @@ class ConversationVisitor implements
|
|||||||
String text = ctx.getString(R.string.introduction_request_sent,
|
String text = ctx.getString(R.string.introduction_request_sent,
|
||||||
contactName.getValue(), name);
|
contactName.getValue(), name);
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text, r);
|
R.layout.list_item_conversation_notice_out, text,
|
||||||
|
contactName, r);
|
||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
if (r.wasAnswered()) {
|
if (r.wasAnswered()) {
|
||||||
@@ -243,7 +270,7 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue(), name);
|
contactName.getValue(), name);
|
||||||
}
|
}
|
||||||
return new ConversationRequestItem(
|
return new ConversationRequestItem(
|
||||||
R.layout.list_item_conversation_request, text,
|
R.layout.list_item_conversation_request, text, contactName,
|
||||||
INTRODUCTION, r);
|
INTRODUCTION, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,13 +289,18 @@ class ConversationVisitor implements
|
|||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.introduction_response_accepted_sent,
|
R.string.introduction_response_accepted_sent,
|
||||||
introducedAuthor) + suffix;
|
introducedAuthor) + suffix;
|
||||||
|
} else if (r.isAutoDecline()) {
|
||||||
|
text = ctx.getString(
|
||||||
|
R.string.introduction_response_declined_auto,
|
||||||
|
introducedAuthor);
|
||||||
} else {
|
} else {
|
||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.introduction_response_declined_sent,
|
R.string.introduction_response_declined_sent,
|
||||||
introducedAuthor);
|
introducedAuthor);
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text, r);
|
R.layout.list_item_conversation_notice_out, text,
|
||||||
|
contactName, r);
|
||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
if (r.wasAccepted()) {
|
if (r.wasAccepted()) {
|
||||||
@@ -288,7 +320,8 @@ class ConversationVisitor implements
|
|||||||
introducedAuthor);
|
introducedAuthor);
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_in, text, r);
|
R.layout.list_item_conversation_notice_in, text,
|
||||||
|
contactName, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|||||||
import org.briarproject.briar.android.DestroyableContext;
|
import org.briarproject.briar.android.DestroyableContext;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
@@ -47,13 +46,11 @@ public abstract class BaseFragment extends Fragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
case android.R.id.home:
|
requireActivity().onBackPressed();
|
||||||
listener.onBackPressed();
|
return true;
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@@ -79,6 +76,7 @@ public abstract class BaseFragment extends Fragment
|
|||||||
void handleException(Exception e);
|
void handleException(Exception e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@Override
|
@Override
|
||||||
public void runOnUiThreadUnlessDestroyed(Runnable r) {
|
public void runOnUiThreadUnlessDestroyed(Runnable r) {
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
import de.hdodenhof.circleimageview.CircleImageView;
|
import de.hdodenhof.circleimageview.CircleImageView;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
@@ -46,6 +48,8 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
|||||||
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
|
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.hideSoftKeyboard;
|
import static org.briarproject.briar.android.util.UiUtils.hideSoftKeyboard;
|
||||||
import static org.briarproject.briar.android.view.AuthorView.setAvatar;
|
import static org.briarproject.briar.android.view.AuthorView.setAvatar;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -201,8 +205,8 @@ public class IntroductionMessageFragment extends BaseFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendClick(@Nullable String text,
|
public LiveData<SendState> onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers) {
|
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
||||||
// disable button to prevent accidental double invitations
|
// disable button to prevent accidental double invitations
|
||||||
ui.message.setReady(false);
|
ui.message.setReady(false);
|
||||||
|
|
||||||
@@ -212,6 +216,7 @@ public class IntroductionMessageFragment extends BaseFragment
|
|||||||
hideSoftKeyboard(ui.message);
|
hideSoftKeyboard(ui.message);
|
||||||
introductionActivity.setResult(RESULT_OK);
|
introductionActivity.setResult(RESULT_OK);
|
||||||
introductionActivity.supportFinishAfterTransition();
|
introductionActivity.supportFinishAfterTransition();
|
||||||
|
return new MutableLiveData<>(SENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeIntroduction(Contact c1, Contact c2,
|
private void makeIntroduction(Contact c1, Contact c2,
|
||||||
@@ -219,8 +224,7 @@ public class IntroductionMessageFragment extends BaseFragment
|
|||||||
introductionActivity.runOnDbThread(() -> {
|
introductionActivity.runOnDbThread(() -> {
|
||||||
// actually make the introduction
|
// actually make the introduction
|
||||||
try {
|
try {
|
||||||
long timestamp = System.currentTimeMillis();
|
introductionManager.makeIntroduction(c1, c2, text);
|
||||||
introductionManager.makeIntroduction(c1, c2, text, timestamp);
|
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
introductionError();
|
introductionError();
|
||||||
|
|||||||
@@ -411,6 +411,8 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
|||||||
@UiThread
|
@UiThread
|
||||||
public void onRequestPermissionsResult(int requestCode,
|
public void onRequestPermissionsResult(int requestCode,
|
||||||
String[] permissions, int[] grantResults) {
|
String[] permissions, int[] grantResults) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions,
|
||||||
|
grantResults);
|
||||||
if (requestCode != REQUEST_PERMISSION_CAMERA_LOCATION)
|
if (requestCode != REQUEST_PERMISSION_CAMERA_LOCATION)
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
if (gotPermission(CAMERA, permissions, grantResults)) {
|
if (gotPermission(CAMERA, permissions, grantResults)) {
|
||||||
|
|||||||
@@ -49,14 +49,12 @@ import androidx.annotation.DrawableRes;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.ActionBar;
|
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.lifecycle.ViewModelProviders;
|
import androidx.lifecycle.ViewModelProviders;
|
||||||
@@ -67,9 +65,7 @@ import static android.view.View.GONE;
|
|||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static androidx.core.view.GravityCompat.START;
|
import static androidx.core.view.GravityCompat.START;
|
||||||
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
|
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
|
||||||
import static androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE;
|
|
||||||
import static androidx.lifecycle.Lifecycle.State.STARTED;
|
import static androidx.lifecycle.Lifecycle.State.STARTED;
|
||||||
import static java.util.Objects.requireNonNull;
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING;
|
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING;
|
||||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||||
@@ -146,7 +142,7 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
if (ask) showDozeDialog(getString(R.string.setup_doze_intro));
|
if (ask) showDozeDialog(getString(R.string.setup_doze_intro));
|
||||||
});
|
});
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = setUpCustomToolbar(false);
|
||||||
drawerLayout = findViewById(R.id.drawer_layout);
|
drawerLayout = findViewById(R.id.drawer_layout);
|
||||||
navigation = findViewById(R.id.navigation);
|
navigation = findViewById(R.id.navigation);
|
||||||
GridView transportsView = findViewById(R.id.transportsView);
|
GridView transportsView = findViewById(R.id.transportsView);
|
||||||
@@ -156,11 +152,6 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
startActivity(new Intent(this, TransportsActivity.class));
|
startActivity(new Intent(this, TransportsActivity.class));
|
||||||
});
|
});
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
ActionBar actionBar = requireNonNull(getSupportActionBar());
|
|
||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
||||||
actionBar.setHomeButtonEnabled(true);
|
|
||||||
|
|
||||||
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
|
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
|
||||||
R.string.nav_drawer_open_description,
|
R.string.nav_drawer_open_description,
|
||||||
R.string.nav_drawer_close_description) {
|
R.string.nav_drawer_close_description) {
|
||||||
@@ -184,9 +175,6 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
|
|
||||||
if (lifecycleManager.getLifecycleState().isAfter(RUNNING)) {
|
if (lifecycleManager.getLifecycleState().isAfter(RUNNING)) {
|
||||||
showSignOutFragment();
|
showSignOutFragment();
|
||||||
} else if (state == null) {
|
|
||||||
startFragment(ContactListFragment.newInstance(),
|
|
||||||
R.id.nav_btn_contacts);
|
|
||||||
}
|
}
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
// do not call this again when there's existing state
|
// do not call this again when there's existing state
|
||||||
@@ -276,7 +264,6 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||||
drawerLayout.closeDrawer(START);
|
drawerLayout.closeDrawer(START);
|
||||||
clearBackStack();
|
|
||||||
if (item.getItemId() == R.id.nav_btn_lock) {
|
if (item.getItemId() == R.id.nav_btn_lock) {
|
||||||
lockManager.setLocked(true);
|
lockManager.setLocked(true);
|
||||||
ActivityCompat.finishAfterTransition(this);
|
ActivityCompat.finishAfterTransition(this);
|
||||||
@@ -296,8 +283,8 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
FragmentManager fm = getSupportFragmentManager();
|
FragmentManager fm = getSupportFragmentManager();
|
||||||
if (fm.findFragmentByTag(SignOutFragment.TAG) != null) {
|
if (fm.findFragmentByTag(SignOutFragment.TAG) != null) {
|
||||||
finish();
|
finish();
|
||||||
} else if (fm.getBackStackEntryCount() == 0
|
} else if (fm.getBackStackEntryCount() == 0 &&
|
||||||
&& fm.findFragmentByTag(ContactListFragment.TAG) == null) {
|
fm.findFragmentByTag(ContactListFragment.TAG) == null) {
|
||||||
// don't start fragments in the wrong part of lifecycle (#1904)
|
// don't start fragments in the wrong part of lifecycle (#1904)
|
||||||
if (!getLifecycle().getCurrentState().isAtLeast(STARTED)) {
|
if (!getLifecycle().getCurrentState().isAtLeast(STARTED)) {
|
||||||
LOG.warning("Tried to start contacts fragment in state " +
|
LOG.warning("Tried to start contacts fragment in state " +
|
||||||
@@ -346,30 +333,12 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
startFragment(fragment);
|
startFragment(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startFragment(BaseFragment fragment) {
|
private void startFragment(BaseFragment f) {
|
||||||
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
|
getSupportFragmentManager().beginTransaction()
|
||||||
startFragment(fragment, false);
|
.setCustomAnimations(R.anim.fade_in, R.anim.fade_out,
|
||||||
else startFragment(fragment, true);
|
R.anim.fade_in, R.anim.fade_out)
|
||||||
}
|
.replace(R.id.fragmentContainer, f, f.getUniqueTag())
|
||||||
|
.commit();
|
||||||
private void startFragment(BaseFragment fragment,
|
|
||||||
boolean isAddedToBackStack) {
|
|
||||||
FragmentTransaction trans =
|
|
||||||
getSupportFragmentManager().beginTransaction()
|
|
||||||
.setCustomAnimations(R.anim.fade_in,
|
|
||||||
R.anim.fade_out, R.anim.fade_in,
|
|
||||||
R.anim.fade_out)
|
|
||||||
.replace(R.id.fragmentContainer, fragment,
|
|
||||||
fragment.getUniqueTag());
|
|
||||||
if (isAddedToBackStack) {
|
|
||||||
trans.addToBackStack(fragment.getUniqueTag());
|
|
||||||
}
|
|
||||||
trans.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clearBackStack() {
|
|
||||||
getSupportFragmentManager().popBackStackImmediate(null,
|
|
||||||
POP_BACK_STACK_INCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.NoSuchContactException;
|
import org.briarproject.bramble.api.db.NoSuchContactException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
@@ -15,6 +17,8 @@ import org.briarproject.bramble.api.sync.GroupId;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
||||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessage;
|
import org.briarproject.briar.api.privategroup.GroupMessage;
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
|
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
|
||||||
@@ -36,6 +40,8 @@ import javax.inject.Inject;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -44,9 +50,12 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
implements CreateGroupController {
|
implements CreateGroupController {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(CreateGroupControllerImpl.class.getName());
|
getLogger(CreateGroupControllerImpl.class.getName());
|
||||||
|
|
||||||
private final Executor cryptoExecutor;
|
private final Executor cryptoExecutor;
|
||||||
|
private final TransactionManager db;
|
||||||
|
private final AutoDeleteManager autoDeleteManager;
|
||||||
|
private final ConversationManager conversationManager;
|
||||||
private final ContactManager contactManager;
|
private final ContactManager contactManager;
|
||||||
private final IdentityManager identityManager;
|
private final IdentityManager identityManager;
|
||||||
private final PrivateGroupFactory groupFactory;
|
private final PrivateGroupFactory groupFactory;
|
||||||
@@ -57,17 +66,27 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CreateGroupControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
CreateGroupControllerImpl(
|
||||||
|
@DatabaseExecutor Executor dbExecutor,
|
||||||
@CryptoExecutor Executor cryptoExecutor,
|
@CryptoExecutor Executor cryptoExecutor,
|
||||||
LifecycleManager lifecycleManager, ContactManager contactManager,
|
TransactionManager db,
|
||||||
AuthorManager authorManager, IdentityManager identityManager,
|
AutoDeleteManager autoDeleteManager,
|
||||||
|
ConversationManager conversationManager,
|
||||||
|
LifecycleManager lifecycleManager,
|
||||||
|
ContactManager contactManager,
|
||||||
|
AuthorManager authorManager,
|
||||||
|
IdentityManager identityManager,
|
||||||
PrivateGroupFactory groupFactory,
|
PrivateGroupFactory groupFactory,
|
||||||
GroupMessageFactory groupMessageFactory,
|
GroupMessageFactory groupMessageFactory,
|
||||||
PrivateGroupManager groupManager,
|
PrivateGroupManager groupManager,
|
||||||
GroupInvitationFactory groupInvitationFactory,
|
GroupInvitationFactory groupInvitationFactory,
|
||||||
GroupInvitationManager groupInvitationManager, Clock clock) {
|
GroupInvitationManager groupInvitationManager,
|
||||||
|
Clock clock) {
|
||||||
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
||||||
this.cryptoExecutor = cryptoExecutor;
|
this.cryptoExecutor = cryptoExecutor;
|
||||||
|
this.db = db;
|
||||||
|
this.autoDeleteManager = autoDeleteManager;
|
||||||
|
this.conversationManager = conversationManager;
|
||||||
this.contactManager = contactManager;
|
this.contactManager = contactManager;
|
||||||
this.identityManager = identityManager;
|
this.identityManager = identityManager;
|
||||||
this.groupFactory = groupFactory;
|
this.groupFactory = groupFactory;
|
||||||
@@ -131,16 +150,14 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
ResultExceptionHandler<Void, DbException> handler) {
|
ResultExceptionHandler<Void, DbException> handler) {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
db.transaction(false, txn -> {
|
||||||
List<Contact> contacts = new ArrayList<>();
|
LocalAuthor localAuthor =
|
||||||
for (ContactId c : contactIds) {
|
identityManager.getLocalAuthor(txn);
|
||||||
try {
|
List<InvitationContext> contexts =
|
||||||
contacts.add(contactManager.getContact(c));
|
createInvitationContexts(txn, contactIds);
|
||||||
} catch (NoSuchContactException e) {
|
txn.attach(() -> signInvitations(g, localAuthor, contexts,
|
||||||
// Continue
|
text, handler));
|
||||||
}
|
});
|
||||||
}
|
|
||||||
signInvitations(g, localAuthor, contacts, text, handler);
|
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
handler.onException(e);
|
handler.onException(e);
|
||||||
@@ -148,17 +165,32 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<InvitationContext> createInvitationContexts(Transaction txn,
|
||||||
|
Collection<ContactId> contactIds) throws DbException {
|
||||||
|
List<InvitationContext> contexts = new ArrayList<>();
|
||||||
|
for (ContactId c : contactIds) {
|
||||||
|
try {
|
||||||
|
Contact contact = contactManager.getContact(txn, c);
|
||||||
|
long timestamp = conversationManager
|
||||||
|
.getTimestampForOutgoingMessage(txn, c);
|
||||||
|
long timer = autoDeleteManager.getAutoDeleteTimer(txn, c,
|
||||||
|
timestamp);
|
||||||
|
contexts.add(new InvitationContext(contact, timestamp, timer));
|
||||||
|
} catch (NoSuchContactException e) {
|
||||||
|
// Continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return contexts;
|
||||||
|
}
|
||||||
|
|
||||||
private void signInvitations(GroupId g, LocalAuthor localAuthor,
|
private void signInvitations(GroupId g, LocalAuthor localAuthor,
|
||||||
Collection<Contact> contacts, @Nullable String text,
|
List<InvitationContext> contexts, @Nullable String text,
|
||||||
ResultExceptionHandler<Void, DbException> handler) {
|
ResultExceptionHandler<Void, DbException> handler) {
|
||||||
cryptoExecutor.execute(() -> {
|
cryptoExecutor.execute(() -> {
|
||||||
long timestamp = clock.currentTimeMillis();
|
for (InvitationContext ctx : contexts) {
|
||||||
List<InvitationContext> contexts = new ArrayList<>();
|
ctx.signature = groupInvitationFactory.signInvitation(
|
||||||
for (Contact c : contacts) {
|
ctx.contact, g, ctx.timestamp,
|
||||||
byte[] signature = groupInvitationFactory.signInvitation(c, g,
|
localAuthor.getPrivateKey());
|
||||||
timestamp, localAuthor.getPrivateKey());
|
|
||||||
contexts.add(new InvitationContext(c.getId(), timestamp,
|
|
||||||
signature));
|
|
||||||
}
|
}
|
||||||
sendInvitations(g, contexts, text, handler);
|
sendInvitations(g, contexts, text, handler);
|
||||||
});
|
});
|
||||||
@@ -169,11 +201,12 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
ResultExceptionHandler<Void, DbException> handler) {
|
ResultExceptionHandler<Void, DbException> handler) {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
for (InvitationContext context : contexts) {
|
for (InvitationContext ctx : contexts) {
|
||||||
try {
|
try {
|
||||||
groupInvitationManager.sendInvitation(g,
|
groupInvitationManager.sendInvitation(g,
|
||||||
context.contactId, text, context.timestamp,
|
ctx.contact.getId(), text, ctx.timestamp,
|
||||||
context.signature);
|
requireNonNull(ctx.signature),
|
||||||
|
ctx.autoDeleteTimer);
|
||||||
} catch (NoSuchContactException e) {
|
} catch (NoSuchContactException e) {
|
||||||
// Continue
|
// Continue
|
||||||
}
|
}
|
||||||
@@ -188,15 +221,16 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
|
|
||||||
private static class InvitationContext {
|
private static class InvitationContext {
|
||||||
|
|
||||||
private final ContactId contactId;
|
private final Contact contact;
|
||||||
private final long timestamp;
|
private final long timestamp, autoDeleteTimer;
|
||||||
private final byte[] signature;
|
@Nullable
|
||||||
|
private byte[] signature = null;
|
||||||
|
|
||||||
private InvitationContext(ContactId contactId, long timestamp,
|
private InvitationContext(Contact contact, long timestamp,
|
||||||
byte[] signature) {
|
long autoDeleteTimer) {
|
||||||
this.contactId = contactId;
|
this.contact = contact;
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
this.signature = signature;
|
this.autoDeleteTimer = autoDeleteTimer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ import android.view.View;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.BaseActivity;
|
import org.briarproject.briar.android.activity.BaseActivity;
|
||||||
|
import org.briarproject.briar.android.conversation.glide.GlideApp;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@@ -32,7 +35,7 @@ public class ConfirmAvatarDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
private SettingsViewModel settingsViewModel;
|
private SettingsViewModel viewModel;
|
||||||
|
|
||||||
private static final String ARG_URI = "uri";
|
private static final String ARG_URI = "uri";
|
||||||
private Uri uri;
|
private Uri uri;
|
||||||
@@ -51,6 +54,9 @@ public class ConfirmAvatarDialogFragment extends DialogFragment {
|
|||||||
public void onAttach(Context ctx) {
|
public void onAttach(Context ctx) {
|
||||||
super.onAttach(ctx);
|
super.onAttach(ctx);
|
||||||
((BaseActivity) requireActivity()).getActivityComponent().inject(this);
|
((BaseActivity) requireActivity()).getActivityComponent().inject(this);
|
||||||
|
ViewModelProvider provider =
|
||||||
|
new ViewModelProvider(requireActivity(), viewModelFactory);
|
||||||
|
viewModel = provider.get(SettingsViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -60,32 +66,34 @@ public class ConfirmAvatarDialogFragment extends DialogFragment {
|
|||||||
uri = Uri.parse(argUri);
|
uri = Uri.parse(argUri);
|
||||||
|
|
||||||
FragmentActivity activity = requireActivity();
|
FragmentActivity activity = requireActivity();
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(activity);
|
||||||
ViewModelProvider provider =
|
|
||||||
new ViewModelProvider(activity, viewModelFactory);
|
|
||||||
settingsViewModel = provider.get(SettingsViewModel.class);
|
|
||||||
|
|
||||||
AlertDialog.Builder builder =
|
|
||||||
new AlertDialog.Builder(activity, R.style.BriarDialogTheme);
|
|
||||||
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
|
||||||
final View view =
|
final View view =
|
||||||
inflater.inflate(R.layout.fragment_confirm_avatar_dialog, null);
|
inflater.inflate(R.layout.fragment_confirm_avatar_dialog, null);
|
||||||
builder.setView(view);
|
|
||||||
|
|
||||||
builder.setTitle(R.string.dialog_confirm_profile_picture_title);
|
|
||||||
builder.setNegativeButton(R.string.cancel, null);
|
|
||||||
builder.setPositiveButton(R.string.change,
|
|
||||||
(dialog, id) -> settingsViewModel.setAvatar(uri));
|
|
||||||
|
|
||||||
ImageView imageView = view.findViewById(R.id.image);
|
ImageView imageView = view.findViewById(R.id.image);
|
||||||
imageView.setImageURI(uri);
|
|
||||||
|
|
||||||
TextView textViewUserName = view.findViewById(R.id.username);
|
TextView textViewUserName = view.findViewById(R.id.username);
|
||||||
settingsViewModel.getOwnIdentityInfo().observe(activity,
|
|
||||||
us -> textViewUserName.setText(us.getLocalAuthor().getName()));
|
|
||||||
|
|
||||||
return builder.create();
|
GlideApp.with(imageView)
|
||||||
|
.load(uri)
|
||||||
|
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||||
|
.error(R.drawable.ic_image_broken)
|
||||||
|
.into(imageView)
|
||||||
|
.waitForLayout();
|
||||||
|
|
||||||
|
// we can't use getViewLifecycleOwner() here
|
||||||
|
// as this fragment technically doesn't have a view
|
||||||
|
viewModel.getOwnIdentityInfo().observe(activity, us ->
|
||||||
|
textViewUserName.setText(us.getLocalAuthor().getName())
|
||||||
|
);
|
||||||
|
|
||||||
|
int theme = R.style.BriarDialogTheme;
|
||||||
|
return new AlertDialog.Builder(activity, theme)
|
||||||
|
.setView(view)
|
||||||
|
.setTitle(R.string.dialog_confirm_profile_picture_title)
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.setPositiveButton(R.string.change, (d, id) ->
|
||||||
|
viewModel.setAvatar(uri)
|
||||||
|
)
|
||||||
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class SettingsViewModel extends AndroidViewModel {
|
|||||||
return ownIdentityInfo;
|
return ownIdentityInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveEvent<Boolean> getSetAvatarFailed() {
|
LiveEvent<Boolean> getSetAvatarFailed() {
|
||||||
return setAvatarFailed;
|
return setAvatarFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
|||||||
import org.briarproject.briar.android.view.LargeTextInputView;
|
import org.briarproject.briar.android.view.LargeTextInputView;
|
||||||
import org.briarproject.briar.android.view.TextSendController;
|
import org.briarproject.briar.android.view.TextSendController;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
||||||
|
import org.briarproject.briar.android.view.TextSendController.SendState;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -22,6 +23,10 @@ import java.util.List;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
@@ -79,13 +84,14 @@ public abstract class BaseMessageFragment extends BaseFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendClick(@Nullable String text,
|
public LiveData<SendState> onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers) {
|
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
||||||
// disable button to prevent accidental double actions
|
// disable button to prevent accidental double actions
|
||||||
sendController.setReady(false);
|
sendController.setReady(false);
|
||||||
message.hideSoftKeyboard();
|
message.hideSoftKeyboard();
|
||||||
|
|
||||||
listener.onButtonClick(text);
|
listener.onButtonClick(text);
|
||||||
|
return new MutableLiveData<>(SENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|||||||
@@ -10,11 +10,9 @@ import org.briarproject.bramble.api.db.NoSuchGroupException;
|
|||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
|
||||||
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
||||||
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
||||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -26,6 +24,7 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -34,22 +33,17 @@ class ShareBlogControllerImpl extends ContactSelectorControllerImpl
|
|||||||
implements ShareBlogController {
|
implements ShareBlogController {
|
||||||
|
|
||||||
private final static Logger LOG =
|
private final static Logger LOG =
|
||||||
Logger.getLogger(ShareBlogControllerImpl.class.getName());
|
getLogger(ShareBlogControllerImpl.class.getName());
|
||||||
|
|
||||||
private final ConversationManager conversationManager;
|
|
||||||
private final BlogSharingManager blogSharingManager;
|
private final BlogSharingManager blogSharingManager;
|
||||||
private final Clock clock;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ShareBlogControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
ShareBlogControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
LifecycleManager lifecycleManager, ContactManager contactManager,
|
LifecycleManager lifecycleManager, ContactManager contactManager,
|
||||||
AuthorManager authorManager,
|
AuthorManager authorManager,
|
||||||
ConversationManager conversationManager,
|
BlogSharingManager blogSharingManager) {
|
||||||
BlogSharingManager blogSharingManager, Clock clock) {
|
|
||||||
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
||||||
this.conversationManager = conversationManager;
|
|
||||||
this.blogSharingManager = blogSharingManager;
|
this.blogSharingManager = blogSharingManager;
|
||||||
this.clock = clock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -64,10 +58,7 @@ class ShareBlogControllerImpl extends ContactSelectorControllerImpl
|
|||||||
try {
|
try {
|
||||||
for (ContactId c : contacts) {
|
for (ContactId c : contacts) {
|
||||||
try {
|
try {
|
||||||
long time = Math.max(clock.currentTimeMillis(),
|
blogSharingManager.sendInvitation(g, c, text);
|
||||||
conversationManager.getGroupCount(c)
|
|
||||||
.getLatestMsgTime() + 1);
|
|
||||||
blogSharingManager.sendInvitation(g, c, text, time);
|
|
||||||
} catch (NoSuchContactException | NoSuchGroupException e) {
|
} catch (NoSuchContactException | NoSuchGroupException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,8 @@ import org.briarproject.bramble.api.db.NoSuchGroupException;
|
|||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
|
||||||
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
||||||
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
|
||||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
|
||||||
@@ -26,6 +24,7 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -34,22 +33,17 @@ class ShareForumControllerImpl extends ContactSelectorControllerImpl
|
|||||||
implements ShareForumController {
|
implements ShareForumController {
|
||||||
|
|
||||||
private final static Logger LOG =
|
private final static Logger LOG =
|
||||||
Logger.getLogger(ShareForumControllerImpl.class.getName());
|
getLogger(ShareForumControllerImpl.class.getName());
|
||||||
|
|
||||||
private final ConversationManager conversationManager;
|
|
||||||
private final ForumSharingManager forumSharingManager;
|
private final ForumSharingManager forumSharingManager;
|
||||||
private final Clock clock;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ShareForumControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
ShareForumControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
LifecycleManager lifecycleManager, ContactManager contactManager,
|
LifecycleManager lifecycleManager, ContactManager contactManager,
|
||||||
AuthorManager authorManager,
|
AuthorManager authorManager,
|
||||||
ConversationManager conversationManager,
|
ForumSharingManager forumSharingManager) {
|
||||||
ForumSharingManager forumSharingManager, Clock clock) {
|
|
||||||
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
||||||
this.conversationManager = conversationManager;
|
|
||||||
this.forumSharingManager = forumSharingManager;
|
this.forumSharingManager = forumSharingManager;
|
||||||
this.clock = clock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -64,10 +58,7 @@ class ShareForumControllerImpl extends ContactSelectorControllerImpl
|
|||||||
try {
|
try {
|
||||||
for (ContactId c : contacts) {
|
for (ContactId c : contacts) {
|
||||||
try {
|
try {
|
||||||
long time = Math.max(clock.currentTimeMillis(),
|
forumSharingManager.sendInvitation(g, c, text);
|
||||||
conversationManager.getGroupCount(c)
|
|
||||||
.getLatestMsgTime() + 1);
|
|
||||||
forumSharingManager.sendInvitation(g, c, text, time);
|
|
||||||
} catch (NoSuchContactException | NoSuchGroupException e) {
|
} catch (NoSuchContactException | NoSuchGroupException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.briarproject.briar.android.view.BriarRecyclerView;
|
|||||||
import org.briarproject.briar.android.view.TextInputView;
|
import org.briarproject.briar.android.view.TextInputView;
|
||||||
import org.briarproject.briar.android.view.TextSendController;
|
import org.briarproject.briar.android.view.TextSendController;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
||||||
|
import org.briarproject.briar.android.view.TextSendController.SendState;
|
||||||
import org.briarproject.briar.android.view.UnreadMessageButton;
|
import org.briarproject.briar.android.view.UnreadMessageButton;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
|
|
||||||
@@ -29,10 +30,13 @@ import javax.annotation.Nullable;
|
|||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
@@ -231,8 +235,8 @@ public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendClick(@Nullable String text,
|
public LiveData<SendState> onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers) {
|
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
||||||
if (isNullOrEmpty(text)) throw new AssertionError();
|
if (isNullOrEmpty(text)) throw new AssertionError();
|
||||||
|
|
||||||
MessageId replyId = getViewModel().getReplyId();
|
MessageId replyId = getViewModel().getReplyId();
|
||||||
@@ -241,6 +245,7 @@ public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadI
|
|||||||
textInput.clearText();
|
textInput.clearText();
|
||||||
getViewModel().setReplyId(null);
|
getViewModel().setReplyId(null);
|
||||||
updateTextInput();
|
updateTextInput();
|
||||||
|
return new MutableLiveData<>(SENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract int getMaxTextLength();
|
protected abstract int getMaxTextLength();
|
||||||
|
|||||||
@@ -197,6 +197,10 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
|
|||||||
*/
|
*/
|
||||||
@UiThread
|
@UiThread
|
||||||
protected void addItem(I item, boolean scrollToItem) {
|
protected void addItem(I item, boolean scrollToItem) {
|
||||||
|
// If items haven't loaded, we need to wait until they have.
|
||||||
|
// Since this was a R/W DB transaction, the load will pick up this item.
|
||||||
|
if (items.getValue() == null) return;
|
||||||
|
|
||||||
messageTree.add(item);
|
messageTree.add(item);
|
||||||
if (scrollToItem) this.scrollToItem.set(item.getId());
|
if (scrollToItem) this.scrollToItem.set(item.getId());
|
||||||
items.setValue(new LiveResult<>(messageTree.depthFirstOrder()));
|
items.setValue(new LiveResult<>(messageTree.depthFirstOrder()));
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.app.KeyguardManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
@@ -76,6 +77,7 @@ import static android.text.format.DateUtils.FORMAT_ABBREV_TIME;
|
|||||||
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
|
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
|
||||||
import static android.text.format.DateUtils.FORMAT_SHOW_TIME;
|
import static android.text.format.DateUtils.FORMAT_SHOW_TIME;
|
||||||
import static android.text.format.DateUtils.FORMAT_SHOW_YEAR;
|
import static android.text.format.DateUtils.FORMAT_SHOW_YEAR;
|
||||||
|
import static android.text.format.DateUtils.HOUR_IN_MILLIS;
|
||||||
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
||||||
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
|
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
|
||||||
import static android.text.format.DateUtils.YEAR_IN_MILLIS;
|
import static android.text.format.DateUtils.YEAR_IN_MILLIS;
|
||||||
@@ -167,6 +169,37 @@ public class UiUtils {
|
|||||||
return DateUtils.formatDateTime(ctx, time, flags);
|
return DateUtils.formatDateTime(ctx, time, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the given duration in a human-friendly format. For example,
|
||||||
|
* "7 days" or "1 hour". Returns only the largest meaningful unit of time,
|
||||||
|
* from days up to minutes.
|
||||||
|
*/
|
||||||
|
public static String formatDuration(Context ctx, long millis) {
|
||||||
|
Resources r = ctx.getResources();
|
||||||
|
if (millis >= DAY_IN_MILLIS) {
|
||||||
|
int days = (int) (millis / DAY_IN_MILLIS);
|
||||||
|
int rest = (int) (millis % DAY_IN_MILLIS);
|
||||||
|
String dayStr =
|
||||||
|
r.getQuantityString(R.plurals.duration_days, days, days);
|
||||||
|
if (rest < HOUR_IN_MILLIS / 2) return dayStr;
|
||||||
|
else return dayStr + " " + formatDuration(ctx, rest);
|
||||||
|
} else if (millis >= HOUR_IN_MILLIS) {
|
||||||
|
int hours = (int) (millis / HOUR_IN_MILLIS);
|
||||||
|
int rest = (int) (millis % HOUR_IN_MILLIS);
|
||||||
|
String hourStr =
|
||||||
|
r.getQuantityString(R.plurals.duration_hours, hours, hours);
|
||||||
|
if (rest < MINUTE_IN_MILLIS / 2) return hourStr;
|
||||||
|
else return hourStr + " " + formatDuration(ctx, rest);
|
||||||
|
} else {
|
||||||
|
int minutes =
|
||||||
|
(int) ((millis + MINUTE_IN_MILLIS / 2) / MINUTE_IN_MILLIS);
|
||||||
|
// anything less than one minute is shown as one minute
|
||||||
|
if (minutes < 1) minutes = 1;
|
||||||
|
return r.getQuantityString(R.plurals.duration_minutes, minutes,
|
||||||
|
minutes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static long getDaysUntilExpiry() {
|
public static long getDaysUntilExpiry() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
return (EXPIRY_DATE - now) / DAYS.toMillis(1);
|
return (EXPIRY_DATE - now) / DAYS.toMillis(1);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.util.AttributeSet;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
@@ -19,6 +20,7 @@ import static java.util.Objects.requireNonNull;
|
|||||||
public class CompositeSendButton extends FrameLayout {
|
public class CompositeSendButton extends FrameLayout {
|
||||||
|
|
||||||
private final AppCompatImageButton sendButton, imageButton;
|
private final AppCompatImageButton sendButton, imageButton;
|
||||||
|
private final ImageView bombBadge;
|
||||||
private final ProgressBar progressBar;
|
private final ProgressBar progressBar;
|
||||||
|
|
||||||
private boolean hasImageSupport = false;
|
private boolean hasImageSupport = false;
|
||||||
@@ -32,6 +34,7 @@ public class CompositeSendButton extends FrameLayout {
|
|||||||
|
|
||||||
sendButton = findViewById(R.id.sendButton);
|
sendButton = findViewById(R.id.sendButton);
|
||||||
imageButton = findViewById(R.id.imageButton);
|
imageButton = findViewById(R.id.imageButton);
|
||||||
|
bombBadge = findViewById(R.id.bombBadge);
|
||||||
progressBar = findViewById(R.id.progressBar);
|
progressBar = findViewById(R.id.progressBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +74,10 @@ public class CompositeSendButton extends FrameLayout {
|
|||||||
return hasImageSupport;
|
return hasImageSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBombVisible(boolean visible) {
|
||||||
|
bombBadge.setVisibility(visible ? VISIBLE : INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
public void showImageButton(boolean showImageButton, boolean sendEnabled) {
|
public void showImageButton(boolean showImageButton, boolean sendEnabled) {
|
||||||
if (showImageButton) {
|
if (showImageButton) {
|
||||||
imageButton.setVisibility(VISIBLE);
|
imageButton.setVisibility(VISIBLE);
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.appcompat.app.AlertDialog.Builder;
|
import androidx.appcompat.app.AlertDialog.Builder;
|
||||||
import androidx.customview.view.AbsSavedState;
|
import androidx.customview.view.AbsSavedState;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
||||||
@@ -39,6 +38,7 @@ import static androidx.core.content.ContextCompat.getColor;
|
|||||||
import static androidx.customview.view.AbsSavedState.EMPTY_STATE;
|
import static androidx.customview.view.AbsSavedState.EMPTY_STATE;
|
||||||
import static androidx.lifecycle.Lifecycle.State.DESTROYED;
|
import static androidx.lifecycle.Lifecycle.State.DESTROYED;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.resolveColorAttribute;
|
import static org.briarproject.briar.android.util.UiUtils.resolveColorAttribute;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@@ -52,7 +52,6 @@ public class TextAttachmentController extends TextSendController
|
|||||||
private final AttachmentManager attachmentManager;
|
private final AttachmentManager attachmentManager;
|
||||||
|
|
||||||
private final List<Uri> imageUris = new ArrayList<>();
|
private final List<Uri> imageUris = new ArrayList<>();
|
||||||
private final CharSequence textHint;
|
|
||||||
private boolean loadingUris = false;
|
private boolean loadingUris = false;
|
||||||
|
|
||||||
public TextAttachmentController(TextInputView v, ImagePreview imagePreview,
|
public TextAttachmentController(TextInputView v, ImagePreview imagePreview,
|
||||||
@@ -66,23 +65,44 @@ public class TextAttachmentController extends TextSendController
|
|||||||
|
|
||||||
sendButton = (CompositeSendButton) compositeSendButton;
|
sendButton = (CompositeSendButton) compositeSendButton;
|
||||||
sendButton.setOnImageClickListener(view -> onImageButtonClicked());
|
sendButton.setOnImageClickListener(view -> onImageButtonClicked());
|
||||||
|
|
||||||
textHint = textInput.getHint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateViewState() {
|
protected void updateViewState() {
|
||||||
textInput.setEnabled(ready && !loadingUris);
|
super.updateViewState();
|
||||||
boolean sendEnabled = ready && !loadingUris &&
|
|
||||||
(!textIsEmpty || canSendEmptyText());
|
|
||||||
if (loadingUris) {
|
if (loadingUris) {
|
||||||
sendButton.showProgress(true);
|
sendButton.showProgress(true);
|
||||||
} else if (imageUris.isEmpty()) {
|
} else if (imageUris.isEmpty()) {
|
||||||
sendButton.showProgress(false);
|
sendButton.showProgress(false);
|
||||||
sendButton.showImageButton(textIsEmpty, sendEnabled);
|
sendButton.showImageButton(textIsEmpty, isSendButtonEnabled());
|
||||||
} else {
|
} else {
|
||||||
sendButton.showProgress(false);
|
sendButton.showProgress(false);
|
||||||
sendButton.showImageButton(false, sendEnabled);
|
sendButton.showImageButton(false, isSendButtonEnabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isTextInputEnabled() {
|
||||||
|
return super.isTextInputEnabled() && !loadingUris;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isSendButtonEnabled() {
|
||||||
|
return super.isSendButtonEnabled() && !loadingUris;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isBombVisible() {
|
||||||
|
return super.isBombVisible() && (!textIsEmpty || !imageUris.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CharSequence getCurrentTextHint() {
|
||||||
|
if (imageUris.isEmpty()) {
|
||||||
|
return super.getCurrentTextHint();
|
||||||
|
} else {
|
||||||
|
Context ctx = textInput.getContext();
|
||||||
|
return ctx.getString(R.string.image_caption_hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,11 +111,17 @@ public class TextAttachmentController extends TextSendController
|
|||||||
if (canSend()) {
|
if (canSend()) {
|
||||||
if (loadingUris) throw new AssertionError();
|
if (loadingUris) throw new AssertionError();
|
||||||
listener.onSendClick(textInput.getText(),
|
listener.onSendClick(textInput.getText(),
|
||||||
attachmentManager.getAttachmentHeadersForSending());
|
attachmentManager.getAttachmentHeadersForSending(),
|
||||||
reset();
|
expectedTimer).observe(listener, this::onSendStateChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSendStateChanged(SendState sendState) {
|
||||||
|
super.onSendStateChanged(sendState);
|
||||||
|
if (sendState == SENT) reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canSendEmptyText() {
|
protected boolean canSendEmptyText() {
|
||||||
return !imageUris.isEmpty();
|
return !imageUris.isEmpty();
|
||||||
@@ -154,6 +180,7 @@ public class TextAttachmentController extends TextSendController
|
|||||||
private void onNewUris(boolean restart, List<Uri> newUris) {
|
private void onNewUris(boolean restart, List<Uri> newUris) {
|
||||||
if (newUris.isEmpty()) return;
|
if (newUris.isEmpty()) return;
|
||||||
if (loadingUris) throw new AssertionError();
|
if (loadingUris) throw new AssertionError();
|
||||||
|
if (textIsEmpty) onStartingMessage();
|
||||||
loadingUris = true;
|
loadingUris = true;
|
||||||
if (newUris.size() > MAX_ATTACHMENTS_PER_MESSAGE) {
|
if (newUris.size() > MAX_ATTACHMENTS_PER_MESSAGE) {
|
||||||
newUris = newUris.subList(0, MAX_ATTACHMENTS_PER_MESSAGE);
|
newUris = newUris.subList(0, MAX_ATTACHMENTS_PER_MESSAGE);
|
||||||
@@ -161,7 +188,6 @@ public class TextAttachmentController extends TextSendController
|
|||||||
}
|
}
|
||||||
imageUris.addAll(newUris);
|
imageUris.addAll(newUris);
|
||||||
updateViewState();
|
updateViewState();
|
||||||
textInput.setHint(R.string.image_caption_hint);
|
|
||||||
List<ImagePreviewItem> items = ImagePreviewItem.fromUris(imageUris);
|
List<ImagePreviewItem> items = ImagePreviewItem.fromUris(imageUris);
|
||||||
imagePreview.showPreview(items);
|
imagePreview.showPreview(items);
|
||||||
// store attachments and show preview when successful
|
// store attachments and show preview when successful
|
||||||
@@ -207,8 +233,6 @@ public class TextAttachmentController extends TextSendController
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reset() {
|
private void reset() {
|
||||||
// restore hint
|
|
||||||
textInput.setHint(textHint);
|
|
||||||
// hide image layout
|
// hide image layout
|
||||||
imagePreview.setVisibility(GONE);
|
imagePreview.setVisibility(GONE);
|
||||||
// reset image URIs
|
// reset image URIs
|
||||||
@@ -303,7 +327,7 @@ public class TextAttachmentController extends TextSendController
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
public interface AttachmentListener extends SendListener, LifecycleOwner {
|
public interface AttachmentListener extends SendListener {
|
||||||
|
|
||||||
void onAttachImage(Intent intent);
|
void onAttachImage(Intent intent);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package org.briarproject.briar.android.view;
|
package org.briarproject.briar.android.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
@@ -12,11 +14,20 @@ import org.briarproject.briar.api.attachment.AttachmentHeader;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import androidx.annotation.CallSuper;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
|
import static android.widget.Toast.LENGTH_LONG;
|
||||||
import static com.google.android.material.snackbar.Snackbar.LENGTH_SHORT;
|
import static com.google.android.material.snackbar.Snackbar.LENGTH_SHORT;
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.ERROR;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
||||||
|
import static org.briarproject.briar.android.view.TextSendController.SendState.UNEXPECTED_TIMER;
|
||||||
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -26,8 +37,12 @@ public class TextSendController implements TextInputListener {
|
|||||||
protected final View compositeSendButton;
|
protected final View compositeSendButton;
|
||||||
protected final SendListener listener;
|
protected final SendListener listener;
|
||||||
|
|
||||||
protected boolean ready = true, textIsEmpty = true;
|
protected boolean textIsEmpty = true;
|
||||||
|
private boolean ready = true;
|
||||||
|
private long currentTimer = NO_AUTO_DELETE_TIMER;
|
||||||
|
protected long expectedTimer = NO_AUTO_DELETE_TIMER;
|
||||||
|
|
||||||
|
private final CharSequence defaultHint;
|
||||||
private final boolean allowEmptyText;
|
private final boolean allowEmptyText;
|
||||||
|
|
||||||
public TextSendController(TextInputView v, SendListener listener,
|
public TextSendController(TextInputView v, SendListener listener,
|
||||||
@@ -36,31 +51,91 @@ public class TextSendController implements TextInputListener {
|
|||||||
this.compositeSendButton.setOnClickListener(view -> onSendEvent());
|
this.compositeSendButton.setOnClickListener(view -> onSendEvent());
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.textInput = v.getEmojiTextInputView();
|
this.textInput = v.getEmojiTextInputView();
|
||||||
|
this.defaultHint = textInput.getHint();
|
||||||
this.allowEmptyText = allowEmptyText;
|
this.allowEmptyText = allowEmptyText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextIsEmptyChanged(boolean isEmpty) {
|
public void onTextIsEmptyChanged(boolean isEmpty) {
|
||||||
textIsEmpty = isEmpty;
|
textIsEmpty = isEmpty;
|
||||||
|
if (!isEmpty) onStartingMessage();
|
||||||
updateViewState();
|
updateViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendEvent() {
|
public void onSendEvent() {
|
||||||
if (canSend()) {
|
if (canSend()) {
|
||||||
listener.onSendClick(textInput.getText(), emptyList());
|
listener.onSendClick(textInput.getText(), emptyList(),
|
||||||
|
expectedTimer).observe(listener, this::onSendStateChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
protected void onSendStateChanged(SendState sendState) {
|
||||||
|
if (sendState == SENT) {
|
||||||
|
textInput.clearText();
|
||||||
|
} else if (sendState == UNEXPECTED_TIMER) {
|
||||||
|
boolean enabled = expectedTimer == NO_AUTO_DELETE_TIMER;
|
||||||
|
showTimerChangedDialog(enabled);
|
||||||
|
} else if (sendState == ERROR) {
|
||||||
|
Toast.makeText(textInput.getContext(), R.string.message_error,
|
||||||
|
LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call whenever the user starts a new message,
|
||||||
|
* either by entering text or adding an attachment.
|
||||||
|
* This updates the expected auto-delete timer to the current value.
|
||||||
|
*/
|
||||||
|
protected void onStartingMessage() {
|
||||||
|
expectedTimer = currentTimer;
|
||||||
|
}
|
||||||
|
|
||||||
public void setReady(boolean ready) {
|
public void setReady(boolean ready) {
|
||||||
this.ready = ready;
|
this.ready = ready;
|
||||||
updateViewState();
|
updateViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current auto delete timer and updates the UI accordingly.
|
||||||
|
*/
|
||||||
|
public void setAutoDeleteTimer(long timer) {
|
||||||
|
currentTimer = timer;
|
||||||
|
updateViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
protected void updateViewState() {
|
protected void updateViewState() {
|
||||||
textInput.setEnabled(ready);
|
textInput.setEnabled(isTextInputEnabled());
|
||||||
compositeSendButton
|
textInput.setHint(getCurrentTextHint());
|
||||||
.setEnabled(ready && (!textIsEmpty || canSendEmptyText()));
|
compositeSendButton.setEnabled(isSendButtonEnabled());
|
||||||
|
if (compositeSendButton instanceof CompositeSendButton) {
|
||||||
|
CompositeSendButton sendButton =
|
||||||
|
(CompositeSendButton) compositeSendButton;
|
||||||
|
sendButton.setBombVisible(isBombVisible());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isTextInputEnabled() {
|
||||||
|
return ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isSendButtonEnabled() {
|
||||||
|
return ready && (!textIsEmpty || canSendEmptyText());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isBombVisible() {
|
||||||
|
return currentTimer != NO_AUTO_DELETE_TIMER;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CharSequence getCurrentTextHint() {
|
||||||
|
if (currentTimer == NO_AUTO_DELETE_TIMER) {
|
||||||
|
return defaultHint;
|
||||||
|
} else {
|
||||||
|
Context ctx = textInput.getContext();
|
||||||
|
return ctx.getString(R.string.message_hint_auto_delete);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean canSend() {
|
protected final boolean canSend() {
|
||||||
@@ -76,6 +151,23 @@ public class TextSendController implements TextInputListener {
|
|||||||
return allowEmptyText;
|
return allowEmptyText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showTimerChangedDialog(boolean enabled) {
|
||||||
|
Context ctx = textInput.getContext();
|
||||||
|
int message =
|
||||||
|
enabled ? R.string.auto_delete_changed_warning_message_enabled :
|
||||||
|
R.string.auto_delete_changed_warning_message_disabled;
|
||||||
|
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme)
|
||||||
|
.setTitle(R.string.auto_delete_changed_warning_title)
|
||||||
|
.setMessage(message)
|
||||||
|
.setPositiveButton(R.string.auto_delete_changed_warning_send,
|
||||||
|
(dialog, which) -> {
|
||||||
|
expectedTimer = currentTimer;
|
||||||
|
onSendEvent();
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Parcelable onSaveInstanceState(@Nullable Parcelable superState) {
|
public Parcelable onSaveInstanceState(@Nullable Parcelable superState) {
|
||||||
return superState;
|
return superState;
|
||||||
@@ -86,9 +178,11 @@ public class TextSendController implements TextInputListener {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
public enum SendState {SENT, ERROR, UNEXPECTED_TIMER}
|
||||||
public interface SendListener {
|
|
||||||
void onSendClick(@Nullable String text, List<AttachmentHeader> headers);
|
public interface SendListener extends LifecycleOwner {
|
||||||
|
LiveData<SendState> onSendClick(@Nullable String text,
|
||||||
|
List<AttachmentHeader> headers, long expectedAutoDeleteTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package org.briarproject.briar.android.widget;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.StringRes;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public class OnboardingFullDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
public final static String TAG =
|
||||||
|
OnboardingFullDialogFragment.class.getName();
|
||||||
|
|
||||||
|
private final static String RES_TITLE = "resTitle";
|
||||||
|
private final static String RES_CONTENT = "resContent";
|
||||||
|
|
||||||
|
public static OnboardingFullDialogFragment newInstance(@StringRes int title,
|
||||||
|
@StringRes int content) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putInt(RES_TITLE, title);
|
||||||
|
args.putInt(RES_CONTENT, content);
|
||||||
|
OnboardingFullDialogFragment f = new OnboardingFullDialogFragment();
|
||||||
|
f.setArguments(args);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setStyle(DialogFragment.STYLE_NORMAL,
|
||||||
|
R.style.BriarFullScreenDialogTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.fragment_onboarding_full,
|
||||||
|
container, false);
|
||||||
|
|
||||||
|
Bundle args = requireArguments();
|
||||||
|
|
||||||
|
Toolbar toolbar = view.findViewById(R.id.toolbar);
|
||||||
|
toolbar.setNavigationOnClickListener(v -> dismiss());
|
||||||
|
toolbar.setTitle(args.getInt(RES_TITLE));
|
||||||
|
|
||||||
|
TextView contentView = view.findViewById(R.id.contentView);
|
||||||
|
contentView.setText(args.getInt(RES_CONTENT));
|
||||||
|
|
||||||
|
view.findViewById(R.id.button).setOnClickListener(v -> dismiss());
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -39,7 +39,8 @@ public interface AndroidNotificationManager {
|
|||||||
String BLOG_CHANNEL_ID = "blogs";
|
String BLOG_CHANNEL_ID = "blogs";
|
||||||
// Channels are sorted by channel ID in the Settings app, so use IDs
|
// Channels are sorted by channel ID in the Settings app, so use IDs
|
||||||
// that will sort below the main channels such as contacts
|
// that will sort below the main channels such as contacts
|
||||||
String ONGOING_CHANNEL_ID = "zForegroundService";
|
String ONGOING_CHANNEL_OLD_ID = "zForegroundService";
|
||||||
|
String ONGOING_CHANNEL_ID = "zForegroundService2";
|
||||||
String FAILURE_CHANNEL_ID = "zStartupFailure";
|
String FAILURE_CHANNEL_ID = "zStartupFailure";
|
||||||
String REMINDER_CHANNEL_ID = "zSignInReminder";
|
String REMINDER_CHANNEL_ID = "zSignInReminder";
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import androidx.lifecycle.LiveData;
|
|||||||
public interface LockManager {
|
public interface LockManager {
|
||||||
|
|
||||||
String ACTION_LOCK = "lock";
|
String ACTION_LOCK = "lock";
|
||||||
|
String EXTRA_PID = "PID";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the inactivity timer when the user interacts with the app.
|
* Stops the inactivity timer when the user interacts with the app.
|
||||||
|
|||||||
9
briar-android/src/main/res/drawable/ic_bomb.xml
Normal file
9
briar-android/src/main/res/drawable/ic_bomb.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="16dp"
|
||||||
|
android:height="16dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M11.25,6A3.25,3.25 0 0,1 14.5,2.75A3.25,3.25 0 0,1 17.75,6C17.75,6.42 18.08,6.75 18.5,6.75C18.92,6.75 19.25,6.42 19.25,6V5.25H20.75V6A2.25,2.25 0 0,1 18.5,8.25A2.25,2.25 0 0,1 16.25,6A1.75,1.75 0 0,0 14.5,4.25A1.75,1.75 0 0,0 12.75,6H14V7.29C16.89,8.15 19,10.83 19,14A7,7 0 0,1 12,21A7,7 0 0,1 5,14C5,10.83 7.11,8.15 10,7.29V6H11.25M22,6H24V7H22V6M19,4V2H20V4H19M20.91,4.38L22.33,2.96L23.04,3.67L21.62,5.09L20.91,4.38Z" />
|
||||||
|
</vector>
|
||||||
@@ -52,16 +52,17 @@
|
|||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:contentDescription="@string/close"
|
android:contentDescription="@string/close"
|
||||||
android:scaleType="center"
|
android:scaleType="center"
|
||||||
app:srcCompat="@drawable/ic_close"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:srcCompat="@drawable/ic_close"
|
||||||
app:tint="@color/briar_text_tertiary_inverse" />
|
app:tint="@color/briar_text_tertiary_inverse" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<androidx.fragment.app.FragmentContainerView
|
||||||
android:id="@+id/fragmentContainer"
|
android:id="@+id/fragmentContainer"
|
||||||
|
android:name="org.briarproject.briar.android.contact.ContactListFragment"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
style="@style/BriarToolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:navigationIcon="@drawable/abc_ic_ab_back_material"
|
||||||
|
app:title="@string/disappearing_messages_title" />
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/toolbar">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/imageViewBomb"
|
||||||
|
android:layout_width="64dp"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:srcCompat="@drawable/ic_bomb"
|
||||||
|
app:tint="?attr/colorControlNormal"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
|
android:id="@+id/switchDisappearingMessages"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:enabled="false"
|
||||||
|
android:text="@string/disappearing_messages_summary"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/imageViewBomb"
|
||||||
|
tools:enabled="true" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonLearnMore"
|
||||||
|
style="@style/BriarButtonFlat.Positive"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:text="@string/learn_more"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textSize="14sp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/switchDisappearingMessages" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
style="@style/BriarToolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:elevation="4dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:navigationIcon="@drawable/abc_ic_ab_back_material"
|
||||||
|
tools:title="Onboarding Fullscreen Dialog" />
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/briar_primary"
|
||||||
|
android:fillViewport="true">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/imageView"
|
||||||
|
android:layout_width="64dp"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:srcCompat="@drawable/ic_info_white"
|
||||||
|
app:tint="@color/briar_text_secondary_inverse"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/contentView"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:textColor="@color/briar_text_secondary_inverse"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/button"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/imageView"
|
||||||
|
app:layout_constraintVertical_bias="0.0"
|
||||||
|
tools:text="@tools:sample/lorem/random" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button"
|
||||||
|
style="@style/BriarButtonFlat.Positive"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/got_it"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!-- This layout is only used indirectly by cloning and setting its ConstraintSet -->
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
@@ -68,6 +70,16 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/bomb"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_marginEnd="4dp"
|
||||||
|
app:srcCompat="@drawable/ic_bomb"
|
||||||
|
app:tint="?android:attr/textColorSecondary"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!-- This layout is only used indirectly by cloning and setting its ConstraintSet -->
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
@@ -58,7 +60,8 @@
|
|||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="1.0"
|
app:layout_constraintHorizontal_bias="1.0"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/text">
|
app:layout_constraintTop_toBottomOf="@+id/text"
|
||||||
|
tools:ignore="UseCompoundDrawables">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/time"
|
android:id="@+id/time"
|
||||||
@@ -67,6 +70,16 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/bomb"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_marginEnd="4dp"
|
||||||
|
app:srcCompat="@drawable/ic_bomb"
|
||||||
|
app:tint="?android:attr/textColorSecondary"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/list_item_background_selectable">
|
android:background="@drawable/list_item_background_selectable"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
We need to wrap the actual layout, because
|
We need to wrap the actual layout, because we want to
|
||||||
* we want to clone the ConstraintLayout's constraints in the ViewHolder
|
* clone the ConstraintLayout's constraints in the ViewHolder
|
||||||
* we want to have a selectable frame around the message bubble
|
* have a selectable frame around the message bubble
|
||||||
|
* insert a top notice with its own independent width
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<include layout="@layout/list_item_conversation_top_notice_in" />
|
||||||
|
|
||||||
<include layout="@layout/list_item_conversation_msg_in_content" />
|
<include layout="@layout/list_item_conversation_msg_in_content" />
|
||||||
|
|
||||||
</FrameLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!-- This layout gets wrapped in *_msg_in.xml -->
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
@@ -68,6 +70,17 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/bomb"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_marginLeft="4dp"
|
||||||
|
app:srcCompat="@drawable/ic_bomb"
|
||||||
|
app:tint="?android:attr/textColorSecondary"
|
||||||
|
tools:ignore="ContentDescription"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/list_item_background_selectable">
|
android:background="@drawable/list_item_background_selectable"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingTop="@dimen/message_bubble_margin">
|
||||||
|
|
||||||
|
<include layout="@layout/list_item_conversation_top_notice_out" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/layout"
|
android:id="@+id/layout"
|
||||||
@@ -73,15 +77,26 @@
|
|||||||
style="@style/TextMessage.Timestamp"
|
style="@style/TextMessage.Timestamp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="6dp"
|
android:layout_marginEnd="4dp"
|
||||||
android:layout_marginRight="6dp"
|
android:layout_marginRight="4dp"
|
||||||
android:textColor="@color/private_message_date_inverse"
|
android:textColor="@color/private_message_date_inverse"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/bomb"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="4dp"
|
||||||
|
android:layout_marginRight="4dp"
|
||||||
|
app:srcCompat="@drawable/ic_bomb"
|
||||||
|
app:tint="@color/private_message_date_inverse"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/status"
|
android:id="@+id/status"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
app:tint="@color/private_message_date_inverse"
|
||||||
tools:ignore="ContentDescription"
|
tools:ignore="ContentDescription"
|
||||||
tools:src="@drawable/message_delivered" />
|
tools:src="@drawable/message_delivered" />
|
||||||
|
|
||||||
@@ -89,4 +104,4 @@
|
|||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</LinearLayout>
|
||||||
@@ -5,8 +5,9 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/list_item_background_selectable"
|
android:background="@drawable/list_item_background_selectable"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical">
|
||||||
android:paddingTop="@dimen/message_bubble_margin">
|
|
||||||
|
<include layout="@layout/list_item_conversation_top_notice_in" />
|
||||||
|
|
||||||
<com.vanniktech.emoji.EmojiTextView
|
<com.vanniktech.emoji.EmojiTextView
|
||||||
android:id="@+id/msgText"
|
android:id="@+id/msgText"
|
||||||
@@ -15,11 +16,13 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/message_bubble_margin_tail"
|
android:layout_marginStart="@dimen/message_bubble_margin_tail"
|
||||||
android:layout_marginLeft="@dimen/message_bubble_margin_tail"
|
android:layout_marginLeft="@dimen/message_bubble_margin_tail"
|
||||||
|
android:layout_marginTop="@dimen/message_bubble_margin"
|
||||||
android:layout_marginEnd="@dimen/message_bubble_margin_non_tail"
|
android:layout_marginEnd="@dimen/message_bubble_margin_non_tail"
|
||||||
android:layout_marginRight="@dimen/message_bubble_margin_non_tail"
|
android:layout_marginRight="@dimen/message_bubble_margin_non_tail"
|
||||||
android:background="@drawable/msg_in_top"
|
android:background="@drawable/msg_in_top"
|
||||||
android:elevation="@dimen/message_bubble_elevation"
|
android:elevation="@dimen/message_bubble_elevation"
|
||||||
tools:text="Short message" />
|
tools:text="Short message"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/layout"
|
android:id="@+id/layout"
|
||||||
@@ -48,10 +51,28 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/message_bubble_timestamp_margin"
|
android:layout_marginTop="@dimen/message_bubble_timestamp_margin"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/text"
|
app:layout_constraintEnd_toStartOf="@+id/bomb"
|
||||||
|
app:layout_constraintHorizontal_bias="1.0"
|
||||||
|
app:layout_constraintHorizontal_chainStyle="packed"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/text"
|
app:layout_constraintTop_toBottomOf="@+id/text"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/bomb"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_marginLeft="4dp"
|
||||||
|
android:layout_marginTop="@dimen/message_bubble_timestamp_margin"
|
||||||
|
app:layout_constraintEnd_toEndOf="@+id/text"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/time"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/text"
|
||||||
|
app:srcCompat="@drawable/ic_bomb"
|
||||||
|
app:tint="?android:attr/textColorSecondary"
|
||||||
|
tools:ignore="ContentDescription"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingTop="@dimen/message_bubble_margin">
|
android:paddingTop="@dimen/message_bubble_margin">
|
||||||
|
|
||||||
|
<include layout="@layout/list_item_conversation_top_notice_out" />
|
||||||
|
|
||||||
<com.vanniktech.emoji.EmojiTextView
|
<com.vanniktech.emoji.EmojiTextView
|
||||||
android:id="@+id/msgText"
|
android:id="@+id/msgText"
|
||||||
style="@style/TextMessage"
|
style="@style/TextMessage"
|
||||||
@@ -15,12 +17,14 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/message_bubble_margin_non_tail"
|
android:layout_marginStart="@dimen/message_bubble_margin_non_tail"
|
||||||
android:layout_marginLeft="@dimen/message_bubble_margin_non_tail"
|
android:layout_marginLeft="@dimen/message_bubble_margin_non_tail"
|
||||||
|
android:layout_marginTop="@dimen/message_bubble_margin"
|
||||||
android:layout_marginEnd="@dimen/message_bubble_margin_tail"
|
android:layout_marginEnd="@dimen/message_bubble_margin_tail"
|
||||||
android:layout_marginRight="@dimen/message_bubble_margin_tail"
|
android:layout_marginRight="@dimen/message_bubble_margin_tail"
|
||||||
android:background="@drawable/msg_out_top"
|
android:background="@drawable/msg_out_top"
|
||||||
android:elevation="@dimen/message_bubble_elevation"
|
android:elevation="@dimen/message_bubble_elevation"
|
||||||
android:textColor="@color/briar_text_primary_inverse"
|
android:textColor="@color/briar_text_primary_inverse"
|
||||||
tools:text="This is a long long long message that spans over several lines.\n\nIt ends here." />
|
tools:text="This is a long long long message that spans over several lines.\n\nIt ends here."
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/layout"
|
android:id="@+id/layout"
|
||||||
@@ -56,14 +60,28 @@
|
|||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/status"
|
android:id="@+id/bomb"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/margin_medium"
|
android:layout_marginStart="4dp"
|
||||||
android:layout_marginLeft="@dimen/margin_medium"
|
android:layout_marginLeft="4dp"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/time"
|
app:layout_constraintBottom_toBottomOf="@+id/time"
|
||||||
app:layout_constraintStart_toEndOf="@+id/time"
|
app:layout_constraintStart_toEndOf="@+id/time"
|
||||||
app:layout_constraintTop_toTopOf="@+id/time"
|
app:layout_constraintTop_toTopOf="@+id/time"
|
||||||
|
app:srcCompat="@drawable/ic_bomb"
|
||||||
|
app:tint="@color/private_message_date_inverse"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/status"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_marginLeft="4dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/time"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/bomb"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/time"
|
||||||
|
app:tint="@color/private_message_date_inverse"
|
||||||
tools:ignore="ContentDescription"
|
tools:ignore="ContentDescription"
|
||||||
tools:src="@drawable/message_delivered" />
|
tools:src="@drawable/message_delivered" />
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,9 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/list_item_background_selectable"
|
android:background="@drawable/list_item_background_selectable"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical">
|
||||||
android:paddingTop="@dimen/message_bubble_margin">
|
|
||||||
|
<include layout="@layout/list_item_conversation_top_notice_in" />
|
||||||
|
|
||||||
<com.vanniktech.emoji.EmojiTextView
|
<com.vanniktech.emoji.EmojiTextView
|
||||||
android:id="@+id/msgText"
|
android:id="@+id/msgText"
|
||||||
@@ -15,6 +16,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/message_bubble_margin_tail"
|
android:layout_marginStart="@dimen/message_bubble_margin_tail"
|
||||||
android:layout_marginLeft="@dimen/message_bubble_margin_tail"
|
android:layout_marginLeft="@dimen/message_bubble_margin_tail"
|
||||||
|
android:layout_marginTop="@dimen/message_bubble_margin"
|
||||||
android:layout_marginEnd="@dimen/message_bubble_margin_non_tail"
|
android:layout_marginEnd="@dimen/message_bubble_margin_non_tail"
|
||||||
android:layout_marginRight="@dimen/message_bubble_margin_non_tail"
|
android:layout_marginRight="@dimen/message_bubble_margin_non_tail"
|
||||||
android:background="@drawable/msg_in_top"
|
android:background="@drawable/msg_in_top"
|
||||||
@@ -68,10 +70,27 @@
|
|||||||
style="@style/TextMessage.Timestamp"
|
style="@style/TextMessage.Timestamp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toStartOf="@+id/bomb"
|
||||||
|
app:layout_constraintHorizontal_bias="1.0"
|
||||||
|
app:layout_constraintHorizontal_chainStyle="packed"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/acceptButton"
|
app:layout_constraintTop_toBottomOf="@+id/acceptButton"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/bomb"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_marginLeft="4dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/time"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/acceptButton"
|
||||||
|
app:srcCompat="@drawable/ic_bomb"
|
||||||
|
app:tint="?android:attr/textColorSecondary"
|
||||||
|
tools:ignore="ContentDescription"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.vanniktech.emoji.EmojiTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/topNotice"
|
||||||
|
style="@style/TextMessage.Notice"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/message_bubble_margin_tail"
|
||||||
|
android:layout_marginLeft="@dimen/message_bubble_margin_tail"
|
||||||
|
android:layout_marginTop="@dimen/message_bubble_margin"
|
||||||
|
android:layout_marginEnd="@dimen/message_bubble_margin_non_tail"
|
||||||
|
android:layout_marginRight="@dimen/message_bubble_margin_non_tail"
|
||||||
|
android:layout_marginBottom="@dimen/message_bubble_margin"
|
||||||
|
android:background="@drawable/notice_in"
|
||||||
|
android:elevation="@dimen/message_bubble_elevation"
|
||||||
|
android:paddingBottom="@dimen/message_bubble_padding_top"
|
||||||
|
android:textIsSelectable="false"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:text="@string/auto_delete_msg_contact_enabled"
|
||||||
|
tools:visibility="visible" />
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.vanniktech.emoji.EmojiTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/topNotice"
|
||||||
|
style="@style/TextMessage.Notice"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end|right"
|
||||||
|
android:layout_marginStart="@dimen/message_bubble_margin_non_tail"
|
||||||
|
android:layout_marginLeft="@dimen/message_bubble_margin_non_tail"
|
||||||
|
android:layout_marginEnd="@dimen/message_bubble_margin_tail"
|
||||||
|
android:layout_marginRight="@dimen/message_bubble_margin_tail"
|
||||||
|
android:layout_marginBottom="@dimen/message_bubble_margin"
|
||||||
|
android:background="@drawable/notice_out"
|
||||||
|
android:elevation="@dimen/message_bubble_elevation"
|
||||||
|
android:paddingBottom="@dimen/message_bubble_padding_top"
|
||||||
|
android:textColor="@color/private_message_date_inverse"
|
||||||
|
android:textIsSelectable="false"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:showIn="@layout/list_item_conversation_msg_out"
|
||||||
|
tools:text="@string/auto_delete_msg_you_enabled"
|
||||||
|
tools:visibility="visible" />
|
||||||
@@ -37,6 +37,18 @@
|
|||||||
app:srcCompat="@drawable/social_send_now_white"
|
app:srcCompat="@drawable/social_send_now_white"
|
||||||
app:tint="@color/briar_accent" />
|
app:tint="@color/briar_accent" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/bombBadge"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end|bottom"
|
||||||
|
android:layout_margin="3dp"
|
||||||
|
android:contentDescription="@string/auto_delete_msg_contact_enabled"
|
||||||
|
android:visibility="invisible"
|
||||||
|
app:srcCompat="@drawable/ic_bomb"
|
||||||
|
app:tint="@color/briar_accent"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
android:layout_width="@dimen/text_input_height"
|
android:layout_width="@dimen/text_input_height"
|
||||||
|
|||||||
@@ -1,30 +1,37 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_introduction"
|
android:id="@+id/action_introduction"
|
||||||
|
android:enabled="false"
|
||||||
android:icon="@drawable/introduction_white"
|
android:icon="@drawable/introduction_white"
|
||||||
android:title="@string/introduction_menu_item"
|
android:title="@string/introduction_menu_item"
|
||||||
android:enabled="false"
|
app:showAsAction="never" />
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_set_alias"
|
android:id="@+id/action_set_alias"
|
||||||
android:title="@string/set_contact_alias"
|
|
||||||
android:enabled="false"
|
android:enabled="false"
|
||||||
app:showAsAction="never"/>
|
android:title="@string/set_contact_alias"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_conversation_settings"
|
||||||
|
android:title="@string/menu_item_disappearing_messages"
|
||||||
|
android:visible="false"
|
||||||
|
app:showAsAction="never"
|
||||||
|
tools:visible="true" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_delete_all_messages"
|
android:id="@+id/action_delete_all_messages"
|
||||||
android:title="@string/delete_all_messages"
|
android:title="@string/delete_all_messages"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_social_remove_person"
|
android:id="@+id/action_social_remove_person"
|
||||||
android:icon="@drawable/action_delete_white"
|
android:icon="@drawable/action_delete_white"
|
||||||
android:title="@string/delete_contact"
|
android:title="@string/delete_contact"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
@@ -5,27 +5,28 @@
|
|||||||
<group android:checkableBehavior="single">
|
<group android:checkableBehavior="single">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_btn_contacts"
|
android:id="@+id/nav_btn_contacts"
|
||||||
|
android:checked="true"
|
||||||
android:icon="@drawable/ic_contacts"
|
android:icon="@drawable/ic_contacts"
|
||||||
android:title="@string/contact_list_button"/>
|
android:title="@string/contact_list_button" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_btn_groups"
|
android:id="@+id/nav_btn_groups"
|
||||||
android:icon="@drawable/ic_group"
|
android:icon="@drawable/ic_group"
|
||||||
android:title="@string/groups_button"/>
|
android:title="@string/groups_button" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_btn_forums"
|
android:id="@+id/nav_btn_forums"
|
||||||
android:icon="@drawable/ic_forums_black_24dp"
|
android:icon="@drawable/ic_forums_black_24dp"
|
||||||
android:title="@string/forums_button"/>
|
android:title="@string/forums_button" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_btn_blogs"
|
android:id="@+id/nav_btn_blogs"
|
||||||
android:icon="@drawable/blogs"
|
android:icon="@drawable/blogs"
|
||||||
android:title="@string/blogs_button"/>
|
android:title="@string/blogs_button" />
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
<group android:checkableBehavior="single">
|
<group android:checkableBehavior="single">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_btn_settings"
|
android:id="@+id/nav_btn_settings"
|
||||||
android:icon="@drawable/ic_settings_black"
|
android:icon="@drawable/ic_settings_black"
|
||||||
android:title="@string/settings_button"/>
|
android:title="@string/settings_button" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_btn_lock"
|
android:id="@+id/nav_btn_lock"
|
||||||
android:icon="@drawable/startup_lock"
|
android:icon="@drawable/startup_lock"
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/nav_btn_signout"
|
android:id="@+id/nav_btn_signout"
|
||||||
android:icon="@drawable/ic_signout"
|
android:icon="@drawable/ic_signout"
|
||||||
android:title="@string/sign_out_button"/>
|
android:title="@string/sign_out_button" />
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
@@ -67,8 +67,11 @@
|
|||||||
<string name="lock_button">قفل کردن برنامه</string>
|
<string name="lock_button">قفل کردن برنامه</string>
|
||||||
<string name="settings_button">تنظیمات</string>
|
<string name="settings_button">تنظیمات</string>
|
||||||
<string name="sign_out_button">خروج</string>
|
<string name="sign_out_button">خروج</string>
|
||||||
|
<string name="transports_onboarding_text">برای کنترل چگونگی اتصال Briar (برایر) به مخاطبین خود، اینجا را لمس کنید.</string>
|
||||||
<!--Transports: Tor-->
|
<!--Transports: Tor-->
|
||||||
<string name="transport_tor">اینترنت</string>
|
<string name="transport_tor">اینترنت</string>
|
||||||
|
<string name="tor_device_status_online_wifi">تلفن شما از طریق Wi-Fi به اینترنت دسترسی دارد.</string>
|
||||||
|
<string name="tor_device_status_online_mobile">تلفن شما از طریق دیتا سیمکارت به اینترنت دسترسی دارد.</string>
|
||||||
<string name="tor_device_status_offline">تلفن شما دارای دسترسی اینترنتی نیست</string>
|
<string name="tor_device_status_offline">تلفن شما دارای دسترسی اینترنتی نیست</string>
|
||||||
<string name="tor_plugin_status_enabling">Briar در حال اتصال به اینترنت می باشد</string>
|
<string name="tor_plugin_status_enabling">Briar در حال اتصال به اینترنت می باشد</string>
|
||||||
<string name="tor_plugin_status_active">Briar به اینترنت متصل شد</string>
|
<string name="tor_plugin_status_active">Briar به اینترنت متصل شد</string>
|
||||||
@@ -462,6 +465,10 @@
|
|||||||
برای وارد کردن خوراک روی آیکون + ضربه بزنید</string>
|
برای وارد کردن خوراک روی آیکون + ضربه بزنید</string>
|
||||||
<string name="blogs_rss_feeds_manage_error">مشکلی با بارگذاری فیدهای شما وجود داشت. لطفا بعدا امتحان کنید.</string>
|
<string name="blogs_rss_feeds_manage_error">مشکلی با بارگذاری فیدهای شما وجود داشت. لطفا بعدا امتحان کنید.</string>
|
||||||
<!--Settings Profile Picture-->
|
<!--Settings Profile Picture-->
|
||||||
|
<string name="change_profile_picture">برای تغییر تصویر نمایه خود اینجا را لمس کنید.</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_title">تغییر تصویر نمایه</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_remark">تنها مخاطبین شما میتوانند تصویر نمایه شما را مشاهده کنند.</string>
|
||||||
|
<string name="change_profile_picture_failed_message">تاسفیم اما هنگام بروزرسانی تصویر نمایه شما مشکلی رخ داد.</string>
|
||||||
<!--Settings Display-->
|
<!--Settings Display-->
|
||||||
<string name="pref_language_title">زبان و منطقه</string>
|
<string name="pref_language_title">زبان و منطقه</string>
|
||||||
<string name="pref_language_changed">این تنظیمات زمانی که Briar (برایر) را ری استارت کنید تاثیر خود را می گذارند. لطفا خارج شوید و Briar (برایر) را دوباره راه اندازی کنید.</string>
|
<string name="pref_language_changed">این تنظیمات زمانی که Briar (برایر) را ری استارت کنید تاثیر خود را می گذارند. لطفا خارج شوید و Briar (برایر) را دوباره راه اندازی کنید.</string>
|
||||||
@@ -571,17 +578,20 @@
|
|||||||
<string name="include_debug_report_feedback">قرار دادن داده های ناشناس درباره این دستگاه</string>
|
<string name="include_debug_report_feedback">قرار دادن داده های ناشناس درباره این دستگاه</string>
|
||||||
<string name="dev_report_basic_info">اطلاعات پایه</string>
|
<string name="dev_report_basic_info">اطلاعات پایه</string>
|
||||||
<string name="dev_report_device_info">اطلاعات دستگاه</string>
|
<string name="dev_report_device_info">اطلاعات دستگاه</string>
|
||||||
|
<string name="dev_report_stacktrace">Stacktrace</string>
|
||||||
<string name="dev_report_time_info">اطلاعات زمانی</string>
|
<string name="dev_report_time_info">اطلاعات زمانی</string>
|
||||||
<string name="dev_report_memory">حافظه</string>
|
<string name="dev_report_memory">حافظه</string>
|
||||||
<string name="dev_report_storage">حافظه</string>
|
<string name="dev_report_storage">حافظه</string>
|
||||||
<string name="dev_report_connectivity">اتصال</string>
|
<string name="dev_report_connectivity">اتصال</string>
|
||||||
<string name="dev_report_build_config">پیکربندی ساخت</string>
|
<string name="dev_report_build_config">پیکربندی ساخت</string>
|
||||||
|
<string name="dev_report_logcat">لاگ برنامه</string>
|
||||||
<string name="dev_report_device_features">ویژگیهای دستگاه</string>
|
<string name="dev_report_device_features">ویژگیهای دستگاه</string>
|
||||||
<string name="send_report">ارسال گزارش</string>
|
<string name="send_report">ارسال گزارش</string>
|
||||||
<string name="close">بستن</string>
|
<string name="close">بستن</string>
|
||||||
<string name="dev_report_sending">در حال فرستادن نظر...</string>
|
<string name="dev_report_sending">در حال فرستادن نظر...</string>
|
||||||
<string name="dev_report_sent">بازخورد ارسال شد</string>
|
<string name="dev_report_sent">بازخورد ارسال شد</string>
|
||||||
<string name="dev_report_saved">گزارش ذخیره شد. دفعه بعدی که وارد Briar (برایر) شدید فرستاده خواهد شد.</string>
|
<string name="dev_report_saved">گزارش ذخیره شد. دفعه بعدی که وارد Briar (برایر) شدید فرستاده خواهد شد.</string>
|
||||||
|
<string name="dev_report_error">خطا در ارسال گزارش</string>
|
||||||
<!--Sign Out-->
|
<!--Sign Out-->
|
||||||
<string name="progress_title_logout">خروج از Briar (برایر)...</string>
|
<string name="progress_title_logout">خروج از Briar (برایر)...</string>
|
||||||
<!--Screen Filters & Tapjacking-->
|
<!--Screen Filters & Tapjacking-->
|
||||||
@@ -591,7 +601,9 @@
|
|||||||
این برنامه ها ممکن است روی Briar (برایر) قرار گرفته باشند:
|
این برنامه ها ممکن است روی Briar (برایر) قرار گرفته باشند:
|
||||||
|
|
||||||
%1$s</string>
|
%1$s</string>
|
||||||
|
<string name="screen_filter_body_api_30">برنامه دیگری بر روی برنامه Briar (برایر) قرار دارد. برای محافظت از امنیت شما، Briar (برایر) هنگامی که برنامه دیگری روی آن باز است، به لمس پاسخ نخواهد داد. \n\nبرای یافتن برنامه مذکور، برنامههای زیر را بررسی کنید.</string>
|
||||||
<string name="screen_filter_allow">به این برنامه ها اجازه بده تا روی Briar (برایر) قرار بگیرند</string>
|
<string name="screen_filter_allow">به این برنامه ها اجازه بده تا روی Briar (برایر) قرار بگیرند</string>
|
||||||
|
<string name="screen_filter_review_apps">بررسی برنامهها</string>
|
||||||
<!--Permission Requests-->
|
<!--Permission Requests-->
|
||||||
<string name="permission_camera_title">دسترسی به دوربین</string>
|
<string name="permission_camera_title">دسترسی به دوربین</string>
|
||||||
<string name="permission_camera_request_body">برای اسکن کردن کد کیوآر دسترسی به دوربین لازم است.</string>
|
<string name="permission_camera_request_body">برای اسکن کردن کد کیوآر دسترسی به دوربین لازم است.</string>
|
||||||
@@ -608,6 +620,7 @@ Briar (برایر) موقعیت شما را ذخیره نمیکند و آن
|
|||||||
<string name="permission_camera_denied_body">شما دسترسی به دوربین را رد کرده اید، اما افزودن مخاطب نیاز به دوربین دارد.
|
<string name="permission_camera_denied_body">شما دسترسی به دوربین را رد کرده اید، اما افزودن مخاطب نیاز به دوربین دارد.
|
||||||
|
|
||||||
لطفا اجازه دسترسی را بدهید.</string>
|
لطفا اجازه دسترسی را بدهید.</string>
|
||||||
|
<string name="permission_location_denied_body">شما دسترسی به موقعیت خود را ندادهاید اما Briar (برایر) برای یافتن دستگاههای بلوتوث نیاز به این دسترسی دارد.\n\nلطفا این دسترسی را فراهم کنید.</string>
|
||||||
<string name="qr_code">کد کیوآر</string>
|
<string name="qr_code">کد کیوآر</string>
|
||||||
<string name="show_qr_code_fullscreen">نمایش کد کیوآر به صورت فول اسکرین</string>
|
<string name="show_qr_code_fullscreen">نمایش کد کیوآر به صورت فول اسکرین</string>
|
||||||
<!--App Locking-->
|
<!--App Locking-->
|
||||||
@@ -618,6 +631,7 @@ Briar (برایر) موقعیت شما را ذخیره نمیکند و آن
|
|||||||
<string name="lock_is_locked">Briar (برایر) قفل می باشد</string>
|
<string name="lock_is_locked">Briar (برایر) قفل می باشد</string>
|
||||||
<string name="lock_tap_to_unlock">برای آنلاک کردن کلیک کنید</string>
|
<string name="lock_tap_to_unlock">برای آنلاک کردن کلیک کنید</string>
|
||||||
<!--Connections Screen-->
|
<!--Connections Screen-->
|
||||||
|
<string name="transports_help_text">Briar (برایر) میتواند از طریق اینترنت، Wi-Fi و یا بلوتوث به مخاطبین شما متصل گردد.\n\nارتباط با اینترنت از طریق شبکهی تور صورت میپذیرد.\n\nاگر دسترسی به مخاطب شما از روشهای مختلفی ممکن باشد، Briar (برایر) به صورت موازی از آنها استفاده خواهد کرد.</string>
|
||||||
<!--Screenshots-->
|
<!--Screenshots-->
|
||||||
<!--This is a name to be used in screenshots. Feel free to change it to a local name.-->
|
<!--This is a name to be used in screenshots. Feel free to change it to a local name.-->
|
||||||
<string name="screenshot_alice">آلیس</string>
|
<string name="screenshot_alice">آلیس</string>
|
||||||
|
|||||||
@@ -425,6 +425,10 @@
|
|||||||
<string name="blogs_rss_feeds_manage_empty_state">Sen fontes RSS que mostrar\n\nToque na icona + para importar unha fonte</string>
|
<string name="blogs_rss_feeds_manage_empty_state">Sen fontes RSS que mostrar\n\nToque na icona + para importar unha fonte</string>
|
||||||
<string name="blogs_rss_feeds_manage_error">Aconteceu un problema ao cargar as súas fontes. Por favor, inténteo máis tarde.</string>
|
<string name="blogs_rss_feeds_manage_error">Aconteceu un problema ao cargar as súas fontes. Por favor, inténteo máis tarde.</string>
|
||||||
<!--Settings Profile Picture-->
|
<!--Settings Profile Picture-->
|
||||||
|
<string name="change_profile_picture">Toca para cambiar a túa imaxe de perfil</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_title">Mudar imaxe de perfil</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_remark">Só os teus contactos poden ver a túa imaxe de perfil</string>
|
||||||
|
<string name="change_profile_picture_failed_message">Lamentámolo, pero algo fallou cando intentamos actualizar a túa imaxe de pefil</string>
|
||||||
<!--Settings Display-->
|
<!--Settings Display-->
|
||||||
<string name="pref_language_title">Idioma & rexión</string>
|
<string name="pref_language_title">Idioma & rexión</string>
|
||||||
<string name="pref_language_changed">Este axuste terá efecto cando reinicie Briar. Por favor desconecte e volte a iniciar Briar.</string>
|
<string name="pref_language_changed">Este axuste terá efecto cando reinicie Briar. Por favor desconecte e volte a iniciar Briar.</string>
|
||||||
|
|||||||
@@ -449,6 +449,10 @@
|
|||||||
<string name="blogs_rss_feeds_manage_empty_state">אין הזנות RSS להראות\n\nהקש על הצלמית + כדי לייבא הזנה</string>
|
<string name="blogs_rss_feeds_manage_empty_state">אין הזנות RSS להראות\n\nהקש על הצלמית + כדי לייבא הזנה</string>
|
||||||
<string name="blogs_rss_feeds_manage_error">הייתה בעיה בטעינת ההזנות שלך. אנא נסה שוב מאוחר יותר.</string>
|
<string name="blogs_rss_feeds_manage_error">הייתה בעיה בטעינת ההזנות שלך. אנא נסה שוב מאוחר יותר.</string>
|
||||||
<!--Settings Profile Picture-->
|
<!--Settings Profile Picture-->
|
||||||
|
<string name="change_profile_picture">הקש כדי לשנות את תמונת הפרופיל שלך</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_title">שנה תמונת פרופיל</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_remark">רק אנשי הקשר שלך יכולים לראות את תמונת הפרופיל שלך</string>
|
||||||
|
<string name="change_profile_picture_failed_message">אנו מצטערים משהו השתבש בעת עדכון תמונת הפרופיל שלך</string>
|
||||||
<!--Settings Display-->
|
<!--Settings Display-->
|
||||||
<string name="pref_language_title">שפה ואזור</string>
|
<string name="pref_language_title">שפה ואזור</string>
|
||||||
<string name="pref_language_changed">הגדרה זו תיכנס לתוקף כשתפעיל מחדש את Briar. אנא התנתק והפעל מחדש את Briar.</string>
|
<string name="pref_language_changed">הגדרה זו תיכנס לתוקף כשתפעיל מחדש את Briar. אנא התנתק והפעל מחדש את Briar.</string>
|
||||||
@@ -558,6 +562,7 @@
|
|||||||
<string name="include_debug_report_feedback">כלול נתונים אלמוניים לגבי מכשיר זה</string>
|
<string name="include_debug_report_feedback">כלול נתונים אלמוניים לגבי מכשיר זה</string>
|
||||||
<string name="dev_report_basic_info">מידע בסיסי</string>
|
<string name="dev_report_basic_info">מידע בסיסי</string>
|
||||||
<string name="dev_report_device_info">מידע מכשיר</string>
|
<string name="dev_report_device_info">מידע מכשיר</string>
|
||||||
|
<string name="dev_report_stacktrace">מחסנית עקיבה (Stacktrace)</string>
|
||||||
<string name="dev_report_time_info">מידע זמן</string>
|
<string name="dev_report_time_info">מידע זמן</string>
|
||||||
<string name="dev_report_memory">זיכרון</string>
|
<string name="dev_report_memory">זיכרון</string>
|
||||||
<string name="dev_report_storage">אחסון</string>
|
<string name="dev_report_storage">אחסון</string>
|
||||||
|
|||||||
@@ -425,6 +425,10 @@
|
|||||||
<string name="blogs_rss_feeds_manage_empty_state">Engin RSS-streymi til að birta\n\nÝttu á + táknið til að flytja inn streymi</string>
|
<string name="blogs_rss_feeds_manage_empty_state">Engin RSS-streymi til að birta\n\nÝttu á + táknið til að flytja inn streymi</string>
|
||||||
<string name="blogs_rss_feeds_manage_error">Vandamál hefur komið upp með að hlaða inn streymunum þínum. Reyndu aftur síðar.</string>
|
<string name="blogs_rss_feeds_manage_error">Vandamál hefur komið upp með að hlaða inn streymunum þínum. Reyndu aftur síðar.</string>
|
||||||
<!--Settings Profile Picture-->
|
<!--Settings Profile Picture-->
|
||||||
|
<string name="change_profile_picture">Ýttu til að skipta um auðkennismyndina þína</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_title">Skipta um auðkennismynd</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_remark">Einungis tengiliðirnir þínir geta séð auðkennismyndina þína</string>
|
||||||
|
<string name="change_profile_picture_failed_message">Því miður, eitthvað fór úrskeiðis við að uppfæra auðkennismyndina þína.</string>
|
||||||
<!--Settings Display-->
|
<!--Settings Display-->
|
||||||
<string name="pref_language_title">Tungumál og landsvæði</string>
|
<string name="pref_language_title">Tungumál og landsvæði</string>
|
||||||
<string name="pref_language_changed">Þessi stilling tekur gildi í næst þegar þú skráir þig inn í Briar. Skráðu þig út og endurræstu Briar.</string>
|
<string name="pref_language_changed">Þessi stilling tekur gildi í næst þegar þú skráir þig inn í Briar. Skráðu þig út og endurræstu Briar.</string>
|
||||||
|
|||||||
@@ -425,6 +425,10 @@
|
|||||||
<string name="blogs_rss_feeds_manage_empty_state">Nessun feed RSS da mostrare\n\nClicca l\'icona + per importare un feed</string>
|
<string name="blogs_rss_feeds_manage_empty_state">Nessun feed RSS da mostrare\n\nClicca l\'icona + per importare un feed</string>
|
||||||
<string name="blogs_rss_feeds_manage_error">C\'è stato un problema nel caricare i tuoi feeds. Per favore riprova fra poco.</string>
|
<string name="blogs_rss_feeds_manage_error">C\'è stato un problema nel caricare i tuoi feeds. Per favore riprova fra poco.</string>
|
||||||
<!--Settings Profile Picture-->
|
<!--Settings Profile Picture-->
|
||||||
|
<string name="change_profile_picture">Tocca per cambiare l\'immagine del profilo</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_title">Cambia immagine profilo</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_remark">Solo i tuoi contatti possono vedere l\'immagine del profilo</string>
|
||||||
|
<string name="change_profile_picture_failed_message">Spiacenti, qualcosa è andato storto aggiornando la tua foto del profilo.</string>
|
||||||
<!--Settings Display-->
|
<!--Settings Display-->
|
||||||
<string name="pref_language_title">Lingua & regione</string>
|
<string name="pref_language_title">Lingua & regione</string>
|
||||||
<string name="pref_language_changed">Questa impostazione avrà effetto quando riavvierai Briar. Per favore, esci e riavvia Briar.</string>
|
<string name="pref_language_changed">Questa impostazione avrà effetto quando riavvierai Briar. Per favore, esci e riavvia Briar.</string>
|
||||||
|
|||||||
@@ -425,6 +425,10 @@
|
|||||||
<string name="blogs_rss_feeds_manage_empty_state">Geen RSS-feeds om te tonen\n\nTik op het +-icoon om een feed te importeren</string>
|
<string name="blogs_rss_feeds_manage_empty_state">Geen RSS-feeds om te tonen\n\nTik op het +-icoon om een feed te importeren</string>
|
||||||
<string name="blogs_rss_feeds_manage_error">Er was een probleem met het laden van je feeds. Probeer het alsjeblieft later nog een keer.</string>
|
<string name="blogs_rss_feeds_manage_error">Er was een probleem met het laden van je feeds. Probeer het alsjeblieft later nog een keer.</string>
|
||||||
<!--Settings Profile Picture-->
|
<!--Settings Profile Picture-->
|
||||||
|
<string name="change_profile_picture">Tik om je profielfoto te wijzigen</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_title">Wijzig profielfoto</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_remark">Alleen je contacten kunnen je profielfoto zien</string>
|
||||||
|
<string name="change_profile_picture_failed_message">Excuses, maar er is iets misgegaan met het updaten van je profielfoto</string>
|
||||||
<!--Settings Display-->
|
<!--Settings Display-->
|
||||||
<string name="pref_language_title">Taal & regio</string>
|
<string name="pref_language_title">Taal & regio</string>
|
||||||
<string name="pref_language_changed">Deze instelling zal werken wanneer u Briar opnieuw opstart. Gelieve uit te loggen en Briar opnieuw te starten.</string>
|
<string name="pref_language_changed">Deze instelling zal werken wanneer u Briar opnieuw opstart. Gelieve uit te loggen en Briar opnieuw te starten.</string>
|
||||||
@@ -564,7 +568,7 @@
|
|||||||
<string name="permission_camera_location_title">Camera en locatie</string>
|
<string name="permission_camera_location_title">Camera en locatie</string>
|
||||||
<string name="permission_camera_location_request_body">Om de QR-code in te scannen heeft Briar toegang nodig tot de camera.\n\nOm bluetoothapparaten te ontdekken heeft Briar toestemming nodig tot je locatie.\n\nBriar slaat je locatie niet op en deelt het met niemand.</string>
|
<string name="permission_camera_location_request_body">Om de QR-code in te scannen heeft Briar toegang nodig tot de camera.\n\nOm bluetoothapparaten te ontdekken heeft Briar toestemming nodig tot je locatie.\n\nBriar slaat je locatie niet op en deelt het met niemand.</string>
|
||||||
<string name="permission_camera_denied_body">Je hebt toegang tot de camera niet vrijgegeven, terwijl het toevoegen van contacten de camera nodig heeft.\n\nOverweeg alsjeblieft toegang vrij te geven.</string>
|
<string name="permission_camera_denied_body">Je hebt toegang tot de camera niet vrijgegeven, terwijl het toevoegen van contacten de camera nodig heeft.\n\nOverweeg alsjeblieft toegang vrij te geven.</string>
|
||||||
<string name="permission_location_denied_body">Je hebt geen toegang tot je locatie gegeven, maar Briar heeft deze rechten nodig om apparaten via bleutooth te vinden.\n\nOverweeg a.u.b. deze rechten te geven.</string>
|
<string name="permission_location_denied_body">Je hebt geen toegang tot je locatie gegeven, maar Briar heeft deze rechten nodig om apparaten via bluetooth te vinden.\n\nOverweeg a.u.b. deze rechten te geven.</string>
|
||||||
<string name="qr_code">QR-code</string>
|
<string name="qr_code">QR-code</string>
|
||||||
<string name="show_qr_code_fullscreen">Toon QR-code op volledig scherm</string>
|
<string name="show_qr_code_fullscreen">Toon QR-code op volledig scherm</string>
|
||||||
<!--App Locking-->
|
<!--App Locking-->
|
||||||
|
|||||||
@@ -435,6 +435,10 @@
|
|||||||
<string name="blogs_rss_feeds_manage_empty_state">Nici un flux RSS de arătat\n\nAtingeți iconița + pentru a adăuga un flux</string>
|
<string name="blogs_rss_feeds_manage_empty_state">Nici un flux RSS de arătat\n\nAtingeți iconița + pentru a adăuga un flux</string>
|
||||||
<string name="blogs_rss_feeds_manage_error">A apărut o eroare la încărcarea fluxurilor dumneavoastră. Vă rugăm să încercați din nou mai târziu.</string>
|
<string name="blogs_rss_feeds_manage_error">A apărut o eroare la încărcarea fluxurilor dumneavoastră. Vă rugăm să încercați din nou mai târziu.</string>
|
||||||
<!--Settings Profile Picture-->
|
<!--Settings Profile Picture-->
|
||||||
|
<string name="change_profile_picture">Atingeți pentru a vă schimba poza de profil</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_title">Schimbare poză de profil</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_remark">Doar contactele vor vedea poza de contact</string>
|
||||||
|
<string name="change_profile_picture_failed_message">Ne pare rău, dar ceva nu a funcționat cum trebuie la actualizarea pozei de profil</string>
|
||||||
<!--Settings Display-->
|
<!--Settings Display-->
|
||||||
<string name="pref_language_title">Limbă & Regiune</string>
|
<string name="pref_language_title">Limbă & Regiune</string>
|
||||||
<string name="pref_language_changed">Această setare va avea efect după repornirea Briar. Vă rugăm să ieșiți din Briar și să reporniți aplicația.</string>
|
<string name="pref_language_changed">Această setare va avea efect după repornirea Briar. Vă rugăm să ieșiți din Briar și să reporniți aplicația.</string>
|
||||||
|
|||||||
@@ -447,6 +447,10 @@
|
|||||||
<string name="blogs_rss_feeds_manage_empty_state">Нет RSS-лент для отображения\n\nКоснитесь значка + для импорта ленты</string>
|
<string name="blogs_rss_feeds_manage_empty_state">Нет RSS-лент для отображения\n\nКоснитесь значка + для импорта ленты</string>
|
||||||
<string name="blogs_rss_feeds_manage_error">Ошибка при загрузке вашей ленты. Повторите попытку позже.</string>
|
<string name="blogs_rss_feeds_manage_error">Ошибка при загрузке вашей ленты. Повторите попытку позже.</string>
|
||||||
<!--Settings Profile Picture-->
|
<!--Settings Profile Picture-->
|
||||||
|
<string name="change_profile_picture">Нажмите, чтобы изменить изображение вашего профиля </string>
|
||||||
|
<string name="dialog_confirm_profile_picture_title">Изменить изображение профиля</string>
|
||||||
|
<string name="dialog_confirm_profile_picture_remark">Только ваши контакты могут видеть изображение вашего профиля</string>
|
||||||
|
<string name="change_profile_picture_failed_message">Нам очень жаль, но что-то пошло не так во время обновления изображения вашего профиля.</string>
|
||||||
<!--Settings Display-->
|
<!--Settings Display-->
|
||||||
<string name="pref_language_title">Язык и регион</string>
|
<string name="pref_language_title">Язык и регион</string>
|
||||||
<string name="pref_language_changed">Этот параметр вступит в силу после перезапуска Briar. Пожалуйста, выйдите и перезапустите Briar.</string>
|
<string name="pref_language_changed">Этот параметр вступит в силу после перезапуска Briar. Пожалуйста, выйдите и перезапустите Briar.</string>
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user