Skip to content

Commit

Permalink
Refactored known users, fixed bug in prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
mrusme committed Apr 4, 2021
1 parent fb6c1f8 commit 85ee4f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
9 changes: 6 additions & 3 deletions mast/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func CmdAvailable() ([]string) {
"open",
"share",

// "whois",
"whois",

// "search",

Expand All @@ -83,14 +83,15 @@ func CmdAvailable() ([]string) {
}
}

func CmdAutocompleter(input string, knownUsers []string) ([]string) {
func CmdAutocompleter(input string, knownUsers map[string]string) ([]string) {
var entries []string

if input == "" {
return entries
}

if input[len(input)-1:] == "@" {
if input[len(input)-1:] == "@" ||
input == "whois " {
for _, knownUser := range knownUsers {
line := input + knownUser
lineFound := false
Expand Down Expand Up @@ -150,6 +151,8 @@ func CmdProcessor(timeline *Timeline, input string) (CmdReturnCode) {

timeline.Switch(TimelineHashtag, &timelineOptions)
return CodeOk
case "whois":
return CodeOk
case "t", "toot":
return CmdToot(timeline, args, -1, VisibilityPublic)
case "tp", "tootprivate":
Expand Down
21 changes: 6 additions & 15 deletions mast/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Timeline struct {
Account mastodon.Account
Toots []Toot
TootIndexStatusIDMappings map[string]int
KnownUsers []string
KnownUsers map[string]string
}

func NewTimeline(mastodonClient *mastodon.Client) Timeline {
Expand All @@ -41,6 +41,7 @@ func NewTimeline(mastodonClient *mastodon.Client) Timeline {

LastRenderedIndex: -1,
TootIndexStatusIDMappings: make(map[string]int),
KnownUsers: make(map[string]string),
}

return timeline
Expand Down Expand Up @@ -111,25 +112,15 @@ func (timeline *Timeline) Load() (error) {
for i := oldestStatusIndex; i >= 0; i-- {
status := statuses[i]

id := string(status.ID)
_, exists := timeline.TootIndexStatusIDMappings[id]
statusID := string(status.ID)
_, exists := timeline.TootIndexStatusIDMappings[statusID]
if exists == false {
tootIndex := len(timeline.Toots)
timeline.Toots =
append(timeline.Toots, NewToot(timeline.client, status, tootIndex))

knownUserExists := false
for _, knownUser := range timeline.KnownUsers {
if knownUser == status.Account.Acct {
knownUserExists = true
}
}
if knownUserExists == false {
timeline.KnownUsers =
append(timeline.KnownUsers, status.Account.Acct)
}

timeline.TootIndexStatusIDMappings[id] = tootIndex
timeline.TootIndexStatusIDMappings[statusID] = tootIndex
timeline.KnownUsers[string(status.Account.ID)] = status.Account.Acct
}
}

Expand Down
2 changes: 1 addition & 1 deletion tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (tuiCore *TUICore) ExitCommandMode(force bool) bool {
tuiCore.App.SetFocus(tuiCore.Stream)
tuiCore.CmdLine.SetLabelColor(tcell.ColorDefault)

tuiCore.Prompt = tuiCore.Timeline.Account.Username
tuiCore.Prompt = tuiCore.Timeline.Account.Username + " "
tuiCore.CmdLine.
SetLabel(tuiCore.Prompt)

Expand Down

0 comments on commit 85ee4f7

Please sign in to comment.