chatsecureios / ChatSecure / Classes / Controllers / XMPP / XMPPManager.swift @ 8358d691
History | View | Annotate | Download (1.75 KB)
1 |
// |
---|---|
2 |
// XMPPManager.swift |
3 |
// ChatSecureCore |
4 |
// |
5 |
// Created by Chris Ballinger on 11/27/17. |
6 |
// Copyright © 2017 Chris Ballinger. All rights reserved. |
7 |
// |
8 |
|
9 |
import Foundation |
10 |
import XMPPFramework |
11 |
|
12 |
public extension XMPPMessageArchiveManagement { |
13 |
@objc public func fetchHistory(archiveJID: XMPPJID? = nil, userJID: XMPPJID? = nil, since: Date? = nil) { |
14 |
var fields: [XMLElement] = [] |
15 |
|
16 |
if let userJID = userJID { |
17 |
let with = XMPPMessageArchiveManagement.field(withVar: "with", type: nil, andValue: userJID.bare) |
18 |
fields.append(with) |
19 |
} |
20 |
|
21 |
if let since = since { |
22 |
let xmppDateString = (since as NSDate).xmppDateTimeString |
23 |
|
24 |
let start = XMPPMessageArchiveManagement.field(withVar: "start", type: nil, andValue: xmppDateString) |
25 |
fields.append(start) |
26 |
} |
27 |
retrieveMessageArchive(at: archiveJID ?? xmppStream?.myJID?.bareJID, withFields: fields, with: nil) |
28 |
} |
29 |
} |
30 |
|
31 |
/// Formerly known in Obj-C as OTRXMPPManager |
32 |
public extension XMPPManager { |
33 |
|
34 |
|
35 |
/** Fetches history for a thread after the most recent message */ |
36 |
@objc public func fetchHistoryForThread(_ thread: OTRThreadOwner, transaction: YapDatabaseReadTransaction) { |
37 |
var archiveJID: XMPPJID? = nil |
38 |
var userJID: XMPPJID? = nil |
39 |
if let buddy = thread as? OTRXMPPBuddy, |
40 |
let buddyJID = buddy.bareJID { |
41 |
archiveJID = account.bareJID |
42 |
userJID = buddyJID |
43 |
} else if let room = thread as? OTRXMPPRoom { |
44 |
archiveJID = room.roomJID |
45 |
} |
46 |
let lastMessageDate = thread.lastMessage(with: transaction)?.messageDate |
47 |
messageStorage.archiving.fetchHistory(archiveJID: archiveJID, userJID: userJID, since: lastMessageDate) |
48 |
} |
49 |
} |