Fix some bugs and adding some features

This commit is contained in:
erroneousboat 2016-09-28 22:10:04 +02:00
parent b70370be1d
commit 544397dee9
8 changed files with 57 additions and 26 deletions

33
TODO.md
View File

@ -1,17 +1,22 @@
Sources:
Bugs:
Slack:
- https://api.slack.com/rtm
- https://github.com/evanyeung/terminal-slack
- https://github.com/nlopes/slack
- [ ] when switching channels sometimes messages are persisted in the new
channel, the Buffer() in Chat will probably not go further than the
latest message. Could be that items are added to List and not cleared
when switching channels
- [ ] GetMessages for a channel can result in `json: cannot unmarshal number
into Go value of type string` https://github.com/nlopes/slack/issues/92
- [ ] send message as user, now it will send it as a bot
- [ ] alot of usernames 'unknown' should be a better way to uncover this
- [ ] uncovering usernames takes too long, should find a better way
- [ ] docs at exported functions
- [ ] message creation in input.go and events.go should be made into function
CreateMessage
- [ ] restarting the application will always add the latest sent message
through RTM in the selected channel
UI
- https://github.com/jroimartin/gocui
- https://github.com/fatih/color
- https://github.com/nsf/termbox-go
- https://github.com/gizak/termui
Features:
Examples:
- https://github.com/nsf/godit
- https://github.com/moncho/dry
- https://github.com/mikepea/go-jira-ui
- [ ] scrolling in chat pane
- [ ] scrolling in channel pane
- [x] channel name in chat pane

View File

@ -24,8 +24,7 @@ func CreateChannels(svc *service.SlackService, inputHeight int) *Channels {
channels.List.BorderLabel = "Channels"
channels.List.Height = termui.TermHeight() - inputHeight
// TODO: should be SetSelectedChannel
channels.SelectedChannel = 4
channels.SelectedChannel = 0
channels.GetChannels(svc)

View File

@ -12,14 +12,16 @@ type Chat struct {
SelectedChannel string
}
func CreateChat(svc *service.SlackService, inputHeight int) *Chat {
func CreateChat(svc *service.SlackService, inputHeight int, selectedChannel SlackChannel) *Chat {
chat := &Chat{
List: termui.NewList(),
}
chat.List.Height = termui.TermHeight() - inputHeight
chat.List.Overflow = "wrap"
// chat.GetMessages(svc)
chat.GetMessages(svc, selectedChannel.ID)
chat.SetBorderLabel(selectedChannel.Name)
return chat
}
@ -145,3 +147,7 @@ func (c *Chat) ScrollUp() {
}
func (c *Chat) ScrollDown() {}
func (c *Chat) SetBorderLabel(label string) {
c.List.BorderLabel = label
}

View File

@ -62,8 +62,8 @@ func (i *Input) SetY(y int) {
i.Par.SetY(y)
}
func (i *Input) SendMessage(svc *service.SlackService, channel string, message string) {
svc.SendMessage(channel, message)
func (i *Input) SendMessage(svc *service.SlackService, channel string, user string, message string) {
svc.SendMessage(channel, user, message)
}
// Insert will insert a given key at the place of the current CursorPosition

View File

@ -7,6 +7,7 @@ import (
type Config struct {
SlackToken string `json:"slack_token"`
User string `json:"user"`
}
func NewConfig(filepath string) (*Config, error) {

View File

@ -93,7 +93,10 @@ func incomingMessageHandler(ctx *context.AppContext) {
if err == nil {
name = user.Name
} else {
name = "unknown"
name = ev.Username
if name == "" {
name = "unknown"
}
}
// Parse the time we get from slack which is a Unix time float
@ -154,6 +157,7 @@ func actionSend(ctx *context.AppContext) {
ctx.View.Input.SendMessage(
ctx.Service,
ctx.View.Channels.SlackChannels[ctx.View.Channels.SelectedChannel].ID,
ctx.Config.User,
ctx.View.Input.Text(),
)
ctx.View.Input.Clear()
@ -199,6 +203,10 @@ func actionMoveCursorUpChannels(ctx *context.AppContext) {
ctx.View.Channels.SlackChannels[ctx.View.Channels.SelectedChannel].ID,
)
ctx.View.Chat.SetBorderLabel(
ctx.View.Channels.SlackChannels[ctx.View.Channels.SelectedChannel].Name,
)
termui.Render(ctx.View.Channels)
termui.Render(ctx.View.Chat)
}
@ -211,6 +219,10 @@ func actionMoveCursorDownChannels(ctx *context.AppContext) {
ctx.View.Channels.SlackChannels[ctx.View.Channels.SelectedChannel].ID,
)
ctx.View.Chat.SetBorderLabel(
ctx.View.Channels.SlackChannels[ctx.View.Channels.SelectedChannel].Name,
)
termui.Render(ctx.View.Channels)
termui.Render(ctx.View.Chat)
}

View File

@ -52,9 +52,11 @@ func (s *SlackService) GetChannels() []Channel {
return chans
}
func (s *SlackService) SendMessage(channel, message string) {
func (s *SlackService) SendMessage(channel string, user string, message string) {
// https://godoc.org/github.com/nlopes/slack#PostMessageParameters
postParams := slack.PostMessageParameters{}
postParams := slack.PostMessageParameters{
Username: user,
}
// https://godoc.org/github.com/nlopes/slack#Client.PostMessage
s.Client.PostMessage(channel, message, postParams)
@ -90,8 +92,8 @@ func (s *SlackService) GetMessages(channel string, count int) []string {
name = user.Name
users[message.User] = user.Name
} else {
name = "unknown"
users[message.User] = user.Name
name = message.Username
users[message.User] = name
}
}

View File

@ -16,8 +16,14 @@ type View struct {
func CreateChatView(svc *service.SlackService) *View {
input := components.CreateInput()
channels := components.CreateChannels(svc, input.Par.Height)
chat := components.CreateChat(svc, input.Par.Height)
chat := components.CreateChat(
svc, input.Par.Height,
channels.SlackChannels[channels.SelectedChannel],
)
mode := components.CreateMode()
view := &View{