|
@@ -9,6 +9,7 @@ import Foundation
|
|
|
|
|
|
public class Chat: Model {
|
|
|
|
|
|
+ public let fpin: String
|
|
|
public let pin: String
|
|
|
public let messageId: String
|
|
|
public let counter: String
|
|
@@ -22,8 +23,10 @@ public class Chat: Model {
|
|
|
public let name: String
|
|
|
public let profile: String
|
|
|
public let official: String
|
|
|
+ public let status: String
|
|
|
|
|
|
public init(pin: String) {
|
|
|
+ self.fpin = ""
|
|
|
self.pin = pin
|
|
|
self.messageId = ""
|
|
|
self.counter = ""
|
|
@@ -37,9 +40,11 @@ public class Chat: Model {
|
|
|
self.name = ""
|
|
|
self.profile = ""
|
|
|
self.official = ""
|
|
|
+ self.status = ""
|
|
|
}
|
|
|
|
|
|
- public init(pin: String, messageId: String, counter: String, messageText: String, serverDate: String, image: String, video: String, file: String, attachmentFlag: String, messageScope: String, name: String, profile: String, official: String ) {
|
|
|
+ public init(fpin:String, pin: String, messageId: String, counter: String, messageText: String, serverDate: String, image: String, video: String, file: String, attachmentFlag: String, messageScope: String, name: String, profile: String, official: String, status: String ) {
|
|
|
+ self.fpin = fpin
|
|
|
self.pin = pin
|
|
|
self.messageId = messageId
|
|
|
self.counter = counter
|
|
@@ -53,6 +58,7 @@ public class Chat: Model {
|
|
|
self.name = name
|
|
|
self.profile = profile
|
|
|
self.official = official
|
|
|
+ self.status = status
|
|
|
}
|
|
|
|
|
|
public static func == (lhs: Chat, rhs: Chat) -> Bool {
|
|
@@ -68,30 +74,32 @@ public class Chat: Model {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
do {
|
|
|
let query = """
|
|
|
- select ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, b.first_name || ' ' || ifnull(b.last_name, '') name, b.image_id profile, b.official_account from MESSAGE_SUMMARY ms, MESSAGE m, BUDDY b where ms.message_id = m.message_id and ms.l_pin = b.f_pin \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
|
|
|
+ select m.f_pin, ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, b.first_name || ' ' || ifnull(b.last_name, '') name, b.image_id profile, b.official_account, m.status from MESSAGE_SUMMARY ms, MESSAGE m, BUDDY b where ms.message_id = m.message_id and ms.l_pin = b.f_pin \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
|
|
|
union
|
|
|
- select ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, 'Bot' name, '' profile, '' from MESSAGE_SUMMARY ms, MESSAGE m where ms.message_id = m.message_id and ms.l_pin = '-999' \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
|
|
|
+ select m.f_pin, ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, 'Bot' name, '' profile, '', m.status from MESSAGE_SUMMARY ms, MESSAGE m where ms.message_id = m.message_id and ms.l_pin = '-999' \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
|
|
|
union
|
|
|
- select ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, b.f_name || ' (\("Lounge".localized()))', b.image_id profile, b.official from MESSAGE_SUMMARY ms, MESSAGE m, GROUPZ b where ms.message_id = m.message_id and ms.l_pin = b.group_id \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
|
|
|
+ select m.f_pin, ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, b.f_name || ' (\("Lounge".localized()))', b.image_id profile, b.official, m.status from MESSAGE_SUMMARY ms, MESSAGE m, GROUPZ b where ms.message_id = m.message_id and ms.l_pin = b.group_id \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
|
|
|
union
|
|
|
- select ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, c.f_name || ' (' || b.title || ')', b.thumb profile, '' from MESSAGE_SUMMARY ms, MESSAGE m, DISCUSSION_FORUM b, GROUPZ c where ms.message_id = m.message_id and ms.l_pin = b.chat_id and b.group_id = c.group_id \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
|
|
|
+ select m.f_pin, ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, c.f_name || ' (' || b.title || ')', b.thumb profile, '', m.status from MESSAGE_SUMMARY ms, MESSAGE m, DISCUSSION_FORUM b, GROUPZ c where ms.message_id = m.message_id and ms.l_pin = b.chat_id and b.group_id = c.group_id \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
|
|
|
order by 5 desc
|
|
|
"""
|
|
|
if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: query) {
|
|
|
while cursorData.next() {
|
|
|
- let chat = Chat(pin: cursorData.string(forColumnIndex: 0) ?? "",
|
|
|
- messageId: cursorData.string(forColumnIndex: 1) ?? "",
|
|
|
- counter: cursorData.string(forColumnIndex: 2) ?? "",
|
|
|
- messageText: cursorData.string(forColumnIndex: 3) ?? "",
|
|
|
- serverDate: cursorData.string(forColumnIndex: 4) ?? "",
|
|
|
- image: cursorData.string(forColumnIndex: 5) ?? "",
|
|
|
- video: cursorData.string(forColumnIndex: 6) ?? "",
|
|
|
- file: cursorData.string(forColumnIndex: 7) ?? "",
|
|
|
- attachmentFlag: cursorData.string(forColumnIndex: 8) ?? "",
|
|
|
- messageScope: cursorData.string(forColumnIndex: 9) ?? "",
|
|
|
- name: cursorData.string(forColumnIndex: 10) ?? "",
|
|
|
- profile: cursorData.string(forColumnIndex: 11) ?? "",
|
|
|
- official: cursorData.string(forColumnIndex: 12) ?? "")
|
|
|
+ let chat = Chat(fpin: cursorData.string(forColumnIndex: 0) ?? "",
|
|
|
+ pin: cursorData.string(forColumnIndex: 1) ?? "",
|
|
|
+ messageId: cursorData.string(forColumnIndex: 2) ?? "",
|
|
|
+ counter: cursorData.string(forColumnIndex: 3) ?? "",
|
|
|
+ messageText: cursorData.string(forColumnIndex: 4) ?? "",
|
|
|
+ serverDate: cursorData.string(forColumnIndex: 5) ?? "",
|
|
|
+ image: cursorData.string(forColumnIndex: 6) ?? "",
|
|
|
+ video: cursorData.string(forColumnIndex: 7) ?? "",
|
|
|
+ file: cursorData.string(forColumnIndex: 8) ?? "",
|
|
|
+ attachmentFlag: cursorData.string(forColumnIndex: 9) ?? "",
|
|
|
+ messageScope: cursorData.string(forColumnIndex: 10) ?? "",
|
|
|
+ name: cursorData.string(forColumnIndex: 11) ?? "",
|
|
|
+ profile: cursorData.string(forColumnIndex: 12) ?? "",
|
|
|
+ official: cursorData.string(forColumnIndex: 13) ?? "",
|
|
|
+ status: cursorData.string(forColumnIndex: 14) ?? "")
|
|
|
chats.append(chat)
|
|
|
}
|
|
|
cursorData.close()
|