Skip to content

Commit 5789d46

Browse files
authored
Merge pull request #430 from zapcannon87/master
fix: create unique conversation and return existing
2 parents 10aa7fe + aec3aeb commit 5789d46

File tree

6 files changed

+910
-377
lines changed

6 files changed

+910
-377
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
17.9.0
1+
17.9.1

LeanCloud.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'LeanCloud'
3-
s.version = '17.9.0'
3+
s.version = '17.9.1'
44
s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' }
55
s.summary = 'LeanCloud Swift SDK'
66
s.homepage = 'https://leancloud.cn/'

LeanCloudTests/IMConversationTestCase.swift

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -208,56 +208,55 @@ class IMConversationTestCase: RTMBaseTestCase {
208208
break
209209
}
210210
}
211-
try? clientA.createConversation(clientIDs: [clientA.ID, clientB.ID], completion: { (result) in
212-
if let conv: IMConversation = result.value {
213-
XCTAssertTrue(type(of: conv) == IMConversation.self)
214-
XCTAssertEqual(conv.rawData["objectId"] as? String, conv.ID)
215-
XCTAssertEqual(conv.rawData["conv_type"] as? Int, 1)
216-
XCTAssertEqual(conv.convType, .normal)
217-
XCTAssertTrue(conv.isUnique)
218-
XCTAssertNotNil(conv.uniqueID)
219-
} else {
220-
XCTFail()
221-
}
222-
exp1.fulfill()
223-
})
211+
let existingKey = "existingKey"
212+
let existingValue = "existingValue"
213+
try? clientA.createConversation(
214+
clientIDs: [clientA.ID, clientB.ID],
215+
attributes: [existingKey : existingValue],
216+
completion: { (result) in
217+
if let conv: IMConversation = result.value {
218+
XCTAssertTrue(type(of: conv) == IMConversation.self)
219+
XCTAssertEqual(conv.rawData["objectId"] as? String, conv.ID)
220+
XCTAssertEqual(conv.rawData["conv_type"] as? Int, 1)
221+
XCTAssertEqual(conv.convType, .normal)
222+
XCTAssertTrue(conv.isUnique)
223+
XCTAssertNotNil(conv.uniqueID)
224+
XCTAssertFalse(conv.isOutdated)
225+
XCTAssertEqual(conv.attributes?[existingKey] as? String, existingValue)
226+
} else {
227+
XCTFail()
228+
}
229+
exp1.fulfill()
230+
})
224231
wait(for: [exp1], timeout: timeout)
225232

226233
delegatorA.conversationEvent = nil
227234
delegatorB.conversationEvent = nil
228235

229-
let exp2 = expectation(description: "create unique conversation")
230-
exp2.expectedFulfillmentCount = 5
231-
delegatorA.conversationEvent = { _, _, event in
232-
switch event {
233-
case .joined:
234-
exp2.fulfill()
235-
case .membersJoined:
236-
exp2.fulfill()
237-
default:
238-
break
239-
}
240-
}
241-
delegatorB.conversationEvent = { _, _, event in
242-
switch event {
243-
case .joined:
244-
exp2.fulfill()
245-
case .membersJoined:
246-
exp2.fulfill()
247-
default:
248-
break
249-
}
250-
}
236+
delay(seconds: 5)
237+
238+
clientB.convCollection.removeAll()
239+
240+
let exp2 = expectation(description: "recreate unique conversation")
251241
try? clientB.createConversation(clientIDs: [clientA.ID, clientB.ID], completion: { (result) in
252242
if let conv: IMConversation = result.value {
253243
XCTAssertTrue(type(of: conv) == IMConversation.self)
254244
XCTAssertEqual(conv.convType, .normal)
255245
XCTAssertTrue(conv.isUnique)
256246
XCTAssertNotNil(conv.uniqueID)
247+
XCTAssertTrue(conv.isOutdated)
248+
XCTAssertNil(conv.attributes?[existingKey])
249+
try? conv.refresh { result in
250+
XCTAssertTrue(result.isSuccess)
251+
XCTAssertNil(result.error)
252+
XCTAssertFalse(conv.isOutdated)
253+
XCTAssertEqual(conv.attributes?[existingKey] as? String, existingValue)
254+
exp2.fulfill()
255+
}
257256
} else {
258257
XCTFail()
258+
exp2.fulfill()
259259
}
260-
exp2.fulfill()
261260
})
262261
wait(for: [exp2], timeout: timeout)
263262

Sources/Foundation/Version.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
import Foundation
1010

1111
public struct Version {
12-
public static let versionString = "17.9.0"
12+
public static let versionString = "17.9.1"
1313
}

0 commit comments

Comments
 (0)