Download list of servers fro m GitHub.

This commit is contained in:
Marcin Czachursk 2023-02-19 07:50:21 +01:00
parent 94dacbd0ab
commit 7fb550985b
7 changed files with 46 additions and 12 deletions

View File

@ -70,9 +70,9 @@ In pixelfed source code there is hardcoded application name. API always retruns
],
```
### ** (fixed) Place is not available in the API**
### ** Place is not available in the API**
In the status response there is no information about place.
In the status response there is no information about place (even if we save place we cannot display it).
That information is visible when using Pixelfed web app.
There is `place_id` field in status create endpoint.

View File

@ -113,6 +113,7 @@
F89992CE296D92E7005994BF /* AttachmentModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F89992CD296D92E7005994BF /* AttachmentModel.swift */; };
F89A46DC296EAACE0062125F /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F89A46DB296EAACE0062125F /* SettingsView.swift */; };
F89A46DE296EABA20062125F /* StatusPlaceholder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F89A46DD296EABA20062125F /* StatusPlaceholder.swift */; };
F89AC00529A1F9B500F4159F /* Servers.swift in Sources */ = {isa = PBXBuildFile; fileRef = F89AC00429A1F9B500F4159F /* Servers.swift */; };
F89CEB802984198600A1376F /* AttachmentData+HighestImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F89CEB7F2984198600A1376F /* AttachmentData+HighestImage.swift */; };
F89D6C3F29716E41001DA3D4 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = F89D6C3E29716E41001DA3D4 /* Theme.swift */; };
F89D6C4229717FDC001DA3D4 /* AccountsSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = F89D6C4129717FDC001DA3D4 /* AccountsSection.swift */; };
@ -250,6 +251,7 @@
F89992CD296D92E7005994BF /* AttachmentModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentModel.swift; sourceTree = "<group>"; };
F89A46DB296EAACE0062125F /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
F89A46DD296EABA20062125F /* StatusPlaceholder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusPlaceholder.swift; sourceTree = "<group>"; };
F89AC00429A1F9B500F4159F /* Servers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Servers.swift; sourceTree = "<group>"; };
F89CEB7F2984198600A1376F /* AttachmentData+HighestImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AttachmentData+HighestImage.swift"; sourceTree = "<group>"; };
F89D6C3E29716E41001DA3D4 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };
F89D6C4129717FDC001DA3D4 /* AccountsSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsSection.swift; sourceTree = "<group>"; };
@ -392,6 +394,7 @@
F86167C7297FE781004D1F67 /* AvatarShape.swift */,
F8764186298ABB520057D362 /* ViewState.swift */,
F8FA9918299FA35A007AB130 /* PhotoAttachment.swift */,
F89AC00429A1F9B500F4159F /* Servers.swift */,
);
path = Models;
sourceTree = "<group>";
@ -759,6 +762,7 @@
F85D497929640B9D00751DF7 /* ImagesCarousel.swift in Sources */,
F8C5E55F2988E92600ADF6A7 /* AccountModel.swift in Sources */,
F89D6C3F29716E41001DA3D4 /* Theme.swift in Sources */,
F89AC00529A1F9B500F4159F /* Servers.swift in Sources */,
F8CC95CE2970761D00C9C2AC /* TintColor.swift in Sources */,
F89992CC296D9231005994BF /* StatusModel.swift in Sources */,
F80048052961850500E6868A /* StatusData+CoreDataClass.swift in Sources */,

View File

@ -10,8 +10,8 @@ import MastodonKit
/// Mastodon 'Search'.
extension Client {
public class Instances {
public let pixelfedInstances: [String] = [
private let urlJson = URL(string: "https://raw.githubusercontent.com/VernissageApp/Home/main/instances.json")!
private let backupInstances: [String] = [
"https://pixelfed.de",
"https://pixelfed.social",
"https://pxlmo.com",
@ -39,18 +39,21 @@ extension Client {
"https://pixelfed.fioverse.zone",
"https://pixel.artemai.art",
"https://pix.anduin.net",
"https://jauntypix.net",
"https://faf.photos",
"https://pix.vleij.com",
"https://pixels.gsi.li",
"https://eorzea.photos"
]
func instances(urls: [String]) async -> [Instance] {
func instances() async -> [Instance] {
var instances: [Instance] = []
// First we have to download list of instances from github.
let instanceUrls = await self.servers()
// Now we have to download information about each instance.
await withTaskGroup(of: Instance?.self) { group in
for url in urls {
for url in instanceUrls {
group.addTask {
do {
if let baseUrl = URL(string: url) {
@ -80,5 +83,21 @@ extension Client {
let client = MastodonClient(baseURL: url)
return try await client.readInstanceInformation()
}
private func servers() async -> [String] {
do {
let (data, response) = try await URLSession.shared.data(from: urlJson)
guard (response as? HTTPURLResponse)?.status?.responseType == .success else {
throw NetworkError.notSuccessResponse(response)
}
let servers = try JSONDecoder().decode(Servers.self, from: data)
return servers.instances
} catch {
ErrorService.shared.handle(error, message: "Error during downloading list of instances")
return backupInstances
}
}
}
}

View File

@ -0,0 +1,11 @@
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import Foundation
public struct Servers: Codable {
public let instances: [String]
}

View File

@ -48,12 +48,12 @@ struct ComposeView: View {
ScrollView {
VStack (alignment: .leading){
if self.isSensitive {
TextField("Write content warning", text: $spoilerText)
TextField("Write content warning", text: $spoilerText, axis: .vertical)
.padding(8)
.lineLimit(1...2)
.focused($focusedField, equals: .spoilerText)
.keyboardType(.default)
.background(Color.red)
.foregroundColor(.white)
.background(Color.dangerColor.opacity(0.4))
}

View File

@ -204,7 +204,7 @@ struct MainView: View {
@ToolbarContentBuilder
private func getTrailingToolbar() -> some ToolbarContent {
if viewMode == .local || viewMode == .home || viewMode == .federated {
if viewMode == .local || viewMode == .home || viewMode == .federated || viewMode == .trending {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
HapticService.shared.touch()

View File

@ -64,7 +64,7 @@ struct SignInView: View {
}
.onFirstAppear {
self.instances = await self.client.instances.instances(urls: self.client.instances.pixelfedInstances)
self.instances = await self.client.instances.instances()
}
.navigationBarTitle("Sign in to Pixelfed")
.navigationBarTitleDisplayMode(.inline)