-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTopic.swift
135 lines (122 loc) · 3.58 KB
/
Topic.swift
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
//
// Topic.swift
// ForPDA
//
// Created by Xialtal on 7.09.24.
//
import Foundation
public struct Topic: Codable, Sendable, Identifiable, Hashable {
public let id: Int
public let name: String
public let description: String
public let flag: Int
public let createdAt: Date
public let authorId: Int
public let authorName: String
public let curatorId: Int
public let curatorName: String
public let poll: Poll?
public let postsCount: Int
public let posts: [Post]
public let navigation: [ForumInfo]
public var canPost: Bool {
return (flag & 64) != 0 && (flag & 16) == 0
}
public var isFavorite: Bool
public struct Poll: Sendable, Codable, Hashable {
public let name: String
public let voted: Bool
public let totalVotes: Int
public let options: [Option]
public init(name: String, voted: Bool, totalVotes: Int, options: [Option]) {
self.name = name
self.voted = voted
self.totalVotes = totalVotes
self.options = options
}
public struct Choice: Sendable, Codable, Hashable {
public let id: Int
public let votes: Int
public let name: String
public init(id: Int, name: String, votes: Int) {
self.id = id
self.votes = votes
self.name = name
}
}
public struct Option: Sendable, Codable, Hashable {
public let name: String
public let several: Bool
public let choices: [Choice]
public init(name: String, several: Bool, choices: [Choice]) {
self.name = name
self.several = several
self.choices = choices
}
}
}
public init(
id: Int,
name: String,
description: String,
flag: Int,
createdAt: Date,
authorId: Int,
authorName: String,
curatorId: Int,
curatorName: String,
poll: Poll?,
postsCount: Int,
posts: [Post],
navigation: [ForumInfo]
) {
self.id = id
self.name = name
self.description = description
self.flag = flag
self.createdAt = createdAt
self.authorId = authorId
self.authorName = authorName
self.curatorId = curatorId
self.curatorName = curatorName
self.poll = poll
self.postsCount = postsCount
self.posts = posts
self.navigation = navigation
self.isFavorite = (flag & 8) != 0
}
}
public extension Topic {
static let mock = Topic(
id: 3242552,
name: "ForPDA",
description: "Unofficial 4PDA client for iOS.",
flag: 8,
createdAt: Date(timeIntervalSince1970: 1725706883),
authorId: 3640948,
authorName: "4spander",
curatorId: 6176341,
curatorName: "AirFlare",
poll: Poll(
name: "Some simple poll...",
voted: false,
totalVotes: 2134,
options: [
Poll.Option(
name: "Select this choise...",
several: false,
choices: [
Poll.Choice(id: 2, name: "First choice", votes: 2)
]
)
]
),
postsCount: 1709,
posts: [
.mock
],
navigation: [
ForumInfo(id: 1, name: "iOS - Apps", flag: 32)
]
)
}