-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathinput.go
More file actions
1487 lines (1425 loc) · 39 KB
/
Copy pathinput.go
File metadata and controls
1487 lines (1425 loc) · 39 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package ui
import (
"fmt"
"strings"
"sync"
"time"
"github.com/RasmusLindroth/go-mastodon"
"github.com/RasmusLindroth/tut/api"
"github.com/RasmusLindroth/tut/config"
"github.com/RasmusLindroth/tut/util"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
func (tv *TutView) Input(event *tcell.EventKey) *tcell.EventKey {
if tv.PageFocus != LoginFocus {
switch event.Rune() {
case ':':
tv.SetPage(CmdFocus)
case '?':
tv.SetPage(HelpFocus)
}
if event.Rune() == '/' && (tv.PageFocus == MainFocus || tv.PageFocus == ViewFocus) {
tv.SetPage(PaneSearchFocus)
return nil
}
}
if tv.PageFocus != LoginFocus && tv.PageFocus != CmdFocus && tv.PageFocus != PaneSearchFocus {
event = tv.InputLeaderKey(event)
if event == nil {
return nil
}
}
if tv.tut.Config.Input.MainNextAccount.Match(event.Key(), event.Rune()) {
tv.NextAcct()
return nil
}
if tv.tut.Config.Input.MainPrevAccount.Match(event.Key(), event.Rune()) {
tv.NextAcct()
return nil
}
switch tv.PageFocus {
case LoginFocus:
return tv.InputLoginView(event)
case MainFocus:
return tv.InputMainView(event)
case ViewFocus:
return tv.InputViewItem(event)
case ComposeFocus:
return tv.InputComposeView(event)
case PollFocus:
return tv.InputPollView(event)
case LinkFocus:
return tv.InputLinkView(event)
case CmdFocus:
return tv.InputCmdView(event)
case PaneSearchFocus:
return tv.InputCmdView(event)
case MediaFocus:
return tv.InputMedia(event)
case MediaAddFocus:
return tv.InputMediaAdd(event)
case VoteFocus:
return tv.InputVote(event)
case HelpFocus:
return tv.InputHelp(event)
case PreferenceFocus:
return tv.InputPreference(event)
case EditorFocus:
return tv.InputEditorView(event)
default:
return event
}
}
func (tv *TutView) InputLoginView(event *tcell.EventKey) *tcell.EventKey {
if tv.tut.Config.Input.GlobalDown.Match(event.Key(), event.Rune()) {
tv.LoginView.Next()
return nil
}
if tv.tut.Config.Input.GlobalUp.Match(event.Key(), event.Rune()) {
tv.LoginView.Prev()
return nil
}
if tv.tut.Config.Input.GlobalEnter.Match(event.Key(), event.Rune()) {
tv.LoginView.Selected()
return nil
}
if tv.tut.Config.Input.GlobalExit.Match(event.Key(), event.Rune()) {
tv.tut.App.Stop()
tv.CleanExit(0)
return nil
}
return event
}
func (tv *TutView) InputLeaderKey(event *tcell.EventKey) *tcell.EventKey {
if tv.tut.Config.General.LeaderKey == rune(0) {
return event
}
if event.Rune() == tv.tut.Config.General.LeaderKey {
tv.Leader.Reset()
return nil
} else if tv.Leader.IsActive() {
if event.Rune() != rune(0) {
tv.Leader.AddRune(event.Rune())
}
action := config.LeaderNone
var subaction string
content := tv.Leader.Content()
foundFeed := false
for i, fh := range tv.Timeline.Feeds {
for _, f := range fh.Feeds {
if f.Timeline.Shortcut == "" || f.Timeline.Shortcut != content {
continue
}
switch f.Timeline.OnFocus {
case config.TimelineFocusPane:
tv.FocusFeed(i, nil)
case config.TimelineFocusTimeline:
tv.FocusFeed(i, f.Timeline)
}
foundFeed = true
tv.Leader.ResetInactive()
return nil
}
}
if !foundFeed {
for _, tl := range tv.tut.Config.General.Timelines {
if tl.Shortcut == "" || tl.Shortcut != content {
continue
}
tv.matchedTimeline(tl)
tv.Leader.ResetInactive()
return nil
}
}
for _, la := range tv.tut.Config.General.LeaderActions {
if la.Shortcut == content {
action = la.Command
subaction = la.Subaction
break
}
}
if action == config.LeaderNone {
return nil
}
switch action {
case config.LeaderClearNotifications:
tv.ClearNotificationsCommand()
case config.LeaderCompose:
tv.ComposeCommand()
case config.LeaderEdit:
tv.EditCommand()
case config.LeaderBlocking:
tv.BlockingCommand()
case config.LeaderFavorited:
tv.FavoritedCommand()
case config.LeaderHistory:
tv.HistoryCommand()
case config.LeaderBoosts:
tv.BoostsCommand()
case config.LeaderFavorites:
tv.FavoritesCommand()
case config.LeaderFollowing:
tv.FollowingCommand()
case config.LeaderFollowers:
tv.FollowersCommand()
case config.LeaderMuting:
tv.MutingCommand()
case config.LeaderPreferences:
tv.PreferencesCommand()
case config.LeaderProfile:
tv.ProfileCommand()
case config.LeaderLoadNewer:
tv.LoadNewerCommand()
case config.LeaderStickToTop:
tv.ToggleStickToTop()
case config.LeaderRefetch:
tv.RefetchCommand()
case config.LeaderTags:
tv.TagsCommand()
case config.LeaderPane:
tv.PaneCommand(subaction)
case config.LeaderClosePane:
tv.ClosePaneCommand()
case config.LeaderMovePaneLeft:
tv.MovePaneLeft()
case config.LeaderMovePaneRight:
tv.MovePaneRight()
case config.LeaderMovePaneHome:
tv.MovePaneHome()
case config.LeaderMovePaneEnd:
tv.MovePaneEnd()
case config.LeaderListPlacement:
switch subaction {
case "top":
tv.ListPlacementCommand(config.ListPlacementTop)
case "right":
tv.ListPlacementCommand(config.ListPlacementRight)
case "bottom":
tv.ListPlacementCommand(config.ListPlacementBottom)
case "left":
tv.ListPlacementCommand(config.ListPlacementLeft)
}
case config.LeaderListSplit:
switch subaction {
case "row":
tv.ListSplitCommand(config.ListRow)
case "column":
tv.ListSplitCommand(config.ListColumn)
}
case config.LeaderProportions:
parts := strings.Split(subaction, " ")
if len(parts) == 2 {
tv.ProportionsCommand(parts[0], parts[1])
}
}
tv.Leader.ResetInactive()
return nil
}
return event
}
func (tv *TutView) InputMainView(event *tcell.EventKey) *tcell.EventKey {
if event.Rune() == 'n' && tv.paneSearchTerm != "" {
tv.NextPaneSearch(true)
return nil
}
if event.Rune() == 'N' && tv.paneSearchTerm != "" {
tv.NextPaneSearch(false)
return nil
}
switch tv.SubFocus {
case ListFocus:
return tv.InputMainViewFeed(event)
case ContentFocus:
return tv.InputMainViewContent(event)
default:
return event
}
}
func (tv *TutView) matchedTimeline(tl *config.Timeline) {
nf := CreateFeed(tv, tl)
switch tl.OnCreationClosed {
case config.TimelineCreationClosedCurrentPane:
tv.Timeline.AddFeed(nf, false)
case config.TimelineCreationClosedNewPane:
tv.Timeline.AddFeed(nf, true)
}
}
func (tv *TutView) InputMainViewFeed(event *tcell.EventKey) *tcell.EventKey {
if tv.tut.Config.Input.MainHome.Match(event.Key(), event.Rune()) {
tv.Timeline.HomeItemFeed()
return nil
}
if tv.tut.Config.Input.MainEnd.Match(event.Key(), event.Rune()) {
tv.Timeline.EndItemFeed()
return nil
}
if tv.tut.Config.Input.MainPrevFeed.Match(event.Key(), event.Rune()) {
tv.Timeline.PrevFeed()
return nil
}
if tv.tut.Config.Input.MainNextFeed.Match(event.Key(), event.Rune()) {
tv.Timeline.NextFeed()
return nil
}
if tv.tut.Config.Input.GlobalDown.Match(event.Key(), event.Rune()) {
tv.Timeline.NextItemFeed()
return nil
}
if tv.tut.Config.Input.GlobalUp.Match(event.Key(), event.Rune()) {
tv.Timeline.PrevItemFeed()
return nil
}
if tv.tut.Config.Input.MainPrevPane.Match(event.Key(), event.Rune()) {
tv.PrevFeed()
return nil
}
if tv.tut.Config.Input.MainNextPane.Match(event.Key(), event.Rune()) {
tv.NextFeed()
return nil
}
if tv.tut.Config.Input.GlobalExit.Match(event.Key(), event.Rune()) {
exiting := tv.Timeline.RemoveCurrent(false)
if exiting && tv.Timeline.FeedFocusIndex == 0 {
tv.ModalView.Run("Do you want to exit tut?",
func() {
tv.Timeline.RemoveCurrent(true)
})
return nil
} else if exiting && tv.Timeline.FeedFocusIndex != 0 {
tv.FocusFeed(0, nil)
}
return nil
}
foundFeed := false
for i, fh := range tv.Timeline.Feeds {
for _, f := range fh.Feeds {
if f.Timeline.Key.Match(event.Key(), event.Rune()) {
switch f.Timeline.OnFocus {
case config.TimelineFocusPane:
tv.FocusFeed(i, nil)
case config.TimelineFocusTimeline:
tv.FocusFeed(i, f.Timeline)
}
foundFeed = true
return nil
}
}
}
if !foundFeed {
for _, tl := range tv.tut.Config.General.Timelines {
if tl.Key.Match(event.Key(), event.Rune()) {
tv.matchedTimeline(tl)
return nil
}
}
}
if tv.tut.Config.Input.GlobalBack.Match(event.Key(), event.Rune()) {
exiting := tv.Timeline.RemoveCurrent(false)
if exiting && tv.Timeline.FeedFocusIndex != 0 {
tv.FocusFeed(0, nil)
}
return nil
}
if tv.tut.Config.Input.MainCompose.Match(event.Key(), event.Rune()) {
tv.InitPost(nil, nil)
return nil
}
return tv.InputItem(event)
}
func (tv *TutView) InputMainViewContent(event *tcell.EventKey) *tcell.EventKey {
if tv.tut.Config.Input.GlobalDown.Match(event.Key(), event.Rune()) {
tv.Timeline.ScrollDown()
return nil
}
if tv.tut.Config.Input.GlobalUp.Match(event.Key(), event.Rune()) {
tv.Timeline.ScrollDown()
return nil
}
if tv.tut.Config.Input.MainCompose.Match(event.Key(), event.Rune()) {
tv.InitPost(nil, nil)
return nil
}
return tv.InputItem(event)
}
func (tv *TutView) InputHelp(event *tcell.EventKey) *tcell.EventKey {
if tv.tut.Config.Input.GlobalBack.Match(event.Key(), event.Rune()) ||
tv.tut.Config.Input.GlobalExit.Match(event.Key(), event.Rune()) {
tv.PrevFocus()
return nil
}
return event
}
func (tv *TutView) InputViewItem(event *tcell.EventKey) *tcell.EventKey {
if event.Rune() == 'n' && tv.paneSearchTerm != "" {
tv.NextPaneSearch(true)
return nil
}
if event.Rune() == 'N' && tv.paneSearchTerm != "" {
tv.NextPaneSearch(false)
return nil
}
if tv.tut.Config.Input.GlobalBack.Match(event.Key(), event.Rune()) ||
tv.tut.Config.Input.GlobalExit.Match(event.Key(), event.Rune()) {
tv.FocusMainNoHistory()
return nil
}
return event
}
func (tv *TutView) InputItem(event *tcell.EventKey) *tcell.EventKey {
fd := tv.GetCurrentFeed()
ft := fd.Data.Type()
item, err := tv.GetCurrentItem()
if err != nil {
return event
}
switch item.Type() {
case api.StatusType:
return tv.InputStatus(event, item, item.Raw().(*mastodon.Status), nil, fd.Data.Type())
case api.StatusHistoryType:
return tv.InputStatusHistory(event, item, item.Raw().(*mastodon.StatusHistory), nil)
case api.UserType, api.ProfileType:
switch ft {
case config.FollowRequests:
return tv.InputUser(event, item.Raw().(*api.User), InputUserFollowRequest)
case config.ListUsersAdd:
return tv.InputUser(event, item.Raw().(*api.User), InputUserListAdd)
case config.ListUsersIn:
return tv.InputUser(event, item.Raw().(*api.User), InputUserListDelete)
default:
return tv.InputUser(event, item.Raw().(*api.User), InputUserNormal)
}
case api.NotificationType:
nd := item.Raw().(*api.NotificationData)
switch nd.Item.Type {
case "follow":
return tv.InputUser(event, nd.User.Raw().(*api.User), InputUserNormal)
case "favourite":
user := nd.User.Raw().(*api.User)
return tv.InputStatus(event, nd.Status, nd.Status.Raw().(*mastodon.Status), user.Data, config.Notifications)
case "reblog":
user := nd.User.Raw().(*api.User)
return tv.InputStatus(event, nd.Status, nd.Status.Raw().(*mastodon.Status), user.Data, config.Notifications)
case "mention":
return tv.InputStatus(event, nd.Status, nd.Status.Raw().(*mastodon.Status), nil, config.Notifications)
case "update":
return tv.InputStatus(event, nd.Status, nd.Status.Raw().(*mastodon.Status), nil, config.Notifications)
case "status":
return tv.InputStatus(event, nd.Status, nd.Status.Raw().(*mastodon.Status), nil, config.Notifications)
case "poll":
return tv.InputStatus(event, nd.Status, nd.Status.Raw().(*mastodon.Status), nil, config.Notifications)
case "follow_request":
return tv.InputUser(event, nd.User.Raw().(*api.User), InputUserFollowRequest)
}
case api.ListsType:
ld := item.Raw().(*mastodon.List)
return tv.InputList(event, ld)
case api.TagType:
tag := item.Raw().(*mastodon.Tag)
return tv.InputTag(event, tag)
}
return event
}
func (tv *TutView) InputStatus(event *tcell.EventKey, item api.Item, status *mastodon.Status, nAcc *mastodon.Account, fd config.FeedType) *tcell.EventKey {
sr := util.StatusOrReblog(status)
hasMedia := len(sr.MediaAttachments) > 0
hasPoll := sr.Poll != nil
hasSpoiler := sr.Sensitive
isMine := sr.Account.ID == tv.tut.Client.Me.ID
boosted, favorited, bookmarked := false, false, false
if sr.Reblogged != nil {
boosted = sr.Reblogged.(bool)
}
if sr.Favourited != nil {
favorited = sr.Favourited.(bool)
}
if sr.Bookmarked != nil {
bookmarked = sr.Bookmarked.(bool)
}
if tv.tut.Config.Input.StatusAvatar.Match(event.Key(), event.Rune()) {
if nAcc != nil {
openAvatar(tv, *nAcc)
} else {
openAvatar(tv, sr.Account)
}
return nil
}
if tv.tut.Config.Input.StatusBoost.Match(event.Key(), event.Rune()) {
txt := "boost"
if boosted {
txt = "unboost"
}
tv.ModalView.Run(
fmt.Sprintf("Do you want to %s this toot?", txt), func() {
ns, err := tv.tut.Client.BoostToggle(status)
if err != nil {
tv.ShowError(
fmt.Sprintf("Couldn't boost toot. Error: %v\n", err),
)
return
}
*status = *ns
tv.RedrawControls()
})
return nil
}
if tv.tut.Config.Input.StatusDelete.Match(event.Key(), event.Rune()) {
if !isMine {
return nil
}
tv.ModalView.Run("Do you want to delete this toot?", func() {
err := tv.tut.Client.DeleteStatus(sr)
if err != nil {
tv.ShowError(
fmt.Sprintf("Couldn't delete toot. Error: %v\n", err),
)
return
}
status.Card = nil
status.Sensitive = false
status.SpoilerText = ""
status.Favourited = false
status.MediaAttachments = nil
status.Reblogged = false
status.Content = "Deleted"
tv.RedrawContent()
})
return nil
}
if tv.tut.Config.Input.StatusEdit.Match(event.Key(), event.Rune()) {
tv.EditCommand()
return nil
}
if tv.tut.Config.Input.StatusFavorite.Match(event.Key(), event.Rune()) {
txt := "favorite"
if favorited {
txt = "unfavorite"
}
tv.ModalView.Run(fmt.Sprintf("Do you want to %s this toot?", txt),
func() {
ns, err := tv.tut.Client.FavoriteToogle(status)
if err != nil {
tv.ShowError(
fmt.Sprintf("Couldn't favorite toot. Error: %v\n", err),
)
return
}
*status = *ns
tv.RedrawControls()
})
return nil
}
if tv.tut.Config.Input.StatusMedia.Match(event.Key(), event.Rune()) {
if hasMedia {
openMedia(tv, sr)
}
return nil
}
if tv.tut.Config.Input.StatusLinks.Match(event.Key(), event.Rune()) {
tv.SetPage(LinkFocus)
return nil
}
if tv.tut.Config.Input.StatusPoll.Match(event.Key(), event.Rune()) {
if !hasPoll {
return nil
}
tv.VoteView.SetPoll(sr.Poll)
tv.SetPage(VoteFocus)
return nil
}
if tv.tut.Config.Input.StatusReply.Match(event.Key(), event.Rune()) {
tv.InitPost(status, nil)
return nil
}
if tv.tut.Config.Input.StatusBookmark.Match(event.Key(), event.Rune()) {
txt := "save"
if bookmarked {
txt = "unsave"
}
tv.ModalView.Run(fmt.Sprintf("Do you want to %s this toot?", txt),
func() {
ns, err := tv.tut.Client.BookmarkToogle(status)
if err != nil {
tv.ShowError(
fmt.Sprintf("Couldn't bookmark toot. Error: %v\n", err),
)
return
}
*status = *ns
tv.RedrawControls()
})
return nil
}
if tv.tut.Config.Input.StatusThread.Match(event.Key(), event.Rune()) {
tv.Timeline.AddFeed(NewThreadFeed(tv, item, config.NewTimeline(config.Timeline{
FeedType: config.Thread,
})), false)
return nil
}
if tv.tut.Config.Input.StatusUser.Match(event.Key(), event.Rune()) {
id := sr.Account.ID
if nAcc != nil {
id = nAcc.ID
}
user, err := tv.tut.Client.GetUserByID(id)
if err != nil {
return nil
}
tv.Timeline.AddFeed(NewUserFeed(tv, user, config.NewTimeline(config.Timeline{
FeedType: config.User,
})), false)
return nil
}
if tv.tut.Config.Input.StatusViewFocus.Match(event.Key(), event.Rune()) {
tv.SetPage(ViewFocus)
return nil
}
if tv.tut.Config.Input.StatusYank.Match(event.Key(), event.Rune()) {
copyToClipboard(sr.URL)
return nil
}
if tv.tut.Config.Input.StatusToggleCW.Match(event.Key(), event.Rune()) {
filtered, _, _, forceView := item.Filtered(fd)
if filtered && !forceView {
item.ForceViewFilter()
tv.RedrawContent()
return nil
}
if !hasSpoiler {
return nil
}
if !item.ShowCW() {
item.ToggleCW()
tv.RedrawContent()
}
return nil
}
return event
}
func (tv *TutView) InputStatusHistory(event *tcell.EventKey, item api.Item, sr *mastodon.StatusHistory, nAcc *mastodon.Account) *tcell.EventKey {
hasMedia := len(sr.MediaAttachments) > 0
hasSpoiler := sr.Sensitive
status := &mastodon.Status{
Content: sr.Content,
SpoilerText: sr.SpoilerText,
Account: sr.Account,
Sensitive: sr.Sensitive,
CreatedAt: sr.CreatedAt,
Emojis: sr.Emojis,
MediaAttachments: sr.MediaAttachments,
}
if tv.tut.Config.Input.StatusAvatar.Match(event.Key(), event.Rune()) {
if nAcc != nil {
openAvatar(tv, *nAcc)
} else {
openAvatar(tv, sr.Account)
}
return nil
}
if tv.tut.Config.Input.StatusMedia.Match(event.Key(), event.Rune()) {
if hasMedia {
openMedia(tv, status)
}
return nil
}
if tv.tut.Config.Input.StatusLinks.Match(event.Key(), event.Rune()) {
tv.SetPage(LinkFocus)
return nil
}
if tv.tut.Config.Input.StatusViewFocus.Match(event.Key(), event.Rune()) {
tv.SetPage(ViewFocus)
return nil
}
if tv.tut.Config.Input.StatusToggleCW.Match(event.Key(), event.Rune()) {
if !hasSpoiler {
return nil
}
if !item.ShowCW() {
item.ToggleCW()
tv.RedrawContent()
}
return nil
}
return event
}
type InputUserType uint
const (
InputUserNormal = iota
InputUserFollowRequest
InputUserListAdd
InputUserListDelete
)
func (tv *TutView) InputUser(event *tcell.EventKey, user *api.User, ut InputUserType) *tcell.EventKey {
blocking := user.Relation.Blocking
muting := user.Relation.Muting
following := user.Relation.Following
if ut == InputUserListAdd {
if tv.tut.Config.Input.GlobalEnter.Match(event.Key(), event.Rune()) ||
tv.tut.Config.Input.ListUserAdd.Match(event.Key(), event.Rune()) {
ad := user.AdditionalData
switch ad.(type) {
case *mastodon.List:
l := user.AdditionalData.(*mastodon.List)
err := tv.tut.Client.AddUserToList(user.Data, l)
if err != nil {
tv.ShowError(fmt.Sprintf("Couldn't add user to list. Error: %v", err))
}
return nil
default:
return event
}
}
return event
}
if ut == InputUserListDelete {
if tv.tut.Config.Input.GlobalEnter.Match(event.Key(), event.Rune()) ||
tv.tut.Config.Input.ListUserDelete.Match(event.Key(), event.Rune()) {
ad := user.AdditionalData
switch ad.(type) {
case *mastodon.List:
l := user.AdditionalData.(*mastodon.List)
err := tv.tut.Client.DeleteUserFromList(user.Data, l)
if err != nil {
tv.ShowError(fmt.Sprintf("Couldn't remove user from list. Error: %v", err))
}
return nil
default:
return event
}
}
return event
}
if ut == InputUserFollowRequest && tv.tut.Config.Input.UserFollowRequestDecide.Match(event.Key(), event.Rune()) {
tv.ModalView.RunDecide("Do you want accept the follow request?",
func() {
err := tv.tut.Client.FollowRequestAccept(user.Data)
if err != nil {
tv.ShowError(
fmt.Sprintf("Couldn't accept follow request. Error: %v\n", err),
)
return
}
f := tv.GetCurrentFeed()
f.Delete()
tv.RedrawContent()
},
func() {
err := tv.tut.Client.FollowRequestDeny(user.Data)
if err != nil {
tv.ShowError(
fmt.Sprintf("Couldn't deny follow request. Error: %v\n", err),
)
return
}
f := tv.GetCurrentFeed()
f.Delete()
tv.RedrawContent()
})
return nil
}
if tv.tut.Config.Input.UserAvatar.Match(event.Key(), event.Rune()) {
openAvatar(tv, *user.Data)
return nil
}
if tv.tut.Config.Input.UserBlock.Match(event.Key(), event.Rune()) {
txt := "block"
if blocking {
txt = "unblock"
}
tv.ModalView.Run(fmt.Sprintf("Do you want to %s this user?", txt),
func() {
rel, err := tv.tut.Client.BlockToggle(user)
if err != nil {
tv.ShowError(
fmt.Sprintf("Couldn't block user. Error: %v\n", err),
)
return
}
user.Relation = rel
tv.RedrawControls()
})
return nil
}
if tv.tut.Config.Input.UserFollow.Match(event.Key(), event.Rune()) {
txt := "follow"
if following {
txt = "unfollow"
}
tv.ModalView.Run(fmt.Sprintf("Do you want to %s this user?", txt),
func() {
rel, err := tv.tut.Client.FollowToggle(user)
if err != nil {
tv.ShowError(
fmt.Sprintf("Couldn't follow user. Error: %v\n", err),
)
return
}
user.Relation = rel
tv.RedrawControls()
})
return nil
}
if tv.tut.Config.Input.UserMute.Match(event.Key(), event.Rune()) {
txt := "mute"
if muting {
txt = "unmute"
}
tv.ModalView.Run(fmt.Sprintf("Do you want to %s this user?", txt),
func() {
rel, err := tv.tut.Client.MuteToggle(user)
if err != nil {
tv.ShowError(
fmt.Sprintf("Couldn't follow user. Error: %v\n", err),
)
return
}
user.Relation = rel
tv.RedrawControls()
})
return nil
}
if tv.tut.Config.Input.UserLinks.Match(event.Key(), event.Rune()) {
tv.SetPage(LinkFocus)
return nil
}
if tv.tut.Config.Input.UserUser.Match(event.Key(), event.Rune()) {
tv.Timeline.AddFeed(NewUserFeed(tv, api.NewUserItem(user, true), config.NewTimeline(config.Timeline{
FeedType: config.User,
})), false)
return nil
}
if tv.tut.Config.Input.UserViewFocus.Match(event.Key(), event.Rune()) {
tv.SetPage(ViewFocus)
return nil
}
if tv.tut.Config.Input.UserYank.Match(event.Key(), event.Rune()) {
copyToClipboard(user.Data.URL)
return nil
}
if tv.tut.Config.Input.GlobalEnter.Match(event.Key(), event.Rune()) {
tv.Timeline.AddFeed(NewUserFeed(tv, api.NewUserItem(user, true), config.NewTimeline(config.Timeline{
FeedType: config.User,
})), false)
return nil
}
return event
}
func (tv *TutView) InputList(event *tcell.EventKey, list *mastodon.List) *tcell.EventKey {
if tv.tut.Config.Input.ListOpenFeed.Match(event.Key(), event.Rune()) ||
tv.tut.Config.Input.GlobalEnter.Match(event.Key(), event.Rune()) {
tv.Timeline.AddFeed(NewListFeed(tv, list, config.NewTimeline(config.Timeline{
FeedType: config.List,
})), false)
return nil
}
if tv.tut.Config.Input.ListUserList.Match(event.Key(), event.Rune()) {
tv.Timeline.AddFeed(NewUsersInListFeed(tv, list, config.NewTimeline(config.Timeline{
FeedType: config.ListUsersIn,
})), false)
return nil
}
if tv.tut.Config.Input.ListUserAdd.Match(event.Key(), event.Rune()) {
tv.Timeline.AddFeed(NewUsersAddListFeed(tv, list, config.NewTimeline(config.Timeline{
FeedType: config.ListUsersAdd,
})), false)
return nil
}
return event
}
func (tv *TutView) InputTag(event *tcell.EventKey, tag *mastodon.Tag) *tcell.EventKey {
if tv.tut.Config.Input.TagOpenFeed.Match(event.Key(), event.Rune()) ||
tv.tut.Config.Input.GlobalEnter.Match(event.Key(), event.Rune()) {
tv.Timeline.AddFeed(NewTagFeed(tv, config.NewTimeline(config.Timeline{
FeedType: config.Tag,
Subaction: tag.Name,
})), false)
return nil
}
if tv.tut.Config.Input.TagFollow.Match(event.Key(), event.Rune()) {
txt := "follow"
if tag.Following != nil && tag.Following == true {
txt = "unfollow"
}
tv.ModalView.Run(fmt.Sprintf("Do you want to %s #%s?", txt, tag.Name),
func() {
nt, err := tv.tut.Client.TagToggleFollow(tag)
if err != nil {
tv.ShowError(
fmt.Sprintf("Couldn't %s tag. Error: %v\n", txt, err),
)
return
}
*tag = *nt
tv.RedrawControls()
})
return nil
}
return event
}
func (tv *TutView) InputLinkView(event *tcell.EventKey) *tcell.EventKey {
if tv.tut.Config.Input.GlobalDown.Match(event.Key(), event.Rune()) {
tv.LinkView.Next()
return nil
}
if tv.tut.Config.Input.GlobalUp.Match(event.Key(), event.Rune()) {
tv.LinkView.Prev()
return nil
}
if tv.tut.Config.Input.LinkOpen.Match(event.Key(), event.Rune()) ||
tv.tut.Config.Input.GlobalEnter.Match(event.Key(), event.Rune()) {
tv.LinkView.Open()
return nil
}
if tv.tut.Config.Input.LinkYank.Match(event.Key(), event.Rune()) {
tv.LinkView.Yank()
return nil
}
if tv.tut.Config.Input.GlobalBack.Match(event.Key(), event.Rune()) ||
tv.tut.Config.Input.GlobalExit.Match(event.Key(), event.Rune()) {
tv.SetPage(MainFocus)
return nil
}
for _, oc := range tv.tut.Config.OpenCustom.OpenCustoms {
if oc.Key.Match(event.Key(), event.Rune()) {
tv.LinkView.OpenCustom(oc)
return nil
}
}
return event
}
func (tv *TutView) InputComposeView(event *tcell.EventKey) *tcell.EventKey {
if tv.tut.Config.Input.ComposeEditCW.Match(event.Key(), event.Rune()) {
tv.ComposeView.EditSpoiler()
return nil
}
if tv.tut.Config.Input.ComposeEditText.Match(event.Key(), event.Rune()) {
tv.ComposeView.EditText()
return nil
}
if tv.tut.Config.Input.ComposeIncludeQuote.Match(event.Key(), event.Rune()) {
tv.ComposeView.IncludeQuote()
return nil
}
if tv.tut.Config.Input.ComposeMediaFocus.Match(event.Key(), event.Rune()) {
if tv.PollView.HasPoll() {
tv.ShowError("Can't add media when you have a poll")
return nil
}
tv.SetPage(MediaFocus)
return nil
}
if tv.tut.Config.Input.ComposePoll.Match(event.Key(), event.Rune()) {
if tv.ComposeView.HasMedia() {
tv.ShowError("Can't add poll when you have added media")
return nil
}
tv.SetPage(PollFocus)
return nil
}
if tv.tut.Config.Input.ComposePost.Match(event.Key(), event.Rune()) {
tv.ComposeView.Post()
return nil
}
if tv.tut.Config.Input.ComposeToggleContentWarning.Match(event.Key(), event.Rune()) {
tv.ComposeView.ToggleCW()
return nil
}
if tv.tut.Config.Input.ComposeVisibility.Match(event.Key(), event.Rune()) {
tv.ComposeView.FocusVisibility()
return nil
}
if tv.tut.Config.Input.ComposeLanguage.Match(event.Key(), event.Rune()) {
tv.ComposeView.FocusLang()
return nil
}
if tv.tut.Config.Input.GlobalBack.Match(event.Key(), event.Rune()) ||
tv.tut.Config.Input.GlobalExit.Match(event.Key(), event.Rune()) {
tv.ModalView.Run(
"Do you want exit the compose view?", func() {
tv.FocusMainNoHistory()
})
return nil
}
return event
}
func (tv *TutView) InputMedia(event *tcell.EventKey) *tcell.EventKey {
if tv.tut.Config.Input.GlobalDown.Match(event.Key(), event.Rune()) {
tv.ComposeView.media.Next()
return nil
}
if tv.tut.Config.Input.GlobalUp.Match(event.Key(), event.Rune()) {
tv.ComposeView.media.Prev()
return nil
}
if tv.tut.Config.Input.MediaDelete.Match(event.Key(), event.Rune()) {
tv.ComposeView.media.Delete()
return nil
}
if tv.tut.Config.Input.MediaEditDesc.Match(event.Key(), event.Rune()) {
tv.ComposeView.media.EditDesc()
return nil
}
if tv.tut.Config.Input.MediaAdd.Match(event.Key(), event.Rune()) {
tv.SetPage(MediaAddFocus)