// Member returns a corresponding Member object to a User if the Member is // present in this room. func (r *Room) Member(u *message.User) (*Member, bool) { m, ok := r.MemberById(u.Id()) if !ok { return nil, false } // Check that it's the same user if m.User != u { return nil, false } return m, true }
// Join the room as a user, will announce. func (r *Room) Join(u *message.User) (*Member, error) { if r.closed { return nil, ErrRoomClosed } if u.Id() == "" { return nil, ErrInvalidName } member := Member{u, false} err := r.members.Add(&member) if err != nil { return nil, err } r.History(u) s := fmt.Sprintf("%s joined. (Connected: %d)", u.Name(), r.members.Len()) r.Send(message.NewAnnounceMsg(s)) return &member, nil }