Skip to content

Commit ef46ba5

Browse files
bocopsandregasser
andauthored
Add missing Status methods, except for Status editing (#149)
* Add missing Status methods, except for Status editing - adds: translating, bookmarking, muting, pinning - postStatus now has language parameter - deleteStatus now returns a Status for subsequent editing - reblogStatus now has visibility parameter - implements posting of poll statuses - implements status scheduling - removes getCard (removed in Mastodon 3.0.0 after deprecation in 2.6.0) - adds entities Poll, ScheduledStatus, Translation - makes all new methods available via Rx - includes tests and test assets for all new methods - does not implement status editing (see #124) Closes #125, #129, #16 * Adds missing JvmOverloads annotation and links to entity documentation --------- Co-authored-by: André Gasser <[email protected]>
1 parent d860e14 commit ef46ba5

File tree

16 files changed

+1137
-49
lines changed

16 files changed

+1137
-49
lines changed

bigbone-rx/src/main/kotlin/social/bigbone/rx/RxStatusMethods.kt

Lines changed: 176 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package social.bigbone.rx
22

3-
import io.reactivex.rxjava3.core.Completable
43
import io.reactivex.rxjava3.core.Single
54
import social.bigbone.MastodonClient
65
import social.bigbone.api.Pageable
76
import social.bigbone.api.Range
87
import social.bigbone.api.entity.Account
98
import social.bigbone.api.entity.Context
10-
import social.bigbone.api.entity.PreviewCard
9+
import social.bigbone.api.entity.ScheduledStatus
1110
import social.bigbone.api.entity.Status
11+
import social.bigbone.api.entity.Translation
1212
import social.bigbone.api.method.StatusMethods
1313

1414
/**
@@ -41,17 +41,19 @@ class RxStatusMethods(client: MastodonClient) {
4141
}
4242
}
4343

44-
fun getCard(statusId: String): Single<PreviewCard> {
44+
@JvmOverloads
45+
fun translateStatus(statusId: String, language: String? = null): Single<Translation> {
4546
return Single.create {
4647
try {
47-
val context = statusMethods.getCard(statusId)
48-
it.onSuccess(context.execute())
48+
val translation = statusMethods.translateStatus(statusId, language)
49+
it.onSuccess(translation.execute())
4950
} catch (e: Throwable) {
5051
it.onError(e)
5152
}
5253
}
5354
}
5455

56+
@JvmOverloads
5557
fun getRebloggedBy(statusId: String, range: Range = Range()): Single<Pageable<Account>> {
5658
return Single.create {
5759
try {
@@ -63,7 +65,7 @@ class RxStatusMethods(client: MastodonClient) {
6365
}
6466
}
6567

66-
// GET /api/v1/favourited_by
68+
@JvmOverloads
6769
fun getFavouritedBy(statusId: String, range: Range = Range()): Single<Pageable<Account>> {
6870
return Single.create {
6971
try {
@@ -75,39 +77,133 @@ class RxStatusMethods(client: MastodonClient) {
7577
}
7678
}
7779

80+
@JvmOverloads
7881
fun postStatus(
7982
status: String,
8083
inReplyToId: String? = null,
8184
mediaIds: List<String>? = null,
8285
sensitive: Boolean = false,
8386
spoilerText: String? = null,
84-
visibility: Status.Visibility = Status.Visibility.Public
87+
visibility: Status.Visibility = Status.Visibility.Public,
88+
language: String? = null
8589
): Single<Status> {
8690
return Single.create {
8791
try {
88-
val result = statusMethods.postStatus(status, inReplyToId, mediaIds, sensitive, spoilerText, visibility)
92+
val result = statusMethods.postStatus(status, inReplyToId, mediaIds, sensitive, spoilerText, visibility, language)
8993
it.onSuccess(result.execute())
9094
} catch (e: Throwable) {
9195
it.onError(e)
9296
}
9397
}
9498
}
9599

96-
fun deleteStatus(statusId: String): Completable {
97-
return Completable.create {
100+
@JvmOverloads
101+
fun postPoll(
102+
status: String,
103+
pollOptions: List<String>,
104+
pollExpiresIn: Int,
105+
pollMultiple: Boolean = false,
106+
pollHideTotals: Boolean = false,
107+
inReplyToId: String? = null,
108+
sensitive: Boolean = false,
109+
spoilerText: String? = null,
110+
visibility: Status.Visibility = Status.Visibility.Public,
111+
language: String? = null
112+
): Single<Status> {
113+
return Single.create {
98114
try {
99-
statusMethods.deleteStatus(statusId)
100-
it.onComplete()
115+
val result = statusMethods.postPoll(
116+
status,
117+
pollOptions,
118+
pollExpiresIn,
119+
pollMultiple,
120+
pollHideTotals,
121+
inReplyToId,
122+
sensitive,
123+
spoilerText,
124+
visibility,
125+
language
126+
)
127+
it.onSuccess(result.execute())
101128
} catch (e: Throwable) {
102129
it.onError(e)
103130
}
104131
}
105132
}
106133

107-
fun reblogStatus(statusId: String): Single<Status> {
134+
@JvmOverloads
135+
fun scheduleStatus(
136+
status: String,
137+
inReplyToId: String? = null,
138+
mediaIds: List<String>? = null,
139+
sensitive: Boolean = false,
140+
spoilerText: String? = null,
141+
visibility: Status.Visibility = Status.Visibility.Public,
142+
language: String? = null,
143+
scheduledAt: String
144+
): Single<ScheduledStatus> {
108145
return Single.create {
109146
try {
110-
val status = statusMethods.reblogStatus(statusId)
147+
val result = statusMethods.scheduleStatus(status, inReplyToId, mediaIds, sensitive, spoilerText, visibility, language, scheduledAt)
148+
it.onSuccess(result.execute())
149+
} catch (e: Throwable) {
150+
it.onError(e)
151+
}
152+
}
153+
}
154+
155+
@JvmOverloads
156+
fun schedulePoll(
157+
status: String,
158+
pollOptions: List<String>,
159+
pollExpiresIn: Int,
160+
pollMultiple: Boolean = false,
161+
pollHideTotals: Boolean = false,
162+
inReplyToId: String? = null,
163+
sensitive: Boolean = false,
164+
spoilerText: String? = null,
165+
visibility: Status.Visibility = Status.Visibility.Public,
166+
language: String? = null,
167+
scheduledAt: String
168+
): Single<ScheduledStatus> {
169+
return Single.create {
170+
try {
171+
val result = statusMethods.schedulePoll(
172+
status,
173+
pollOptions,
174+
pollExpiresIn,
175+
pollMultiple,
176+
pollHideTotals,
177+
inReplyToId,
178+
sensitive,
179+
spoilerText,
180+
visibility,
181+
language,
182+
scheduledAt
183+
)
184+
it.onSuccess(result.execute())
185+
} catch (e: Throwable) {
186+
it.onError(e)
187+
}
188+
}
189+
}
190+
191+
fun deleteStatus(statusId: String): Single<Status> {
192+
return Single.create {
193+
try {
194+
val status = statusMethods.deleteStatus(statusId)
195+
it.onSuccess(status.execute())
196+
} catch (e: Throwable) {
197+
it.onError(e)
198+
}
199+
}
200+
}
201+
202+
@JvmOverloads
203+
fun reblogStatus(statusId: String, visibility: Status.Visibility = Status.Visibility.Public): Single<Status> {
204+
return Single.create {
205+
try {
206+
val status = statusMethods.reblogStatus(statusId, visibility)
111207
it.onSuccess(status.execute())
112208
} catch (e: Throwable) {
113209
it.onError(e)
@@ -147,4 +243,70 @@ class RxStatusMethods(client: MastodonClient) {
147243
}
148244
}
149245
}
246+
247+
fun bookmarkStatus(statusId: String): Single<Status> {
248+
return Single.create {
249+
try {
250+
val status = statusMethods.bookmarkStatus(statusId)
251+
it.onSuccess(status.execute())
252+
} catch (e: Throwable) {
253+
it.onError(e)
254+
}
255+
}
256+
}
257+
258+
fun unbookmarkStatus(statusId: String): Single<Status> {
259+
return Single.create {
260+
try {
261+
val status = statusMethods.unbookmarkStatus(statusId)
262+
it.onSuccess(status.execute())
263+
} catch (e: Throwable) {
264+
it.onError(e)
265+
}
266+
}
267+
}
268+
269+
fun muteConversation(statusId: String): Single<Status> {
270+
return Single.create {
271+
try {
272+
val status = statusMethods.muteConversation(statusId)
273+
it.onSuccess(status.execute())
274+
} catch (e: Throwable) {
275+
it.onError(e)
276+
}
277+
}
278+
}
279+
280+
fun unmuteConversation(statusId: String): Single<Status> {
281+
return Single.create {
282+
try {
283+
val status = statusMethods.unmuteConversation(statusId)
284+
it.onSuccess(status.execute())
285+
} catch (e: Throwable) {
286+
it.onError(e)
287+
}
288+
}
289+
}
290+
291+
fun pinStatus(statusId: String): Single<Status> {
292+
return Single.create {
293+
try {
294+
val status = statusMethods.pinStatus(statusId)
295+
it.onSuccess(status.execute())
296+
} catch (e: Throwable) {
297+
it.onError(e)
298+
}
299+
}
300+
}
301+
302+
fun unpinStatus(statusId: String): Single<Status> {
303+
return Single.create {
304+
try {
305+
val status = statusMethods.unpinStatus(statusId)
306+
it.onSuccess(status.execute())
307+
} catch (e: Throwable) {
308+
it.onError(e)
309+
}
310+
}
311+
}
150312
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package social.bigbone.api.entity
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
/**
6+
* Represents a poll attached to a status.
7+
* @see <a href="https://docs.joinmastodon.org/entities/Poll/">Mastodon API Poll</a>
8+
*/
9+
data class Poll(
10+
/**
11+
* The ID of the poll in the database.
12+
*/
13+
@SerializedName("id")
14+
val id: String = "",
15+
16+
/**
17+
* When the poll ends. ISO 8601 Datetime string, or null if the poll does not end.
18+
*/
19+
@SerializedName("expires_at")
20+
val expiresAt: String? = null,
21+
22+
/**
23+
* Is the poll currently expired?
24+
*/
25+
@SerializedName("expired")
26+
val expired: Boolean = false,
27+
28+
/**
29+
* Does the poll allow multiple-choice answers?
30+
*/
31+
@SerializedName("multiple")
32+
val multiple: Boolean = false,
33+
34+
/**
35+
* How many votes have been received.
36+
*/
37+
@SerializedName("votes_count")
38+
val votesCount: Int = 0,
39+
40+
/**
41+
* How many unique accounts have voted on a multiple-choice poll; integer, or null if [multiple] is false.
42+
*/
43+
@SerializedName("voters_count")
44+
val votersCount: Int? = null,
45+
46+
/**
47+
* Possible answers for the poll.
48+
*/
49+
@SerializedName("options")
50+
val options: List<Option> = emptyList(),
51+
52+
/**
53+
* Custom emoji to be used for rendering poll options.
54+
*/
55+
@SerializedName("emojis")
56+
val emojis: List<CustomEmoji> = emptyList(),
57+
58+
/**
59+
* When called with a user token, has the authorized user voted?
60+
*/
61+
@SerializedName("voted")
62+
val voted: Boolean? = null,
63+
64+
/**
65+
* When called with a user token, which options has the authorized user chosen? Contains an array of index values for [options].
66+
*/
67+
@SerializedName("own_votes")
68+
val ownVotes: List<Int>? = null
69+
70+
) {
71+
/**
72+
* Possible answers for the poll.
73+
* @see <a href="https://docs.joinmastodon.org/entities/Poll/#Option">Mastodon API Poll::Option</a>
74+
*/
75+
data class Option(
76+
/**
77+
* The text value of the poll option.
78+
*/
79+
@SerializedName("title")
80+
val title: String = "",
81+
82+
/**
83+
* The total number of received votes for this option; integer, or null if results are not published yet.
84+
*/
85+
@SerializedName("votes_count")
86+
val votesCount: Int? = null
87+
)
88+
}

0 commit comments

Comments
 (0)