Skip to content

Commit ecb2e49

Browse files
committed
fix: allow pushing messages with client auth
1 parent 29f74f7 commit ecb2e49

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

app/src/main/kotlin/com/github/gotify/sharing/ShareActivity.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ internal class ShareActivity : AppCompatActivity() {
115115
message.priority = priority.toLong()
116116

117117
launchCoroutine {
118-
val response = executeMessageCall(appIndex, message)
118+
val response = executeMessageCall(appsHolder.get()[appIndex], message)
119119
withContext(Dispatchers.Main) {
120120
if (response) {
121121
Toast.makeText(this@ShareActivity, "Pushed!", Toast.LENGTH_LONG).show()
@@ -131,10 +131,16 @@ internal class ShareActivity : AppCompatActivity() {
131131
}
132132
}
133133

134-
private fun executeMessageCall(appIndex: Int, message: Message): Boolean {
135-
val pushClient = ClientFactory.clientToken(settings, appsHolder.get()[appIndex].token)
134+
private fun executeMessageCall(app: Application, message: Message): Boolean {
135+
// In gotify 3.0, tokens aren't returned in the API anymore, but the push api allows setting the appid with client auth.
136+
val client = if (app.token == null) {
137+
message.appid = app.id
138+
ClientFactory.clientToken(settings)
139+
} else {
140+
ClientFactory.clientToken(settings, app.token)
141+
}
136142
return try {
137-
val messageApi = pushClient.createService(MessageApi::class.java)
143+
val messageApi = client.createService(MessageApi::class.java)
138144
Api.execute(messageApi.createMessage(message))
139145
true
140146
} catch (apiException: ApiException) {

0 commit comments

Comments
 (0)