Skip to content

Commit

Permalink
Added 'Pod' dependency 'NioKit'
Browse files Browse the repository at this point in the history
  • Loading branch information
regexident committed May 14, 2020
1 parent 603d848 commit 3b67277
Show file tree
Hide file tree
Showing 59 changed files with 4,432 additions and 290 deletions.
316 changes: 215 additions & 101 deletions Nio.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions Nio.xcodeproj/xcshareddata/xcschemes/NioKit.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CADF662C24614D2300F5063F"
BuildableName = "NioKit.framework"
BlueprintName = "NioKit"
ReferencedContainer = "container:Nio.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CADF662C24614D2300F5063F"
BuildableName = "NioKit.framework"
BlueprintName = "NioKit"
ReferencedContainer = "container:Nio.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
2 changes: 2 additions & 0 deletions Nio/AccountStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Combine
import SwiftMatrixSDK
import KeychainAccess

import NioKit

enum LoginState {
case loggedOut
case authenticating
Expand Down
2 changes: 2 additions & 0 deletions Nio/Conversations/Event Views/EventContainerView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import SwiftUI
import SwiftMatrixSDK

import NioKit

struct EventContainerView: View {
var event: MXEvent
var reactions: [Reaction]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import SwiftUI

import NioKit

struct BorderedMessageView<Model>: View where Model: MessageViewModelProtocol {
@Environment(\.colorScheme) var colorScheme
@Environment(\.colorSchemeContrast) var colorSchemeContrast
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import SwiftUI

import NioKit

struct BorderlessMessageView<Model>: View where Model: MessageViewModelProtocol {
@Environment(\.colorScheme) var colorScheme
@Environment(\.colorSchemeContrast) var colorSchemeContrast
Expand Down
2 changes: 2 additions & 0 deletions Nio/Conversations/Event Views/MessageView/MessageView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import SwiftUI

import NioKit

struct MessageView<Model>: View where Model: MessageViewModelProtocol {
@Environment(\.colorScheme) var colorScheme
@Environment(\.sizeCategory) var sizeCategory: ContentSizeCategory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftMatrixSDK
import NioKit

protocol MessageViewModelProtocol {
var id: String { get }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI
import SwiftMatrixSDK
import NioKit

struct GroupedReactionsView: View {
@Environment(\.colorScheme) var colorScheme: ColorScheme
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import SwiftUI

struct ReactionGroupView: View {
let text: String
let count: Int
public struct ReactionGroupView: View {
public let text: String
public let count: Int

let backgroundColor: Color
public let backgroundColor: Color

public init(text: String, count: Int, backgroundColor: Color) {
assert(count > 0, "Expected non-zero positive integer")
Expand All @@ -14,7 +14,7 @@ struct ReactionGroupView: View {
self.backgroundColor = backgroundColor
}

var body: some View {
public var body: some View {
return HStack(spacing: 1) {
Text(self.text)
Text(String(self.count))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import SwiftUI

import NioKit

struct ReactionsListItemView: View {
@Environment(\.colorScheme) var colorScheme: ColorScheme
@Environment(\.colorSchemeContrast) var colorSchemeContrast: ColorSchemeContrast
Expand Down
2 changes: 2 additions & 0 deletions Nio/Conversations/RecentRoomsView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import SwiftUI
import SwiftMatrixSDK

import NioKit

struct RecentRoomsContainerView: View {
@EnvironmentObject var store: AccountStore
@EnvironmentObject var settings: AppSettings
Expand Down
4 changes: 3 additions & 1 deletion Nio/Conversations/RoomListItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import SwiftUI
import SwiftMatrixSDK
import SDWebImageSwiftUI

import NioKit

struct RoomListItemContainerView: View {
@EnvironmentObject var store: AccountStore

var room: NIORoom
public var room: NIORoom

var body: some View {
let roomName = room.summary.displayname ?? ""
Expand Down
2 changes: 2 additions & 0 deletions Nio/Conversations/RoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Combine
import KeyboardObserving
import SwiftMatrixSDK

import NioKit

struct RoomContainerView: View {
@ObservedObject var room: NIORoom

Expand Down
2 changes: 2 additions & 0 deletions Nio/Conversations/TypingIndicatorView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import SwiftUI

import NioKit

struct TypingIndicatorContainerView: View {
@EnvironmentObject private var room: NIORoom
@Environment(\.userId) var userId
Expand Down
17 changes: 17 additions & 0 deletions Nio/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// String+Extension.swift
// Nio
//
// Created by Vincent Esche on 5/13/20.
// Copyright © 2020 Kilian Koeltzsch. All rights reserved.
//

import Foundation

// FIXME: this seems like it could back-fire,
// encouraging the use of stringly-typed code.
extension String: Identifiable {
public var id: String {
self
}
}
32 changes: 0 additions & 32 deletions Nio/Models/Reaction.swift

This file was deleted.

6 changes: 0 additions & 6 deletions Nio/Shared Views/ReverseList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,3 @@ struct ReverseList_Previews: PreviewProvider {
}
}
}

extension String: Identifiable {
public var id: String {
self
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Combine
import SwiftMatrixSDK

extension MXRestClient {
func nio_publicRooms(onServer: String? = nil, limit: UInt? = nil) -> AnyPublisher<MXPublicRoomsResponse, Error> {
public func nio_publicRooms(onServer: String? = nil, limit: UInt? = nil) -> AnyPublisher<MXPublicRoomsResponse, Error> {
Future<MXPublicRoomsResponse, Error> { promise in
self.publicRooms(onServer: onServer, limit: limit) { response in
switch response {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SwiftMatrixSDK
import KeychainAccess

extension MXCredentials {
func save(to keychain: Keychain) {
public func save(to keychain: Keychain) {
guard
let homeserver = self.homeServer,
let userId = self.userId,
Expand All @@ -17,14 +17,14 @@ extension MXCredentials {
keychain["deviceId"] = deviceId
}

func clear(from keychain: Keychain) {
public func clear(from keychain: Keychain) {
keychain["homeserver"] = nil
keychain["userId"] = nil
keychain["accessToken"] = nil
keychain["deviceId"] = nil
}

static func from(_ keychain: Keychain) -> MXCredentials? {
public static func from(_ keychain: Keychain) -> MXCredentials? {
guard
let homeserver = keychain["homeserver"],
let userId = keychain["userId"],
Expand All @@ -33,7 +33,11 @@ extension MXCredentials {
else {
return nil
}
let credentials = MXCredentials(homeServer: homeserver, userId: userId, accessToken: accessToken)
let credentials = MXCredentials(
homeServer: homeserver,
userId: userId,
accessToken: accessToken
)
credentials.deviceId = deviceId
return credentials
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import Foundation
import SwiftMatrixSDK

extension MXEvent {
var timestamp: Date {
public var timestamp: Date {
Date(timeIntervalSince1970: TimeInterval(self.originServerTs / 1000))
}

func content<T>(valueFor key: String) -> T? {
public func content<T>(valueFor key: String) -> T? {
if let value = self.content?[key] as? T {
return value
}
return nil
}

func prevContent<T>(valueFor key: String) -> T? {
public func prevContent<T>(valueFor key: String) -> T? {
if let value = self.unsignedData?.prevContent?[key] as? T {
return value
}
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions NioKit/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

//extension String: Identifiable {
// public var id: String {
// self
// }
//}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation
import SwiftMatrixSDK

struct EventCollection {
var wrapped: [MXEvent]
public struct EventCollection {
internal var wrapped: [MXEvent]

init(_ events: [MXEvent]) {
public init(_ events: [MXEvent]) {
self.wrapped = events
}

Expand All @@ -18,15 +18,15 @@ struct EventCollection {

/// Events that can be directly rendered in the timeline with a corresponding view. This for example does not
/// include reactions, which are instead rendered as accessories on their corresponding related events.
var renderableEvents: [MXEvent] {
public var renderableEvents: [MXEvent] {
wrapped.filter { Self.renderableEventTypes.contains($0.type) }
}

func relatedEvents(of event: MXEvent) -> [MXEvent] {
public func relatedEvents(of event: MXEvent) -> [MXEvent] {
wrapped.filter { $0.relatesTo?.eventId == event.eventId }
}

func reactions(for event: MXEvent) -> [Reaction] {
public func reactions(for event: MXEvent) -> [Reaction] {
relatedEvents(of: event)
.filter { $0.type == kMXEventTypeStringReaction }
.compactMap { event in
Expand All @@ -52,11 +52,11 @@ struct EventCollection {
// MARK: Grouping

extension EventCollection {
static let groupableEventTypes = [
public static let groupableEventTypes = [
kMXEventTypeStringRoomMessage,
]

func connectedEdges(of event: MXEvent) -> ConnectedEdges {
public func connectedEdges(of event: MXEvent) -> ConnectedEdges {
guard let idx = wrapped.firstIndex(of: event) else {
fatalError("Event not found in event collection.")
}
Expand Down Expand Up @@ -108,9 +108,13 @@ extension EventCollection {
}
}

struct ConnectedEdges: OptionSet {
let rawValue: Int
public struct ConnectedEdges: OptionSet {
public let rawValue: Int

static let topEdge: Self = .init(rawValue: 1 << 0)
static let bottomEdge: Self = .init(rawValue: 1 << 1)
public static let topEdge: Self = .init(rawValue: 1 << 0)
public static let bottomEdge: Self = .init(rawValue: 1 << 1)

public init(rawValue: Int) {
self.rawValue = rawValue
}
}
Loading

0 comments on commit 3b67277

Please sign in to comment.