fix editing scheduled/drafted polls

closes sk22#894
This commit is contained in:
sk
2023-10-22 21:44:02 +02:00
parent b60c1a5db3
commit 9f0ff2dcd4
3 changed files with 24 additions and 19 deletions

View File

@@ -200,7 +200,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
public Instance instance; public Instance instance;
public Status editingStatus; public Status editingStatus;
private ScheduledStatus scheduledStatus; public ScheduledStatus scheduledStatus;
private boolean redraftStatus; private boolean redraftStatus;
private ContentType contentType; private ContentType contentType;

View File

@@ -6,6 +6,7 @@ import org.joinmastodon.android.model.Poll.Option;
import org.parceler.Parcel; import org.parceler.Parcel;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -27,10 +28,10 @@ public class ScheduledStatus extends BaseModel implements DisplayItemsParent{
@Override @Override
public void postprocess() throws ObjectValidationException { public void postprocess() throws ObjectValidationException {
super.postprocess(); super.postprocess();
if (mediaAttachments == null) mediaAttachments = List.of(); if(mediaAttachments==null) mediaAttachments=List.of();
for(Attachment a:mediaAttachments) for(Attachment a:mediaAttachments)
a.postprocess(); a.postprocess();
if (params != null) params.postprocess(); if(params!=null) params.postprocess();
} }
@Parcel @Parcel
@@ -53,7 +54,7 @@ public class ScheduledStatus extends BaseModel implements DisplayItemsParent{
@Override @Override
public void postprocess() throws ObjectValidationException { public void postprocess() throws ObjectValidationException {
super.postprocess(); super.postprocess();
if (poll != null) poll.postprocess(); if(poll!=null) poll.postprocess();
} }
} }
@@ -67,25 +68,26 @@ public class ScheduledStatus extends BaseModel implements DisplayItemsParent{
public boolean hideTotals; public boolean hideTotals;
public Poll toPoll() { public Poll toPoll() {
Poll p = new Poll(); Poll p=new Poll();
p.voted = true; p.voted=true;
p.emojis = List.of(); p.emojis=List.of();
p.ownVotes = List.of(); p.ownVotes=List.of();
p.multiple = multiple; p.multiple=multiple;
p.options = options.stream().map(Option::new).collect(Collectors.toList()); p.options=options.stream().map(Option::new).collect(Collectors.toList());
p.expiresAt=Instant.now().plus(Integer.parseInt(expiresIn)+1, ChronoUnit.SECONDS);
return p; return p;
} }
} }
public Status toStatus() { public Status toStatus() {
Status s = Status.ofFake(id, params.text, scheduledAt); Status s=Status.ofFake(id, params.text, scheduledAt);
s.mediaAttachments = mediaAttachments; s.mediaAttachments=mediaAttachments;
s.inReplyToId = params.inReplyToId > 0 ? "" + params.inReplyToId : null; s.inReplyToId=params.inReplyToId>0 ? ""+params.inReplyToId : null;
s.spoilerText = params.spoilerText; s.spoilerText=params.spoilerText;
s.visibility = params.visibility; s.visibility=params.visibility;
s.language = params.language; s.language=params.language;
s.sensitive = params.sensitive; s.sensitive=params.sensitive;
if (params.poll != null) s.poll = params.poll.toPoll(); if(params.poll!=null) s.poll=params.poll.toPoll();
return s; return s;
} }
} }

View File

@@ -134,6 +134,9 @@ public class ComposePollViewController{
DraftPollOption opt=createDraftPollOption(false); DraftPollOption opt=createDraftPollOption(false);
opt.edit.setText(eopt.title); opt.edit.setText(eopt.title);
} }
if(fragment.scheduledStatus!=null && fragment.scheduledStatus.params.poll!=null)
pollDuration=Integer.parseInt(fragment.scheduledStatus.params.poll.expiresIn);
else if(fragment.editingStatus.poll.expiresAt!=null)
pollDuration=(int)fragment.editingStatus.poll.expiresAt.minus(fragment.editingStatus.createdAt.toEpochMilli(), ChronoUnit.MILLIS).getEpochSecond(); pollDuration=(int)fragment.editingStatus.poll.expiresAt.minus(fragment.editingStatus.createdAt.toEpochMilli(), ChronoUnit.MILLIS).getEpochSecond();
updatePollOptionHints(); updatePollOptionHints();
pollDurationValue.setText(UiUtils.formatDuration(fragment.getContext(), pollDuration)); pollDurationValue.setText(UiUtils.formatDuration(fragment.getContext(), pollDuration));