Skip to content

Commit

Permalink
Merge pull request #430 from zapcannon87/master
Browse files Browse the repository at this point in the history
fix: create unique conversation and return existing
  • Loading branch information
zapcannon87 authored Jul 27, 2021
2 parents 10aa7fe + aec3aeb commit 5789d46
Show file tree
Hide file tree
Showing 6 changed files with 910 additions and 377 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17.9.0
17.9.1
2 changes: 1 addition & 1 deletion LeanCloud.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'LeanCloud'
s.version = '17.9.0'
s.version = '17.9.1'
s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' }
s.summary = 'LeanCloud Swift SDK'
s.homepage = 'https://leancloud.cn/'
Expand Down
71 changes: 35 additions & 36 deletions LeanCloudTests/IMConversationTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,56 +208,55 @@ class IMConversationTestCase: RTMBaseTestCase {
break
}
}
try? clientA.createConversation(clientIDs: [clientA.ID, clientB.ID], completion: { (result) in
if let conv: IMConversation = result.value {
XCTAssertTrue(type(of: conv) == IMConversation.self)
XCTAssertEqual(conv.rawData["objectId"] as? String, conv.ID)
XCTAssertEqual(conv.rawData["conv_type"] as? Int, 1)
XCTAssertEqual(conv.convType, .normal)
XCTAssertTrue(conv.isUnique)
XCTAssertNotNil(conv.uniqueID)
} else {
XCTFail()
}
exp1.fulfill()
})
let existingKey = "existingKey"
let existingValue = "existingValue"
try? clientA.createConversation(
clientIDs: [clientA.ID, clientB.ID],
attributes: [existingKey : existingValue],
completion: { (result) in
if let conv: IMConversation = result.value {
XCTAssertTrue(type(of: conv) == IMConversation.self)
XCTAssertEqual(conv.rawData["objectId"] as? String, conv.ID)
XCTAssertEqual(conv.rawData["conv_type"] as? Int, 1)
XCTAssertEqual(conv.convType, .normal)
XCTAssertTrue(conv.isUnique)
XCTAssertNotNil(conv.uniqueID)
XCTAssertFalse(conv.isOutdated)
XCTAssertEqual(conv.attributes?[existingKey] as? String, existingValue)
} else {
XCTFail()
}
exp1.fulfill()
})
wait(for: [exp1], timeout: timeout)

delegatorA.conversationEvent = nil
delegatorB.conversationEvent = nil

let exp2 = expectation(description: "create unique conversation")
exp2.expectedFulfillmentCount = 5
delegatorA.conversationEvent = { _, _, event in
switch event {
case .joined:
exp2.fulfill()
case .membersJoined:
exp2.fulfill()
default:
break
}
}
delegatorB.conversationEvent = { _, _, event in
switch event {
case .joined:
exp2.fulfill()
case .membersJoined:
exp2.fulfill()
default:
break
}
}
delay(seconds: 5)

clientB.convCollection.removeAll()

let exp2 = expectation(description: "recreate unique conversation")
try? clientB.createConversation(clientIDs: [clientA.ID, clientB.ID], completion: { (result) in
if let conv: IMConversation = result.value {
XCTAssertTrue(type(of: conv) == IMConversation.self)
XCTAssertEqual(conv.convType, .normal)
XCTAssertTrue(conv.isUnique)
XCTAssertNotNil(conv.uniqueID)
XCTAssertTrue(conv.isOutdated)
XCTAssertNil(conv.attributes?[existingKey])
try? conv.refresh { result in
XCTAssertTrue(result.isSuccess)
XCTAssertNil(result.error)
XCTAssertFalse(conv.isOutdated)
XCTAssertEqual(conv.attributes?[existingKey] as? String, existingValue)
exp2.fulfill()
}
} else {
XCTFail()
exp2.fulfill()
}
exp2.fulfill()
})
wait(for: [exp2], timeout: timeout)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Foundation/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
import Foundation

public struct Version {
public static let versionString = "17.9.0"
public static let versionString = "17.9.1"
}
Loading

0 comments on commit 5789d46

Please sign in to comment.