mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 15:47:17 +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
|
||||
/vendor
|
||||
host_key
|
||||
host_key.pub
|
||||
ssh-chat
|
||||
|
@ -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
|
||||
|
@ -13,9 +13,9 @@ type roomMember struct {
|
||||
|
||||
type Member interface {
|
||||
ID() string
|
||||
SetID(string)
|
||||
|
||||
Name() string
|
||||
SetName(string)
|
||||
|
||||
Config() message.UserConfig
|
||||
SetConfig(message.UserConfig)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user