Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(im): key-muted and key-joinedAt handling of system conversation #388

Merged
merged 3 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions LeanCloudTests/IMConversationTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,12 @@ class IMConversationTestCase: RTMBaseTestCase {

func testServiceConversationSubscription() {
guard let client = newOpenedClient(),
let serviceConversationID = IMConversationTestCase.newServiceConversation() else {
XCTFail()
return
let serviceConversationID = IMConversationTestCase.newServiceConversation() else {
XCTFail()
return
}

delay()

var serviceConversation: IMServiceConversation?

expecting { (exp) in
try! client.conversationQuery.getConversation(by: serviceConversationID) { (result) in
XCTAssertTrue(result.isSuccess)
Expand All @@ -404,7 +401,10 @@ class IMConversationTestCase: RTMBaseTestCase {
exp.fulfill()
}
}

guard let _ = serviceConversation else {
XCTFail()
return
}
expecting(
description: "service conversation subscription",
count: 3)
Expand All @@ -428,6 +428,21 @@ class IMConversationTestCase: RTMBaseTestCase {
})
})
}
let query = client.conversationQuery
expecting { (exp) in
try! query.getConversation(by: serviceConversationID) { (result) in
XCTAssertNil(result.error)
if let conv = result.value as? IMServiceConversation {
XCTAssertEqual(conv.isMuted, false)
XCTAssertTrue(conv.rawData["muted"] != nil)
XCTAssertNotNil(conv.subscribedTimestamp)
XCTAssertNotNil(conv.subscribedAt)
} else {
XCTFail()
}
exp.fulfill()
}
}
}

func testNormalConversationUnreadEvent() {
Expand Down
8 changes: 4 additions & 4 deletions Sources/Foundation/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ protocol InternalSynchronizing {

extension InternalSynchronizing {

func sync<T>(_ closure: @autoclosure () -> T) -> T {
self.sync(closure: closure)
func sync<T>(_ closure: @autoclosure () throws -> T) rethrows -> T {
return try self.sync(closure: closure)
}

func sync<T>(closure: () -> T) -> T {
func sync<T>(closure: () throws -> T) rethrows -> T {
self.mutex.lock()
defer {
self.mutex.unlock()
}
return closure()
return try closure()
}
}
20 changes: 19 additions & 1 deletion Sources/RTM/IMConversation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class IMConversation {
case transient = "tr"
case system = "sys"
case joined = "joined"
case joinedAt = "joinedAt"
case muted = "muted"
case temporary = "temp"
case temporaryTTL = "ttl"
case convType = "conv_type"
Expand Down Expand Up @@ -104,7 +106,7 @@ public class IMConversation {
return self.safeDecodingRawData(with: .members)
}

/// Indicates whether the conversation has been muted.
/// Whether the offline notification of this conversation has been muted by the client.
public var isMuted: Bool {
if let mutedMembers: [String] = self.safeDecodingRawData(with: .mutedMembers) {
return mutedMembers.contains(self.clientID)
Expand Down Expand Up @@ -2940,6 +2942,22 @@ public class IMServiceConversation: IMConversation {
return self.safeDecodingRawData(with: .joined)
}

/// The date when the client subscribe this service conversation.
public var subscribedAt: Date? {
return IMClient.date(
fromMillisecond: self.subscribedTimestamp)
}

/// The timestamp when the client subscribe this service conversation, unit of measurement is millisecond.
public var subscribedTimestamp: Int64? {
return self.safeDecodingRawData(with: .joinedAt)
}

/// Whether the offline notification of this service conversation has been muted by the client.
public override var isMuted: Bool {
return self.safeDecodingRawData(with: .muted) ?? false
}

@available(*, unavailable)
public override func countMembers(completion: @escaping (LCCountResult) -> Void) {
completion(.failure(error: LCError.conversationNotSupport(convType: type(of: self))))
Expand Down