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
|
usersByMXID map[id.UserID]*User
|
||||||
usersByUsername map[string]*User
|
usersByUsername map[string]*User
|
||||||
usersLock sync.Mutex
|
usersLock sync.Mutex
|
||||||
managementRooms map[id.RoomID]*User
|
spaceRooms map[id.RoomID]*User
|
||||||
managementRoomsLock sync.Mutex
|
managementRoomsLock sync.Mutex
|
||||||
|
managementRooms map[id.RoomID]*User
|
||||||
portalsByMXID map[id.RoomID]*Portal
|
portalsByMXID map[id.RoomID]*Portal
|
||||||
portalsByJID map[database.PortalKey]*Portal
|
portalsByJID map[database.PortalKey]*Portal
|
||||||
portalsLock sync.Mutex
|
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)
|
portal.ensureUserInvited(user)
|
||||||
user.syncChatDoublePuppetDetails(portal, true)
|
user.syncChatDoublePuppetDetails(portal, true)
|
||||||
|
|
||||||
|
portal.addToSpace(user.getSpaceRoom(), portal.MXID)
|
||||||
|
|
||||||
if groupInfo != nil {
|
if groupInfo != nil {
|
||||||
portal.SyncParticipants(user, groupInfo)
|
portal.SyncParticipants(user, groupInfo)
|
||||||
if groupInfo.IsAnnounce {
|
if groupInfo.IsAnnounce {
|
||||||
|
@ -1176,6 +1178,15 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, i
|
||||||
return nil
|
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 {
|
func (portal *Portal) IsPrivateChat() bool {
|
||||||
return portal.Key.JID.Server == types.DefaultUserServer
|
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)
|
invite = append(invite, user.MXID)
|
||||||
|
|
||||||
resp, err := user.bridge.Bot.CreateRoom(&mautrix.ReqCreateRoom{
|
resp, err := user.bridge.Bot.CreateRoom(&mautrix.ReqCreateRoom{
|
||||||
|
Visibility: "private",
|
||||||
|
Name: "WhatsApp",
|
||||||
Topic: "WhatsApp bridge Space",
|
Topic: "WhatsApp bridge Space",
|
||||||
Invite: invite,
|
Invite: invite,
|
||||||
CreationContent: creationContent,
|
CreationContent: creationContent,
|
||||||
|
@ -207,12 +209,21 @@ func (user *User) getSpaceRoom() id.RoomID {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
user.log.Debugln("Space found" + user.SpaceRoom)
|
user.log.Debugln("Space found" + user.SpaceRoom)
|
||||||
|
roomID = user.SpaceRoom
|
||||||
}
|
}
|
||||||
return roomID
|
return roomID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) setSpaceRoom(roomID id.RoomID) {
|
func (user *User) setSpaceRoom(spaceID id.RoomID) {
|
||||||
user.log.Debugln("Space ID to set" + 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 {
|
func (user *User) GetManagementRoom() id.RoomID {
|
||||||
|
|
Loading…
Reference in a new issue