Browse Source

Stream experiment

pull/1/head
Gregory Rudolph 5 years ago
parent
commit
b1b470bf47
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 17
      main.go

17
main.go

@ -12,7 +12,7 @@ import (
var k = keybase.NewKeybase() var k = keybase.NewKeybase()
var channel keybase.Channel var channel keybase.Channel
var channels [] keybase.Channel var channels [] keybase.Channel
var stream bool = false
func main() { func main() {
if !k.LoggedIn { if !k.LoggedIn {
fmt.Println("You are not logged in.") fmt.Println("You are not logged in.")
@ -124,6 +124,7 @@ func layout(g *gocui.Gui) error {
fmt.Fprintf(chatView, "Your chats will appear here.\nSupported commands are as follows:\n") fmt.Fprintf(chatView, "Your chats will appear here.\nSupported commands are as follows:\n")
fmt.Fprintln(chatView, "/j $username - Open your chat with $username") fmt.Fprintln(chatView, "/j $username - Open your chat with $username")
fmt.Fprintln(chatView, "/j $team $channel - Open $channel from $team") fmt.Fprintln(chatView, "/j $team $channel - Open $channel from $team")
fmt.Fprintln(chatView, "/s - Experimental: View all incoming messages from everywhere.")
fmt.Fprintln(chatView, " Please note: small teams only have #general") fmt.Fprintln(chatView, " Please note: small teams only have #general")
fmt.Fprintln(chatView, "/q - Exit") fmt.Fprintln(chatView, "/q - Exit")
} }
@ -186,6 +187,7 @@ func handleMessage(api keybase.ChatAPI, g *gocui.Gui) {
msgBody := api.Msg.Content.Text.Body msgBody := api.Msg.Content.Text.Body
msgSender := api.Msg.Sender.Username msgSender := api.Msg.Sender.Username
channelName := api.Msg.Channel.Name channelName := api.Msg.Channel.Name
if !stream {
if msgSender != k.Username { if msgSender != k.Username {
if api.Msg.Channel.MembersType == keybase.TEAM { if api.Msg.Channel.MembersType == keybase.TEAM {
topicName := api.Msg.Channel.TopicName topicName := api.Msg.Channel.TopicName
@ -202,6 +204,14 @@ func handleMessage(api keybase.ChatAPI, g *gocui.Gui) {
if api.Msg.Channel.MembersType == channel.MembersType && cleanChannelName(api.Msg.Channel.Name) == channel.Name { if api.Msg.Channel.MembersType == channel.MembersType && cleanChannelName(api.Msg.Channel.Name) == channel.Name {
printToView(g, "Chat", fmt.Sprintf("[%s]: %s", msgSender, msgBody)) printToView(g, "Chat", fmt.Sprintf("[%s]: %s", msgSender, msgBody))
} }
} else {
if api.Msg.Channel.MembersType == keybase.TEAM {
topicName := api.Msg.Channel.TopicName
printToView(g, "Chat", fmt.Sprintf("@%s#%s [%s]: %s", channelName, topicName, msgSender, msgBody))
} else {
printToView(g, "Chat", fmt.Sprintf("PM @%s [%s]: %s", cleanChannelName(channelName), msgSender, msgBody))
}
}
} }
} }
@ -213,6 +223,7 @@ func handleInput(g *gocui.Gui) error {
case "/q": case "/q":
return gocui.ErrQuit return gocui.ErrQuit
case "/j": case "/j":
stream = false
if len(command) == 3 { if len(command) == 3 {
channel.MembersType = keybase.TEAM channel.MembersType = keybase.TEAM
channel.Name = command[1] channel.Name = command[1]
@ -231,6 +242,10 @@ func handleInput(g *gocui.Gui) error {
printToView(g, "Feed", "To join a team use /j <team> <channel>") printToView(g, "Feed", "To join a team use /j <team> <channel>")
printToView(g, "Feed", "To join a PM use /j <user>") printToView(g, "Feed", "To join a PM use /j <user>")
} }
case "/s":
clearView(g, "Chat")
stream = true
printToView(g, "Feed", "You have begun viewing the formatted stream.")
default: default:
go sendChat(inputString) go sendChat(inputString)
} }

Loading…
Cancel
Save