Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds error message on status header #662

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add error_message to DB
ariel10aguero committed Oct 19, 2023
commit 1c2fb764b71e66605b95ec13456e3317fbd819aa
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package chat.sphinx.wrapper_message

@Suppress("NOTHING_TO_INLINE")
inline fun String.toErrorMessage(): ErrorMessage? =
try {
ErrorMessage(this)
} catch (e: IllegalArgumentException) {
null
}

@JvmInline
value class ErrorMessage(val value: String) {
init {
require(value.isNotEmpty()) {
"ErrorMessage cannot be empty"
}
}
}
Original file line number Diff line number Diff line change
@@ -357,6 +357,7 @@ abstract class Message {
abstract val recipientPic: PhotoUrl?
abstract val person: MessagePerson?
abstract val threadUUID: ThreadUUID?
abstract val errorMessage: ErrorMessage?
abstract val isPinned: Boolean

abstract val messageContentDecrypted: MessageContentDecrypted?
@@ -405,6 +406,7 @@ abstract class Message {
other.recipientPic == recipientPic &&
other.person == person &&
other.threadUUID == threadUUID &&
other.errorMessage == errorMessage &&
other.isPinned == isPinned &&
other.reactions.let { a ->
reactions.let { b ->
@@ -461,6 +463,7 @@ abstract class Message {
result = _31 * result + recipientPic.hashCode()
result = _31 * result + person.hashCode()
result = _31 * result + threadUUID.hashCode()
result = _31 * result + errorMessage.hashCode()
result = _31 * result + isPinned.hashCode()
reactions?.forEach { result = _31 * result + it.hashCode() }
purchaseItems?.forEach { result = _31 * result + it.hashCode() }
@@ -482,6 +485,7 @@ abstract class Message {
"giphyData=$giphyData,reactions=$reactions,purchaseItems=$purchaseItems," +
"replyMessage=$replyMessage),recipientAlias=$recipientAlias," +
"recipientPic=$recipientPic,person=$person,threadUUID=$threadUUID," +
"errorMessage=$errorMessage" +
"callLink=$callLinkMessage" +
"isPinned=$isPinned"
}
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ import chat.sphinx.wrapper_feed.FeedModelType;
import chat.sphinx.wrapper_feed.FeedPlayerSpeed;
import chat.sphinx.wrapper_feed.FeedTitle;
import chat.sphinx.wrapper_invite.InviteString;
import chat.sphinx.wrapper_message.ErrorMessage;
import chat.sphinx.wrapper_message.Flagged;
import chat.sphinx.wrapper_message.MessageContent;
import chat.sphinx.wrapper_message.MessageContentDecrypted;
@@ -602,7 +603,8 @@ CREATE TABLE messageDbo(
recipient_pic TEXT AS PhotoUrl,
push INTEGER AS Push DEFAULT 0,
person TEXT AS MessagePerson,
thread_uuid TEXT AS ThreadUUID
thread_uuid TEXT AS ThreadUUID,
error_message TEXT AS ErrorMessage
);

messageGetAllReactionsByUUID:
@@ -803,7 +805,8 @@ messageUpsert {
recipient_pic = :recipient_pic,
push = :push,
person = :person,
thread_uuid = :thread_uuid
thread_uuid = :thread_uuid,
error_message = :error_message
WHERE id = :id;

INSERT OR IGNORE INTO messageDbo(
@@ -832,7 +835,8 @@ messageUpsert {
recipient_pic,
push,
person,
thread_uuid
thread_uuid,
error_message
)
VALUES (
:id,
@@ -860,7 +864,8 @@ messageUpsert {
:recipient_pic,
:push,
:person,
:thread_uuid
:thread_uuid,
:error_message
);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import chat.sphinx.wrapper_message.ErrorMessage;

ALTER TABLE messageDbo ADD COLUMN error_message TEXT AS ErrorMessage DEFAULT NULL;
Original file line number Diff line number Diff line change
@@ -154,7 +154,8 @@ abstract class CoreDBImpl(private val moshi: Moshi): CoreDB() {
recipient_picAdapter = PhotoUrlAdapter.getInstance(),
pushAdapter = PushAdapter(),
personAdapter = PersonAdapter(),
thread_uuidAdapter = ThreadUUIDAdapter()
thread_uuidAdapter = ThreadUUIDAdapter(),
error_messageAdapter = ErrorMessageAdapter()
),
messageMediaDboAdapter = MessageMediaDbo.Adapter(
idAdapter = MessageIdAdapter.getInstance(),
Original file line number Diff line number Diff line change
@@ -162,3 +162,13 @@ internal class ThreadUUIDAdapter: ColumnAdapter<ThreadUUID, String> {
}
}

internal class ErrorMessageAdapter: ColumnAdapter<ErrorMessage, String> {
override fun decode(databaseValue: String): ErrorMessage {
return ErrorMessage(databaseValue)
}

override fun encode(value: ErrorMessage): String {
return value.value
}
}

Original file line number Diff line number Diff line change
@@ -2662,6 +2662,7 @@ abstract class SphinxRepository(
Push.False,
null,
threadUUID,
null,
provisionalId,
null,
chatDbo.id,
Original file line number Diff line number Diff line change
@@ -64,7 +64,8 @@ class MessageDboWrapper(
get() = messageDbo.person
override val threadUUID: ThreadUUID?
get() = messageDbo.thread_uuid

override val errorMessage: ErrorMessage?
get() = messageDbo.error_message

@Volatile
@Suppress("PropertyName")
Original file line number Diff line number Diff line change
@@ -395,6 +395,7 @@ fun TransactionCallbacks.upsertMessage(
dto.pushActual.toPush(),
dto.person?.toMessagePerson(),
dto.thread_uuid?.toThreadUUID(),
dto.error_message?.toErrorMessage(),
MessageId(dto.id),
dto.uuid?.toMessageUUID(),
chatId,
Original file line number Diff line number Diff line change
@@ -42,7 +42,8 @@ data class MessageDto(
val recipient_pic: String?,
val push: Any?,
val person: String?,
val thread_uuid: String?
val thread_uuid: String?,
val error_message: String?
) {
@Transient
val seenActual: Boolean =
Original file line number Diff line number Diff line change
@@ -1009,7 +1009,7 @@ abstract class ChatViewModel<ARGS : NavArgs>(
}
} else {
messageRepository.getAllMessagesToShowByChatId(getChat().id, 100).firstOrNull()?.let { messages ->
delay(200)
m delay(200)

messageHolderViewStateFlow.value = getMessageHolderViewStateList(messages).toList()
shimmerViewState.updateViewState(ShimmerViewState.Off)