Skip to content

Commit

Permalink
Merge pull request #8602 from shamim-emon/fix-issue-8309
Browse files Browse the repository at this point in the history
Always mark as read when archiving messages
  • Loading branch information
cketti authored Dec 5, 2024
2 parents 5eb5656 + ed72788 commit 9cb7ddb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
1 change: 1 addition & 0 deletions legacy/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {

implementation(projects.plugins.openpgpApiLib.openpgpApi)
implementation(projects.feature.telemetry.api)
implementation(projects.core.featureflags)

api(libs.androidx.annotation)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.fsck.k9.controller

import app.k9mail.core.featureflag.FeatureFlagProvider
import app.k9mail.core.featureflag.FeatureFlagResult
import app.k9mail.core.featureflag.toFeatureFlagKey
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.message.controller.MessageReference
import com.fsck.k9.controller.MessagingController.MessageActor
Expand All @@ -10,6 +13,7 @@ import timber.log.Timber

internal class ArchiveOperations(
private val messagingController: MessagingController,
private val featureFlagProvider: FeatureFlagProvider,
) {
fun archiveThreads(messages: List<MessageReference>) {
archiveByFolder("archiveThreads", messages) { account, folderId, messagesInFolder, archiveFolderId ->
Expand Down Expand Up @@ -69,12 +73,17 @@ internal class ArchiveOperations(
messages: List<LocalMessage>,
archiveFolderId: Long,
) {
val operation = when (featureFlagProvider.provide("archive_marks_as_read".toFeatureFlagKey())) {
FeatureFlagResult.Enabled -> MoveOrCopyFlavor.MOVE_AND_MARK_AS_READ
FeatureFlagResult.Disabled -> MoveOrCopyFlavor.MOVE
FeatureFlagResult.Unavailable -> MoveOrCopyFlavor.MOVE
}
messagingController.moveOrCopyMessageSynchronous(
account,
sourceFolderId,
messages,
archiveFolderId,
MoveOrCopyFlavor.MOVE,
operation,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fsck.k9.controller

import android.content.Context
import app.k9mail.core.featureflag.FeatureFlagProvider
import app.k9mail.legacy.mailstore.MessageStoreManager
import app.k9mail.legacy.message.controller.MessageCountsProvider
import app.k9mail.legacy.message.controller.MessagingControllerRegistry
Expand Down Expand Up @@ -28,6 +29,7 @@ val controllerModule = module {
get<SpecialLocalFoldersCreator>(),
get<LocalDeleteOperationDecider>(),
get(named("controllerExtensions")),
get<FeatureFlagProvider>(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import app.k9mail.core.featureflag.FeatureFlagProvider;
import app.k9mail.legacy.account.Account;
import app.k9mail.legacy.account.Account.DeletePolicy;
import app.k9mail.legacy.di.DI;
Expand Down Expand Up @@ -142,10 +143,12 @@ public static MessagingController getInstance(Context context) {


MessagingController(Context context, NotificationController notificationController,
NotificationStrategy notificationStrategy, LocalStoreProvider localStoreProvider,
BackendManager backendManager, Preferences preferences, MessageStoreManager messageStoreManager,
SaveMessageDataCreator saveMessageDataCreator, SpecialLocalFoldersCreator specialLocalFoldersCreator,
LocalDeleteOperationDecider localDeleteOperationDecider, List<ControllerExtension> controllerExtensions) {
NotificationStrategy notificationStrategy, LocalStoreProvider localStoreProvider,
BackendManager backendManager, Preferences preferences, MessageStoreManager messageStoreManager,
SaveMessageDataCreator saveMessageDataCreator, SpecialLocalFoldersCreator specialLocalFoldersCreator,
LocalDeleteOperationDecider localDeleteOperationDecider, List<ControllerExtension> controllerExtensions,
FeatureFlagProvider featureFlagProvider
) {
this.context = context;
this.notificationController = notificationController;
this.notificationStrategy = notificationStrategy;
Expand All @@ -171,7 +174,7 @@ public void run() {

draftOperations = new DraftOperations(this, messageStoreManager, saveMessageDataCreator);
notificationOperations = new NotificationOperations(notificationController, preferences, messageStoreManager);
archiveOperations = new ArchiveOperations(this);
archiveOperations = new ArchiveOperations(this, featureFlagProvider);
}

private void initializeControllerExtensions(List<ControllerExtension> controllerExtensions) {
Expand Down Expand Up @@ -1754,10 +1757,6 @@ public void copyMessage(Account account, long srcFolderId, MessageReference mess
void moveOrCopyMessageSynchronous(Account account, long srcFolderId, List<LocalMessage> inMessages,
long destFolderId, MoveOrCopyFlavor operation) {

if (operation == MoveOrCopyFlavor.MOVE_AND_MARK_AS_READ) {
throw new UnsupportedOperationException("MOVE_AND_MARK_AS_READ unsupported");
}

try {
LocalStore localStore = localStoreProvider.getInstance(account);
if (operation == MoveOrCopyFlavor.MOVE && !isMoveCapable(account)) {
Expand All @@ -1781,8 +1780,15 @@ void moveOrCopyMessageSynchronous(Account account, long srcFolderId, List<LocalM
uids.add(uid);
}

if (!unreadCountAffected && !message.isSet(Flag.SEEN)) {
unreadCountAffected = true;
if (operation == MoveOrCopyFlavor.MOVE_AND_MARK_AS_READ) {
if (!message.isSet(Flag.SEEN)) {
unreadCountAffected = true;
message.setFlag(Flag.SEEN, true);
}
} else {
if (!unreadCountAffected && !message.isSet(Flag.SEEN)) {
unreadCountAffected = true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import java.util.Set;

import android.content.Context;

import app.k9mail.core.featureflag.FeatureFlagProvider;
import app.k9mail.core.featureflag.FeatureFlagResult.Disabled;
import app.k9mail.legacy.account.Account;
import app.k9mail.legacy.message.controller.SimpleMessagingListener;
import com.fsck.k9.K9;
Expand Down Expand Up @@ -111,6 +112,7 @@ public class MessagingControllerTest extends K9RobolectricTest {

private Preferences preferences;
private String accountUuid;
private FeatureFlagProvider featureFlagProvider;


@Before
Expand All @@ -120,11 +122,14 @@ public void setUp() throws MessagingException {
appContext = RuntimeEnvironment.getApplication();

preferences = Preferences.getPreferences();
featureFlagProvider = key -> Disabled.INSTANCE;

controller = new MessagingController(appContext, notificationController, notificationStrategy,
localStoreProvider, backendManager, preferences, messageStoreManager,
saveMessageDataCreator, specialLocalFoldersCreator, new LocalDeleteOperationDecider(),
Collections.<ControllerExtension>emptyList());
Collections.<ControllerExtension>emptyList(),
featureFlagProvider
);

configureAccount();
configureBackendManager();
Expand Down

0 comments on commit 9cb7ddb

Please sign in to comment.