mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-10 20:32:10 +03:00
refactor: Identifier.SetID -> Identifier.SetName
Identifier.ID() is now read-only and derived from name.
This commit is contained in:
parent
bccb5f3c32
commit
4bca1f0294
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
/build
|
/build
|
||||||
|
/vendor
|
||||||
host_key
|
host_key
|
||||||
host_key.pub
|
host_key.pub
|
||||||
ssh-chat
|
ssh-chat
|
||||||
|
@ -156,10 +156,10 @@ func InitCommands(c *Commands) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
oldID := member.ID()
|
oldID := member.ID()
|
||||||
member.SetID(SanitizeName(args[0]))
|
member.SetName(args[0])
|
||||||
err := room.Rename(oldID, member)
|
err := room.Rename(oldID, member)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
member.SetID(oldID)
|
member.SetName(oldID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -13,9 +13,9 @@ type roomMember struct {
|
|||||||
|
|
||||||
type Member interface {
|
type Member interface {
|
||||||
ID() string
|
ID() string
|
||||||
SetID(string)
|
|
||||||
|
|
||||||
Name() string
|
Name() string
|
||||||
|
SetName(string)
|
||||||
|
|
||||||
Config() message.UserConfig
|
Config() message.UserConfig
|
||||||
SetConfig(message.UserConfig)
|
SetConfig(message.UserConfig)
|
||||||
|
@ -3,8 +3,8 @@ package message
|
|||||||
// Identifier is an interface that can uniquely identify itself.
|
// Identifier is an interface that can uniquely identify itself.
|
||||||
type Identifier interface {
|
type Identifier interface {
|
||||||
ID() string
|
ID() string
|
||||||
SetID(string)
|
|
||||||
Name() string
|
Name() string
|
||||||
|
SetName(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SimpleID is a simple Identifier implementation used for testing.
|
// SimpleID is a simple Identifier implementation used for testing.
|
||||||
@ -15,12 +15,12 @@ func (i SimpleID) ID() string {
|
|||||||
return string(i)
|
return string(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetID is a no-op
|
|
||||||
func (i SimpleID) SetID(s string) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
|
|
||||||
// Name returns the ID
|
// Name returns the ID
|
||||||
func (i SimpleID) Name() string {
|
func (i SimpleID) Name() string {
|
||||||
return i.ID()
|
return i.ID()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetName is a no-op
|
||||||
|
func (i SimpleID) SetName(s string) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
@ -65,8 +65,8 @@ func (u *User) SetConfig(cfg UserConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rename the user with a new Identifier.
|
// Rename the user with a new Identifier.
|
||||||
func (u *User) SetID(id string) {
|
func (u *User) SetName(name string) {
|
||||||
u.Identifier.SetID(id)
|
u.Identifier.SetName(name)
|
||||||
u.setColorIdx(rand.Int())
|
u.setColorIdx(rand.Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +30,8 @@ func (i Identity) ID() string {
|
|||||||
return i.id
|
return i.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Identity) SetID(id string) {
|
|
||||||
i.id = id
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Identity) SetName(name string) {
|
func (i *Identity) SetName(name string) {
|
||||||
i.SetID(name)
|
i.id = chat.SanitizeName(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Identity) Name() string {
|
func (i Identity) Name() string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user