Skip to content

Instantly share code, notes, and snippets.

@SergeyPetrachkov
Created September 3, 2018 07:14
Show Gist options
  • Save SergeyPetrachkov/25a5a8855d113dd5e0b7ac68ac178435 to your computer and use it in GitHub Desktop.
Save SergeyPetrachkov/25a5a8855d113dd5e0b7ac68ac178435 to your computer and use it in GitHub Desktop.
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