Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
571 additions
and
439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// CKMessagesModelDelegate.swift | ||
// ChatK!t | ||
// | ||
// Created by ben3 on 04/05/2021. | ||
// | ||
|
||
import Foundation | ||
import ChatSDK | ||
import RXPromise | ||
|
||
public class CKChatModelDelegate: ChatModelDelegate { | ||
|
||
public override func loadMessages(with oldestMessage: Message?) -> Single<[Message]> { | ||
return Single<[Message]>.create { [weak self] single in | ||
if let model = self?._model, let thread = BChatSDK.db().fetchEntity(withID: model.thread().threadId(), withType: bThreadEntity) as? PThread { | ||
_ = BChatSDK.thread().loadMoreMessages(from: oldestMessage?.messageDate(), for: thread).thenOnMain({ success in | ||
if let messages = success as? [PMessage] { | ||
single(.success(CKChatModelDelegate.convert(messages))) | ||
} else { | ||
single(.success([])) | ||
} | ||
return success | ||
}, { error in | ||
single(.success([])) | ||
return error | ||
}) | ||
} | ||
return Disposables.create {} | ||
} | ||
} | ||
|
||
public override func initialMessages() -> [Message] { | ||
var messages = [Message]() | ||
if let model = _model, let thread = BChatSDK.db().fetchEntity(withID: model.thread().threadId(), withType: bThreadEntity) as? PThread { | ||
for message in BChatSDK.db().loadMessages(for: thread, newest: 15) { | ||
if let message = message as? PMessage { | ||
messages.insert(CKMessage(message: message), at: 0) | ||
} | ||
} | ||
} | ||
return messages | ||
} | ||
|
||
public static func convert(_ messages: [PMessage]) -> [Message] { | ||
var output = [Message]() | ||
for message in messages { | ||
output.append(CKMessage(message: message)) | ||
} | ||
return output | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.