Skip to content

Commit 28f07de

Browse files
authored
Merge pull request #313 from zapcannon87/developer
feat(IM): conversation query can set where condition string directly
2 parents e03b260 + 6c8ee88 commit 28f07de

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Sources/RTM/IMConversationQuery.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ public class IMConversationQuery: LCQuery {
3737

3838
let eventQueue: DispatchQueue?
3939

40+
// MARK: Init
41+
4042
init(client: IMClient, eventQueue: DispatchQueue? = nil) {
4143
self.eventQueue = eventQueue
4244
self.client = client
4345
super.init(application: client.application, className: "_Conversation")
4446
}
4547

48+
// MARK: Combine
49+
4650
/**
4751
Get logic AND of another query.
4852
Note that it only combine constraints of two queries, the limit and skip option will be discarded.
@@ -77,6 +81,11 @@ public class IMConversationQuery: LCQuery {
7781
return result
7882
}
7983

84+
// MARK: Where Condition
85+
86+
/// If this property is a non-nil value, query will always use it as where condition, default is nil.
87+
public var whereString: String?
88+
8089
/// Add constraint in query.
8190
///
8291
/// - Parameters:
@@ -106,6 +115,8 @@ public class IMConversationQuery: LCQuery {
106115
try super.where(key, constraint)
107116
}
108117

118+
// MARK: Find
119+
109120
/// Get Conversation by ID.
110121
///
111122
/// - Parameters:
@@ -356,9 +367,11 @@ private extension IMConversationQuery {
356367

357368
func whereAndSort() throws -> (whereString: String?, sortString: String?) {
358369
let dictionary = self.lconValue
359-
var whereString: String? = nil
360-
var sortString: String? = nil
361-
if let whereCondition: Any = dictionary["where"] {
370+
var whereString: String?
371+
var sortString: String?
372+
if let whereCondition = self.whereString {
373+
whereString = whereCondition
374+
} else if let whereCondition: Any = dictionary["where"] {
362375
let data = try JSONSerialization.data(withJSONObject: whereCondition)
363376
whereString = String(data: data, encoding: .utf8)
364377
}

0 commit comments

Comments
 (0)