Fix test notifications in different languages
This commit is contained in:
parent
fc27b0ce99
commit
e600d15505
2 changed files with 23 additions and 17 deletions
|
@ -1,5 +1,6 @@
|
||||||
package io.heckel.ntfy.msg
|
package io.heckel.ntfy.msg
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import io.heckel.ntfy.BuildConfig
|
import io.heckel.ntfy.BuildConfig
|
||||||
import io.heckel.ntfy.db.Notification
|
import io.heckel.ntfy.db.Notification
|
||||||
|
@ -8,6 +9,8 @@ import io.heckel.ntfy.util.*
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.net.URL
|
||||||
|
import java.net.URLEncoder
|
||||||
import java.nio.charset.StandardCharsets.UTF_8
|
import java.nio.charset.StandardCharsets.UTF_8
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
@ -43,33 +46,34 @@ class ApiService {
|
||||||
filename: String = ""
|
filename: String = ""
|
||||||
) {
|
) {
|
||||||
val url = topicUrl(baseUrl, topic)
|
val url = topicUrl(baseUrl, topic)
|
||||||
Log.d(TAG, "Publishing to $url")
|
val query = mutableListOf<String>()
|
||||||
|
|
||||||
val builder = requestBuilder(url, user)
|
|
||||||
if (priority in 1..5) {
|
if (priority in 1..5) {
|
||||||
builder.addHeader("X-Priority", priority.toString())
|
query.add("priority=$priority")
|
||||||
}
|
}
|
||||||
if (tags.isNotEmpty()) {
|
if (tags.isNotEmpty()) {
|
||||||
builder.addHeader("X-Tags", tags.joinToString(","))
|
query.add("tags=${URLEncoder.encode(tags.joinToString(","), "UTF-8")}")
|
||||||
}
|
}
|
||||||
if (title.isNotEmpty()) {
|
if (title.isNotEmpty()) {
|
||||||
builder.addHeader("X-Title", title)
|
query.add("title=${URLEncoder.encode(title, "UTF-8")}")
|
||||||
}
|
}
|
||||||
if (delay.isNotEmpty()) {
|
if (delay.isNotEmpty()) {
|
||||||
builder.addHeader("X-Delay", delay)
|
query.add("delay=${URLEncoder.encode(delay, "UTF-8")}")
|
||||||
}
|
}
|
||||||
if (filename.isNotEmpty()) {
|
if (filename.isNotEmpty()) {
|
||||||
builder.addHeader("X-Filename", filename)
|
query.add("filename=${URLEncoder.encode(filename, "UTF-8")}")
|
||||||
}
|
}
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
builder
|
query.add("message=${URLEncoder.encode(message.replace("\n", "\\n"), "UTF-8")}")
|
||||||
.addHeader("X-Message", message.replace("\n", "\\n"))
|
|
||||||
.put(body)
|
|
||||||
} else {
|
|
||||||
builder.put(message.toRequestBody())
|
|
||||||
}
|
}
|
||||||
val request = builder.build()
|
val urlWithQuery = if (query.isNotEmpty()) {
|
||||||
Log.d(TAG, request.toString())
|
url + "?" + query.joinToString("&")
|
||||||
|
} else {
|
||||||
|
url
|
||||||
|
}
|
||||||
|
val request = requestBuilder(urlWithQuery, user)
|
||||||
|
.put(body ?: message.toRequestBody())
|
||||||
|
.build()
|
||||||
|
Log.d(TAG, "Publishing to $request")
|
||||||
publishClient.newCall(request).execute().use { response ->
|
publishClient.newCall(request).execute().use { response ->
|
||||||
if (response.code == 401 || response.code == 403) {
|
if (response.code == 401 || response.code == 403) {
|
||||||
throw UnauthorizedException(user)
|
throw UnauthorizedException(user)
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
Features:
|
Features:
|
||||||
* Support for ntfy:// deep links (#20, thanks to @Copephobia for reporting)
|
* Support for ntfy:// deep links (#20, thanks to @Copephobia for reporting)
|
||||||
|
* Fastlane metadata can now be translated too (#198, thanks to @StoyanDimitrov for reporting)
|
||||||
|
|
||||||
Bugs:
|
Bugs:
|
||||||
* Validate URLs when changing default server and server in user management (#193, thanks to @StoyanDimitrov)
|
* Validate URLs when changing default server and server in user management (#193, thanks to @StoyanDimitrov for reporting)
|
||||||
|
* Error in sending test notification in different languages (#209, thanks to @StoyanDimitrov for reporting)
|
||||||
|
|
||||||
Translations:
|
Additional translations:
|
||||||
* Japanese (thanks to @shak)
|
* Japanese (thanks to @shak)
|
||||||
|
|
Loading…
Reference in a new issue