about summary refs log tree commit diff stats
path: root/tests/unittests/test_plugins_disco.h
blob: 4377e28eb59faffdab6e121b4e5e9746ab7b71f3 (plain) (blame)
1
2
3
4
5
6
7
void returns_empty_list_when_none(void** state);
void returns_added_feature(void** state);
void resets_features_on_close(void** state);
void returns_all_added_features(void** state);
void does_not_add_duplicate_feature(void** state);
void removes_plugin_features(void** state);
void does_not_remove_feature_when_more_than_one_reference(void** state);
title='author Wagner Riffel <wgrriffel@gmail.com> 2019-09-03 16:34:03 -0300 committer Drew DeVault <sir@cmpwn.com> 2019-09-04 16:30:57 -1000 all: purge redundant underscores' href='/akspecs/aerc/commit/commands/msg/delete.go?h=0.5.2&id=6838c23478944a9b45df1fa9a0f432ec77423987'>6838c23 ^
312a53e ^
455c6f0 ^
312a53e ^
753adb9 ^
7b359be ^



312a53e ^
7b359be ^


8bb115d ^
7b359be ^
217e85a ^

ddd0fa4 ^
7b359be ^
db213fd ^







7b359be ^














f3158b3 ^




7b359be ^


312a53e ^

7b359be ^

























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
           


                


                                  
 

                                         

                                               

 

                    
             


                          
                                  


                                                   
                                                                    
                  

 
                                                                
                           
                                                   
         
 



                               
         


                             
         
                                

                          
         
                                                          







                                                                               














                                                               




                                                                                                     


                                

                  

























                                                                                        
package msg

import (
	"errors"
	"time"

	"github.com/gdamore/tcell"

	"git.sr.ht/~sircmpwn/aerc/lib"
	"git.sr.ht/~sircmpwn/aerc/models"
	"git.sr.ht/~sircmpwn/aerc/widgets"
	"git.sr.ht/~sircmpwn/aerc/worker/types"
)

type Delete struct{}

func init() {
	register(Delete{})
}

func (Delete) Aliases() []string {
	return []string{"delete", "delete-message"}
}

func (Delete) Complete(aerc *widgets.Aerc, args []string) []string {
	return nil
}

func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
	if len(args) != 1 {
		return errors.New("Usage: :delete")
	}

	h := newHelper(aerc)
	store, err := h.store()
	if err != nil {
		return err
	}
	uids, err := h.uids()
	if err != nil {
		return err
	}
	acct, err := h.account()
	if err != nil {
		return err
	}
	store.Delete(uids, func(msg types.WorkerMessage) {
		switch msg := msg.(type) {
		case *types.Done:
			aerc.PushStatus("Messages deleted.", 10*time.Second)
		case *types.Error:
			aerc.PushStatus(" "+msg.Error.Error(), 10*time.Second).
				Color(tcell.ColorDefault, tcell.ColorRed)
		}
	})

	//caution, can be nil
	next := findNextNonDeleted(uids, store)

	mv, isMsgView := h.msgProvider.(*widgets.MessageViewer)
	if isMsgView {
		if !aerc.Config().Ui.NextMessageOnDelete {
			aerc.RemoveTab(h.msgProvider)
		} else {
			// no more messages in the list
			if next == nil {
				aerc.RemoveTab(h.msgProvider)
				acct.Messages().Scroll()
				return nil
			}
			lib.NewMessageStoreView(next, store, aerc.DecryptKeys,
				func(view lib.MessageView) {
					nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view)
					aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject)
				})
		}
	}
	acct.Messages().Scroll()
	return nil
}

func findNextNonDeleted(deleted []uint32, store *lib.MessageStore) *models.MessageInfo {
	selected := store.Selected()
	if !contains(deleted, selected.Uid) {
		return selected
	}
	for {
		store.Next()
		next := store.Selected()
		if next == selected || next == nil {
			// the last message is in the deleted state or doesn't exist
			return nil
		}
		return next
	}
	return nil // Never reached
}

func contains(uids []uint32, uid uint32) bool {
	for _, item := range uids {
		if item == uid {
			return true
		}
	}
	return false
}