Convert MessageTable to kotlin.

This commit is contained in:
Greyson Parrelli
2023-03-11 15:35:14 -05:00
parent c2a76c4313
commit 90cc672c37
19 changed files with 5245 additions and 5682 deletions

View File

@@ -18,7 +18,7 @@ class SmsSettingsRepository(
@WorkerThread
private fun checkInsecureMessageCount(): SmsExportState? {
val totalSmsMmsCount = smsDatabase.insecureMessageCount + mmsDatabase.insecureMessageCount
val totalSmsMmsCount = smsDatabase.getInsecureMessageCount() + mmsDatabase.getInsecureMessageCount()
return if (totalSmsMmsCount == 0) {
SmsExportState.NO_SMS_MESSAGES_IN_DATABASE
@@ -29,7 +29,7 @@ class SmsSettingsRepository(
@WorkerThread
private fun checkUnexportedInsecureMessageCount(): SmsExportState {
val totalUnexportedCount = smsDatabase.unexportedInsecureMessagesCount + mmsDatabase.unexportedInsecureMessagesCount
val totalUnexportedCount = smsDatabase.getUnexportedInsecureMessagesCount() + mmsDatabase.getUnexportedInsecureMessagesCount()
return if (totalUnexportedCount > 0) {
SmsExportState.HAS_UNEXPORTED_MESSAGES

View File

@@ -1193,7 +1193,6 @@ public class ConversationFragment extends LoggingFragment implements Multiselect
if (message.getScheduledDate() != -1) {
return;
}
MessageRecord messageRecord = MessageTable.readerFor(message, threadId).getCurrent();
if (getListAdapter() != null) {
setLastSeen(0);

File diff suppressed because it is too large Load Diff

View File

@@ -128,7 +128,7 @@ class SearchTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
* Be smart about where you call this.
*/
fun rebuildIndex(batchSize: Long = 10_000L) {
val maxId: Long = SignalDatabase.messages.nextId
val maxId: Long = SignalDatabase.messages.getNextId()
Log.i(TAG, "Re-indexing. Operating on ID's 1-$maxId in steps of $batchSize.")

View File

@@ -38,7 +38,7 @@ class SignalSmsExportReader(
}
fun getCount(): Int {
return messageTable.unexportedInsecureMessagesCount
return messageTable.getUnexportedInsecureMessagesCount()
}
override fun close() {
@@ -51,7 +51,7 @@ class SignalSmsExportReader(
messageReader = null
val refreshedMmsReader = MessageTable.mmsReaderFor(messageTable.getUnexportedInsecureMessages(CURSOR_LIMIT))
if (refreshedMmsReader.count > 0) {
if (refreshedMmsReader.getCount() > 0) {
messageReader = refreshedMmsReader
return
} else {
@@ -88,14 +88,14 @@ class SignalSmsExportReader(
try {
return if (messageIterator?.hasNext() == true) {
record = messageIterator!!.next()
readExportableMmsMessageFromRecord(record, messageReader!!.messageExportStateForCurrentRecord)
readExportableMmsMessageFromRecord(record, messageReader!!.getMessageExportStateForCurrentRecord())
} else {
throw NoSuchElementException()
}
} catch (e: Throwable) {
if (e.cause is JSONException) {
Log.w(TAG, "Error processing attachment json, skipping message.", e)
return ExportableMessage.Skip(messageReader!!.currentId)
return ExportableMessage.Skip(messageReader!!.getCurrentId())
}
Log.w(TAG, "Error processing message: isMms: ${record?.isMms} type: ${record?.type}")

View File

@@ -1,118 +0,0 @@
package org.thoughtcrime.securesms.mms;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.database.model.Mention;
import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import java.util.Collections;
import java.util.List;
public class QuoteModel {
private final long id;
private final RecipientId author;
private final String text;
private final boolean missing;
private final List<Attachment> attachments;
private final List<Mention> mentions;
private final Type type;
private final BodyRangeList bodyRanges;
public QuoteModel(long id,
@NonNull RecipientId author,
String text,
boolean missing,
@Nullable List<Attachment> attachments,
@Nullable List<Mention> mentions,
@NonNull Type type,
@Nullable BodyRangeList bodyRanges)
{
this.id = id;
this.author = author;
this.text = text;
this.missing = missing;
this.attachments = attachments;
this.mentions = mentions != null ? mentions : Collections.emptyList();
this.type = type;
this.bodyRanges = bodyRanges;
}
public long getId() {
return id;
}
public RecipientId getAuthor() {
return author;
}
public String getText() {
return text;
}
public boolean isOriginalMissing() {
return missing;
}
public List<Attachment> getAttachments() {
return attachments;
}
public @NonNull List<Mention> getMentions() {
return mentions;
}
public Type getType() {
return type;
}
public @Nullable BodyRangeList getBodyRanges() {
return bodyRanges;
}
public enum Type {
NORMAL(0, SignalServiceDataMessage.Quote.Type.NORMAL),
GIFT_BADGE(1, SignalServiceDataMessage.Quote.Type.GIFT_BADGE);
private final int code;
private final SignalServiceDataMessage.Quote.Type dataMessageType;
Type(int code, @NonNull SignalServiceDataMessage.Quote.Type dataMessageType) {
this.code = code;
this.dataMessageType = dataMessageType;
}
public int getCode() {
return code;
}
public @NonNull SignalServiceDataMessage.Quote.Type getDataMessageType() {
return dataMessageType;
}
public static Type fromCode(int code) {
for (final Type value : values()) {
if (value.code == code) {
return value;
}
}
throw new IllegalArgumentException("Invalid code: " + code);
}
public static Type fromDataMessageType(@NonNull SignalServiceDataMessage.Quote.Type dataMessageType) {
for (final Type value : values()) {
if (value.dataMessageType == dataMessageType) {
return value;
}
}
return NORMAL;
}
}
}

View File

@@ -0,0 +1,52 @@
package org.thoughtcrime.securesms.mms
import org.thoughtcrime.securesms.attachments.Attachment
import org.thoughtcrime.securesms.database.model.Mention
import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList
import org.thoughtcrime.securesms.recipients.RecipientId
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage
class QuoteModel(
val id: Long,
val author: RecipientId,
val text: String,
val isOriginalMissing: Boolean,
val attachments: List<Attachment>,
mentions: List<Mention>?,
val type: Type,
val bodyRanges: BodyRangeList?
) {
val mentions: List<Mention>
init {
this.mentions = mentions ?: emptyList()
}
enum class Type(val code: Int, val dataMessageType: SignalServiceDataMessage.Quote.Type) {
NORMAL(0, SignalServiceDataMessage.Quote.Type.NORMAL),
GIFT_BADGE(1, SignalServiceDataMessage.Quote.Type.GIFT_BADGE);
companion object {
@JvmStatic
fun fromCode(code: Int): Type {
for (value in values()) {
if (value.code == code) {
return value
}
}
throw IllegalArgumentException("Invalid code: $code")
}
@JvmStatic
fun fromDataMessageType(dataMessageType: SignalServiceDataMessage.Quote.Type): Type {
for (value in values()) {
if (value.dataMessageType === dataMessageType) {
return value
}
}
return NORMAL
}
}
}
}

View File

@@ -33,7 +33,7 @@ object NotificationStateProvider {
}
MessageTable.mmsReaderFor(unreadMessages).use { reader ->
var record: MessageRecord? = reader.next
var record: MessageRecord? = reader.getNext()
while (record != null) {
val threadRecipient: Recipient? = SignalDatabase.threads.getRecipientForThreadId(record.threadId)
if (threadRecipient != null) {
@@ -73,7 +73,7 @@ object NotificationStateProvider {
)
}
try {
record = reader.next
record = reader.getNext()
} catch (e: IllegalStateException) {
// XXX Weird SQLCipher bug that's being investigated
record = null

View File

@@ -34,7 +34,7 @@ class ConversationListTabRepository {
fun getNumberOfUnseenStories(): Observable<Long> {
return Observable.create<Long> { emitter ->
fun refresh() {
emitter.onNext(SignalDatabase.messages.unreadStoryThreadRecipientIds.map { Recipient.resolved(it) }.filterNot { it.shouldHideStory() }.size.toLong())
emitter.onNext(SignalDatabase.messages.getUnreadStoryThreadRecipientIds().map { Recipient.resolved(it) }.filterNot { it.shouldHideStory() }.size.toLong())
}
val listener = DatabaseObserver.Observer {

View File

@@ -38,7 +38,7 @@ open class StoryViewerRepository {
}
fun getStories(hiddenStories: Boolean, isOutgoingOnly: Boolean): Single<List<RecipientId>> {
return Single.create<List<RecipientId>> { emitter ->
return Single.create { emitter ->
val myStoriesId = SignalDatabase.recipients.getOrInsertFromDistributionListId(DistributionListId.MY_STORY)
val myStories = Recipient.resolved(myStoriesId)
val releaseChannelId = SignalStore.releaseChannelValues().releaseChannelRecipientId

View File

@@ -20,7 +20,7 @@ class StoryGroupReplyDataSource(private val parentStoryId: Long) : PagedDataSour
cursor.moveToPosition(start - 1)
val mmsReader = MessageTable.MmsReader(cursor)
while (cursor.moveToNext() && cursor.position < start + length) {
results.add(readRowFromRecord(mmsReader.current as MmsMessageRecord))
results.add(readRowFromRecord(mmsReader.getCurrent() as MmsMessageRecord))
}
}