refactor: Move extraneous User interfaces from chat to host

This commit is contained in:
Andrey Petrov 2016-09-16 12:31:02 -04:00
parent 7f2b8e4689
commit cd5686e20e
3 changed files with 18 additions and 14 deletions

View File

@ -1,8 +1,6 @@
package chat package chat
import ( import (
"time"
"github.com/shazow/ssh-chat/chat/message" "github.com/shazow/ssh-chat/chat/message"
"github.com/shazow/ssh-chat/set" "github.com/shazow/ssh-chat/set"
) )
@ -16,16 +14,10 @@ type roomMember struct {
type Member interface { type Member interface {
message.Author message.Author
SetName(string)
Config() message.UserConfig Config() message.UserConfig
SetConfig(message.UserConfig) SetConfig(message.UserConfig)
Send(message.Message) error Send(message.Message) error
Joined() time.Time SetName(string)
ReplyTo() message.Author
SetReplyTo(message.Author)
Prompt() string
SetHighlight(string) error
} }

View File

@ -2,13 +2,15 @@ package sshchat
import ( import (
"sync" "sync"
"time"
"github.com/shazow/ssh-chat/chat" "github.com/shazow/ssh-chat/chat"
"github.com/shazow/ssh-chat/chat/message"
"github.com/shazow/ssh-chat/sshd" "github.com/shazow/ssh-chat/sshd"
) )
type client struct { type client struct {
chat.Member UserMember
sync.Mutex sync.Mutex
conns []sshd.Connection conns []sshd.Connection
} }
@ -25,9 +27,19 @@ func (cl *client) Close() error {
return nil return nil
} }
type User interface { type UserMember interface {
chat.Member chat.Member
Joined() time.Time
Prompt() string
ReplyTo() message.Author
SetHighlight(string) error
SetReplyTo(message.Author)
}
type User interface {
UserMember
Connections() []sshd.Connection Connections() []sshd.Connection
Close() error Close() error
} }

View File

@ -77,8 +77,8 @@ func (h *Host) Connect(term *sshd.Terminal) {
requestedName := term.Conn.Name() requestedName := term.Conn.Name()
screen := message.BufferedScreen(requestedName, term) screen := message.BufferedScreen(requestedName, term)
user := &client{ user := &client{
Member: screen, UserMember: screen,
conns: []sshd.Connection{term.Conn}, conns: []sshd.Connection{term.Conn},
} }
h.mu.Lock() h.mu.Lock()
@ -316,7 +316,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
return errors.New("must specify message") return errors.New("must specify message")
} }
target := msg.From().(chat.Member).ReplyTo() target := msg.From().(UserMember).ReplyTo()
if target == nil { if target == nil {
return errors.New("no message to reply to") return errors.New("no message to reply to")
} }