Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions app/src/main/kotlin/com/github/gotify/sharing/ShareActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.github.gotify.api.ApiException
import com.github.gotify.api.ClientFactory
import com.github.gotify.client.api.MessageApi
import com.github.gotify.client.model.Application
import com.github.gotify.client.model.Message
import com.github.gotify.client.model.CreateMessage
import com.github.gotify.databinding.ActivityShareBinding
import com.github.gotify.messages.provider.ApplicationHolder
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -107,15 +107,15 @@ internal class ShareActivity : AppCompatActivity() {
return
}

val message = Message()
val message = CreateMessage()
if (titleText.isNotEmpty()) {
message.title = titleText
}
message.message = contentText
message.priority = priority.toLong()

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

private fun executeMessageCall(appIndex: Int, message: Message): Boolean {
val pushClient = ClientFactory.clientToken(settings, appsHolder.get()[appIndex].token)
private fun executeMessageCall(app: Application, message: CreateMessage): Boolean {
// In gotify 3.0, tokens aren't returned in the API anymore, but the push api allows setting the appid with client auth.
val client = if (app.token == null) {
message.appid = app.id
ClientFactory.clientToken(settings)
} else {
ClientFactory.clientToken(settings, app.token)
}
return try {
val messageApi = pushClient.createService(MessageApi::class.java)
val messageApi = client.createService(MessageApi::class.java)
Api.execute(messageApi.createMessage(message))
true
} catch (apiException: ApiException) {
Expand Down
4 changes: 4 additions & 0 deletions client/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ src/main/java/com/github/gotify/client/model/Application.java
src/main/java/com/github/gotify/client/model/ApplicationParams.java
src/main/java/com/github/gotify/client/model/Client.java
src/main/java/com/github/gotify/client/model/ClientParams.java
src/main/java/com/github/gotify/client/model/CreateMessage.java
src/main/java/com/github/gotify/client/model/CreateUserExternal.java
src/main/java/com/github/gotify/client/model/CurrentUser.java
src/main/java/com/github/gotify/client/model/ElevateRequest.java
Expand All @@ -39,6 +40,9 @@ src/main/java/com/github/gotify/client/model/OIDCExternalTokenResponse.java
src/main/java/com/github/gotify/client/model/PagedMessages.java
src/main/java/com/github/gotify/client/model/Paging.java
src/main/java/com/github/gotify/client/model/PluginConf.java
src/main/java/com/github/gotify/client/model/RegenerateTokenResponse.java
src/main/java/com/github/gotify/client/model/SecurityUpdateAction.java
src/main/java/com/github/gotify/client/model/SecurityUpdateActionResponse.java
src/main/java/com/github/gotify/client/model/UpdateUserExternal.java
src/main/java/com/github/gotify/client/model/User.java
src/main/java/com/github/gotify/client/model/UserPass.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.github.gotify.client.model.ApplicationParams;
import com.github.gotify.client.model.Error;
import java.io.File;
import com.github.gotify.client.model.SecurityUpdateAction;
import com.github.gotify.client.model.SecurityUpdateActionResponse;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -66,6 +68,21 @@ Call<Void> removeAppImage(
@retrofit2.http.Path("id") Long id
);

/**
* Perform security updates on an application.
* Requires elevated authentication.
* @param id the application id (required)
* @param body security update action descriptor (required)
* @return Call&lt;SecurityUpdateActionResponse&gt;
*/
@Headers({
"Content-Type:application/json"
})
@PUT("application/{id}/security")
Call<SecurityUpdateActionResponse> updateAppSecurity(
@retrofit2.http.Path("id") Long id, @retrofit2.http.Body SecurityUpdateAction body
);

/**
* Update an application.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ Call<Void> deleteClient(
/**
* Elevate a client session.
* Requires elevated authentication.
* @param id the client id (required)
* @param body the elevation request (required)
* @return Call&lt;Void&gt;
*/
@Headers({
"Content-Type:application/json"
})
@POST("client:elevate")
@POST("client/{id}/elevate")
Call<Void> elevateClient(
@retrofit2.http.Body ElevateRequest body
@retrofit2.http.Path("id") Long id, @retrofit2.http.Body ElevateRequest body
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import okhttp3.ResponseBody;
import okhttp3.MultipartBody;

import com.github.gotify.client.model.CreateMessage;
import com.github.gotify.client.model.Error;
import com.github.gotify.client.model.Message;
import com.github.gotify.client.model.PagedMessages;
Expand All @@ -22,7 +23,7 @@
public interface MessageApi {
/**
* Create a message.
* __NOTE__: This API ONLY accepts an application token as authentication.
* __NOTE__: When authenticating with a client token or basic auth, the request body must include \&quot;appid\&quot; referencing an application owned by the authenticated user. When authenticating with an application token, the application is derived from the token and any \&quot;appid\&quot; in the body is ignored.
* @param body the message to add (required)
* @return Call&lt;Message&gt;
*/
Expand All @@ -31,7 +32,7 @@ public interface MessageApi {
})
@POST("message")
Call<Message> createMessage(
@retrofit2.http.Body Message body
@retrofit2.http.Body CreateMessage body
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.19.0")
public class Application {
public static final String SERIALIZED_NAME_CREATED_AT = "createdAt";
@SerializedName(SERIALIZED_NAME_CREATED_AT)
@javax.annotation.Nonnull
private OffsetDateTime createdAt;

public static final String SERIALIZED_NAME_DEFAULT_PRIORITY = "defaultPriority";
@SerializedName(SERIALIZED_NAME_DEFAULT_PRIORITY)
@javax.annotation.Nullable
Expand Down Expand Up @@ -70,7 +75,7 @@ public class Application {

public static final String SERIALIZED_NAME_TOKEN = "token";
@SerializedName(SERIALIZED_NAME_TOKEN)
@javax.annotation.Nonnull
@javax.annotation.Nullable
private String token;

public Application() {
Expand All @@ -80,20 +85,34 @@ public Application() {
*/

public Application(
OffsetDateTime createdAt,
Long id,
String image,
Boolean internal,
OffsetDateTime lastUsed,
String token
) {
this();
this.createdAt = createdAt;
this.id = id;
this.image = image;
this.internal = internal;
this.lastUsed = lastUsed;
this.token = token;
}

/**
* The date the application was created.
* @return createdAt
*/
@javax.annotation.Nonnull

public OffsetDateTime getCreatedAt() {
return createdAt;
}



public Application defaultPriority(@javax.annotation.Nullable Long defaultPriority) {

this.defaultPriority = defaultPriority;
Expand Down Expand Up @@ -230,7 +249,7 @@ public void setSortKey(@javax.annotation.Nonnull String sortKey) {
* The application token. Can be used as &#x60;appToken&#x60;. See Authentication.
* @return token
*/
@javax.annotation.Nonnull
@javax.annotation.Nullable

public String getToken() {
return token;
Expand All @@ -247,7 +266,8 @@ public boolean equals(Object o) {
return false;
}
Application application = (Application) o;
return Objects.equals(this.defaultPriority, application.defaultPriority) &&
return Objects.equals(this.createdAt, application.createdAt) &&
Objects.equals(this.defaultPriority, application.defaultPriority) &&
Objects.equals(this.description, application.description) &&
Objects.equals(this.id, application.id) &&
Objects.equals(this.image, application.image) &&
Expand All @@ -260,13 +280,14 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(defaultPriority, description, id, image, internal, lastUsed, name, sortKey, token);
return Objects.hash(createdAt, defaultPriority, description, id, image, internal, lastUsed, name, sortKey, token);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Application {\n");
sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n");
sb.append(" defaultPriority: ").append(toIndentedString(defaultPriority)).append("\n");
sb.append(" description: ").append(toIndentedString(description)).append("\n");
sb.append(" id: ").append(toIndentedString(id)).append("\n");
Expand Down
78 changes: 74 additions & 4 deletions client/src/main/java/com/github/gotify/client/model/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,26 @@
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.19.0")
public class Client {
public static final String SERIALIZED_NAME_CREATED_AT = "createdAt";
@SerializedName(SERIALIZED_NAME_CREATED_AT)
@javax.annotation.Nonnull
private OffsetDateTime createdAt;

public static final String SERIALIZED_NAME_ELEVATED_UNTIL = "elevatedUntil";
@SerializedName(SERIALIZED_NAME_ELEVATED_UNTIL)
@javax.annotation.Nullable
private OffsetDateTime elevatedUntil;

public static final String SERIALIZED_NAME_EXPIRES_AFTER_INACTIVITY_SECONDS = "expiresAfterInactivitySeconds";
@SerializedName(SERIALIZED_NAME_EXPIRES_AFTER_INACTIVITY_SECONDS)
@javax.annotation.Nullable
private Long expiresAfterInactivitySeconds;

public static final String SERIALIZED_NAME_EXPIRES_AT = "expiresAt";
@SerializedName(SERIALIZED_NAME_EXPIRES_AT)
@javax.annotation.Nullable
private OffsetDateTime expiresAt;

public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)
@javax.annotation.Nonnull
Expand All @@ -50,7 +65,7 @@ public class Client {

public static final String SERIALIZED_NAME_TOKEN = "token";
@SerializedName(SERIALIZED_NAME_TOKEN)
@javax.annotation.Nonnull
@javax.annotation.Nullable
private String token;

public Client() {
Expand All @@ -60,18 +75,34 @@ public Client() {
*/

public Client(
OffsetDateTime createdAt,
OffsetDateTime elevatedUntil,
OffsetDateTime expiresAt,
Long id,
OffsetDateTime lastUsed,
String token
) {
this();
this.createdAt = createdAt;
this.elevatedUntil = elevatedUntil;
this.expiresAt = expiresAt;
this.id = id;
this.lastUsed = lastUsed;
this.token = token;
}

/**
* The date the client was created.
* @return createdAt
*/
@javax.annotation.Nonnull

public OffsetDateTime getCreatedAt() {
return createdAt;
}



/**
* The time until which this client&#39;s session is elevated.
* @return elevatedUntil
Expand All @@ -84,6 +115,39 @@ public OffsetDateTime getElevatedUntil() {



public Client expiresAfterInactivitySeconds(@javax.annotation.Nullable Long expiresAfterInactivitySeconds) {

this.expiresAfterInactivitySeconds = expiresAfterInactivitySeconds;
return this;
}

/**
* The number of seconds of inactivity after which the client is removed. 0 means the client never expires.
* @return expiresAfterInactivitySeconds
*/
@javax.annotation.Nullable

public Long getExpiresAfterInactivitySeconds() {
return expiresAfterInactivitySeconds;
}


public void setExpiresAfterInactivitySeconds(@javax.annotation.Nullable Long expiresAfterInactivitySeconds) {
this.expiresAfterInactivitySeconds = expiresAfterInactivitySeconds;
}

/**
* The time at which this client will expire due to inactivity, or null if it never expires.
* @return expiresAt
*/
@javax.annotation.Nullable

public OffsetDateTime getExpiresAt() {
return expiresAt;
}



/**
* The client id.
* @return id
Expand Down Expand Up @@ -133,7 +197,7 @@ public void setName(@javax.annotation.Nonnull String name) {
* The client token. Can be used as &#x60;clientToken&#x60;. See Authentication.
* @return token
*/
@javax.annotation.Nonnull
@javax.annotation.Nullable

public String getToken() {
return token;
Expand All @@ -150,7 +214,10 @@ public boolean equals(Object o) {
return false;
}
Client client = (Client) o;
return Objects.equals(this.elevatedUntil, client.elevatedUntil) &&
return Objects.equals(this.createdAt, client.createdAt) &&
Objects.equals(this.elevatedUntil, client.elevatedUntil) &&
Objects.equals(this.expiresAfterInactivitySeconds, client.expiresAfterInactivitySeconds) &&
Objects.equals(this.expiresAt, client.expiresAt) &&
Objects.equals(this.id, client.id) &&
Objects.equals(this.lastUsed, client.lastUsed) &&
Objects.equals(this.name, client.name) &&
Expand All @@ -159,14 +226,17 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(elevatedUntil, id, lastUsed, name, token);
return Objects.hash(createdAt, elevatedUntil, expiresAfterInactivitySeconds, expiresAt, id, lastUsed, name, token);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Client {\n");
sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n");
sb.append(" elevatedUntil: ").append(toIndentedString(elevatedUntil)).append("\n");
sb.append(" expiresAfterInactivitySeconds: ").append(toIndentedString(expiresAfterInactivitySeconds)).append("\n");
sb.append(" expiresAt: ").append(toIndentedString(expiresAt)).append("\n");
sb.append(" id: ").append(toIndentedString(id)).append("\n");
sb.append(" lastUsed: ").append(toIndentedString(lastUsed)).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
Expand Down
Loading
Loading