neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
Log in to mark this repository.
Android: locks, posting rules, moderated and hidden posts, the cooldown banner, flagging from the post menu
9b377f5 · gmorell · 2026-12-03 03:04
Message
{commit_body(@commit)}
Files changed
modified
android/app/src/main/java/org/neiam/recourse/app/data/Models.kt
+59
−1
| 24 | 24 | @SerialName("preferred_sort") val preferredSort: String = "latest", |
| 25 | 25 | @SerialName("reaction_notifications") val reactionNotifications: Boolean = true, |
| 26 | 26 | @SerialName("created_at") val createdAt: String = "", |
| 27 | + /** A cooldown in force: read-only until `until`. */ | |
| 28 | + val silenced: Sanction? = null, | |
| 29 | + @SerialName("read_only_until") val readOnlyUntil: String? = null, | |
| 30 | +) | |
| 31 | + | |
| 32 | +@Serializable | |
| 33 | +data class Sanction( | |
| 34 | + val until: String? = null, | |
| 35 | + val reason: String? = null, | |
| 36 | + /** The web's sentence: "Read-only until …: reason". */ | |
| 37 | + val message: String = "", | |
| 38 | +) | |
| 39 | + | |
| 40 | +/** Why a control is hidden: `code` for the app, `message` for the person. */ | |
| 41 | +@Serializable | |
| 42 | +data class Blocked(val code: String = "", val message: String = "") | |
| 43 | + | |
| 44 | +@Serializable | |
| 45 | +data class Rule( | |
| 46 | + /** `everyone` (who can read it), `min_trust` or `staff`. */ | |
| 47 | + val kind: String = "everyone", | |
| 48 | + @SerialName("min_trust") val minTrust: Int? = null, | |
| 49 | +) | |
| 50 | + | |
| 51 | +@Serializable | |
| 52 | +data class Posting( | |
| 53 | + @SerialName("create_topic") val createTopic: Rule = Rule(), | |
| 54 | + val reply: Rule = Rule(), | |
| 27 | 55 | ) |
| 28 | 56 | |
| 29 | 57 | @Serializable |
| 83 | 111 | val depth: Int = 1, |
| 84 | 112 | @SerialName("topic_count") val topicCount: Long = 0, |
| 85 | 113 | val watching: Boolean = false, |
| 114 | + val posting: Posting = Posting(), | |
| 115 | + @SerialName("can_create_topic") val canCreateTopic: Boolean = true, | |
| 116 | + @SerialName("can_reply") val canReply: Boolean = true, | |
| 86 | 117 | ) { |
| 87 | 118 | fun ref() = CategoryRef(id, slug, name, colors) |
| 88 | 119 | } |
| 103 | 134 | val category: CategoryRef? = null, |
| 104 | 135 | val author: Author, |
| 105 | 136 | @SerialName("is_pinned") val isPinned: Boolean = false, |
| 137 | + @SerialName("is_locked") val isLocked: Boolean = false, | |
| 106 | 138 | @SerialName("is_closed") val isClosed: Boolean = false, |
| 107 | 139 | @SerialName("posts_count") val postsCount: Int = 0, |
| 108 | 140 | val replies: Int = 0, |
| 125 | 157 | val sort: String = "latest", |
| 126 | 158 | val topics: List<TopicSummary> = emptyList(), |
| 127 | 159 | @SerialName("can_post") val canPost: Boolean = false, |
| 128 | −) | |
| 160 | + @SerialName("can_create_topic") val canCreateTopic: Boolean? = null, | |
| 161 | + @SerialName("create_blocked") val createBlocked: Blocked? = null, | |
| 162 | +) { | |
| 163 | + /** Older servers send only `can_post`. */ | |
| 164 | + val mayCreateTopic get() = canCreateTopic ?: canPost | |
| 165 | +} | |
| 129 | 166 | |
| 130 | 167 | @Serializable |
| 131 | 168 | data class Reaction( |
| 147 | 184 | val bookmarked: Boolean = false, |
| 148 | 185 | val reactions: List<Reaction> = emptyList(), |
| 149 | 186 | @SerialName("can_edit") val canEdit: Boolean = false, |
| 187 | + /** Staff replaced it with a note: `cooked` is the note ("staff: …"). */ | |
| 188 | + val moderated: Moderated? = null, | |
| 189 | + /** Hidden pending staff review (`cooked` empty unless it's yours). */ | |
| 190 | + val hidden: Boolean = false, | |
| 191 | + @SerialName("can_react") val canReact: Boolean = true, | |
| 192 | + @SerialName("can_flag") val canFlag: Boolean = false, | |
| 193 | + val flagged: Boolean = false, | |
| 150 | 194 | ) |
| 151 | 195 | |
| 196 | +@Serializable | |
| 197 | +data class Moderated(val by: String? = null, val at: String? = null) | |
| 198 | + | |
| 199 | +@Serializable | |
| 200 | +data class FlagBody(val reason: String, val note: String? = null) | |
| 201 | + | |
| 202 | +@Serializable | |
| 203 | +data class FlagResponse(val flagged: Boolean = true) | |
| 204 | + | |
| 152 | 205 | @Serializable |
| 153 | 206 | data class TopicDetail( |
| 154 | 207 | val id: String, |
| 157 | 210 | val ancestors: List<CategoryRef> = emptyList(), |
| 158 | 211 | val author: Author, |
| 159 | 212 | @SerialName("is_pinned") val isPinned: Boolean = false, |
| 213 | + @SerialName("is_locked") val isLocked: Boolean = false, | |
| 160 | 214 | @SerialName("is_closed") val isClosed: Boolean = false, |
| 215 | + @SerialName("lock_reason") val lockReason: String? = null, | |
| 161 | 216 | @SerialName("is_deleted") val isDeleted: Boolean = false, |
| 162 | 217 | val views: Int = 0, |
| 163 | 218 | @SerialName("posts_count") val postsCount: Int = 0, |
| 171 | 226 | val topic: TopicDetail, |
| 172 | 227 | val posts: List<Post> = emptyList(), |
| 173 | 228 | @SerialName("can_reply") val canReply: Boolean = false, |
| 229 | + @SerialName("reply_blocked") val replyBlocked: Blocked? = null, | |
| 230 | + @SerialName("can_react") val canReact: Boolean = true, | |
| 231 | + @SerialName("can_flag") val canFlag: Boolean = false, | |
| 174 | 232 | @SerialName("can_edit_tags") val canEditTags: Boolean = false, |
| 175 | 233 | val watching: Boolean = false, |
| 176 | 234 | ) |
modified
android/app/src/main/java/org/neiam/recourse/app/data/RecourseClient.kt
+4
−0
| 85 | 85 | @PUT("api/v1/posts/{id}/bookmark") |
| 86 | 86 | suspend fun setBookmark(@Path("id") id: String, @Body body: BookmarkBody): BookmarkBody |
| 87 | 87 | |
| 88 | + /** Once per post; 409 already_flagged. */ | |
| 89 | + @POST("api/v1/posts/{id}/flags") | |
| 90 | + suspend fun flag(@Path("id") id: String, @Body body: FlagBody): FlagResponse | |
| 91 | + | |
| 88 | 92 | @GET("api/v1/tags") |
| 89 | 93 | suspend fun tags(): TagsIndex |
| 90 | 94 |
modified
android/app/src/main/java/org/neiam/recourse/app/ui/Common.kt
+15
−3
| 179 | 179 | fun VerifyBanner(modifier: Modifier = Modifier) { |
| 180 | 180 | val me = LocalMe.current ?: return |
| 181 | 181 | if (me.user.mayWrite) return |
| 182 | + // A cooldown says so (and why, and until when) rather than "verify". | |
| 183 | + me.user.silenced?.let { s -> | |
| 184 | + Surface(color = MaterialTheme.colorScheme.errorContainer, modifier = modifier.fillMaxWidth()) { | |
| 185 | + Row(Modifier.padding(12.dp), verticalAlignment = Alignment.CenterVertically) { | |
| 186 | + Icon(Icons.Default.Lock, contentDescription = null) | |
| 187 | + Spacer(Modifier.width(8.dp)) | |
| 188 | + Text(s.message.ifEmpty { "Read-only for now." }, style = MaterialTheme.typography.bodySmall) | |
| 189 | + } | |
| 190 | + } | |
| 191 | + return | |
| 192 | + } | |
| 193 | + if (me.user.emailVerified) return | |
| 182 | 194 | val session = LocalSession.current |
| 183 | 195 | val scope = rememberCoroutineScope() |
| 184 | 196 | var note by remember { mutableStateOf<String?>(null) } |
| 223 | 235 | Column(Modifier.weight(1f)) { |
| 224 | 236 | Row(verticalAlignment = Alignment.CenterVertically) { |
| 225 | 237 | if (t.isPinned) PinMark() |
| 226 | − if (t.isClosed) LockMark() | |
| 238 | + if (t.isLocked || t.isClosed) LockMark() | |
| 227 | 239 | Text( |
| 228 | 240 | t.title, |
| 229 | 241 | style = MaterialTheme.typography.titleSmall, |
| 272 | 284 | } |
| 273 | 285 | Row(verticalAlignment = Alignment.CenterVertically) { |
| 274 | 286 | if (t.isPinned) PinMark() |
| 275 | − if (t.isClosed) LockMark() | |
| 287 | + if (t.isLocked || t.isClosed) LockMark() | |
| 276 | 288 | Text(t.title, style = MaterialTheme.typography.titleSmall, maxLines = 3, overflow = TextOverflow.Ellipsis) |
| 277 | 289 | } |
| 278 | 290 | Row(horizontalArrangement = Arrangement.spacedBy((-6).dp)) { |
| 356 | 368 | |
| 357 | 369 | @Composable |
| 358 | 370 | private fun LockMark() { |
| 359 | − Icon(Icons.Default.Lock, contentDescription = "Closed", modifier = Modifier.size(14.dp).padding(end = 2.dp)) | |
| 371 | + Icon(Icons.Default.Lock, contentDescription = "Locked", modifier = Modifier.size(14.dp).padding(end = 2.dp)) | |
| 360 | 372 | } |
| 361 | 373 | |
| 362 | 374 | /** Sort choices, in the web's order. */ |
modified
android/app/src/main/java/org/neiam/recourse/app/ui/ForumScreen.kt
+10
−1
| 151 | 151 | WatchButton(page.category) { watching -> |
| 152 | 152 | loader.set(page.copy(category = page.category.copy(watching = watching))) |
| 153 | 153 | } |
| 154 | − if (page.canPost) { | |
| 154 | + if (page.mayCreateTopic) { | |
| 155 | 155 | IconButton(onClick = { nav.nav.navigate("newtopic/${page.category.slug}") }) { |
| 156 | 156 | Icon(Icons.Default.Add, contentDescription = "New topic") |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | + // Why there's no "new topic" here (staff only, a trust level). | |
| 161 | + page.createBlocked?.takeIf { it.code != "unverified" && it.code != "silenced" }?.let { | |
| 162 | + Text( | |
| 163 | + it.message, | |
| 164 | + style = MaterialTheme.typography.labelSmall, | |
| 165 | + color = MaterialTheme.colorScheme.onSurfaceVariant, | |
| 166 | + modifier = Modifier.padding(horizontal = 12.dp), | |
| 167 | + ) | |
| 168 | + } | |
| 160 | 169 | } |
| 161 | 170 | }, |
| 162 | 171 | ) |
modified
android/app/src/main/java/org/neiam/recourse/app/ui/ProfileScreen.kt
+1
−1
| 95 | 95 | }) { Text("Remove") } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | − if (me.verificationRequired && !u.emailVerified) VerifyBanner() | |
| 98 | + if ((me.verificationRequired && !u.emailVerified) || u.silenced != null) VerifyBanner() | |
| 99 | 99 | else if (u.emailVerified) Text("Email verified.", style = MaterialTheme.typography.labelMedium) |
| 100 | 100 | |
| 101 | 101 | Section("Layout") { |
modified
android/app/src/main/java/org/neiam/recourse/app/ui/ReaderScreen.kt
+132
−9
Click to load diff…
modified
android/app/src/test/java/org/neiam/recourse/app/data/ContractTest.kt
+36
−0
Click to load diff…
modified
android/app/src/test/resources/api/bookmarks.json
+3
−3
Click to load diff…
modified
android/app/src/test/resources/api/categories.json
+1846
−4
Click to load diff…
modified
android/app/src/test/resources/api/category.json
+45
−29
Click to load diff…
added
android/app/src/test/resources/api/category_staff_only.json
+37
−0
Click to load diff…
modified
android/app/src/test/resources/api/devices.json
+4
−4
Click to load diff…
added
android/app/src/test/resources/api/error_silenced.json
+7
−0
Click to load diff…
added
android/app/src/test/resources/api/flag.json
+3
−0
Click to load diff…
modified
android/app/src/test/resources/api/me.json
+7
−5
Click to load diff…
added
android/app/src/test/resources/api/me_silenced.json
+27
−0
Click to load diff…
modified
android/app/src/test/resources/api/notifications.json
+6
−6
Click to load diff…
modified
android/app/src/test/resources/api/reply.json
+10
−5
Click to load diff…
modified
android/app/src/test/resources/api/search.json
+173
−16
Click to load diff…
modified
android/app/src/test/resources/api/tag.json
+19
−18
Click to load diff…
modified
android/app/src/test/resources/api/tags.json
+17
−2
Click to load diff…
modified
android/app/src/test/resources/api/topic.json
+35
−20
Click to load diff…
added
android/app/src/test/resources/api/topic_locked.json
+164
−0
Click to load diff…
modified
docs/android.md
+12
−0
Click to load diff…
modified
tests/api_db.rs
+40
−0
Click to load diff…
Parents: a4db355