Skip to content

Commit aa7c0a6

Browse files
Merge pull request #1702 from session-foundation/release/1.29.2
Bring Release/1.29.2 to dev
2 parents 2f44b45 + 5419a99 commit aa7c0a6

19 files changed

+112
-108
lines changed

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import androidx.recyclerview.widget.RecyclerView
5858
import com.annimon.stream.Stream
5959
import com.bumptech.glide.Glide
6060
import com.squareup.phrase.Phrase
61+
import dagger.Lazy
6162
import dagger.hilt.android.AndroidEntryPoint
6263
import dagger.hilt.android.lifecycle.withCreationCallback
6364
import kotlinx.coroutines.CancellationException
@@ -261,7 +262,6 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
261262
@Inject lateinit var typingStatusRepository: TypingStatusRepository
262263
@Inject lateinit var typingStatusSender: TypingStatusSender
263264
@Inject lateinit var openGroupManager: OpenGroupManager
264-
@Inject lateinit var attachmentDatabase: AttachmentDatabase
265265
@Inject lateinit var clock: SnodeClock
266266
@Inject lateinit var messageSender: MessageSender
267267
@Inject lateinit var resendMessageUtilities: ResendMessageUtilities
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package org.thoughtcrime.securesms.conversation.v2.input_bar.mentions
22

3-
import android.view.View
43
import network.loki.messenger.databinding.ViewMentionCandidateV2Binding
54
import org.thoughtcrime.securesms.conversation.v2.mention.MentionViewModel
65
import org.thoughtcrime.securesms.ui.components.Avatar
76
import org.thoughtcrime.securesms.ui.setThemedContent
87
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
8+
import org.thoughtcrime.securesms.util.AvatarBadge
99

1010
fun ViewMentionCandidateV2Binding.update(candidate: MentionViewModel.Candidate) {
1111
mentionCandidateNameTextView.text = candidate.nameHighlighted
1212
profilePictureView.setThemedContent {
1313
Avatar(
1414
size = LocalDimensions.current.iconMediumAvatar,
1515
data = candidate.member.avatarData,
16+
badge = if (candidate.member.showAdminCrown) AvatarBadge.Admin else AvatarBadge.None
1617
)
1718
}
18-
19-
moderatorIconImageView.visibility = if (candidate.member.showAdminCrown) View.VISIBLE else View.GONE
2019
}

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import org.thoughtcrime.securesms.ui.theme.LocalColors
6060
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
6161
import org.thoughtcrime.securesms.ui.theme.LocalType
6262
import org.thoughtcrime.securesms.ui.theme.bold
63+
import org.thoughtcrime.securesms.util.AvatarBadge
6364
import org.thoughtcrime.securesms.util.AvatarUtils
6465
import org.thoughtcrime.securesms.util.DateUtils
6566
import org.thoughtcrime.securesms.util.disableClipping
@@ -175,7 +176,6 @@ class VisibleMessageView : FrameLayout {
175176
val isStartOfMessageCluster = isStartOfMessageCluster(message, previous, isGroupThread)
176177
val isEndOfMessageCluster = isEndOfMessageCluster(message, next, isGroupThread)
177178
// Show profile picture and sender name if this is a group thread AND the message is incoming
178-
binding.moderatorIconImageView.isVisible = false
179179
binding.profilePictureView.visibility = when {
180180
threadRecipient.isGroupOrCommunityRecipient && !message.isOutgoing && isEndOfMessageCluster -> View.VISIBLE
181181
threadRecipient.isGroupOrCommunityRecipient -> View.INVISIBLE
@@ -199,22 +199,22 @@ class VisibleMessageView : FrameLayout {
199199

200200
if (isGroupThread && !message.isOutgoing) {
201201
if (isEndOfMessageCluster) {
202+
val showProBadge = if (sender.address is Address.WithAccountId) {
203+
(threadRecipient.data as? RecipientData.GroupLike)
204+
?.shouldShowAdminCrown(sender.address.accountId) == true
205+
} else {
206+
false
207+
}
202208
binding.profilePictureView.setThemedContent {
203209
Avatar(
204210
size = LocalDimensions.current.iconMediumAvatar,
205211
data = avatarUtils.getUIDataFromRecipient(sender),
212+
badge = if(showProBadge) AvatarBadge.Admin else AvatarBadge.None,
206213
modifier = Modifier.clickable {
207214
delegate?.showUserProfileModal(message.recipient)
208215
}
209216
)
210217
}
211-
212-
binding.moderatorIconImageView.isVisible = if (sender.address is Address.WithAccountId) {
213-
(threadRecipient.data as? RecipientData.GroupLike)
214-
?.shouldShowAdminCrown(sender.address.accountId) == true
215-
} else {
216-
false
217-
}
218218
}
219219
}
220220
if(!message.isOutgoing && (isStartOfMessageCluster && isGroupThread)){

app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,16 @@
2626
import android.text.TextUtils;
2727
import android.util.Pair;
2828

29-
import androidx.annotation.NonNull;
30-
import androidx.annotation.Nullable;
3129
import androidx.annotation.VisibleForTesting;
3230

3331
import com.bumptech.glide.Glide;
3432

3533
import net.zetetic.database.sqlcipher.SQLiteDatabase;
3634

37-
import org.apache.commons.lang3.StringUtils;
3835
import org.json.JSONArray;
3936
import org.json.JSONException;
37+
import org.jspecify.annotations.NonNull;
38+
import org.jspecify.annotations.Nullable;
4039
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
4140
import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId;
4241
import org.session.libsession.messaging.sending_receiving.attachments.AttachmentState;
@@ -80,14 +79,19 @@
8079
import java.util.concurrent.ExecutionException;
8180
import java.util.concurrent.ExecutorService;
8281

82+
import javax.inject.Inject;
8383
import javax.inject.Provider;
84+
import javax.inject.Singleton;
8485

86+
import dagger.Lazy;
87+
import dagger.hilt.android.qualifiers.ApplicationContext;
8588
import kotlin.jvm.Synchronized;
8689
import kotlinx.coroutines.channels.BufferOverflow;
8790
import kotlinx.coroutines.flow.MutableSharedFlow;
8891
import kotlinx.coroutines.flow.SharedFlow;
8992
import kotlinx.coroutines.flow.SharedFlowKt;
9093

94+
@Singleton
9195
public class AttachmentDatabase extends Database {
9296

9397
private static final String TAG = AttachmentDatabase.class.getSimpleName();
@@ -161,13 +165,18 @@ public class AttachmentDatabase extends Database {
161165

162166
final ExecutorService thumbnailExecutor = Util.newSingleThreadedLifoExecutor();
163167

164-
private final AttachmentSecret attachmentSecret;
168+
private final Lazy<@NonNull AttachmentSecret> attachmentSecret;
165169

166170
private final MutableSharedFlow<Object> mutableChangesNotification = SharedFlowKt.MutableSharedFlow(
167171
0, 100, BufferOverflow.DROP_OLDEST
168172
);
169173

170-
public AttachmentDatabase(Context context, Provider<SQLCipherOpenHelper> databaseHelper, AttachmentSecret attachmentSecret) {
174+
@Inject
175+
public AttachmentDatabase(
176+
@ApplicationContext Context context,
177+
Provider<SQLCipherOpenHelper> databaseHelper,
178+
Lazy<@NonNull AttachmentSecret> attachmentSecret
179+
) {
171180
super(context, databaseHelper);
172181
this.attachmentSecret = attachmentSecret;
173182
}
@@ -535,9 +544,9 @@ public void setTransferState(@NonNull AttachmentId attachmentId, int transferSta
535544

536545
try {
537546
if (dataInfo.random != null && dataInfo.random.length == 32) {
538-
return ModernDecryptingPartInputStream.createFor(attachmentSecret, dataInfo.random, dataInfo.file, offset);
547+
return ModernDecryptingPartInputStream.createFor(attachmentSecret.get(), dataInfo.random, dataInfo.file, offset);
539548
} else {
540-
InputStream stream = ClassicDecryptingPartInputStream.createFor(attachmentSecret, dataInfo.file);
549+
InputStream stream = ClassicDecryptingPartInputStream.createFor(attachmentSecret.get(), dataInfo.file);
541550
long skipped = stream.skip(offset);
542551

543552
if (skipped != offset) {
@@ -607,7 +616,7 @@ public void setTransferState(@NonNull AttachmentId attachmentId, int transferSta
607616
File dataFile = File.createTempFile("part", ".mms", partsDirectory);
608617

609618
Log.d("AttachmentDatabase", "Writing attachment data to: " + dataFile.getAbsolutePath());
610-
Pair<byte[], OutputStream> out = ModernEncryptingPartOutputStream.createFor(attachmentSecret, dataFile, false);
619+
Pair<byte[], OutputStream> out = ModernEncryptingPartOutputStream.createFor(attachmentSecret.get(), dataFile, false);
611620
long length = Util.copy(in, out.second);
612621

613622
return new DataInfo(dataFile, length, out.first);
@@ -894,7 +903,7 @@ private ThumbnailData generateVideoThumbnail(AttachmentId attachmentId) {
894903
return null;
895904
}
896905

897-
EncryptedMediaDataSource dataSource = new EncryptedMediaDataSource(attachmentSecret, dataInfo.file, dataInfo.random, dataInfo.length);
906+
EncryptedMediaDataSource dataSource = new EncryptedMediaDataSource(attachmentSecret.get(), dataInfo.file, dataInfo.random, dataInfo.length);
898907
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
899908
retriever.setDataSource(dataSource);
900909

app/src/main/java/org/thoughtcrime/securesms/dependencies/DatabaseModule.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ object DatabaseModule {
4949
return manager.openHelper
5050
}
5151

52-
@Provides
53-
@Singleton
54-
fun provideAttachmentDatabase(@ApplicationContext context: Context,
55-
openHelper: Provider<SQLCipherOpenHelper>,
56-
attachmentSecret: AttachmentSecret) = AttachmentDatabase(context, openHelper, attachmentSecret)
5752
@Provides
5853
@Singleton
5954
fun provideMediaDatbase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = MediaDatabase(context, openHelper)

app/src/main/java/org/thoughtcrime/securesms/glide/cache/EncryptedBitmapCacheDecoder.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33

44
import android.graphics.Bitmap;
5+
56
import androidx.annotation.NonNull;
67
import androidx.annotation.Nullable;
7-
import org.session.libsignal.utilities.Log;
88

99
import com.bumptech.glide.load.Options;
1010
import com.bumptech.glide.load.ResourceDecoder;
1111
import com.bumptech.glide.load.engine.Resource;
1212
import com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder;
1313

14+
import org.session.libsignal.utilities.Log;
15+
import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider;
16+
1417
import java.io.File;
1518
import java.io.IOException;
1619
import java.io.InputStream;
@@ -20,10 +23,10 @@ public class EncryptedBitmapCacheDecoder extends EncryptedCoder implements Resou
2023
private static final String TAG = EncryptedBitmapCacheDecoder.class.getSimpleName();
2124

2225
private final StreamBitmapDecoder streamBitmapDecoder;
23-
private final byte[] secret;
26+
private final AttachmentSecretProvider attachmentSecretProvider;
2427

25-
public EncryptedBitmapCacheDecoder(@NonNull byte[] secret, @NonNull StreamBitmapDecoder streamBitmapDecoder) {
26-
this.secret = secret;
28+
public EncryptedBitmapCacheDecoder(@NonNull AttachmentSecretProvider attachmentSecretProvider, @NonNull StreamBitmapDecoder streamBitmapDecoder) {
29+
this.attachmentSecretProvider = attachmentSecretProvider;
2730
this.streamBitmapDecoder = streamBitmapDecoder;
2831
}
2932

@@ -33,7 +36,7 @@ public boolean handles(@NonNull File source, @NonNull Options options)
3336
{
3437
Log.i(TAG, "Checking item for encrypted Bitmap cache decoder: " + source.toString());
3538

36-
try (InputStream inputStream = createEncryptedInputStream(secret, source)) {
39+
try (InputStream inputStream = createEncryptedInputStream(attachmentSecretProvider.getOrCreateAttachmentSecret().getModernKey(), source)) {
3740
return streamBitmapDecoder.handles(inputStream, options);
3841
} catch (IOException e) {
3942
Log.w(TAG, e);
@@ -47,7 +50,7 @@ public Resource<Bitmap> decode(@NonNull File source, int width, int height, @Non
4750
throws IOException
4851
{
4952
Log.i(TAG, "Encrypted Bitmap cache decoder running: " + source.toString());
50-
try (InputStream inputStream = createEncryptedInputStream(secret, source)) {
53+
try (InputStream inputStream = createEncryptedInputStream(attachmentSecretProvider.getOrCreateAttachmentSecret().getModernKey(), source)) {
5154
return streamBitmapDecoder.decode(inputStream, width, height, options);
5255
}
5356
}

app/src/main/java/org/thoughtcrime/securesms/glide/cache/EncryptedBitmapResourceEncoder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.graphics.Bitmap;
55
import androidx.annotation.NonNull;
66
import org.session.libsignal.utilities.Log;
7+
import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider;
78

89
import com.bumptech.glide.load.EncodeStrategy;
910
import com.bumptech.glide.load.Options;
@@ -19,10 +20,10 @@ public class EncryptedBitmapResourceEncoder extends EncryptedCoder implements Re
1920

2021
private static final String TAG = EncryptedBitmapResourceEncoder.class.getSimpleName();
2122

22-
private final byte[] secret;
23+
private final AttachmentSecretProvider secretProvider;
2324

24-
public EncryptedBitmapResourceEncoder(@NonNull byte[] secret) {
25-
this.secret = secret;
25+
public EncryptedBitmapResourceEncoder(@NonNull AttachmentSecretProvider secretProvider) {
26+
this.secretProvider = secretProvider;
2627
}
2728

2829
@Override
@@ -39,7 +40,7 @@ public boolean encode(@NonNull Resource<Bitmap> data, @NonNull File file, @NonNu
3940
Bitmap.CompressFormat format = getFormat(bitmap, options);
4041
int quality = options.get(BitmapEncoder.COMPRESSION_QUALITY);
4142

42-
try (OutputStream os = createEncryptedOutputStream(secret, file)) {
43+
try (OutputStream os = createEncryptedOutputStream(secretProvider.getOrCreateAttachmentSecret().getModernKey(), file)) {
4344
bitmap.compress(format, quality, os);
4445
os.close();
4546
return true;

app/src/main/java/org/thoughtcrime/securesms/glide/cache/EncryptedCacheEncoder.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
package org.thoughtcrime.securesms.glide.cache;
22

33

4-
import androidx.annotation.NonNull;
54

65
import com.bumptech.glide.load.Encoder;
76
import com.bumptech.glide.load.Options;
87
import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool;
98

9+
import org.jspecify.annotations.NonNull;
1010
import org.session.libsignal.utilities.Log;
11+
import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider;
1112

1213
import java.io.File;
1314
import java.io.IOException;
1415
import java.io.InputStream;
1516
import java.io.OutputStream;
1617

18+
import dagger.Lazy;
19+
1720
public class EncryptedCacheEncoder extends EncryptedCoder implements Encoder<InputStream> {
1821

1922
private static final String TAG = EncryptedCacheEncoder.class.getSimpleName();
2023

21-
private final byte[] secret;
24+
private final AttachmentSecretProvider attachmentSecretProvider;
2225
private final ArrayPool byteArrayPool;
2326

24-
public EncryptedCacheEncoder(@NonNull byte[] secret, @NonNull ArrayPool byteArrayPool) {
25-
this.secret = secret;
27+
public EncryptedCacheEncoder(AttachmentSecretProvider attachmentSecretProvider, @NonNull ArrayPool byteArrayPool) {
28+
this.attachmentSecretProvider = attachmentSecretProvider;
2629
this.byteArrayPool = byteArrayPool;
2730
}
2831

@@ -33,7 +36,7 @@ public boolean encode(@NonNull InputStream data, @NonNull File file, @NonNull Op
3336

3437
byte[] buffer = byteArrayPool.get(ArrayPool.STANDARD_BUFFER_SIZE_BYTES, byte[].class);
3538

36-
try (OutputStream outputStream = createEncryptedOutputStream(secret, file)) {
39+
try (OutputStream outputStream = createEncryptedOutputStream(attachmentSecretProvider.getOrCreateAttachmentSecret().getModernKey(), file)) {
3740
int read;
3841

3942
while ((read = data.read(buffer)) != -1) {

app/src/main/java/org/thoughtcrime/securesms/glide/cache/EncryptedGifCacheDecoder.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import androidx.annotation.NonNull;
55
import androidx.annotation.Nullable;
66
import org.session.libsignal.utilities.Log;
7+
import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider;
78

89
import com.bumptech.glide.load.Options;
910
import com.bumptech.glide.load.ResourceDecoder;
@@ -19,19 +20,19 @@ public class EncryptedGifCacheDecoder extends EncryptedCoder implements Resource
1920

2021
private static final String TAG = EncryptedGifCacheDecoder.class.getSimpleName();
2122

22-
private final byte[] secret;
23+
private final AttachmentSecretProvider attachmentSecretProvider;
2324
private final StreamGifDecoder gifDecoder;
2425

25-
public EncryptedGifCacheDecoder(@NonNull byte[] secret, @NonNull StreamGifDecoder gifDecoder) {
26-
this.secret = secret;
26+
public EncryptedGifCacheDecoder(@NonNull AttachmentSecretProvider attachmentSecretProvider, @NonNull StreamGifDecoder gifDecoder) {
27+
this.attachmentSecretProvider = attachmentSecretProvider;
2728
this.gifDecoder = gifDecoder;
2829
}
2930

3031
@Override
3132
public boolean handles(@NonNull File source, @NonNull Options options) {
3233
Log.i(TAG, "Checking item for encrypted GIF cache decoder: " + source.toString());
3334

34-
try (InputStream inputStream = createEncryptedInputStream(secret, source)) {
35+
try (InputStream inputStream = createEncryptedInputStream(attachmentSecretProvider.getOrCreateAttachmentSecret().getModernKey(), source)) {
3536
return gifDecoder.handles(inputStream, options);
3637
} catch (IOException e) {
3738
Log.w(TAG, e);
@@ -43,7 +44,7 @@ public boolean handles(@NonNull File source, @NonNull Options options) {
4344
@Override
4445
public Resource<GifDrawable> decode(@NonNull File source, int width, int height, @NonNull Options options) throws IOException {
4546
Log.i(TAG, "Encrypted GIF cache decoder running...");
46-
try (InputStream inputStream = createEncryptedInputStream(secret, source)) {
47+
try (InputStream inputStream = createEncryptedInputStream(attachmentSecretProvider.getOrCreateAttachmentSecret().getModernKey(), source)) {
4748
return gifDecoder.decode(inputStream, width, height, options);
4849
}
4950
}

app/src/main/java/org/thoughtcrime/securesms/glide/cache/EncryptedGifDrawableResourceEncoder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import androidx.annotation.NonNull;
55
import org.session.libsignal.utilities.Log;
6+
import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider;
67

78
import com.bumptech.glide.load.EncodeStrategy;
89
import com.bumptech.glide.load.Options;
@@ -19,10 +20,10 @@ public class EncryptedGifDrawableResourceEncoder extends EncryptedCoder implemen
1920

2021
private static final String TAG = EncryptedGifDrawableResourceEncoder.class.getSimpleName();
2122

22-
private final byte[] secret;
23+
private final AttachmentSecretProvider secretProvider;
2324

24-
public EncryptedGifDrawableResourceEncoder(@NonNull byte[] secret) {
25-
this.secret = secret;
25+
public EncryptedGifDrawableResourceEncoder(@NonNull AttachmentSecretProvider secretProvider) {
26+
this.secretProvider = secretProvider;
2627
}
2728

2829
@Override
@@ -34,7 +35,7 @@ public EncodeStrategy getEncodeStrategy(@NonNull Options options) {
3435
public boolean encode(@NonNull Resource<GifDrawable> data, @NonNull File file, @NonNull Options options) {
3536
GifDrawable drawable = data.get();
3637

37-
try (OutputStream outputStream = createEncryptedOutputStream(secret, file)) {
38+
try (OutputStream outputStream = createEncryptedOutputStream(secretProvider.getOrCreateAttachmentSecret().getModernKey(), file)) {
3839
ByteBufferUtil.toStream(drawable.getBuffer(), outputStream);
3940
return true;
4041
} catch (IOException e) {

0 commit comments

Comments
 (0)