OutgoingVoipCallOfferMessageTask.kt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* _____ _
  2. * |_ _| |_ _ _ ___ ___ _ __ __ _
  3. * | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. * |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. *
  6. * Threema for Android
  7. * Copyright (c) 2023-2025 Threema GmbH
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. package ch.threema.app.tasks
  22. import ch.threema.app.managers.ServiceManager
  23. import ch.threema.common.now
  24. import ch.threema.domain.models.MessageId
  25. import ch.threema.domain.protocol.csp.messages.voip.VoipCallOfferData
  26. import ch.threema.domain.protocol.csp.messages.voip.VoipCallOfferMessage
  27. import ch.threema.domain.taskmanager.ActiveTaskCodec
  28. import ch.threema.domain.types.Identity
  29. class OutgoingVoipCallOfferMessageTask(
  30. private val voipCallOfferData: VoipCallOfferData,
  31. private val toIdentity: Identity,
  32. serviceManager: ServiceManager,
  33. ) : OutgoingCspMessageTask(serviceManager) {
  34. private val voipStateService by lazy { serviceManager.voipStateService }
  35. override val type: String = "OutgoingVoipCallOfferMessageTask"
  36. override val shortLogInfo: String = "cid=${voipCallOfferData.callId}"
  37. override suspend fun runSendingSteps(handle: ActiveTaskCodec) {
  38. val message = VoipCallOfferMessage()
  39. message.data = voipCallOfferData
  40. voipStateService.addRequiredMessageId(voipCallOfferData.callId ?: 0, message.messageId)
  41. sendContactMessage(
  42. message = message,
  43. messageModel = null,
  44. toIdentity = toIdentity,
  45. messageId = MessageId.random(),
  46. createdAt = now(),
  47. handle = handle,
  48. )
  49. contactService.bumpLastUpdate(toIdentity)
  50. }
  51. // We do not need to persist this message
  52. override fun serialize(): SerializableTaskData? = null
  53. }