Models WIP: RantFeed

This commit is contained in:
Wilhelm Oks 2024-12-12 13:05:58 +01:00
parent 2a15f2ea73
commit fc331b32c3
3 changed files with 40 additions and 9 deletions

View File

@ -12,7 +12,7 @@ public struct Comment: Identifiable, Hashable {
public let voteState: VoteState public let voteState: VoteState
/// The number of upvotes from other users. /// The number of upvotes from other users.
public var score: Int public let score: Int
/// The user who wrote this comment. /// The user who wrote this comment.
public let author: User public let author: User
@ -27,7 +27,7 @@ public struct Comment: Identifiable, Hashable {
public let text: String public let text: String
/// The URLs and user mentions inside of the text of this comment. /// The URLs and user mentions inside of the text of this comment.
public var linksInText: [Link] public let linksInText: [Link]
/// The optional image that the user has uploaded for this comment. /// The optional image that the user has uploaded for this comment.
public let image: AttachedImage? public let image: AttachedImage?

View File

@ -23,13 +23,13 @@ public struct Rant: Identifiable, Hashable {
public let isEdited: Bool public let isEdited: Bool
/// True if this rant has been marked as a favorite by the logged in user. /// True if this rant has been marked as a favorite by the logged in user.
public var isFavorite: Bool public let isFavorite: Bool
/// The text contents of this rant. /// The text contents of this rant.
public let text: String public let text: String
/// The URLs and user mentions inside of the text of this rant. /// The URLs and user mentions inside of the text of this rant.
public var linksInText: [Link] public let linksInText: [Link]
/// The optional image that the user has uploaded for this rant. /// The optional image that the user has uploaded for this rant.
public let image: AttachedImage? public let image: AttachedImage?

View File

@ -1,9 +1,6 @@
/// Contains the list of rants for the logged in user and other random things. /// Contains the list of rants for the logged in user and other random things.
public struct RantFeed: Hashable { public struct RantFeed: Hashable {
public var rants: [Rant] public let rants: [Rant]
/// The notification settings for the logged-in user.
//public let settings: Settings
public let sessionHash: String? public let sessionHash: String?
@ -12,11 +9,19 @@ public struct RantFeed: Hashable {
/// True if the logged in user is subscribed to devRant++. /// True if the logged in user is subscribed to devRant++.
public let devRantSupporter: Bool public let devRantSupporter: Bool
//public let isUserDPP: Int
public let numberOfUnreadNotifications: Int public let numberOfUnreadNotifications: Int
public let news: News? public let news: News?
public init(rants: [Rant], sessionHash: String?, weeklyRantWeek: Int?, devRantSupporter: Bool, numberOfUnreadNotifications: Int, news: RantFeed.News?) {
self.rants = rants
self.sessionHash = sessionHash
self.weeklyRantWeek = weeklyRantWeek
self.devRantSupporter = devRantSupporter
self.numberOfUnreadNotifications = numberOfUnreadNotifications
self.news = news
}
} }
public extension RantFeed { public extension RantFeed {
@ -45,3 +50,29 @@ public extension RantFeed {
case all case all
} }
} }
extension RantFeed {
struct CodingData: Codable {
let rants: [Rant.CodingData]
//let settings //not sure what the purpose is. probably not needed.
let set: String?
let wrw: Int?
let dpp: Int
let num_notifs: Int?
//let unread //probably the same info as already provided by num_notifs, so not needed.
let news: News.CodingData?
}
}
extension RantFeed.CodingData {
var decoded: RantFeed {
.init(
rants: rants.map(\.decoded),
sessionHash: `set`,
weeklyRantWeek: wrw,
devRantSupporter: dpp != 0,
numberOfUnreadNotifications: num_notifs ?? 0,
news: news?.decoded
)
}
}