Updated on 2026-08-14

This commit is contained in:
Tangem 2024-05-22 15:48:49 +08:00
parent da98a6afb2
commit a3f1a3dc9f
13 changed files with 119 additions and 160 deletions

View file

@ -0,0 +1,67 @@
package com.tangem.domain.feedback
import android.content.res.Resources
import com.tangem.domain.feedback.models.CardInfo
import com.tangem.domain.feedback.models.FeedbackEmail
import com.tangem.domain.feedback.models.FeedbackEmailType
import com.tangem.domain.feedback.repository.FeedbackRepository
import com.tangem.domain.feedback.utils.*
/**
* Get email with feedback for support
*
* @property feedbackRepository feedback repository
* @property resources resources for getting strings
*
[REDACTED_AUTHOR]
*/
class GetFeedbackEmailUseCase(
private val feedbackRepository: FeedbackRepository,
private val resources: Resources,
) {
private val emailSubjectResolver = EmailSubjectResolver(resources)
private val emailMessageTitleResolver = EmailMessageTitleResolver(resources)
private val emailMessageBodyResolver = EmailMessageBodyResolver(feedbackRepository)
suspend operator fun invoke(type: FeedbackEmailType): FeedbackEmail {
val cardInfo = feedbackRepository.getCardInfo()
val formattedLogs = AppLogsFormatter().format(appLogs = feedbackRepository.getAppLogs())
return FeedbackEmail(
address = getAddress(cardInfo),
subject = emailSubjectResolver.resolve(type, cardInfo),
message = createMessage(type, cardInfo),
file = feedbackRepository.createLogFile(logs = formattedLogs),
)
}
private fun getAddress(cardInfo: CardInfo): String {
return if (cardInfo.isStart2Coin) START2COIN_SUPPORT_EMAIL else TANGEM_SUPPORT_EMAIL
}
private suspend fun createMessage(type: FeedbackEmailType, cardInfo: CardInfo): String {
return StringBuilder().apply {
val title = emailMessageTitleResolver.resolve(type)
append(title)
skipLine()
appendDisclaimerIfNeeded(type)
skipLine()
val body = emailMessageBodyResolver.resolve(type, cardInfo)
append(body)
}.toString()
}
private fun StringBuilder.appendDisclaimerIfNeeded(type: FeedbackEmailType): StringBuilder {
return if (type is FeedbackEmailType.ScanningProblem) {
this
} else {
append(resources.getString(R.string.feedback_data_collection_message))
}
}
}

View file

@ -1,113 +0,0 @@
package com.tangem.domain.feedback
import android.content.res.Resources
import com.tangem.domain.feedback.models.CardInfo
import com.tangem.domain.feedback.models.SupportFeedbackEmail
import com.tangem.domain.feedback.repository.FeedbackRepository
import com.tangem.domain.feedback.utils.skipLine
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormatterBuilder
import java.util.Locale
/**
* Get email with feedback for support
*
* @property feedbackRepository feedback repository
* @property resources resources for getting strings
*
[REDACTED_AUTHOR]
*/
class GetSupportFeedbackEmailUseCase(
private val feedbackRepository: FeedbackRepository,
private val resources: Resources,
) {
// 00.00 00:00:00.000
private val dateFormatter = DateTimeFormatterBuilder()
.appendDayOfMonth(2)
.appendLiteral('.')
.appendMonthOfYear(2)
.appendLiteral(' ')
.appendHourOfDay(2)
.appendLiteral(':')
.appendMinuteOfHour(2)
.appendLiteral(':')
.appendSecondOfMinute(2)
.appendLiteral('.')
.appendMillisOfSecond(3)
.toFormatter()
.withLocale(Locale.getDefault())
suspend operator fun invoke(): SupportFeedbackEmail {
val cardInfo = feedbackRepository.getCardInfo()
return SupportFeedbackEmail(
address = getEmail(isStart2Coin = cardInfo.isStart2Coin),
subject = getSubject(isStart2Coin = cardInfo.isStart2Coin),
message = createMessage(cardInfo),
file = feedbackRepository.createLogFile(logs = getLogs()),
)
}
private fun getEmail(isStart2Coin: Boolean): String {
return if (isStart2Coin) START2COIN_SUPPORT_EMAIL else TANGEM_SUPPORT_EMAIL
}
private fun getSubject(isStart2Coin: Boolean): String {
return resources.getString(
if (isStart2Coin) {
R.string.feedback_subject_support
} else {
R.string.feedback_subject_support_tangem
},
)
}
private suspend fun createMessage(cardInfo: CardInfo): String {
return StringBuilder().apply {
append(resources.getString(R.string.feedback_preface_support))
skipLine()
append(resources.getString(R.string.feedback_data_collection_message))
skipLine()
append(
FeedbackDataBuilder().apply {
addUserWalletsInfo(userWalletsInfo = feedbackRepository.getUserWalletsInfo())
addDelimiter()
addCardInfo(cardInfo)
addDelimiter()
addBlockchainInfoList(blockchainInfoList = feedbackRepository.getBlockchainInfoList())
addDelimiter()
addPhoneInfo(phoneInfo = feedbackRepository.getPhoneInfo())
}.build(),
)
}.toString()
}
private suspend fun getLogs(): String {
val builder = StringBuilder()
var sum = 0
val appLogs = feedbackRepository.getAppLogs()
for (i in appLogs.lastIndex downTo 0) {
val log = appLogs[i]
val date = dateFormatter.print(DateTime(log.timestamp))
val formattedLog = "$date: ${log.message}\n"
sum += formattedLog.length
if (sum < GMAIL_MAX_FILE_SIZE) {
builder.insert(0, formattedLog)
} else {
break
}
}
return builder.toString()
}
private companion object {
const val START2COIN_SUPPORT_EMAIL = "cardsupport@start2coin.com"
const val TANGEM_SUPPORT_EMAIL = "support@tangem.com"
const val GMAIL_MAX_FILE_SIZE = 24_900_000 // ≈ 25 MB
}
}

View file

@ -2,7 +2,7 @@ package com.tangem.domain.feedback.models
import java.io.File
data class SupportFeedbackEmail(
data class FeedbackEmail(
val address: String,
val subject: String,
val message: String,