signaller/internal/backends/memory/rooms.go

120 lines
2.1 KiB
Go
Raw Normal View History

package memory
import (
"sync"
2019-08-03 14:19:18 +00:00
"github.com/signaller-matrix/signaller/internal"
"github.com/signaller-matrix/signaller/internal/models/createroom"
)
type Room struct {
id string
visibility createroom.VisibilityType
aliasName string
name string
topic string
state createroom.Preset
worldReadable bool
guestCanJoin bool
avatarURL string
creator internal.User
2019-07-22 13:46:59 +00:00
joined []internal.User
2019-08-04 08:47:58 +00:00
invites []internal.User
2019-07-24 15:02:04 +00:00
server *Backend
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
}
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
}
2019-08-08 14:38:30 +00:00
func (room *Room) Aliases() []string {
room.server.mutex.RLock()
defer room.server.mutex.RUnlock()
var aliases []string
for alias, serverRoom := range room.server.roomAliases {
if serverRoom.ID() == room.ID() {
aliases = append(aliases, "#"+alias+":"+room.server.hostname)
}
}
return aliases
}
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 {
room.mutex.RLock()
defer room.mutex.RUnlock()
2019-07-22 16:02:53 +00:00
return room.joined
}
2019-07-31 15:01:20 +00:00
func (room *Room) Visibility() createroom.VisibilityType {
room.mutex.RLock()
defer room.mutex.RUnlock()
return room.visibility
}
func (room *Room) Creator() internal.User {
room.mutex.RLock()
defer room.mutex.RUnlock()
return room.creator
}
2019-08-02 16:46:46 +00:00
func (room *Room) State() createroom.Preset {
room.mutex.RLock()
defer room.mutex.RUnlock()
return room.state
}
func (room *Room) WorldReadable() bool {
room.mutex.RLock()
defer room.mutex.RUnlock()
return room.worldReadable
}
func (room *Room) GuestCanJoin() bool {
room.mutex.RLock()
defer room.mutex.RUnlock()
return room.guestCanJoin
}
func (room *Room) AvatarURL() string {
room.mutex.RLock()
defer room.mutex.RUnlock()
return room.avatarURL
}