mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-12-22 17:01:50 +00:00
Add set romm topic method for memory backend
This commit is contained in:
parent
0dde8e270c
commit
cbb1befd60
@ -22,6 +22,7 @@ type Room interface {
|
||||
AliasName() string
|
||||
Name() string
|
||||
Topic() string
|
||||
SetTopic(user User, topic string) *models.ApiError
|
||||
Events() []rooms.Event
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package memory
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/nxshock/signaller/internal/models"
|
||||
|
||||
"github.com/nxshock/signaller/internal"
|
||||
"github.com/nxshock/signaller/internal/models/createroom"
|
||||
"github.com/nxshock/signaller/internal/models/rooms"
|
||||
@ -77,3 +79,16 @@ func (room *Room) NewEvent(event rooms.Event) {
|
||||
|
||||
room.events = append(room.events, event)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -62,3 +62,39 @@ func TestCreateAlreadyExistingRoom(t *testing.T) {
|
||||
_, err = backend.CreateRoom(user, request)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestSetRoomTopic(t *testing.T) {
|
||||
backend := NewBackend("localhost")
|
||||
|
||||
user, _, _ := backend.Register("user1", "", "")
|
||||
|
||||
request := createroom.Request{
|
||||
RoomAliasName: "room1",
|
||||
Name: "room1",
|
||||
Topic: "topic"}
|
||||
|
||||
room, _ := backend.CreateRoom(user, request)
|
||||
|
||||
var newTopic = "new topic"
|
||||
err := room.SetTopic(user, newTopic)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, newTopic, room.Topic())
|
||||
}
|
||||
|
||||
func TestSetRoomTopicWithnprivelegedUser(t *testing.T) {
|
||||
backend := NewBackend("localhost")
|
||||
|
||||
creator, _, _ := backend.Register("user1", "", "")
|
||||
user2, _, _ := backend.Register("user2", "", "")
|
||||
|
||||
request := createroom.Request{
|
||||
RoomAliasName: "room1",
|
||||
Name: "room1",
|
||||
Topic: "topic"}
|
||||
|
||||
room, _ := backend.CreateRoom(creator, request)
|
||||
|
||||
var newTopic = "new topic"
|
||||
err := room.SetTopic(user2, newTopic)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user