Skip to content

Commit

Permalink
Show notes: fail to save if text is too long instead of truncating
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Nov 13, 2024
1 parent c016763 commit a9cc1bc
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,20 +457,25 @@ class ShowTools2 @Inject constructor(
data class StoreUserNoteResult(val text: String, val traktId: Long?)

/**
* Uploads to Hexagon and Trakt and on success saves to local database.
* Uploads to Hexagon and Trakt and on success saves to local database,
* on failure returns `null`.
*
* [noteDraft] is shortened to at most [SgShow2.MAX_USER_NOTE_LENGTH] characters and a blank
* string is treated as an empty string. If the resulting string is empty, an existing note will
* be deleted at Trakt.
* Fails if [noteDraft] exceeds [SgShow2.MAX_USER_NOTE_LENGTH] characters.
*
* A blank string is treated as an empty string.
*
* If the final string is empty, an existing note will be deleted at Trakt.
*/
suspend fun storeUserNote(
showId: Long,
noteDraft: String,
noteTraktId: Long?
): StoreUserNoteResult? {
val noteText = noteDraft
.take(SgShow2.MAX_USER_NOTE_LENGTH)
.ifBlank { "" } // To provide useful UI, but also Trakt does not allow a blank text
.ifBlank { "" } // Avoid storing useless data, but also Trakt does not allow a blank text

// Fail if string is too long
if (noteText.length > SgShow2.MAX_USER_NOTE_LENGTH) return null

// Send to Cloud first, Trakt may fail if user is not VIP
val isSendToCloudSuccess: Boolean = if (HexagonSettings.isEnabled(context)) {
Expand Down

0 comments on commit a9cc1bc

Please sign in to comment.