~singpolyma/cheogram-android

9a5b2dcdf81b4c9c0f2d34f7cf70442288919c4c — Stephen Paul Weber 11 months ago efeb8fc
Add cleanup conversations option
M src/main/java/eu/siacs/conversations/entities/Conversation.java => src/main/java/eu/siacs/conversations/entities/Conversation.java +1 -1
@@ 695,7 695,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
                .result();
    }

    private long getSortableTime() {
    public long getSortableTime() {
        Draft draft = getDraft();
        long messageTime = getLatestMessage().getTimeReceived();
        if (draft == null) {

M src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java => src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +14 -0
@@ 62,6 62,8 @@ import androidx.databinding.DataBindingUtil;

import com.cheogram.android.DownloadDefaultStickers;

import com.google.common.collect.ImmutableList;

import org.openintents.openpgp.util.OpenPgpApi;

import java.util.Arrays;


@@ 626,6 628,18 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
            case R.id.action_scan_qr_code:
                UriHandlerActivity.scan(this);
                return true;
            case R.id.action_cleanup:
                for (Conversation c : ImmutableList.copyOf(xmppConnectionService.getConversations())) {
                    c.trim();
                    if (c.getDraftMessage() != null) continue;
                    if (c.getReplyTo() != null) continue;
                    if (c.getMode() == Conversation.MODE_MULTI) continue;
                    if (c.getBooleanAttribute(Conversation.ATTRIBUTE_PINNED_ON_TOP, false)) continue;
                    if (c.unreadCount() > 0) continue;
                    if (c.getSortableTime() > System.currentTimeMillis() - 600000) continue;
                    xmppConnectionService.archiveConversation(c);
                }
                break;
            case R.id.action_search_all_conversations:
                startActivity(new Intent(this, SearchActivity.class));
                return true;

M src/main/res/menu/activity_conversations.xml => src/main/res/menu/activity_conversations.xml +7 -1
@@ 22,4 22,10 @@
        android:title="@string/scan_qr_code"
        android:visible="@bool/show_qr_code_scan"
        app:showAsAction="always" />
</menu>
\ No newline at end of file
    <item
        android:id="@+id/action_cleanup"
        android:orderInCategory="15"
        android:title="Cleanup Conversations"
        android:visible="true"
        app:showAsAction="never" />
</menu>