2019-07-21 09:43:14 +00:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
2019-07-21 11:04:24 +00:00
|
|
|
|
2019-08-03 14:19:18 +00:00
|
|
|
"github.com/signaller-matrix/signaller/internal/models/createroom"
|
2019-07-21 09:43:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Room struct {
|
2019-08-02 17:55:35 +00:00
|
|
|
id string
|
|
|
|
visibility createroom.VisibilityType
|
|
|
|
aliasName string
|
|
|
|
name string
|
|
|
|
topic string
|
|
|
|
state createroom.Preset
|
|
|
|
worldReadable bool
|
|
|
|
guestCanJoin bool
|
|
|
|
avatarURL string
|
2019-07-21 09:43:14 +00:00
|
|
|
|
2019-09-05 19:00:22 +00:00
|
|
|
creator string
|
|
|
|
joined []string
|
|
|
|
invites []string
|
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
|
|
|
|
}
|
|
|
|
|
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() {
|
2019-08-08 15:21:22 +00:00
|
|
|
aliases = append(aliases, alias)
|
2019-08-08 14:38:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aliases
|
|
|
|
}
|
|
|
|
|
2019-07-21 09:43:14 +00:00
|
|
|
func (room *Room) Topic() string {
|
|
|
|
room.mutex.RLock()
|
|
|
|
defer room.mutex.RUnlock()
|
|
|
|
|
|
|
|
return room.topic
|
|
|
|
}
|
|
|
|
|
2019-09-05 19:00:22 +00:00
|
|
|
func (this *Room) Users() []string {
|
|
|
|
this.mutex.RLock()
|
|
|
|
defer this.mutex.RUnlock()
|
2019-07-21 09:43:14 +00:00
|
|
|
|
2019-09-05 19:00:22 +00:00
|
|
|
return this.joined
|
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-09-05 19:00:22 +00:00
|
|
|
func (this *Room) Creator() string {
|
|
|
|
this.mutex.RLock()
|
|
|
|
defer this.mutex.RUnlock()
|
2019-07-21 09:43:14 +00:00
|
|
|
|
2019-09-05 19:00:22 +00:00
|
|
|
return this.creator
|
2019-07-21 09:43:14 +00:00
|
|
|
}
|
2019-08-02 16:46:46 +00:00
|
|
|
|
|
|
|
func (room *Room) State() createroom.Preset {
|
|
|
|
room.mutex.RLock()
|
|
|
|
defer room.mutex.RUnlock()
|
|
|
|
|
|
|
|
return room.state
|
|
|
|
}
|
2019-08-02 17:55:35 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2019-09-05 19:00:22 +00:00
|
|
|
|
|
|
|
func (this *Room) PutInvited(invitedID string) {
|
|
|
|
this.mutex.RLock()
|
|
|
|
defer this.mutex.RUnlock()
|
|
|
|
|
|
|
|
this.invites = append(this.invites, invitedID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Room) PutJoined(joinedID string) {
|
|
|
|
this.mutex.RLock()
|
|
|
|
defer this.mutex.RUnlock()
|
|
|
|
|
|
|
|
this.joined = append(this.joined, joinedID)
|
|
|
|
}
|