Skip to content

Commit

Permalink
Fixes a thread safety issue with currentMessage being out of sync.
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardGatt committed Dec 6, 2023
1 parent b54808b commit c0b77f5
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ internal class GistModalManager : GistListener {
}

internal fun showModalMessage(message: Message, position: MessagePosition? = null): Boolean {
currentMessage?.let { currentMessage ->
Log.i(
GIST_TAG,
"Message ${message.messageId} not shown, ${currentMessage.messageId} is already showing."
)
return false
}
synchronized(this) {

Check warning on line 17 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt#L17

Added line #L17 was not covered by tests
currentMessage?.let { currentMessage ->
Log.i(
GIST_TAG,
"Message ${message.messageId} not shown, ${currentMessage.messageId} is already showing."

Check warning on line 21 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt#L19-L21

Added lines #L19 - L21 were not covered by tests
)
return false

Check warning on line 23 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt#L23

Added line #L23 was not covered by tests
}

Log.i(GIST_TAG, "Showing message: ${message.messageId}")
currentMessage = message
Log.i(GIST_TAG, "Showing message: ${message.messageId}")
currentMessage = message

Check warning on line 27 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt#L26-L27

Added lines #L26 - L27 were not covered by tests

val intent = GistModalActivity.newIntent(GistSdk.application)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.putExtra(GIST_MESSAGE_INTENT, Gson().toJson(message))
intent.putExtra(GIST_MODAL_POSITION_INTENT, position?.toString())
GistSdk.application.startActivity(intent)
return true
val intent = GistModalActivity.newIntent(GistSdk.application)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.putExtra(GIST_MESSAGE_INTENT, Gson().toJson(message))

Check warning on line 31 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt#L29-L31

Added lines #L29 - L31 were not covered by tests
intent.putExtra(GIST_MODAL_POSITION_INTENT, position?.toString())
GistSdk.application.startActivity(intent)
return true

Check warning on line 34 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/GistModalManager.kt#L33-L34

Added lines #L33 - L34 were not covered by tests
}
}

internal fun dismissActiveMessage() {
Expand Down

0 comments on commit c0b77f5

Please sign in to comment.