Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class NewMessageCreationWorker(var context: Context, params: WorkerParameters) : Worker(context, params) {
private newMessageDb: newMessageDb = ... // from dependency injection
override fun doWork(): Result {
var jobId = inputData.getString(NewMessage.KEY_JOB_ID)?.run { this } ?: ""
var newMessage = newMessageDb.find(jobId)
return newMessage?.run {
val postMesageResponse = postMessage(this)
if (response.isSuccessful) {
startUploadMediaFile(this, response)
Result.SUCCESS
} else {
Result.RETRY
}
} ?: kotlin.run { Result.FAILURE }
}
private fun postMessage(newMessage: NewMessage): Response<Void> {
... // send POST /message request and return response
}
private fun startUploadMediaFile(newMessage: NewMessage, response: Response<Void>) {
val uploadUrl: String = ... // parse media upload link from response
FileUploader.submitMediaUploadWork(newMessage, uploadUrl)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.