Skip to content

Commit

Permalink
convert init in extension to factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
billypchan committed May 31, 2021
1 parent 576aba7 commit 89277d8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Source/Model/Message/ZMClientMessage+LinkPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ extension ZMClientMessage: ZMImageOwner {

let text = Text.with {
$0.content = textMessageData.messageText ?? ""
$0.mentions = textMessageData.mentions.compactMap { WireProtos.Mention($0) }
$0.mentions = textMessageData.mentions.compactMap { WireProtos.Mention.createMention($0) }
$0.linkPreview = [linkPreview]
}

Expand Down
10 changes: 5 additions & 5 deletions Source/Utilis/Protos/GenericMessage+Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ extension Text {
public init(content: String, mentions: [Mention] = [], linkPreviews: [LinkMetadata] = [], replyingTo: ZMOTRMessage? = nil) {
self = Text.with {
$0.content = content
$0.mentions = mentions.compactMap { WireProtos.Mention($0) }
$0.mentions = mentions.compactMap { WireProtos.Mention.createMention($0) }
$0.linkPreview = linkPreviews.map { WireProtos.LinkPreview($0) }

if let quotedMessage = replyingTo,
Expand Down Expand Up @@ -517,10 +517,10 @@ extension External {
// MARK: - Mention

public extension WireProtos.Mention {
init?(_ mention: WireDataModel.Mention) {
static func createMention(_ mention: WireDataModel.Mention) -> WireProtos.Mention? {
guard let userID = (mention.user as? ZMUser)?.remoteIdentifier.transportString() else { return nil }

self = WireProtos.Mention.with {
return WireProtos.Mention.with {
$0.start = Int32(mention.range.location)
$0.length = Int32(mention.range.length)
$0.userID = userID
Expand All @@ -531,8 +531,8 @@ public extension WireProtos.Mention {
// MARK: - Availability

extension WireProtos.Availability {
public init(_ availability: Availability) {
self = WireProtos.Availability.with {
public static func createAvailability(_ availability: Availability) -> WireProtos.Availability {
return WireProtos.Availability.with {
switch availability {
case .none:
$0.type = .none
Expand Down
2 changes: 1 addition & 1 deletion Tests/Source/Model/Messages/GenericMessageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GenericMessageTests: XCTestCase {
{ return GenericMessage(content: Location(latitude: 1, longitude: 2)) },
{ return GenericMessage(content: MessageDelete(messageId: UUID.create())) },
{ return GenericMessage(content: WireProtos.Reaction.createReaction(emoji: "test", messageID: UUID.create())) },
{ return GenericMessage(content: WireProtos.Availability(.away)) }
{ return GenericMessage(content: WireProtos.Availability.createAvailability(.away)) }
]

generators.forEach { generator in
Expand Down
2 changes: 1 addition & 1 deletion Tests/Source/Model/Messages/ZMClientMessageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ extension ClientMessageTests {
let senderClientID = NSString.createAlphanumerical()
let conversation = ZMConversation.insertNewObject(in: self.uiMOC)
conversation.remoteIdentifier = UUID.create()
let availability = WireProtos.Availability(.away)
let availability = WireProtos.Availability.createAvailability(.away)
let contentData = try? GenericMessage(content: availability, nonce: UUID.create()).serializedData()
let data: NSDictionary = [
"sender": senderClientID,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Source/Model/User/ZMUserTests+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ extension ZMUserTests_Swift {
// given
let user = ZMUser.insert(in: self.uiMOC, name: "Foo")
XCTAssertEqual(user.availability, .none)
let availability = WireProtos.Availability(.away)
let availability = WireProtos.Availability.createAvailability(.away)
// when
user.updateAvailability(from: GenericMessage(content: availability))

Expand Down

0 comments on commit 89277d8

Please sign in to comment.