mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-04-05 14:40:01 +03:00
Fix issue #1147 - Media description not updated when there are several
This commit is contained in:
parent
238f31e3fc
commit
5cb3b43eeb
3 changed files with 112 additions and 18 deletions
|
@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.client.endpoints;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.android.mastodon.client.entities.api.Account;
|
||||
|
@ -25,14 +26,17 @@ import app.fedilab.android.mastodon.client.entities.api.Poll;
|
|||
import app.fedilab.android.mastodon.client.entities.api.ScheduledStatus;
|
||||
import app.fedilab.android.mastodon.client.entities.api.Status;
|
||||
import app.fedilab.android.mastodon.client.entities.api.StatusSource;
|
||||
import app.fedilab.android.mastodon.client.entities.api.params.StatusParams;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.Multipart;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
|
@ -74,6 +78,16 @@ public interface MastodonStatusesService {
|
|||
@Header("Authorization") String token,
|
||||
@Path("id") String id);
|
||||
|
||||
|
||||
@Headers({"Accept: application/json"})
|
||||
@PUT("statuses/{id}")
|
||||
Call<Status> updateStatus(
|
||||
@Header("Idempotency-Key") String idempotency_Key,
|
||||
@Header("Authorization") String token,
|
||||
@Path("id") String id,
|
||||
@Body StatusParams statusParams
|
||||
);
|
||||
|
||||
//Post a status
|
||||
@FormUrlEncoded
|
||||
@PUT("statuses/{id}")
|
||||
|
@ -92,9 +106,9 @@ public interface MastodonStatusesService {
|
|||
@Field("spoiler_text") String spoiler_text,
|
||||
@Field("visibility") String visibility,
|
||||
@Field("language") String language,
|
||||
@Field("media_attributes[][id]") List<String> media_id,
|
||||
@Field("media_attributes[][description]") List<String> media_description,
|
||||
@Field("media_attributes[][focus]") List<String> focus
|
||||
@Field("media_attributes[]") LinkedHashMap<String, String> media_id,
|
||||
@Field("media_attributes[]") LinkedHashMap<String, String> media_description,
|
||||
@Field("media_attributes[]") LinkedHashMap<String, String> focus
|
||||
);
|
||||
|
||||
//Post a scheduled status
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
package app.fedilab.android.mastodon.client.entities.api.params;
|
||||
/* Copyright 2025 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Fedilab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class StatusParams implements Serializable {
|
||||
@SerializedName("id")
|
||||
public String id;
|
||||
@SerializedName("status")
|
||||
public String status;
|
||||
@SerializedName("media_ids")
|
||||
public List<String> media_ids;
|
||||
@SerializedName("poll")
|
||||
public PollParams pollParams;
|
||||
@SerializedName("in_reply_to_id")
|
||||
public String in_reply_to_id;
|
||||
@SerializedName("sensitive")
|
||||
public Boolean sensitive;
|
||||
@SerializedName("spoiler_text")
|
||||
public String spoiler_text;
|
||||
@SerializedName("visibility")
|
||||
public String visibility;
|
||||
@SerializedName("language")
|
||||
public String language;
|
||||
@SerializedName("media_attributes")
|
||||
public List<MediaParams> media_attributes;
|
||||
|
||||
public static class PollParams implements Serializable{
|
||||
@SerializedName("options")
|
||||
public List<String> poll_options;
|
||||
@SerializedName("expires_in")
|
||||
public Integer poll_expire_in;
|
||||
@SerializedName("multiple")
|
||||
public Boolean poll_multiple;
|
||||
@SerializedName("hide_totals")
|
||||
public Boolean poll_hide_totals;
|
||||
|
||||
}
|
||||
|
||||
public static class MediaParams implements Serializable {
|
||||
@SerializedName("id")
|
||||
public String id;
|
||||
@SerializedName("description")
|
||||
public String description;
|
||||
@SerializedName("focus")
|
||||
public String focus;
|
||||
}
|
||||
}
|
|
@ -47,6 +47,7 @@ import com.google.gson.Gson;
|
|||
import java.io.IOException;
|
||||
import java.net.IDN;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -59,6 +60,7 @@ import app.fedilab.android.mastodon.client.entities.api.Attachment;
|
|||
import app.fedilab.android.mastodon.client.entities.api.Poll;
|
||||
import app.fedilab.android.mastodon.client.entities.api.ScheduledStatus;
|
||||
import app.fedilab.android.mastodon.client.entities.api.Status;
|
||||
import app.fedilab.android.mastodon.client.entities.api.params.StatusParams;
|
||||
import app.fedilab.android.mastodon.client.entities.app.Account;
|
||||
import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
|
||||
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
|
||||
|
@ -164,9 +166,8 @@ public class ComposeWorker extends Worker {
|
|||
}
|
||||
dataPost.messageToSend = statuses.size() - startingPosition;
|
||||
dataPost.messageSent = 0;
|
||||
List<String> media_edit_id = null;
|
||||
List<String> media_edit_description = null;
|
||||
List<String> media_edit_focus = null;
|
||||
List<StatusParams.MediaParams> media_attributes = null;
|
||||
|
||||
for (int i = startingPosition; i < statuses.size(); i++) {
|
||||
if (dataPost.notificationBuilder != null) {
|
||||
dataPost.notificationBuilder.setProgress(100, dataPost.messageSent * 100 / dataPost.messageToSend, true);
|
||||
|
@ -179,15 +180,15 @@ public class ComposeWorker extends Worker {
|
|||
attachmentIds = new ArrayList<>();
|
||||
for (Attachment attachment : statuses.get(i).media_attachments) {
|
||||
if (attachment.id != null) {
|
||||
if (media_edit_id == null) {
|
||||
media_edit_id = new ArrayList<>();
|
||||
media_edit_description = new ArrayList<>();
|
||||
media_edit_focus = new ArrayList<>();
|
||||
if (media_attributes == null) {
|
||||
media_attributes = new ArrayList<>();
|
||||
}
|
||||
StatusParams.MediaParams mediaParams = new StatusParams.MediaParams();
|
||||
mediaParams.id = attachment.id;
|
||||
mediaParams.description = attachment.description;
|
||||
mediaParams.focus = attachment.focus;
|
||||
attachmentIds.add(attachment.id);
|
||||
media_edit_id.add(attachment.id);
|
||||
media_edit_description.add(attachment.description);
|
||||
media_edit_focus.add(attachment.focus);
|
||||
media_attributes.add(mediaParams);
|
||||
} else {
|
||||
MultipartBody.Part fileMultipartBody;
|
||||
if (watermark && attachment.mimeType != null && attachment.mimeType.contains("image")) {
|
||||
|
@ -207,7 +208,6 @@ public class ComposeWorker extends Worker {
|
|||
attachmentIds.add(replyId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
List<String> poll_options = null;
|
||||
|
@ -274,10 +274,25 @@ public class ComposeWorker extends Worker {
|
|||
statusCall = mastodonStatusesService.createStatus(null, dataPost.token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
|
||||
poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), statuses.get(i).language, statuses.get(i).quote_id, statuses.get(i).content_type);
|
||||
} else { //Status is edited
|
||||
statusCall = mastodonStatusesService.updateStatus(null, dataPost.token, dataPost.statusEditId, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
|
||||
poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive,
|
||||
statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), statuses.get(i).language,
|
||||
media_edit_id, media_edit_description, media_edit_focus);
|
||||
StatusParams statusParams = new StatusParams();
|
||||
statusParams.status = statuses.get(i).text;
|
||||
statusParams.media_ids = attachmentIds;
|
||||
if(poll_options != null) {
|
||||
statusParams.pollParams = new StatusParams.PollParams();
|
||||
statusParams.pollParams.poll_options = poll_options;
|
||||
statusParams.pollParams.poll_expire_in = poll_expire_in;
|
||||
statusParams.pollParams.poll_multiple = poll_multiple;
|
||||
statusParams.pollParams.poll_hide_totals = poll_hide_totals;
|
||||
}
|
||||
statusParams.in_reply_to_id = statuses.get(i).quote_id == null ? in_reply_to_status : null;
|
||||
statusParams.sensitive = statuses.get(i).sensitive;
|
||||
statusParams.spoiler_text = statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null;
|
||||
statusParams.visibility = statuses.get(i).visibility.toLowerCase();
|
||||
statusParams.language = statuses.get(i).language;
|
||||
statusParams.media_attributes = media_attributes;
|
||||
statusCall = mastodonStatusesService.updateStatus(null, dataPost.token,
|
||||
dataPost.statusEditId,
|
||||
statusParams);
|
||||
}
|
||||
try {
|
||||
Response<Status> statusResponse = statusCall.execute();
|
||||
|
|
Loading…
Reference in a new issue