Created
September 3, 2018 07:14
-
-
Save SergeyPetrachkov/25a5a8855d113dd5e0b7ac68ac178435 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class ConversationsListInteractor: ConversationsListInteractorInput { | |
let chatsProvider: ChatsService = Assembler.container.resolve(ChatsProvider.self)! | |
weak var output: ConversationsListInteractorOutput? | |
// MARK: - Input | |
func requestItems(request: ConversationsList.DataContext.Request) { | |
DispatchQueue(label: "ConversationsListInteractor").async { | |
do { | |
let items = try self.chatsProvider.getChats(request: GetConversationsRequest(skip: request.skip, take: request.take)) | |
let models = items.map({ ConversationsListModel(currentModel: $0) }) | |
DispatchQueue.main.async { | |
self.output?.didReceive(response: ConversationsList.DataContext.Response(originalRequest: request, | |
items: models)) | |
} | |
} catch let error { | |
DispatchQueue.main.async { | |
if error.code == 401 { | |
self.output?.didTokenExpire() | |
} else { | |
self.output?.didFail(with: error) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment