-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
447 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Mlem/Models/Content/Instance/InstanceModel+MenuFunctions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// InstanceModel+MenuFunctions.swift | ||
// Mlem | ||
// | ||
// Created by Sjmarf on 14/01/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
extension InstanceModel { | ||
func menuFunctions() -> [MenuFunction] { | ||
if let url { | ||
return [.shareMenuFunction(url: url)] | ||
} | ||
return [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// InstanceModel.swift | ||
// Mlem | ||
// | ||
// Created by Sjmarf on 13/01/2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct InstanceModel { | ||
var instanceId: Int! | ||
var name: String! | ||
var description: String? | ||
var avatar: URL? | ||
var banner: URL? | ||
var administrators: [UserModel]? | ||
var url: URL! | ||
|
||
init(from response: SiteResponse) { | ||
self.update(with: response) | ||
} | ||
|
||
init(from site: APISite) { | ||
self.update(with: site) | ||
} | ||
|
||
mutating func update(with response: SiteResponse) { | ||
self.administrators = response.admins.map { | ||
var user = UserModel(from: $0, usesExternalData: true) | ||
user.isAdmin = true | ||
return user | ||
} | ||
self.update(with: response.siteView.site) | ||
} | ||
|
||
mutating func update(with site: APISite) { | ||
instanceId = site.id | ||
name = site.name | ||
description = site.sidebar | ||
avatar = site.iconUrl | ||
banner = site.bannerUrl | ||
|
||
if var components = URLComponents(string: site.inboxUrl) { | ||
components.path = "" | ||
url = components.url | ||
} | ||
} | ||
} | ||
|
||
extension InstanceModel: Identifiable { | ||
var id: Int { hashValue } | ||
} | ||
|
||
extension InstanceModel: Hashable { | ||
static func == (lhs: InstanceModel, rhs: InstanceModel) -> Bool { | ||
return lhs.hashValue == rhs.hashValue | ||
} | ||
|
||
/// Hashes all fields for which state changes should trigger view updates. | ||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(instanceId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.