forked from gotify/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtras.kt
More file actions
38 lines (28 loc) · 912 Bytes
/
Copy pathExtras.kt
File metadata and controls
38 lines (28 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.github.gotify.messages
import com.github.gotify.client.model.Message
internal object Extras {
fun useMarkdown(message: Message): Boolean = useMarkdown(message.extras)
fun useMarkdown(extras: Map<String, Any>?): Boolean {
if (extras == null) {
return false
}
val display: Any? = extras["client::display"]
if (display !is Map<*, *>) {
return false
}
return "text/markdown" == display["contentType"]
}
fun <T> getNestedValue(clazz: Class<T>, extras: Map<String, Any>?, vararg keys: String): T? {
var value: Any? = extras
keys.forEach { key ->
if (value == null) {
return null
}
value = (value as Map<*, *>)[key]
}
if (!clazz.isInstance(value)) {
return null
}
return clazz.cast(value)
}
}