Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement features from prose-core-views 0.4.0...0.9.0 #88

Merged
merged 13 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ XCBEAUTIFY:
# ################ Web Views ################

VIEWS_LIB_URL=https://github.com/prose-im/prose-core-views
VIEWS_LIB_VERSION=0.9.0
VIEWS_LIB_VERSION=0.9.2
VIEWS_ARCHIVE_NAME=release-${VIEWS_LIB_VERSION}.tar.gz
DESTINATION=Prose/ProseLib/Sources/ConversationFeature/Resources/Views

Expand Down
57 changes: 51 additions & 6 deletions Prose/ConversationFeaturePreview/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import Combine
import ComposableArchitecture
import ConversationFeature
import IdentifiedCollections
import ProseCoreTCA
import SwiftUI
import Toolbox
Expand All @@ -14,17 +15,49 @@ struct ContentView: View {
let store: Store<ConversationState, ConversationAction>

init() {
let jid: JID = "[email protected]"
let chatId: JID = "[email protected]"
var client = ProseClient.noop

let chatSubject = CurrentValueSubject<[Message], Never>([])
let chatSubject = CurrentValueSubject<IdentifiedArrayOf<Message>, Never>([
Message(
from: chatId,
id: .init(rawValue: UUID().uuidString),
kind: .normal,
body: "Hello preview 👋",
timestamp: .now - 200,
isRead: true,
isEdited: true,
reactions: ["👋": [jid]]
),
Message(
from: jid,
id: .init(rawValue: UUID().uuidString),
kind: .normal,
body: "Hi!",
timestamp: .now - 12,
isRead: true,
isEdited: false,
reactions: ["😃": [chatId]]
),
Message(
from: jid,
id: .init(rawValue: UUID().uuidString),
kind: .normal,
body: "How are you?",
timestamp: .now - 10,
isRead: true,
isEdited: false
),
])

client.sendMessage = { jid, body in
client.sendMessage = { _, body in
.fireAndForget {
chatSubject.value.append(
.init(
from: jid,
id: .init(rawValue: UUID().uuidString),
kind: nil,
kind: .chat,
body: body,
timestamp: Date(),
isRead: true,
Expand All @@ -33,17 +66,29 @@ struct ContentView: View {
)
}
}
client.addReaction = { _, messageId, reaction in
chatSubject.value[id: messageId]?.reactions.addReaction(reaction, for: jid)
return Just(.none).setFailureType(to: EquatableError.self).eraseToEffect()
}
client.toggleReaction = { _, messageId, reaction in
chatSubject.value[id: messageId]?.reactions.toggleReaction(reaction, for: jid)
return Just(.none).setFailureType(to: EquatableError.self).eraseToEffect()
}
client.retractMessage = { messageId in
// TODO: Send an error if message is not found?
chatSubject.value.remove(id: messageId)
return Just(.none).setFailureType(to: EquatableError.self).eraseToEffect()
}
client.messagesInChat = { _ in
chatSubject.setFailureType(to: EquatableError.self).eraseToEffect()
}

self.store = Store(
initialState: ConversationState(
chatId: "[email protected]"
),
initialState: ConversationState(chatId: chatId, loggedInUserJID: jid),
reducer: conversationReducer,
environment: ConversationEnvironment(
proseClient: client,
pasteboard: .live(),
mainQueue: .main
)
)
Expand Down
4 changes: 3 additions & 1 deletion Prose/ProseLib/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ let package = Package(
.target(
name: "ConversationFeature",
dependencies: [
"ConversationInfoFeature",
.featureBase,
"ConversationInfoFeature",
"PasteboardClient",
],
resources: [.process("Resources")]
),
Expand Down Expand Up @@ -109,6 +110,7 @@ let package = Package(

.target(name: "UserDefaultsClient", dependencies: [.base]),
.target(name: "NotificationsClient", dependencies: [.base]),
.target(name: "PasteboardClient", dependencies: [.base]),

.target(
name: "FeatureBase",
Expand Down
11 changes: 10 additions & 1 deletion Prose/ProseLib/Sources/App/AppEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CredentialsClient
import Foundation
import MainWindowFeature
import NotificationsClient
import PasteboardClient
import ProseCore
import struct ProseCoreTCA.ProseClient
import Toolbox
Expand All @@ -27,6 +28,7 @@ public struct AppEnvironment {
public var credentials: CredentialsClient

public var proseClient: ProseClient
public var pasteboard: PasteboardClient
public var notifications: NotificationsClient

public var mainQueue: AnySchedulerOf<DispatchQueue>
Expand All @@ -37,13 +39,15 @@ public struct AppEnvironment {
userDefaults: UserDefaultsClient,
credentials: CredentialsClient,
proseClient: ProseClient,
pasteboard: PasteboardClient,
notifications: NotificationsClient,
mainQueue: AnySchedulerOf<DispatchQueue>,
openURL: @escaping (URL, OpenURLConfiguration) -> Effect<Void, URLOpeningError>
) {
self.userDefaults = userDefaults
self.credentials = credentials
self.proseClient = proseClient
self.pasteboard = pasteboard
self.notifications = notifications
self.mainQueue = mainQueue
self.openURL = openURL
Expand All @@ -56,6 +60,7 @@ public extension AppEnvironment {
userDefaults: .live(.standard),
credentials: .live(service: "org.prose.app"),
proseClient: .live(provider: ProseCore.ProseClient.init),
pasteboard: .live(),
notifications: .live,
mainQueue: .main,
openURL: { url, openConfig -> Effect<Void, URLOpeningError> in
Expand Down Expand Up @@ -87,6 +92,10 @@ extension AppEnvironment {
}

var main: MainScreenEnvironment {
MainScreenEnvironment(proseClient: self.proseClient, mainQueue: self.mainQueue)
MainScreenEnvironment(
proseClient: self.proseClient,
pasteboard: self.pasteboard,
mainQueue: self.mainQueue
)
}
}
Loading