2019-07-21 09:43:14 +00:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
2019-07-21 11:04:24 +00:00
|
|
|
|
2019-07-21 09:43:14 +00:00
|
|
|
"github.com/nxshock/signaller/internal"
|
|
|
|
"github.com/nxshock/signaller/internal/models/createroom"
|
|
|
|
"github.com/nxshock/signaller/internal/models/rooms"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Room struct {
|
|
|
|
id string
|
2019-07-31 15:01:20 +00:00
|
|
|
visibility createroom.VisibilityType
|
2019-07-21 09:43:14 +00:00
|
|
|
aliasName string
|
|
|
|
name string
|
|
|
|
topic string
|
|
|
|
|
|
|
|
creator internal.User
|
2019-07-22 13:46:59 +00:00
|
|
|
joined []internal.User
|
2019-07-21 09:43:14 +00:00
|
|
|
|
2019-07-21 11:30:14 +00:00
|
|
|
events []RoomEvent
|
2019-07-21 09:43:14 +00:00
|
|
|
|
2019-07-24 15:02:04 +00:00
|
|
|
server *Backend
|
|
|
|
|
2019-07-21 09:43:14 +00:00
|
|
|
mutex sync.RWMutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (room *Room) ID() string {
|
|
|
|
room.mutex.RLock()
|
|
|
|
defer room.mutex.RUnlock()
|
|
|
|
|
2019-07-24 15:02:04 +00:00
|
|
|
return "!" + room.id + ":" + room.server.hostname
|
2019-07-21 09:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (room *Room) Name() string {
|
|
|
|
room.mutex.RLock()
|
|
|
|
defer room.mutex.RUnlock()
|
|
|
|
|
|
|
|
return room.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (room *Room) AliasName() string {
|
|
|
|
room.mutex.RLock()
|
|
|
|
defer room.mutex.RUnlock()
|
|
|
|
|
|
|
|
return room.aliasName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (room *Room) Topic() string {
|
|
|
|
room.mutex.RLock()
|
|
|
|
defer room.mutex.RUnlock()
|
|
|
|
|
|
|
|
return room.topic
|
|
|
|
}
|
|
|
|
|
2019-07-22 16:02:53 +00:00
|
|
|
func (room *Room) Users() []internal.User {
|
2019-07-21 09:43:14 +00:00
|
|
|
room.mutex.RLock()
|
|
|
|
defer room.mutex.RUnlock()
|
|
|
|
|
2019-07-22 16:02:53 +00:00
|
|
|
return room.joined
|
2019-07-21 09:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (room *Room) Events() []rooms.Event {
|
|
|
|
room.mutex.RLock()
|
|
|
|
defer room.mutex.RUnlock()
|
|
|
|
|
2019-07-21 11:30:14 +00:00
|
|
|
result := make([]rooms.Event, 0)
|
|
|
|
for _, v := range room.events {
|
|
|
|
result = append(result, v.ToEvent())
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
2019-07-21 09:43:14 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 15:01:20 +00:00
|
|
|
func (room *Room) Visibility() createroom.VisibilityType {
|
|
|
|
room.mutex.RLock()
|
|
|
|
defer room.mutex.RUnlock()
|
|
|
|
|
|
|
|
return room.visibility
|
|
|
|
}
|
|
|
|
|
2019-07-21 09:43:14 +00:00
|
|
|
func (room *Room) Creator() internal.User {
|
|
|
|
room.mutex.RLock()
|
|
|
|
defer room.mutex.RUnlock()
|
|
|
|
|
|
|
|
return room.creator
|
|
|
|
}
|