Cleanup, documentation and ui tests.

This commit is contained in:
David Langley
2021-09-20 08:47:28 +01:00
parent 39409f49b4
commit 205bc35285
46 changed files with 414 additions and 194 deletions
@@ -0,0 +1,26 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
/// Represents a grouped bubble in the View(For example multiple message of different time sent close together).
struct TemplateRoomChatBubble {
let id: String
let sender: TemplateRoomChatMember
var items: [TemplateRoomChatBubbleItem]
}
extension TemplateRoomChatBubble: Identifiable { }
@@ -0,0 +1,22 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import UIKit
/// An image sent as a message.
struct TemplateRoomChatMessageImageContent {
var image: UIImage
}
@@ -16,15 +16,7 @@
import UIKit
struct TemplateRoomChatBubble {
let id: String
let sender: TemplateRoomChatMember
var items: [TemplateRoomChatBubbleItem]
}
extension TemplateRoomChatBubble: Identifiable { }
/// One of the items grouped within a bubble(could be message types like text, image or video, or could be other items like url previews).
struct TemplateRoomChatBubbleItem {
let id: String
var timestamp: Date
@@ -33,15 +25,4 @@ struct TemplateRoomChatBubbleItem {
extension TemplateRoomChatBubbleItem: Identifiable { }
enum TemplateRoomChatBubbleItemContent {
case message(TemplateRoomChatBubbleMessageContent)
case image(TemplateRoomChatBubbleImageContent)
}
struct TemplateRoomChatBubbleMessageContent {
var body: String
}
struct TemplateRoomChatBubbleImageContent {
var image: UIImage
}
@@ -16,6 +16,6 @@
import Foundation
enum TemplateRoomChatViewModelResult {
case done
enum TemplateRoomChatBubbleItemContent {
case message(TemplateRoomChatMessageContent)
}
@@ -16,15 +16,7 @@
import Foundation
struct TemplateRoomChatMessage {
let id: String
let body: String
let sender: TemplateRoomChatMember
let timestamp: Date
}
extension TemplateRoomChatMessage: Identifiable {}
/// A user who is a member of the room.
struct TemplateRoomChatMember {
let id: String
let avatarUrl: String?
@@ -0,0 +1,27 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
/// A chat message send to the timeline within a room.
struct TemplateRoomChatMessage {
let id: String
let content: TemplateRoomChatMessageContent
let sender: TemplateRoomChatMember
let timestamp: Date
}
extension TemplateRoomChatMessage: Identifiable {}
@@ -0,0 +1,23 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
/// The type of message a long with it's content.
enum TemplateRoomChatMessageContent {
case text(TemplateRoomChatMessageTextContent)
case image(TemplateRoomChatMessageImageContent)
}
@@ -0,0 +1,22 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
/// The text content of a message sent by a user.
struct TemplateRoomChatMessageTextContent {
var body: String
}
@@ -0,0 +1,23 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
enum TemplateRoomChatRoomInitializationStatus {
case notInitialized
case initialized
case failedToInitialize
}
@@ -16,7 +16,9 @@
import Foundation
/// Actions to be performed on the `ViewModel` State
enum TemplateRoomChatStateAction {
case clearMessageInput
case updateRoomInitializationStatus(TemplateRoomChatRoomInitializationStatus)
case updateBubbles([TemplateRoomChatBubble])
case clearMessageInput
}
@@ -16,6 +16,7 @@
import Foundation
/// Actions send from the `View` to the `ViewModel`.
enum TemplateRoomChatViewAction {
case sendMessage
case done
@@ -0,0 +1,22 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
/// Actions sent by the `ViewModel` to the `Coordinator`
enum TemplateRoomChatViewModelAction {
case done
}
@@ -16,6 +16,7 @@
import Foundation
/// State bound directly to SwiftUI elements.
struct TemplateRoomChatViewModelBindings {
var messageInput: String
}
@@ -16,7 +16,9 @@
import Foundation
/// State managed by the `ViewModel` delivered to the `View`.
struct TemplateRoomChatViewState: BindableState {
var roomInitializationStatus: TemplateRoomChatRoomInitializationStatus
let roomName: String?
var bubbles: [TemplateRoomChatBubble]
var bindings: TemplateRoomChatViewModelBindings