refactor: Identifier.SetID -> Identifier.SetName

Identifier.ID() is now read-only and derived from name.
This commit is contained in:
Andrey Petrov 2016-09-01 16:22:21 -04:00
parent bccb5f3c32
commit 4bca1f0294
6 changed files with 13 additions and 16 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
/build
/vendor
host_key
host_key.pub
ssh-chat

View File

@ -156,10 +156,10 @@ func InitCommands(c *Commands) {
}
oldID := member.ID()
member.SetID(SanitizeName(args[0]))
member.SetName(args[0])
err := room.Rename(oldID, member)
if err != nil {
member.SetID(oldID)
member.SetName(oldID)
return err
}
return nil

View File

@ -13,9 +13,9 @@ type roomMember struct {
type Member interface {
ID() string
SetID(string)
Name() string
SetName(string)
Config() message.UserConfig
SetConfig(message.UserConfig)

View File

@ -3,8 +3,8 @@ package message
// Identifier is an interface that can uniquely identify itself.
type Identifier interface {
ID() string
SetID(string)
Name() string
SetName(string)
}
// SimpleID is a simple Identifier implementation used for testing.
@ -15,12 +15,12 @@ func (i SimpleID) ID() string {
return string(i)
}
// SetID is a no-op
func (i SimpleID) SetID(s string) {
// no-op
}
// Name returns the ID
func (i SimpleID) Name() string {
return i.ID()
}
// SetName is a no-op
func (i SimpleID) SetName(s string) {
// no-op
}

View File

@ -65,8 +65,8 @@ func (u *User) SetConfig(cfg UserConfig) {
}
// Rename the user with a new Identifier.
func (u *User) SetID(id string) {
u.Identifier.SetID(id)
func (u *User) SetName(name string) {
u.Identifier.SetName(name)
u.setColorIdx(rand.Int())
}

View File

@ -30,12 +30,8 @@ func (i Identity) ID() string {
return i.id
}
func (i *Identity) SetID(id string) {
i.id = id
}
func (i *Identity) SetName(name string) {
i.SetID(name)
i.id = chat.SanitizeName(name)
}
func (i Identity) Name() string {