Add a bunch of "old" methods to be able to still use java code

This commit is contained in:
Lakoja 2023-09-11 22:19:34 +02:00
parent 4af160853d
commit 4f865ec95f
4 changed files with 148 additions and 43 deletions

View File

@ -23,4 +23,8 @@ class EventHub @Inject constructor() {
sharedEventFlow.emit(event)
eventsSubject.onNext(event)
}
fun dispatchOld(event: Event) {
eventsSubject.onNext(event)
}
}

View File

@ -417,17 +417,17 @@ public class NotificationsFragment extends SFragment implements
@Override
public void onReblog(final boolean reblog, final int position) {
// final Notification notification = notifications.get(position).asRight();
// final Status status = notification.getStatus();
// Objects.requireNonNull(status, "Reblog on notification without status");
// timelineCases.reblog(status.getId(), reblog)
// .observeOn(AndroidSchedulers.mainThread())
// .to(autoDisposable(from(this)))
// .subscribe(
// (newStatus) -> setReblogForStatus(status.getId(), reblog),
// (t) -> Log.d(getClass().getSimpleName(),
// "Failed to reblog status: " + status.getId(), t)
// );
final Notification notification = notifications.get(position).asRight();
final Status status = notification.getStatus();
Objects.requireNonNull(status, "Reblog on notification without status");
timelineCases.reblogOld(status.getId(), reblog)
.observeOn(AndroidSchedulers.mainThread())
.to(autoDisposable(from(this)))
.subscribe(
(newStatus) -> setReblogForStatus(status.getId(), reblog),
(t) -> Log.d(getClass().getSimpleName(),
"Failed to reblog status: " + status.getId(), t)
);
}
private void setReblogForStatus(String statusId, boolean reblog) {
@ -436,17 +436,17 @@ public class NotificationsFragment extends SFragment implements
@Override
public void onFavourite(final boolean favourite, final int position) {
// final Notification notification = notifications.get(position).asRight();
// final Status status = notification.getStatus();
//
// timelineCases.favourite(status.getId(), favourite)
// .observeOn(AndroidSchedulers.mainThread())
// .to(autoDisposable(from(this)))
// .subscribe(
// (newStatus) -> setFavouriteForStatus(status.getId(), favourite),
// (t) -> Log.d(getClass().getSimpleName(),
// "Failed to favourite status: " + status.getId(), t)
// );
final Notification notification = notifications.get(position).asRight();
final Status status = notification.getStatus();
timelineCases.favouriteOld(status.getId(), favourite)
.observeOn(AndroidSchedulers.mainThread())
.to(autoDisposable(from(this)))
.subscribe(
(newStatus) -> setFavouriteForStatus(status.getId(), favourite),
(t) -> Log.d(getClass().getSimpleName(),
"Failed to favourite status: " + status.getId(), t)
);
}
private void setFavouriteForStatus(String statusId, boolean favourite) {
@ -455,17 +455,17 @@ public class NotificationsFragment extends SFragment implements
@Override
public void onBookmark(final boolean bookmark, final int position) {
// final Notification notification = notifications.get(position).asRight();
// final Status status = notification.getStatus();
//
// timelineCases.bookmark(status.getActionableId(), bookmark)
// .observeOn(AndroidSchedulers.mainThread())
// .to(autoDisposable(from(this)))
// .subscribe(
// (newStatus) -> setBookmarkForStatus(status.getId(), bookmark),
// (t) -> Log.d(getClass().getSimpleName(),
// "Failed to bookmark status: " + status.getId(), t)
// );
final Notification notification = notifications.get(position).asRight();
final Status status = notification.getStatus();
timelineCases.bookmarkOld(status.getActionableId(), bookmark)
.observeOn(AndroidSchedulers.mainThread())
.to(autoDisposable(from(this)))
.subscribe(
(newStatus) -> setBookmarkForStatus(status.getId(), bookmark),
(t) -> Log.d(getClass().getSimpleName(),
"Failed to bookmark status: " + status.getId(), t)
);
}
private void setBookmarkForStatus(String statusId, boolean bookmark) {
@ -473,16 +473,16 @@ public class NotificationsFragment extends SFragment implements
}
public void onVoteInPoll(int position, @NonNull List<Integer> choices) {
// final Notification notification = notifications.get(position).asRight();
// final Status status = notification.getStatus().getActionableStatus();
// timelineCases.voteInPoll(status.getId(), status.getPoll().getId(), choices)
// .observeOn(AndroidSchedulers.mainThread())
// .to(autoDisposable(from(this)))
// .subscribe(
// (newPoll) -> setVoteForPoll(status, newPoll),
// (t) -> Log.d(TAG,
// "Failed to vote in poll: " + status.getId(), t)
// );
final Notification notification = notifications.get(position).asRight();
final Status status = notification.getStatus().getActionableStatus();
timelineCases.voteInPollOld(status.getId(), status.getPoll().getId(), choices)
.observeOn(AndroidSchedulers.mainThread())
.to(autoDisposable(from(this)))
.subscribe(
(newPoll) -> setVoteForPoll(status, newPoll),
(t) -> Log.d(TAG,
"Failed to vote in poll: " + status.getId(), t)
);
}
@Override

View File

@ -290,6 +290,36 @@ interface MastodonApi {
@Path("id") statusId: String
): NetworkResult<Status>
@POST("api/v1/statuses/{id}/reblog")
fun reblogStatusOld(
@Path("id") statusId: String
): Single<Status>
@POST("api/v1/statuses/{id}/unreblog")
fun unreblogStatusOld(
@Path("id") statusId: String
): Single<Status>
@POST("api/v1/statuses/{id}/favourite")
fun favouriteStatusOld(
@Path("id") statusId: String
): Single<Status>
@POST("api/v1/statuses/{id}/unfavourite")
fun unfavouriteStatusOld(
@Path("id") statusId: String
): Single<Status>
@POST("api/v1/statuses/{id}/bookmark")
fun bookmarkStatusOld(
@Path("id") statusId: String
): Single<Status>
@POST("api/v1/statuses/{id}/unbookmark")
fun unbookmarkStatusOld(
@Path("id") statusId: String
): Single<Status>
@POST("api/v1/statuses/{id}/pin")
suspend fun pinStatus(
@Path("id") statusId: String
@ -310,6 +340,16 @@ interface MastodonApi {
@Path("id") statusId: String
): NetworkResult<Status>
@POST("api/v1/statuses/{id}/mute")
fun muteConversationOld(
@Path("id") statusId: String
): Single<Status>
@POST("api/v1/statuses/{id}/unmute")
fun unmuteConversationOld(
@Path("id") statusId: String
): Single<Status>
@GET("api/v1/scheduled_statuses")
fun scheduledStatuses(
@Query("limit") limit: Int? = null,
@ -681,6 +721,13 @@ interface MastodonApi {
@Field("choices[]") choices: List<Int>
): NetworkResult<Poll>
@FormUrlEncoded
@POST("api/v1/polls/{id}/votes")
fun voteInPollOld(
@Path("id") id: String,
@Field("choices[]") choices: List<Int>
): Single<Poll>
@GET("api/v1/announcements")
suspend fun listAnnouncements(
@Query("with_dismissed") withDismissed: Boolean = true

View File

@ -88,6 +88,50 @@ class TimelineCases @Inject constructor(
}
}
fun reblogOld(statusId: String, reblog: Boolean): Single<Status> {
val call = if (reblog) {
mastodonApi.reblogStatusOld(statusId)
} else {
mastodonApi.unreblogStatusOld(statusId)
}
return call.doAfterSuccess {
eventHub.dispatchOld(ReblogEvent(statusId, reblog))
}
}
fun favouriteOld(statusId: String, favourite: Boolean): Single<Status> {
val call = if (favourite) {
mastodonApi.favouriteStatusOld(statusId)
} else {
mastodonApi.unfavouriteStatusOld(statusId)
}
return call.doAfterSuccess {
eventHub.dispatchOld(FavoriteEvent(statusId, favourite))
}
}
fun bookmarkOld(statusId: String, bookmark: Boolean): Single<Status> {
val call = if (bookmark) {
mastodonApi.bookmarkStatusOld(statusId)
} else {
mastodonApi.unbookmarkStatusOld(statusId)
}
return call.doAfterSuccess {
eventHub.dispatchOld(BookmarkEvent(statusId, bookmark))
}
}
fun muteConversationOld(statusId: String, mute: Boolean): Single<Status> {
val call = if (mute) {
mastodonApi.muteConversationOld(statusId)
} else {
mastodonApi.unmuteConversationOld(statusId)
}
return call.doAfterSuccess {
eventHub.dispatchOld(MuteConversationEvent(statusId, mute))
}
}
suspend fun mute(statusId: String, notifications: Boolean, duration: Int?) {
try {
mastodonApi.muteAccount(statusId, notifications, duration)
@ -136,6 +180,16 @@ class TimelineCases @Inject constructor(
}
}
fun voteInPollOld(statusId: String, pollId: String, choices: List<Int>): Single<Poll> {
if (choices.isEmpty()) {
return Single.error(IllegalStateException())
}
return mastodonApi.voteInPollOld(pollId, choices).doAfterSuccess {
eventHub.dispatchOld(PollVoteEvent(statusId, it))
}
}
fun acceptFollowRequest(accountId: String): Single<Relationship> {
return mastodonApi.authorizeFollowRequest(accountId)
}