Skip to content
Snippets Groups Projects

Messenger example - chat

Merged Dariusz Rybicki requested to merge feature/messenger-example-chat into development
2 files
+ 52
2
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -39,12 +39,14 @@ public struct ChatState: Equatable, Identifiable {
@@ -39,12 +39,14 @@ public struct ChatState: Equatable, Identifiable {
myContactId: Data? = nil,
myContactId: Data? = nil,
messages: IdentifiedArrayOf<Message> = [],
messages: IdentifiedArrayOf<Message> = [],
failure: String? = nil,
failure: String? = nil,
 
sendFailure: String? = nil,
text: String = ""
text: String = ""
) {
) {
self.id = id
self.id = id
self.myContactId = myContactId
self.myContactId = myContactId
self.messages = messages
self.messages = messages
self.failure = failure
self.failure = failure
 
self.sendFailure = sendFailure
self.text = text
self.text = text
}
}
@@ -52,6 +54,7 @@ public struct ChatState: Equatable, Identifiable {
@@ -52,6 +54,7 @@ public struct ChatState: Equatable, Identifiable {
public var myContactId: Data?
public var myContactId: Data?
public var messages: IdentifiedArrayOf<Message>
public var messages: IdentifiedArrayOf<Message>
public var failure: String?
public var failure: String?
 
public var sendFailure: String?
@BindableState public var text: String
@BindableState public var text: String
}
}
@@ -59,6 +62,8 @@ public enum ChatAction: Equatable, BindableAction {
@@ -59,6 +62,8 @@ public enum ChatAction: Equatable, BindableAction {
case start
case start
case didFetchMessages(IdentifiedArrayOf<ChatState.Message>)
case didFetchMessages(IdentifiedArrayOf<ChatState.Message>)
case sendTapped
case sendTapped
 
case sendFailed(String)
 
case dismissSendFailureTapped
case binding(BindingAction<ChatState>)
case binding(BindingAction<ChatState>)
}
}
@@ -152,8 +157,7 @@ public let chatReducer = Reducer<ChatState, ChatAction, ChatEnvironment>
@@ -152,8 +157,7 @@ public let chatReducer = Reducer<ChatState, ChatAction, ChatEnvironment>
text: text,
text: text,
to: recipientId,
to: recipientId,
onError: { error in
onError: { error in
// TODO: handle error
subscriber.send(.sendFailed(error.localizedDescription))
print("^^^ ERROR: \(error)")
},
},
completion: {
completion: {
subscriber.send(completion: .finished)
subscriber.send(completion: .finished)
@@ -166,6 +170,14 @@ public let chatReducer = Reducer<ChatState, ChatAction, ChatEnvironment>
@@ -166,6 +170,14 @@ public let chatReducer = Reducer<ChatState, ChatAction, ChatEnvironment>
.receive(on: env.mainQueue)
.receive(on: env.mainQueue)
.eraseToEffect()
.eraseToEffect()
 
case .sendFailed(let failure):
 
state.sendFailure = failure
 
return .none
 
 
case .dismissSendFailureTapped:
 
state.sendFailure = nil
 
return .none
 
case .binding(_):
case .binding(_):
return .none
return .none
}
}
Loading