Skip to content

Commit bebd74d

Browse files
Merge pull request #1924 from session-foundation/techdebt/remove-guava
Techdebt/remove guava
2 parents 625c667 + ace5153 commit bebd74d

File tree

72 files changed

+1232
-3740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1232
-3740
lines changed

app/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ class AttachmentUploadJob @AssistedInject constructor(
227227
}
228228

229229
private fun handlePermanentFailure(dispatcherName: String, e: Exception) {
230-
Log.w(TAG, "Attachment upload failed permanently due to error: $this.")
230+
Log.w(TAG, "Attachment upload failed permanently due to error:", e)
231231
delegate?.handleJobFailedPermanently(this, dispatcherName, e)
232232
messageDataProvider.handleFailedAttachmentUpload(attachmentID)
233233
failAssociatedMessageSendJob(e)
234234
}
235235

236236
private fun handleFailure(dispatcherName: String, e: Exception) {
237-
Log.w(TAG, "Attachment upload failed due to error: $this.")
237+
Log.w(TAG, "Attachment upload failed due to error:", e)
238238
delegate?.handleJobFailed(this, dispatcherName, e)
239239
if (failureCount + 1 >= maxFailureCount) {
240240
failAssociatedMessageSendJob(e)

app/src/main/java/org/session/libsession/messaging/messages/visible/Attachment.kt

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import com.google.protobuf.ByteString
77
import org.session.libsession.messaging.sending_receiving.attachments.PointerAttachment
88
import org.session.libsignal.messages.SignalServiceAttachmentPointer
99
import org.session.protos.SessionProtos
10-
import org.session.libsignal.utilities.guava.Optional
1110
import java.io.File
1211
import org.session.libsession.messaging.sending_receiving.attachments.Attachment as SignalAttachment
1312

@@ -28,69 +27,63 @@ class Attachment {
2827
val result = Attachment()
2928

3029
// Note: For legacy Session Android clients this filename will be null and we'll synthesise an appropriate filename
31-
// further down the stack
30+
// further down the stack in the Storage.persist
3231
result.filename = proto.fileName
3332

3433
fun inferContentType(): String {
35-
val fileName = result.filename
34+
val fileName = result.filename.orEmpty()
3635
val fileExtension = File(fileName).extension
3736
val mimeTypeMap = MimeTypeMap.getSingleton()
3837
return mimeTypeMap.getMimeTypeFromExtension(fileExtension) ?: "application/octet-stream"
3938
}
4039
result.contentType = proto.contentType ?: inferContentType()
4140

42-
// If we were given a null filename from a legacy client but we at least have a content type (i.e., mime type)
43-
// then the best we can do is synthesise a filename based on the content type and when we received the file.
44-
if (result.filename.isNullOrEmpty() && !result.contentType.isNullOrEmpty()) {
45-
Log.d("", "*** GOT an empty filename")
46-
//result.filename = generateFilenameFromReceivedTypeForLegacyClients(result.contentType!!)
47-
//todo: Found this part with the code commented out... This 'if' is now doing nothing at all, is that normal? Shouldn't we indeed set a filename here or is that handled further down the line? (can't explore this now so I'm leaving a todo)
48-
}
49-
5041
result.key = proto.key.toByteArray()
5142
result.digest = proto.digest.toByteArray()
52-
val kind: Kind = if (proto.hasFlags() && proto.flags.and(SessionProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) > 0) {
53-
Kind.VOICE_MESSAGE
54-
} else {
55-
Kind.GENERIC
56-
}
57-
result.kind = kind
43+
44+
result.kind =
45+
if (proto.hasFlags() && (proto.flags and SessionProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) > 0) {
46+
Kind.VOICE_MESSAGE
47+
} else {
48+
Kind.GENERIC
49+
}
50+
5851
result.caption = if (proto.hasCaption()) proto.caption else null
59-
val size: Size = if (proto.hasWidth() && proto.width > 0 && proto.hasHeight() && proto.height > 0) {
60-
Size(proto.width, proto.height)
61-
} else {
62-
Size(0,0)
63-
}
64-
result.size = size
52+
53+
result.size =
54+
if (proto.hasWidth() && proto.width > 0 && proto.hasHeight() && proto.height > 0) {
55+
Size(proto.width, proto.height)
56+
} else {
57+
Size(0, 0)
58+
}
59+
6560
result.sizeInBytes = if (proto.size > 0) proto.size else null
6661
result.url = proto.url
6762

6863
return result
6964
}
7065

71-
fun createAttachmentPointer(attachment: SignalServiceAttachmentPointer): SessionProtos.AttachmentPointer? {
66+
fun createAttachmentPointer(attachment: SignalServiceAttachmentPointer): SessionProtos.AttachmentPointer {
7267
val builder = SessionProtos.AttachmentPointer.newBuilder()
73-
.setContentType(attachment.contentType)
74-
.setId(attachment.id.toString().toLongOrNull() ?: 0L)
75-
.setKey(ByteString.copyFrom(attachment.key))
76-
.setSize(attachment.size.get())
77-
.setUrl(attachment.url)
78-
79-
if (attachment.digest.isPresent) {
80-
builder.setDigest(ByteString.copyFrom(attachment.digest.get()))
81-
}
82-
68+
.setContentType(attachment.contentType)
69+
.setId(attachment.id)
70+
.setKey(ByteString.copyFrom(attachment.key))
71+
.setSize(attachment.size ?: 0)
72+
.setUrl(attachment.url)
73+
74+
attachment.digest?.let { builder.setDigest(ByteString.copyFrom(it)) }
75+
8376
// Filenames are now mandatory for picked/shared files, Giphy GIFs, and captured photos.
8477
// The images associated with LinkPreviews don't have a "given name" so we'll use the
8578
// attachment ID as the filename. It's not possible to save these preview images or see
8679
// the filename, so what the filename IS isn't important, only that a filename exists.
8780
builder.fileName = attachment.filename ?: attachment.id.toString()
8881

89-
if (attachment.preview.isPresent) { builder.thumbnail = ByteString.copyFrom(attachment.preview.get()) }
90-
if (attachment.width > 0) { builder.width = attachment.width }
91-
if (attachment.height > 0) { builder.height = attachment.height }
92-
if (attachment.voiceNote) { builder.flags = SessionProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE }
93-
if (attachment.caption.isPresent) { builder.caption = attachment.caption.get() }
82+
attachment.preview?.let { builder.thumbnail = ByteString.copyFrom(it) }
83+
if (attachment.width > 0) builder.width = attachment.width
84+
if (attachment.height > 0) builder.height = attachment.height
85+
if (attachment.voiceNote) builder.flags = SessionProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE
86+
attachment.caption?.let { builder.caption = it }
9487

9588
return builder.build()
9689
}
@@ -112,14 +105,31 @@ class Attachment {
112105

113106
fun toSignalAttachment(): SignalAttachment? {
114107
if (!isValid()) return null
115-
return PointerAttachment.forAttachment((this))
108+
return PointerAttachment.forAttachment(this)
116109
}
117110

118111
fun toSignalPointer(): SignalServiceAttachmentPointer? {
119112
if (!isValid()) return null
120-
return SignalServiceAttachmentPointer(0, contentType, key, Optional.fromNullable(sizeInBytes), null,
121-
size?.width ?: 0, size?.height ?: 0, Optional.fromNullable(digest), filename,
122-
kind == Kind.VOICE_MESSAGE, Optional.fromNullable(caption), url)
123-
}
124113

125-
}
114+
// safe because isValid() checked them
115+
val ct = contentType!!
116+
val k = key!!
117+
val u = url!!
118+
val file = filename
119+
120+
return SignalServiceAttachmentPointer(
121+
id = 0L,
122+
contentType = ct,
123+
key = k,
124+
size = sizeInBytes,
125+
preview = null,
126+
width = size?.width ?: 0,
127+
height = size?.height ?: 0,
128+
digest = digest,
129+
filename = file ?: "",
130+
voiceNote = (kind == Kind.VOICE_MESSAGE),
131+
caption = caption,
132+
url = u
133+
)
134+
}
135+
}

app/src/main/java/org/session/libsession/messaging/sending_receiving/VisibleMessageHandler.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import org.session.libsession.utilities.upsertContact
3030
import org.session.libsession.utilities.withMutableUserConfigs
3131
import org.session.libsession.utilities.withUserConfigs
3232
import org.session.libsignal.utilities.Log
33-
import org.session.libsignal.utilities.guava.Optional
3433
import org.session.protos.SessionProtos
3534
import org.thoughtcrime.securesms.database.Storage
3635
import org.thoughtcrime.securesms.database.model.MessageId
@@ -109,11 +108,15 @@ class VisibleMessageHandler @Inject constructor(
109108
if (message.linkPreview != null && proto.dataMessage.previewCount > 0) {
110109
for (preview in proto.dataMessage.previewList) {
111110
val thumbnail = PointerAttachment.forPointer(preview.image)
112-
val url = Optional.fromNullable(preview.url)
113-
val title = Optional.fromNullable(preview.title)
114-
val hasContent = !TextUtils.isEmpty(title.or("")) || thumbnail.isPresent
111+
val url = preview.url
112+
val title = preview.title
113+
val hasContent = !title.isNullOrEmpty() || thumbnail != null
115114
if (hasContent) {
116-
val linkPreview = LinkPreview(url.get(), title.or(""), thumbnail)
115+
val linkPreview = LinkPreview(
116+
url = url.orEmpty(),
117+
title = title.orEmpty(),
118+
thumbnail = thumbnail
119+
)
117120
linkPreviews.add(linkPreview)
118121
} else {
119122
Log.w("Loki", "Discarding an invalid link preview. hasContent: $hasContent")

app/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/PointerAttachment.java

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)