Init space creation

Co-authored-by: clmnin <clament.john.k@gmail.com>
This commit is contained in:
Helder Ferreira 2021-12-28 11:14:07 +00:00
parent 7b5764919a
commit 863c375be0
No known key found for this signature in database
GPG key ID: 3848724EAD604B85
2 changed files with 37 additions and 0 deletions

View file

@ -72,6 +72,7 @@ type User struct {
MXID id.UserID
JID types.JID
ManagementRoom id.RoomID
SpaceRoom id.RoomID
}
func (user *User) Scan(row Scannable) *User {

36
user.go
View file

@ -179,6 +179,42 @@ func (bridge *Bridge) NewUser(dbUser *database.User) *User {
return user
}
func (user *User) getSpaceRoom() id.RoomID {
var roomID id.RoomID
user.log.Debugln("getSpaceRoom called")
if len(user.SpaceRoom) == 0 {
//TODO check if Spaces creation is enabled by config
creationContent := make(map[string]interface{})
creationContent["type"] = "m.space"
user.log.Debugln("Creating a new space for the user")
user.log.Debugln("Inviting user " + user.MXID)
var invite []id.UserID
invite = append(invite, user.MXID)
resp, err := user.bridge.Bot.CreateRoom(&mautrix.ReqCreateRoom{
Topic: "WhatsApp bridge Space",
Invite: invite,
CreationContent: creationContent,
})
if err != nil {
user.log.Errorln("Failed to auto-create space room:", err)
} else {
user.setSpaceRoom(resp.RoomID)
}
} else {
user.log.Debugln("Space found" + user.SpaceRoom)
}
return roomID
}
func (user *User) setSpaceRoom(roomID id.RoomID) {
user.log.Debugln("Space ID to set" + roomID)
}
func (user *User) GetManagementRoom() id.RoomID {
if len(user.ManagementRoom) == 0 {
user.mgmtCreateLock.Lock()