mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-12-22 17:01:50 +00:00
Move changing room topic to user method
This commit is contained in:
parent
d52022726a
commit
9c98ec1cf3
@ -21,7 +21,6 @@ type Room interface {
|
||||
AliasName() string
|
||||
Name() string
|
||||
Topic() string
|
||||
SetTopic(user User, topic string) *models.ApiError
|
||||
Events() []rooms.Event
|
||||
}
|
||||
|
||||
@ -30,4 +29,5 @@ type User interface {
|
||||
ID() string
|
||||
Password() string
|
||||
CreateRoom(request createroom.Request) (Room, *models.ApiError)
|
||||
SetTopic(room Room, topic string) *models.ApiError
|
||||
}
|
||||
|
@ -2,9 +2,6 @@ package memory
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/nxshock/signaller/internal/models"
|
||||
|
||||
"github.com/nxshock/signaller/internal"
|
||||
"github.com/nxshock/signaller/internal/models/createroom"
|
||||
@ -78,21 +75,3 @@ func (room *Room) Creator() internal.User {
|
||||
|
||||
return room.creator
|
||||
}
|
||||
|
||||
func (room *Room) SetTopic(user internal.User, topic string) *models.ApiError {
|
||||
room.mutex.Lock()
|
||||
defer room.mutex.Unlock()
|
||||
|
||||
if room.creator.ID() != user.ID() { // TODO: currently only creator can change topic
|
||||
return internal.NewError(models.M_FORBIDDEN, "")
|
||||
}
|
||||
|
||||
room.topic = topic
|
||||
room.events = append(room.events, RoomEvent{
|
||||
Type: rooms.Topic,
|
||||
Sender: user,
|
||||
OriginServerTS: time.Now(),
|
||||
Room: room})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func TestSetRoomTopic(t *testing.T) {
|
||||
room, _ := user.CreateRoom(request)
|
||||
|
||||
var newTopic = "new topic"
|
||||
err := room.SetTopic(user, newTopic)
|
||||
err := user.SetTopic(room, newTopic)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, newTopic, room.Topic())
|
||||
assert.Equal(t, 5, len(room.Events())) // TODO: check start event count
|
||||
@ -96,6 +96,6 @@ func TestSetRoomTopicWithnprivelegedUser(t *testing.T) {
|
||||
room, _ := creator.CreateRoom(request)
|
||||
|
||||
var newTopic = "new topic"
|
||||
err := room.SetTopic(user2, newTopic)
|
||||
err := user2.SetTopic(room, newTopic)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
@ -93,3 +93,21 @@ func (user *User) CreateRoom(request createroom.Request) (internal.Room, *models
|
||||
|
||||
return room, nil
|
||||
}
|
||||
|
||||
func (user *User) SetTopic(room internal.Room, topic string) *models.ApiError {
|
||||
room.(*Room).mutex.Lock()
|
||||
defer room.(*Room).mutex.Unlock()
|
||||
|
||||
if room.(*Room).creator.ID() != user.ID() { // TODO: currently only creator can change topic
|
||||
return internal.NewError(models.M_FORBIDDEN, "")
|
||||
}
|
||||
|
||||
room.(*Room).topic = topic
|
||||
room.(*Room).events = append(room.(*Room).events, RoomEvent{
|
||||
Type: rooms.Topic,
|
||||
Sender: user,
|
||||
OriginServerTS: time.Now(),
|
||||
Room: room})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user