some fixes for param passing and decoding
This commit is contained in:
@@ -28,7 +28,7 @@ public extension NotificationFeed {
|
||||
let rantId = notification.rantId
|
||||
let commentId = notification.commentId
|
||||
let userId = notification.userId
|
||||
let userInfo = userInfos.first { $0.userId == String(userId) }
|
||||
let userInfo = userInfos.first { $0.userId == userId }
|
||||
let userAvatar = userInfo?.avatar ?? .init(colorHex: "cccccc", imageUrlPath: nil)
|
||||
let userName = userInfo?.username ?? ""
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ public extension NotificationFeed {
|
||||
struct UserInfo: Hashable, Sendable {
|
||||
public let avatar: User.Avatar
|
||||
public let username: String
|
||||
public let userId: String //TODO: why is this String? The other user ids are Int.
|
||||
public let userId: Int
|
||||
|
||||
public init(avatar: User.Avatar, username: String, userId: String) {
|
||||
public init(avatar: User.Avatar, username: String, userId: Int) {
|
||||
self.avatar = avatar
|
||||
self.username = username
|
||||
self.userId = userId
|
||||
@@ -13,37 +13,8 @@ public extension NotificationFeed {
|
||||
}
|
||||
|
||||
extension NotificationFeed.UserInfo {
|
||||
struct CodingData: Decodable {
|
||||
struct Container: Decodable {
|
||||
let array: [CodingData]
|
||||
}
|
||||
|
||||
let avatar: User.Avatar.CodingData
|
||||
struct UsernameMapEntryCodingData: Decodable {
|
||||
let name: String
|
||||
let uidForUsername: String //TODO: why is this String? The other user ids are Int.
|
||||
|
||||
private enum CodingKeys: CodingKey {
|
||||
case avatar
|
||||
case name
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let values = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
avatar = try values.decode(User.Avatar.CodingData.self, forKey: .avatar)
|
||||
name = try values.decode(String.self, forKey: .name)
|
||||
|
||||
uidForUsername = values.codingPath[values.codingPath.endIndex - 1].stringValue //TODO: wtf is this? Check if it can be made simpler and easier to understand.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension NotificationFeed.UserInfo.CodingData {
|
||||
var decoded: NotificationFeed.UserInfo {
|
||||
.init(
|
||||
avatar: avatar.decoded,
|
||||
username: name,
|
||||
userId: uidForUsername
|
||||
)
|
||||
let avatar: User.Avatar.CodingData
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ extension NotificationFeed {
|
||||
let check_time: Int
|
||||
let items: [Notification.CodingData]
|
||||
let unread: UnreadNumbers.CodingData
|
||||
let username_map: UserInfo.CodingData.Container
|
||||
let username_map: [String: NotificationFeed.UserInfo.UsernameMapEntryCodingData]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,9 @@ extension NotificationFeed.CodingData {
|
||||
lastChecked: Date(timeIntervalSince1970: TimeInterval(check_time)),
|
||||
notifications: items.map(\.decoded),
|
||||
unreadNumbers: unread.decoded,
|
||||
userInfos: username_map.array.map(\.decoded)
|
||||
userInfos: username_map.map { (key, value) in
|
||||
.init(avatar: value.avatar.decoded, username: value.name, userId: Int(key) ?? 0)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user