mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 09:23:51 +01:00
add newly created channels to the space
Co-authored-by: clmnin <clament.john.k@gmail.com>
This commit is contained in:
parent
863c375be0
commit
727b11e7ef
3 changed files with 26 additions and 3 deletions
3
main.go
3
main.go
|
@ -179,8 +179,9 @@ type Bridge struct {
|
|||
usersByMXID map[id.UserID]*User
|
||||
usersByUsername map[string]*User
|
||||
usersLock sync.Mutex
|
||||
managementRooms map[id.RoomID]*User
|
||||
spaceRooms map[id.RoomID]*User
|
||||
managementRoomsLock sync.Mutex
|
||||
managementRooms map[id.RoomID]*User
|
||||
portalsByMXID map[id.RoomID]*Portal
|
||||
portalsByJID map[database.PortalKey]*Portal
|
||||
portalsLock sync.Mutex
|
||||
|
|
11
portal.go
11
portal.go
|
@ -1141,6 +1141,8 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, i
|
|||
portal.ensureUserInvited(user)
|
||||
user.syncChatDoublePuppetDetails(portal, true)
|
||||
|
||||
portal.addToSpace(user.getSpaceRoom(), portal.MXID)
|
||||
|
||||
if groupInfo != nil {
|
||||
portal.SyncParticipants(user, groupInfo)
|
||||
if groupInfo.IsAnnounce {
|
||||
|
@ -1176,6 +1178,15 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, i
|
|||
return nil
|
||||
}
|
||||
|
||||
func (portal *Portal) addToSpace(spaceID id.RoomID, portalID id.RoomID) {
|
||||
|
||||
parentSpaceContent := make(map[string]interface{})
|
||||
parentSpaceContent["via"] = []string{"matrix.wounn.xyz"}
|
||||
|
||||
portal.log.Errorln("adding room " + portalID + " to the space " + spaceID)
|
||||
portal.MainIntent().SendStateEvent(spaceID, event.Type{Type: "m.space.child", Class: event.StateEventType}, portalID.String(), parentSpaceContent)
|
||||
}
|
||||
|
||||
func (portal *Portal) IsPrivateChat() bool {
|
||||
return portal.Key.JID.Server == types.DefaultUserServer
|
||||
}
|
||||
|
|
15
user.go
15
user.go
|
@ -196,6 +196,8 @@ func (user *User) getSpaceRoom() id.RoomID {
|
|||
invite = append(invite, user.MXID)
|
||||
|
||||
resp, err := user.bridge.Bot.CreateRoom(&mautrix.ReqCreateRoom{
|
||||
Visibility: "private",
|
||||
Name: "WhatsApp",
|
||||
Topic: "WhatsApp bridge Space",
|
||||
Invite: invite,
|
||||
CreationContent: creationContent,
|
||||
|
@ -207,12 +209,21 @@ func (user *User) getSpaceRoom() id.RoomID {
|
|||
}
|
||||
} else {
|
||||
user.log.Debugln("Space found" + user.SpaceRoom)
|
||||
roomID = user.SpaceRoom
|
||||
}
|
||||
return roomID
|
||||
}
|
||||
|
||||
func (user *User) setSpaceRoom(roomID id.RoomID) {
|
||||
user.log.Debugln("Space ID to set" + roomID)
|
||||
func (user *User) setSpaceRoom(spaceID id.RoomID) {
|
||||
existingUser, ok := user.bridge.spaceRooms[spaceID]
|
||||
if ok {
|
||||
existingUser.SpaceRoom = ""
|
||||
existingUser.Update()
|
||||
}
|
||||
|
||||
user.SpaceRoom = spaceID
|
||||
user.bridge.spaceRooms[user.SpaceRoom] = user
|
||||
user.Update()
|
||||
}
|
||||
|
||||
func (user *User) GetManagementRoom() id.RoomID {
|
||||
|
|
Loading…
Reference in a new issue