Skip to content

Commit 39986f0

Browse files
committed
Renamed MessageData to MessageKind
1 parent ccd6cac commit 39986f0

16 files changed

Lines changed: 55 additions & 53 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ classes that are responsible for sizing the `MessagesCollectionViewCell` types p
4747

4848
### Changed
4949

50+
- **Breaking Change** Renamed `MessageData` enum to `MessageKind` and changed `MessageType`'s `data` property name to `kind`.
51+
[#658](https://github.com/MessageKit/MessageKit/658) by [@zhongwuzw](https://github.com/zhongwuzw).
52+
5053
- **Breaking Change** Changed the `messageFooterView(for:in)` and `messageHeaderView(for:in)` methods of
5154
`MessagesDisplayDelegate` by removing the `message` parameter.
5255
[#615](https://github.com/MessageKit/MessageKit/pull/615) by [@SD10](https://github.com/sd10).

Example/Sources/MockMessage.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,40 +58,40 @@ internal struct MockMessage: MessageType {
5858
var messageId: String
5959
var sender: Sender
6060
var sentDate: Date
61-
var data: MessageData
61+
var kind: MessageKind
6262

63-
private init(data: MessageData, sender: Sender, messageId: String, date: Date) {
64-
self.data = data
63+
private init(kind: MessageKind, sender: Sender, messageId: String, date: Date) {
64+
self.kind = kind
6565
self.sender = sender
6666
self.messageId = messageId
6767
self.sentDate = date
6868
}
6969

7070
init(text: String, sender: Sender, messageId: String, date: Date) {
71-
self.init(data: .text(text), sender: sender, messageId: messageId, date: date)
71+
self.init(kind: .text(text), sender: sender, messageId: messageId, date: date)
7272
}
7373

7474
init(attributedText: NSAttributedString, sender: Sender, messageId: String, date: Date) {
75-
self.init(data: .attributedText(attributedText), sender: sender, messageId: messageId, date: date)
75+
self.init(kind: .attributedText(attributedText), sender: sender, messageId: messageId, date: date)
7676
}
7777

7878
init(image: UIImage, sender: Sender, messageId: String, date: Date) {
7979
let mediaItem = MockMediaItem(image: image)
80-
self.init(data: .photo(mediaItem), sender: sender, messageId: messageId, date: date)
80+
self.init(kind: .photo(mediaItem), sender: sender, messageId: messageId, date: date)
8181
}
8282

8383
init(thumbnail: UIImage, sender: Sender, messageId: String, date: Date) {
8484
let mediaItem = MockMediaItem(image: thumbnail)
85-
self.init(data: .video(mediaItem), sender: sender, messageId: messageId, date: date)
85+
self.init(kind: .video(mediaItem), sender: sender, messageId: messageId, date: date)
8686
}
8787

8888
init(location: CLLocation, sender: Sender, messageId: String, date: Date) {
8989
let locationItem = MockLocationItem(location: location)
90-
self.init(data: .location(locationItem), sender: sender, messageId: messageId, date: date)
90+
self.init(kind: .location(locationItem), sender: sender, messageId: messageId, date: date)
9191
}
9292

9393
init(emoji: String, sender: Sender, messageId: String, date: Date) {
94-
self.init(data: .emoji(emoji), sender: sender, messageId: messageId, date: date)
94+
self.init(kind: .emoji(emoji), sender: sender, messageId: messageId, date: date)
9595
}
9696

9797
}

MessageKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
B7A03F2A1F866895006AEF79 /* MessageStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A03F1F1F866895006AEF79 /* MessageStyle.swift */; };
6060
B7A03F2C1F866895006AEF79 /* DetectorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A03F211F866895006AEF79 /* DetectorType.swift */; };
6161
B7A03F2D1F866895006AEF79 /* LabelAlignment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A03F221F866895006AEF79 /* LabelAlignment.swift */; };
62-
B7A03F2E1F866895006AEF79 /* MessageData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A03F231F866895006AEF79 /* MessageData.swift */; };
62+
B7A03F2E1F866895006AEF79 /* MessageKind.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A03F231F866895006AEF79 /* MessageKind.swift */; };
6363
B7A03F331F866940006AEF79 /* MessageDateHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A03F301F866940006AEF79 /* MessageDateHeaderView.swift */; };
6464
B7A03F3A1F866946006AEF79 /* TextMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A03F361F866946006AEF79 /* TextMessageCell.swift */; };
6565
B7A03F3C1F866946006AEF79 /* LocationMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A03F381F866946006AEF79 /* LocationMessageCell.swift */; };
@@ -167,7 +167,7 @@
167167
B7A03F1F1F866895006AEF79 /* MessageStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageStyle.swift; sourceTree = "<group>"; };
168168
B7A03F211F866895006AEF79 /* DetectorType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetectorType.swift; sourceTree = "<group>"; };
169169
B7A03F221F866895006AEF79 /* LabelAlignment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelAlignment.swift; sourceTree = "<group>"; };
170-
B7A03F231F866895006AEF79 /* MessageData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageData.swift; sourceTree = "<group>"; };
170+
B7A03F231F866895006AEF79 /* MessageKind.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageKind.swift; sourceTree = "<group>"; };
171171
B7A03F301F866940006AEF79 /* MessageDateHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageDateHeaderView.swift; sourceTree = "<group>"; };
172172
B7A03F361F866946006AEF79 /* TextMessageCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextMessageCell.swift; sourceTree = "<group>"; };
173173
B7A03F381F866946006AEF79 /* LocationMessageCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationMessageCell.swift; sourceTree = "<group>"; };
@@ -389,7 +389,7 @@
389389
B7A03F211F866895006AEF79 /* DetectorType.swift */,
390390
B7A03F221F866895006AEF79 /* LabelAlignment.swift */,
391391
B7A03F1D1F866895006AEF79 /* LocationMessageSnapshotOptions.swift */,
392-
B7A03F231F866895006AEF79 /* MessageData.swift */,
392+
B7A03F231F866895006AEF79 /* MessageKind.swift */,
393393
1FF377A320087C82004FD648 /* MessageKitError.swift */,
394394
B7A03F1B1F866895006AEF79 /* MessageKitDateFormatter.swift */,
395395
B7A03F1F1F866895006AEF79 /* MessageStyle.swift */,
@@ -619,7 +619,7 @@
619619
B7A03F3D1F866946006AEF79 /* MediaMessageCell.swift in Sources */,
620620
1FE783A220662905007FA024 /* TextMessageSizeCalculator.swift in Sources */,
621621
B7A03F331F866940006AEF79 /* MessageDateHeaderView.swift in Sources */,
622-
B7A03F2E1F866895006AEF79 /* MessageData.swift in Sources */,
622+
B7A03F2E1F866895006AEF79 /* MessageKind.swift in Sources */,
623623
B7A03F7B1F866B85006AEF79 /* MessageCollectionViewCell.swift in Sources */,
624624
B7A03F6B1F8669EB006AEF79 /* UIColor+Extensions.swift in Sources */,
625625
B7A03F5E1F8669CA006AEF79 /* MessagesLayoutDelegate.swift in Sources */,
@@ -641,7 +641,6 @@
641641
B7A03F2A1F866895006AEF79 /* MessageStyle.swift in Sources */,
642642
B7A03F4D1F86694F006AEF79 /* MessagesCollectionView.swift in Sources */,
643643
0EF0888C206F7E83007F2F58 /* CellSizeCalculator.swift in Sources */,
644-
B7A03F351F866940006AEF79 /* MessageHeaderView.swift in Sources */,
645644
1FE783A4206629A5007FA024 /* MediaMessageSizeCalculator.swift in Sources */,
646645
B7A03F731F866A06006AEF79 /* MessageKit+Availability.swift in Sources */,
647646
1FE7839E20662835007FA024 /* MessageSizeCalculator.swift in Sources */,

Sources/Controllers/MessagesViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
174174

175175
let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)
176176

177-
switch message.data {
177+
switch message.kind {
178178
case .text, .attributedText, .emoji:
179179
let cell = messagesCollectionView.dequeueReusableCell(TextMessageCell.self, for: indexPath)
180180
cell.configure(with: message, at: indexPath, and: messagesCollectionView)
@@ -244,7 +244,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
244244
guard let messagesDataSource = messagesCollectionView.messagesDataSource else { return false }
245245
let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)
246246

247-
switch message.data {
247+
switch message.kind {
248248
case .text, .attributedText, .emoji, .photo:
249249
selectedIndexPathForMenu = indexPath
250250
return true
@@ -264,7 +264,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
264264
let pasteBoard = UIPasteboard.general
265265
let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)
266266

267-
switch message.data {
267+
switch message.kind {
268268
case .text(let text), .emoji(let text):
269269
pasteBoard.string = text
270270
case .attributedText(let attributedText):

Sources/Layout/LocationMessageSizeCalculator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Foundation
2727
open class LocationMessageSizeCalculator: MessageSizeCalculator {
2828

2929
open override func messageContainerSize(for message: MessageType) -> CGSize {
30-
switch message.data {
30+
switch message.kind {
3131
case .location(let item):
3232
let maxWidth = messageContainerMaxWidth(for: message)
3333
if maxWidth < item.size.width {
@@ -37,7 +37,7 @@ open class LocationMessageSizeCalculator: MessageSizeCalculator {
3737
}
3838
return item.size
3939
default:
40-
fatalError("messageContainerSize received unhandled MessageDataType: \(message.data)")
40+
fatalError("messageContainerSize received unhandled MessageDataType: \(message.kind)")
4141
}
4242
}
4343
}

Sources/Layout/MediaMessageSizeCalculator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ open class MediaMessageSizeCalculator: MessageSizeCalculator {
3636
}
3737
return item.size
3838
}
39-
switch message.data {
39+
switch message.kind {
4040
case .photo(let item):
4141
return sizeForMediaItem(maxWidth, item)
4242
case .video(let item):
4343
return sizeForMediaItem(maxWidth, item)
4444
default:
45-
fatalError("messageContainerSize received unhandled MessageDataType: \(message.data)")
45+
fatalError("messageContainerSize received unhandled MessageDataType: \(message.kind)")
4646
}
4747
}
4848
}

Sources/Layout/MessagesCollectionViewFlowLayout.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout {
133133

134134
open func cellSizeCalculatorForItem(at indexPath: IndexPath) -> CellSizeCalculator {
135135
let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)
136-
switch message.data {
136+
switch message.kind {
137137
case .text:
138138
return textMessageSizeCalculator
139139
case .attributedText:
@@ -147,7 +147,7 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout {
147147
case .location:
148148
return locationMessageSizeCalculator
149149
case .custom:
150-
fatalError("Must return a CellSizeCalculator for MessageData.custom(Any?)")
150+
fatalError("Must return a CellSizeCalculator for MessageKind.custom(Any?)")
151151
}
152152
}
153153

Sources/Layout/TextMessageSizeCalculator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ open class TextMessageSizeCalculator: MessageSizeCalculator {
4949
var messageContainerSize: CGSize
5050
let attributedText: NSAttributedString
5151

52-
switch message.data {
52+
switch message.kind {
5353
case .attributedText(let text):
5454
attributedText = text
5555
case .text(let text), .emoji(let text):
5656
attributedText = NSAttributedString(string: text, attributes: [.font: messageLabelFont])
5757
default:
58-
fatalError("messageContainerSize received unhandled MessageDataType: \(message.data)")
58+
fatalError("messageContainerSize received unhandled MessageDataType: \(message.kind)")
5959
}
6060

6161
messageContainerSize = labelSize(for: attributedText, considering: maxWidth)
@@ -78,7 +78,7 @@ open class TextMessageSizeCalculator: MessageSizeCalculator {
7878
attributes.messageLabelInsets = messageLabelInsets(for: message)
7979
attributes.messageLabelFont = messageLabelFont
8080

81-
switch message.data {
81+
switch message.kind {
8282
case .attributedText(let text):
8383
guard !text.string.isEmpty else { return }
8484
guard let font = text.attribute(.font, at: 0, effectiveRange: nil) as? UIFont else { return }
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
import Foundation
2626

27-
/// An enum representing the kind of message and its underlying data.
28-
public enum MessageData {
27+
/// An enum representing the kind of message and its underlying kind.
28+
public enum MessageKind {
2929

3030
/// A standard text message.
3131
///
3232
/// - Note: The font used for this message will be the value of the
3333
/// `messageLabelFont` property in the `MessagesCollectionViewFlowLayout` object.
3434
///
35-
/// Using `MessageData.attributedText(NSAttributedString)` doesn't require you
35+
/// Using `MessageKind.attributedText(NSAttributedString)` doesn't require you
3636
/// to set this property and results in higher performance.
3737
case text(String)
3838

Sources/Models/MessageKitError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ internal enum MessageKitError {
3333
internal static let unrecognizedCheckingResult = "Received an unrecognized NSTextCheckingResult.CheckingType"
3434
internal static let couldNotLoadAssetsBundle = "MessageKit: Could not load the assets bundle"
3535
internal static let couldNotCreateAssetsPath = "MessageKit: Could not create path to the assets bundle."
36-
internal static let customDataUnresolvedCell = "Did not return a cell for MessageData.custom(Any)."
37-
internal static let customDataUnresolvedSize = "Did not return a size for MessageData.custom(Any)."
36+
internal static let customDataUnresolvedCell = "Did not return a cell for MessageKind.custom(Any)."
37+
internal static let customDataUnresolvedSize = "Did not return a size for MessageKind.custom(Any)."
3838
}

0 commit comments

Comments
 (0)