mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-11-22 02:12:20 +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
|
AliasName() string
|
||||||
Name() string
|
Name() string
|
||||||
Topic() string
|
Topic() string
|
||||||
SetTopic(user User, topic string) *models.ApiError
|
|
||||||
Events() []rooms.Event
|
Events() []rooms.Event
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,4 +29,5 @@ type User interface {
|
|||||||
ID() string
|
ID() string
|
||||||
Password() string
|
Password() string
|
||||||
CreateRoom(request createroom.Request) (Room, *models.ApiError)
|
CreateRoom(request createroom.Request) (Room, *models.ApiError)
|
||||||
|
SetTopic(room Room, topic string) *models.ApiError
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,6 @@ package memory
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/nxshock/signaller/internal/models"
|
|
||||||
|
|
||||||
"github.com/nxshock/signaller/internal"
|
"github.com/nxshock/signaller/internal"
|
||||||
"github.com/nxshock/signaller/internal/models/createroom"
|
"github.com/nxshock/signaller/internal/models/createroom"
|
||||||
@ -78,21 +75,3 @@ func (room *Room) Creator() internal.User {
|
|||||||
|
|
||||||
return room.creator
|
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)
|
room, _ := user.CreateRoom(request)
|
||||||
|
|
||||||
var newTopic = "new topic"
|
var newTopic = "new topic"
|
||||||
err := room.SetTopic(user, newTopic)
|
err := user.SetTopic(room, newTopic)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, newTopic, room.Topic())
|
assert.Equal(t, newTopic, room.Topic())
|
||||||
assert.Equal(t, 5, len(room.Events())) // TODO: check start event count
|
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)
|
room, _ := creator.CreateRoom(request)
|
||||||
|
|
||||||
var newTopic = "new topic"
|
var newTopic = "new topic"
|
||||||
err := room.SetTopic(user2, newTopic)
|
err := user2.SetTopic(room, newTopic)
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
}
|
}
|
||||||
|
@ -93,3 +93,21 @@ func (user *User) CreateRoom(request createroom.Request) (internal.Room, *models
|
|||||||
|
|
||||||
return room, nil
|
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