Skip to content

Commit 054971d

Browse files
committed
convenient access to text content
1 parent 097d34d commit 054971d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/Converse/Message.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ public struct Message: Codable, CustomStringConvertible, Sendable {
124124
public func hasTextContent() -> Bool {
125125
content.contains { $0.isText() }
126126
}
127+
public func textContent() -> String? {
128+
let content = content.first(where: { $0.isText() })
129+
if case .text(let text) = content {
130+
return text
131+
} else {
132+
return nil
133+
}
134+
}
135+
127136
public func hasImageContent() -> Bool {
128137
content.contains { $0.isImage() }
129138
}

0 commit comments

Comments
 (0)