Skip to content

Commit 98a5f42

Browse files
committed
Replaced: custom regex fn with UUID.fromString;
1 parent 6276ebc commit 98a5f42

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/main/kotlin/com/wire/bots/application/EventMapper.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ object EventMapper {
3030
val senderId = eventDTO.userId?.let {
3131
QualifiedId(UUID.fromString(it), "")
3232
}
33-
// basic validation if it is a UUID, it means it is a reminder id
34-
if (isUUID(buttonId)) {
33+
34+
val parsedUuid = runCatching { UUID.fromString(buttonId) }.getOrNull()
35+
if (parsedUuid != null) {
3536
Command
3637
.DeleteReminder(
3738
conversationId = eventDTO.conversationId,
@@ -40,8 +41,6 @@ object EventMapper {
4041
senderId = senderId
4142
).right()
4243
} else {
43-
// It was not a UUID, so it's not a delete action.
44-
// We can parse it as a normal command in case other button actions are added in the future.
4544
parseCommand(
4645
conversationId = eventDTO.conversationId,
4746
rawCommand = buttonId,
@@ -174,11 +173,6 @@ object EventMapper {
174173
}
175174
}
176175

177-
private val UUID_REGEX =
178-
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$".toRegex()
179-
180-
private fun isUUID(text: String): Boolean = UUID_REGEX.matches(text)
181-
182176
internal val COMMAND_EXPRESSION: Regex = "\\s+".toRegex()
183177
internal val COMMAND_HINT =
184178
"""

0 commit comments

Comments
 (0)