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

chore: upgrade WatermelonDB to 0.27.1 #5865

Merged
merged 20 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor
  • Loading branch information
diegolmello committed Sep 19, 2024
commit 200b17b8e5b51dd96fc118c7b2298675aea234f1
16 changes: 12 additions & 4 deletions ios/Shared/RocketChat/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,26 @@ class Database {
row[columnName] = nil
}
}
print("Row: \(row)")
results.append(row)
}
} else {
print("Failed to prepare query: \(query)")
}

sqlite3_finalize(statement)
print(results)
return results
}

func decodeQueryResult<T: Decodable>(_ result: [[String: Any]]) -> [T]? {
do {
let jsonData = try JSONSerialization.data(withJSONObject: result, options: [])
let decodedObjects = try JSONDecoder().decode([T].self, from: jsonData)
return decodedObjects
} catch {
print("Failed to decode result: \(error)")
return nil
}
}

func readRoomEncryptionKey(for roomId: String) -> String? {
let query = "SELECT e2e_key FROM subscriptions WHERE rid = ? LIMIT 1"
Expand All @@ -109,8 +118,7 @@ class Database {
let query = "SELECT encrypted FROM subscriptions WHERE rid = ? LIMIT 1"
if let results = self.query(query, args: [roomId]), let firstResult = results.first {
if let encrypted = firstResult["encrypted"] as? NSNumber {
let isEncrypted = encrypted.boolValue
return isEncrypted
return encrypted.boolValue
}
}
return false
Expand Down
36 changes: 7 additions & 29 deletions ios/Watch/WatchConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,22 @@ final class WatchConnection: NSObject {
}
}

private func getServers() -> [DBServer]? {
func getServers() -> [DBServer]? {
guard let serversQuery = database.query("select * from servers") else {
print("No servers found")
return nil
}

if let data = try? JSONSerialization.data(withJSONObject: serversQuery, options: []) {
do {
let servers = try JSONDecoder().decode([DBServer].self, from: data)
return servers
} catch {
print("Failed to decode DBServer: \(error)")
return nil
}
} else {
print("Failed to serialize query result to data.")
return nil
}

return database.decodeQueryResult(serversQuery)
}
private func getUsers(userToken: String) -> [DBUser]? {

func getUsers(userToken: String) -> [DBUser]? {
guard let usersQuery = database.query("select * from users where token == ? limit 1", args: [userToken]) else {
print("No users found")
return nil
}

if let data = try? JSONSerialization.data(withJSONObject: usersQuery, options: []) {
do {
let users = try JSONDecoder().decode([DBUser].self, from: data)
return users
} catch {
print("Failed to decode DBServer: \(error)")
return nil
}
} else {
print("Failed to serialize query result to data.")
return nil
}

return database.decodeQueryResult(usersQuery)
}

private func getMessage() -> WatchMessage? {
Expand Down