Skip to content

Commit 139b1d7

Browse files
authored
Merge pull request #549 from jorgeblacio/release_0_21_13
Various bug fixes.
2 parents 09d7410 + 3b2646d commit 139b1d7

File tree

13 files changed

+98
-17
lines changed

13 files changed

+98
-17
lines changed

src/main/kotlin/com/criptext/mail/bgworker/BackgroundWorkManager.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ abstract class BackgroundWorkManager<in I: Any, O: Any> {
1212
var listener: ((O) -> Unit)? = null
1313
set (newListener) {
1414
if (newListener != null) {
15-
state.keys.forEach({ key ->
15+
state.keys.forEach { key ->
1616
val workState = state[key]
1717
if (workState is WorkState.Done) {
1818
state.remove(key)
1919
newListener(workState.result)
2020
}
21-
})
21+
}
2222
}
2323
field = newListener
2424
}
@@ -35,6 +35,4 @@ abstract class BackgroundWorkManager<in I: Any, O: Any> {
3535
runner.workInBackground(worker)
3636
}
3737
}
38-
39-
4038
}

src/main/kotlin/com/criptext/mail/db/dao/AccountDao.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,9 @@ interface AccountDao {
9595
where recipientId=:recipientId AND domain=:domain""")
9696
fun updateRefreshToken(recipientId: String, domain: String, token: String)
9797

98+
@Query("""UPDATE account
99+
SET signature=:signature
100+
where id=:id""")
101+
fun updateSignature(id: Long, signature: String)
102+
98103
}

src/main/kotlin/com/criptext/mail/push/services/NewMailActionService.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@ class NewMailActionService : IntentService("New Mail Action Service") {
3333
val manager = this.applicationContext
3434
.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
3535
val db = AppDatabase.getAppDatabase(this)
36-
if(activeAccount.userEmail != data.recipientId.plus("@${data.domain}"))
37-
activeAccount = ActiveAccount.loadFromDB(db.accountDao().getAccount(data.recipientId, data.domain)!!)!!
36+
if(activeAccount.userEmail != data.recipientId.plus("@${data.domain}")) {
37+
val account = db.accountDao().getAccount(data.recipientId, data.domain)
38+
if(account != null){
39+
activeAccount = ActiveAccount.loadFromDB(account)!!
40+
} else {
41+
deletePush(storage, manager)
42+
return
43+
}
44+
}
3845
val requestHandler = PushAPIRequestHandler(NotificationError(this), manager,
3946
activeAccount, HttpClient.Default(),
4047
storage)
@@ -49,17 +56,21 @@ class NewMailActionService : IntentService("New Mail Action Service") {
4956
EmailDetailLocalDB.Default(db, this.filesDir), db.emailDao(), db.pendingEventDao(), db.accountDao())
5057
}
5158
DELETE -> {
52-
val notCount = storage.getInt(KeyValueStorage.StringKey.NewMailNotificationCount, 0)
53-
if((notCount - 1) <= 0) {
54-
manager.cancel(CriptextNotification.INBOX_ID)
55-
}
56-
storage.putInt(KeyValueStorage.StringKey.NewMailNotificationCount,
57-
if(notCount <= 0) 0 else notCount - 1)
59+
deletePush(storage, manager)
5860
}
5961
else -> throw IllegalArgumentException("Unsupported action: " + data.action)
6062
}
6163
}
6264

65+
private fun deletePush(storage: KeyValueStorage, manager: NotificationManager){
66+
val notCount = storage.getInt(KeyValueStorage.StringKey.NewMailNotificationCount, 0)
67+
if((notCount - 1) <= 0) {
68+
manager.cancel(CriptextNotification.INBOX_ID)
69+
}
70+
storage.putInt(KeyValueStorage.StringKey.NewMailNotificationCount,
71+
if(notCount <= 0) 0 else notCount - 1)
72+
}
73+
6374
private fun getIntentData(intent: Intent?, activeRecipientId: String): IntentData {
6475
val action = intent!!.action ?: ""
6576
val notificationId = intent.getIntExtra("notificationId", 0)

src/main/kotlin/com/criptext/mail/scenes/composer/workers/SaveEmailWorker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SaveEmailWorker(
6868

6969
private fun getEmailPreview(emailId: Long): EmailThread {
7070
val email = db.loadFullEmail(emailId, account)!!
71-
val label = db.getLabelById(currentLabel.id, account.id)!!
71+
val label = db.getLabelById(currentLabel.id, account.id) ?: Label.defaultItems.inbox
7272
return db.getEmailThreadFromEmail(email.email, label.text, Label.defaultItems.rejectedLabelsByFolder(label.text).map { it.id }, account.userEmail, account)
7373
}
7474

src/main/kotlin/com/criptext/mail/scenes/mailbox/MailboxSceneController.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ class MailboxSceneController(private val scene: MailboxScene,
200200
scene.showExtraAccountsBadge(false)
201201
scene.hideMultipleAccountsMenu()
202202
threadListController.clear()
203-
model.threads.clear()
204203
dataSource.submitRequest(MailboxRequest.SetActiveAccount(account))
205204
}
206205

src/main/kotlin/com/criptext/mail/scenes/mailbox/workers/SendMailWorker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class SendMailWorker(private val signalClient: SignalClient,
338338
return when (finalResult) {
339339
is Result.Success -> {
340340
db.increaseContactScore(listOf(emailId))
341-
val label = db.getLabelById(currentLabel.id, activeAccount.id)!!
341+
val label = db.getLabelById(currentLabel.id, activeAccount.id) ?: Label.defaultItems.inbox
342342
val thread = db.getEmailThreadFromEmail(currentEmail!!, label.text, Label.defaultItems.rejectedLabelsByFolder(label.text).map { it.id }, activeAccount.userEmail, activeAccount)
343343
MailboxResult.SendMail.Success(EmailPreview.fromEmailThread(thread), currentLabel, isSecure)
344344
}

src/main/kotlin/com/criptext/mail/scenes/settings/data/SettingsDataSource.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class SettingsDataSource(
3636
activeAccount = activeAccount,
3737
publishFn = { res -> flushResults(res) }
3838
)
39+
is SettingsRequest.UpdateSignature -> UpdateSignatureWorker(
40+
signature = params.signature,
41+
accountDao = settingsLocalDB.accountDao,
42+
activeAccount = activeAccount,
43+
httpClient = httpClient,
44+
publishFn = { res -> flushResults(res) }
45+
)
3946
}
4047
}
4148
}

src/main/kotlin/com/criptext/mail/scenes/settings/data/SettingsRequest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ package com.criptext.mail.scenes.settings.data
33
sealed class SettingsRequest{
44
class ResetPassword: SettingsRequest()
55
class SyncBegin: SettingsRequest()
6+
data class UpdateSignature(val signature: String): SettingsRequest()
67
}

src/main/kotlin/com/criptext/mail/scenes/settings/data/SettingsResult.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.criptext.mail.scenes.settings.data
22

3-
import com.criptext.mail.db.models.Label
43
import com.criptext.mail.utils.UIMessage
54

65
sealed class SettingsResult{
@@ -14,4 +13,9 @@ sealed class SettingsResult{
1413
data class NoDevicesAvailable(val message: UIMessage): SyncBegin()
1514
data class Failure(val message: UIMessage): SyncBegin()
1615
}
16+
17+
sealed class UpdateSignature: SettingsResult() {
18+
class Success: UpdateSignature()
19+
data class Failure(val message: UIMessage): UpdateSignature()
20+
}
1721
}

src/main/kotlin/com/criptext/mail/scenes/settings/signature/SignatureController.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class SignatureController(
7575

7676
private fun updateSignature(){
7777
activeAccount.updateSignature(storage, scene.getSignature())
78+
dataSource.submitRequest(SettingsRequest.UpdateSignature(scene.getSignature()))
7879
}
7980

8081
}

0 commit comments

Comments
 (0)