Add room creation events

This commit is contained in:
nxshock 2019-07-21 17:08:16 +05:00
parent a6f8ef9bdb
commit d52022726a
3 changed files with 56 additions and 10 deletions

View File

@ -79,7 +79,7 @@ func TestSetRoomTopic(t *testing.T) {
err := room.SetTopic(user, newTopic)
assert.Nil(t, err)
assert.Equal(t, newTopic, room.Topic())
assert.Equal(t, 2, len(room.Events())) // create event + topic event == 2
assert.Equal(t, 5, len(room.Events())) // TODO: check start event count
}
func TestSetRoomTopicWithnprivelegedUser(t *testing.T) {

View File

@ -36,21 +36,58 @@ func (user *User) CreateRoom(request createroom.Request) (internal.Room, *models
}
}
t := time.Now()
events := make([]RoomEvent, 0)
// Create room event
events = append(events, RoomEvent{
Content: nil,
Type: rooms.Create,
EventID: internal.NewToken(eventIDSize),
Sender: user,
OriginServerTS: t})
// Set join rules event
events = append(events, RoomEvent{
Content: []byte(request.Visibility), // TODO: check visibility vs join rules
Type: rooms.JoinRules,
EventID: internal.NewToken(eventIDSize),
Sender: user,
OriginServerTS: t})
// Set room name event
if request.Name != "" {
events = append(events, RoomEvent{
Content: nil, // TODO: add
Type: rooms.Name,
EventID: internal.NewToken(eventIDSize),
Sender: user,
OriginServerTS: t})
}
// Set room alias event
if request.RoomAliasName != "" {
events = append(events, RoomEvent{
Content: nil, // TODO: add
Type: rooms.CanonicalAlias,
EventID: internal.NewToken(eventIDSize),
Sender: user,
OriginServerTS: t})
}
room := &Room{
id: internal.NewToken(groupIDSize),
aliasName: request.RoomAliasName,
name: request.Name,
topic: request.Topic,
events: []RoomEvent{
RoomEvent{
Content: nil,
Type: rooms.Create,
EventID: internal.NewToken(eventIDSize),
Sender: user,
OriginServerTS: time.Now()}},
creator: user}
events: events,
creator: user}
room.events[0].Room = room
for i, _ := range room.events {
room.events[i].Room = room
//v.Room = room
}
user.backend.rooms[room.id] = room

View File

@ -50,6 +50,15 @@ const (
PinnedEvents = "m.room.pinned_events"
)
type JoinRule string
const (
Public JoinRule = "public"
Knock = "knock"
Invite = "invite"
Private = "private"
)
// https://matrix.org/docs/spec/client_server/latest#room-event-fields
type Event struct {
Content json.RawMessage `json:"content"` // Required. The fields in this object will vary depending on the type of event. When interacting with the REST API, this is the HTTP body.