-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathRoute.kt
More file actions
568 lines (477 loc) · 18.3 KB
/
Route.kt
File metadata and controls
568 lines (477 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
package dev.dimension.flare.ui.route
import androidx.navigation3.runtime.NavKey
import dev.dimension.flare.data.model.TimelineTabItem
import dev.dimension.flare.model.AccountType
import dev.dimension.flare.model.MicroBlogKey
import io.ktor.http.Url
import kotlinx.serialization.Serializable
@Serializable
internal sealed interface Route : NavKey {
@Serializable
sealed interface WithAccountType : Route {
val accountType: AccountType
}
@Serializable
sealed interface Status : Route {
@Serializable
data class Detail(
val statusKey: MicroBlogKey,
override val accountType: AccountType,
) : Status,
WithAccountType
@Serializable
data class VVOComment(
val commentKey: MicroBlogKey,
override val accountType: AccountType,
) : Status,
WithAccountType
@Serializable
data class VVOStatus(
val statusKey: MicroBlogKey,
override val accountType: AccountType,
) : Status,
WithAccountType
@Serializable
data class AddReaction(
val statusKey: MicroBlogKey,
override val accountType: AccountType,
) : Status,
WithAccountType
@Serializable
data class AltText(
val text: String,
) : Status
@Serializable
data class BlueskyReport(
val statusKey: MicroBlogKey,
override val accountType: AccountType,
) : Status,
WithAccountType
@Serializable
data class DeleteConfirm(
val statusKey: MicroBlogKey,
override val accountType: AccountType,
) : Status,
WithAccountType
@Serializable
data class MastodonReport(
val userKey: MicroBlogKey,
val statusKey: MicroBlogKey?,
override val accountType: AccountType,
) : Status,
WithAccountType
@Serializable
data class MisskeyReport(
val userKey: MicroBlogKey,
val statusKey: MicroBlogKey?,
override val accountType: AccountType,
) : Status,
WithAccountType
}
@Serializable
sealed interface Settings : Route {
@Serializable
data object Main : Settings
@Serializable
data object Accounts : Settings
@Serializable
data object Appearance : Settings
@Serializable
data object Storage : Settings
@Serializable
data object About : Settings
@Serializable
data object TabCustomization : Settings
@Serializable
data object LocalFilter : Settings
@Serializable
data object GuestSetting : Settings
@Serializable
data object LocalHistory : Settings
@Serializable
data object AiConfig : Settings
@Serializable
data object ColorPicker : Settings
@Serializable
data object AppLogging : Settings
@Serializable
data class LocalFilterEdit(
val keyword: String?,
) : Settings
}
@Serializable
sealed interface Rss : Route {
@Serializable
data object Sources : Rss
@Serializable
data class Timeline(
val id: Int,
) : Rss
@Serializable
data class Detail(
val url: String,
) : Rss
@Serializable
data object Create : Rss
@Serializable
data class Edit(
val id: Int,
) : Rss
}
@Serializable
data class Home(
override val accountType: AccountType,
) : Route,
WithAccountType
@Serializable
data class Timeline(
override val accountType: AccountType,
val tabItem: TimelineTabItem,
) : Route,
WithAccountType
@Serializable
sealed interface ServiceSelect : Route {
@Serializable
data object Selection : ServiceSelect
@Serializable
data object VVOLogin : ServiceSelect
@Serializable
data object XQTLogin : ServiceSelect
}
@Serializable
data class TabSettings(
override val accountType: AccountType,
) : Route,
WithAccountType
@Serializable
data class Discover(
override val accountType: AccountType,
) : Route,
WithAccountType
@Serializable
sealed interface Profile : Route {
@Serializable
data class User(
override val accountType: AccountType,
val userKey: MicroBlogKey,
) : Profile,
WithAccountType
@Serializable
data class UserNameWithHost(
override val accountType: AccountType,
val name: String,
val host: String,
) : Profile,
WithAccountType
@Serializable
data class Following(
override val accountType: AccountType,
val userKey: MicroBlogKey,
) : Profile,
WithAccountType
@Serializable
data class Fans(
override val accountType: AccountType,
val userKey: MicroBlogKey,
) : Profile,
WithAccountType
@Serializable
data class Me(
override val accountType: AccountType,
) : Profile,
WithAccountType
}
@Serializable
data class Notification(
override val accountType: AccountType,
) : Route,
WithAccountType
@Serializable
data class Search(
override val accountType: AccountType,
val query: String,
) : Route,
WithAccountType
@Serializable
sealed interface Lists : Route {
@Serializable
data class List(
override val accountType: AccountType,
) : Lists,
WithAccountType
@Serializable
data class Detail(
override val accountType: AccountType,
val listId: String,
val title: String,
) : Lists,
WithAccountType
@Serializable
data class Create(
override val accountType: AccountType,
) : Lists,
WithAccountType
@Serializable
data class Edit(
override val accountType: AccountType,
val listId: String,
) : Lists,
WithAccountType
@Serializable
data class EditMember(
override val accountType: AccountType,
val listId: String,
) : Lists,
WithAccountType
@Serializable
data class EditAccountList(
override val accountType: AccountType,
val userKey: MicroBlogKey,
) : Lists,
WithAccountType
@Serializable
data class Delete(
override val accountType: AccountType,
val listId: String,
val title: String?,
) : Lists,
WithAccountType
}
@Serializable
sealed interface DM : Route {
@Serializable
data class List(
override val accountType: AccountType,
) : DM,
WithAccountType
@Serializable
data class Conversation(
override val accountType: AccountType,
val roomKey: MicroBlogKey,
) : DM,
WithAccountType
@Serializable
data class UserConversation(
override val accountType: AccountType,
val userKey: MicroBlogKey,
) : DM,
WithAccountType
}
@Serializable
sealed interface Bluesky : Route {
@Serializable
data class Feed(
override val accountType: AccountType,
) : Bluesky,
WithAccountType
@Serializable
data class FeedDetail(
override val accountType: AccountType,
val feedId: String,
) : Bluesky,
WithAccountType
}
@Serializable
sealed interface Compose : Route {
@Serializable
data class New(
override val accountType: AccountType,
) : Compose,
WithAccountType
@Serializable
data class Reply(
val accountKey: MicroBlogKey,
val statusKey: MicroBlogKey,
) : Compose
@Serializable
data class Quote(
val accountKey: MicroBlogKey,
val statusKey: MicroBlogKey,
) : Compose
@Serializable
data class VVOReplyComment(
val accountKey: MicroBlogKey,
val replyTo: MicroBlogKey,
val rootId: String,
) : Compose
}
@Serializable
sealed interface Media : Route {
@Serializable
data class Image(
val uri: String,
val previewUrl: String?,
) : Media
@Serializable
data class StatusMedia(
val statusKey: MicroBlogKey,
override val accountType: AccountType,
val index: Int,
val preview: String?,
) : Media,
WithAccountType
@Serializable
data class Podcast(
override val accountType: AccountType,
val id: String,
) : Media,
WithAccountType
}
@Serializable
data object AccountSelection : Route
companion object {
public fun parse(url: String): Route? {
val data = Url(url)
return when (data.host) {
"Callback" ->
when (data.segments.getOrNull(0)) {
"SignIn" ->
when (data.segments.getOrNull(1)) {
// "Mastodon" -> Route.Callback.Mastodon
// "Misskey" -> Route.Callback.Misskey
else -> null
}
else -> null
}
"Search" -> {
val accountKey = data.parameters["accountKey"]?.let { MicroBlogKey.valueOf(it) }
val keyword = data.segments.getOrNull(0) ?: return null
val accountType = accountKey?.let { AccountType.Specific(it) } ?: AccountType.Guest
Route.Search(accountType, keyword)
}
"Profile" -> {
val accountKey = data.parameters["accountKey"]?.let { MicroBlogKey.valueOf(it) }
val userKey = MicroBlogKey.valueOf(data.segments.getOrNull(0) ?: return null)
val accountType = accountKey?.let { AccountType.Specific(it) } ?: AccountType.Guest
Route.Profile.User(accountType, userKey)
}
"ProfileWithNameAndHost" -> {
val accountKey = data.parameters["accountKey"]?.let { MicroBlogKey.valueOf(it) }
val userName = data.segments.getOrNull(0) ?: return null
val host = data.segments.getOrNull(1) ?: return null
val accountType = accountKey?.let { AccountType.Specific(it) } ?: AccountType.Guest
Route.Profile.UserNameWithHost(accountType, userName, host)
}
"StatusDetail" -> {
val accountKey = data.parameters["accountKey"]?.let { MicroBlogKey.valueOf(it) }
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(0) ?: return null)
val accountType = accountKey?.let { AccountType.Specific(it) } ?: AccountType.Guest
Route.Status.Detail(statusKey, accountType)
}
"Compose" ->
when (data.segments.getOrNull(0)) {
"Reply" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(2) ?: return null)
Route.Compose.Reply(accountKey, statusKey)
}
"Quote" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(2) ?: return null)
Route.Compose.Quote(accountKey, statusKey)
}
"New" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
Route.Compose.New(AccountType.Specific(accountKey))
}
else -> null
}
"RawImage" -> {
val rawImage = data.segments.getOrNull(0) ?: return null
Route.Media.Image(rawImage, previewUrl = null)
}
"VVO" ->
when (data.segments.getOrNull(0)) {
"StatusDetail" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(2) ?: return null)
Route.Status.VVOStatus(statusKey, AccountType.Specific(accountKey))
}
"CommentDetail" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(2) ?: return null)
Route.Status.VVOComment(statusKey, AccountType.Specific(accountKey))
}
"ReplyToComment" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
val replyTo = MicroBlogKey.valueOf(data.segments.getOrNull(2) ?: return null)
val rootId = data.segments.getOrNull(3) ?: return null
Route.Compose.VVOReplyComment(accountKey, replyTo, rootId)
}
else -> null
}
"DeleteStatus" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(0) ?: return null)
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
Route.Status.DeleteConfirm(statusKey, AccountType.Specific(accountKey))
}
"AddReaction" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(0) ?: return null)
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
Route.Status.AddReaction(statusKey, AccountType.Specific(accountKey))
}
"Bluesky" ->
when (data.segments.getOrNull(0)) {
"ReportStatus" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(2) ?: return null)
Route.Status.BlueskyReport(statusKey, AccountType.Specific(accountKey))
}
else -> null
}
"Mastodon" ->
when (data.segments.getOrNull(0)) {
"ReportStatus" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(2) ?: return null)
val userKey = MicroBlogKey.valueOf(data.segments.getOrNull(3) ?: return null)
Route.Status.MastodonReport(
statusKey = statusKey,
userKey = userKey,
accountType = AccountType.Specific(accountKey),
)
}
else -> null
}
"Misskey" ->
when (data.segments.getOrNull(0)) {
"ReportStatus" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(1) ?: return null)
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(2) ?: return null)
val userKey = MicroBlogKey.valueOf(data.segments.getOrNull(3) ?: return null)
Route.Status.MisskeyReport(
accountType = AccountType.Specific(accountKey),
statusKey = statusKey,
userKey = userKey,
)
}
else -> null
}
"StatusMedia" -> {
val accountKey = data.parameters["accountKey"]?.let { MicroBlogKey.valueOf(it) }
val statusKey = MicroBlogKey.valueOf(data.segments.getOrNull(0) ?: return null)
val index = data.segments.getOrNull(1)?.toIntOrNull() ?: return null
val accountType = accountKey?.let { AccountType.Specific(it) } ?: AccountType.Guest
val preview = data.parameters["preview"]
Route.Media.StatusMedia(accountType = accountType, statusKey = statusKey, index = index, preview = preview)
}
"Podcast" -> {
val accountKey = MicroBlogKey.valueOf(data.segments.getOrNull(0) ?: return null)
val id = data.segments.getOrNull(1) ?: return null
val accountType = accountKey.let { AccountType.Specific(it) }
Route.Media.Podcast(accountType = accountType, id = id)
}
"AltText" -> {
val text = data.segments.getOrNull(0) ?: return null
Route.Status.AltText(text)
}
else -> null
}
}
}
}
internal fun Route.accountTypeOr(default: AccountType): AccountType =
when (this) {
is Route.WithAccountType -> this.accountType
else -> default
}