Models WIP: RantFeed
This commit is contained in:
		
							parent
							
								
									2a15f2ea73
								
							
						
					
					
						commit
						fc331b32c3
					
				| @ -12,7 +12,7 @@ public struct Comment: Identifiable, Hashable { | ||||
|     public let voteState: VoteState | ||||
|      | ||||
|     /// The number of upvotes from other users. | ||||
|     public var score: Int | ||||
|     public let score: Int | ||||
|      | ||||
|     /// The user who wrote this comment. | ||||
|     public let author: User | ||||
| @ -27,7 +27,7 @@ public struct Comment: Identifiable, Hashable { | ||||
|     public let text: String | ||||
|      | ||||
|     /// 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. | ||||
|     public let image: AttachedImage? | ||||
|  | ||||
| @ -23,13 +23,13 @@ public struct Rant: Identifiable, Hashable { | ||||
|     public let isEdited: Bool | ||||
|      | ||||
|     /// 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. | ||||
|     public let text: String | ||||
|      | ||||
|     /// 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. | ||||
|     public let image: AttachedImage? | ||||
|  | ||||
| @ -1,9 +1,6 @@ | ||||
| /// Contains the list of rants for the logged in user and other random things. | ||||
| public struct RantFeed: Hashable { | ||||
|     public var rants: [Rant] | ||||
|      | ||||
|     /// The notification settings for the logged-in user. | ||||
|     //public let settings: Settings | ||||
|     public let rants: [Rant] | ||||
|      | ||||
|     public let sessionHash: String? | ||||
|      | ||||
| @ -12,11 +9,19 @@ public struct RantFeed: Hashable { | ||||
|      | ||||
|     /// True if the logged in user is subscribed to devRant++. | ||||
|     public let devRantSupporter: Bool | ||||
|     //public let isUserDPP: Int | ||||
|      | ||||
|     public let numberOfUnreadNotifications: Int | ||||
|      | ||||
|     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 { | ||||
| @ -45,3 +50,29 @@ public extension RantFeed { | ||||
|         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 | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user