|
@@ -725,7 +725,6 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|
portal.log.Infoln("Creating Matrix room. Info source:", user.MXID)
|
|
portal.log.Infoln("Creating Matrix room. Info source:", user.MXID)
|
|
|
|
|
|
var metadata *whatsappExt.GroupInfo
|
|
var metadata *whatsappExt.GroupInfo
|
|
- isPrivateChat := false
|
|
|
|
if portal.IsPrivateChat() {
|
|
if portal.IsPrivateChat() {
|
|
puppet := portal.bridge.GetPuppetByJID(portal.Key.JID)
|
|
puppet := portal.bridge.GetPuppetByJID(portal.Key.JID)
|
|
if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
|
|
if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
|
|
@@ -736,7 +735,6 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|
portal.Name = ""
|
|
portal.Name = ""
|
|
}
|
|
}
|
|
portal.Topic = "WhatsApp private chat"
|
|
portal.Topic = "WhatsApp private chat"
|
|
- isPrivateChat = true
|
|
|
|
} else if portal.IsStatusBroadcastRoom() {
|
|
} else if portal.IsStatusBroadcastRoom() {
|
|
portal.Name = "WhatsApp Status Broadcast"
|
|
portal.Name = "WhatsApp Status Broadcast"
|
|
portal.Topic = "WhatsApp status updates from your contacts"
|
|
portal.Topic = "WhatsApp status updates from your contacts"
|
|
@@ -770,13 +768,26 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|
invite = portal.bridge.Config.Bridge.Relaybot.InviteUsers
|
|
invite = portal.bridge.Config.Bridge.Relaybot.InviteUsers
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if portal.bridge.Config.Bridge.Encryption.Default {
|
|
|
|
+ initialState = append(initialState, &event.Event{
|
|
|
|
+ Type: event.StateEncryption,
|
|
|
|
+ Content: event.Content{
|
|
|
|
+ Parsed: event.EncryptionEventContent{Algorithm: id.AlgorithmMegolmV1},
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+ portal.Encrypted = true
|
|
|
|
+ if portal.IsPrivateChat() {
|
|
|
|
+ invite = append(invite, portal.bridge.Bot.UserID)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
resp, err := intent.CreateRoom(&mautrix.ReqCreateRoom{
|
|
resp, err := intent.CreateRoom(&mautrix.ReqCreateRoom{
|
|
Visibility: "private",
|
|
Visibility: "private",
|
|
Name: portal.Name,
|
|
Name: portal.Name,
|
|
Topic: portal.Topic,
|
|
Topic: portal.Topic,
|
|
Invite: invite,
|
|
Invite: invite,
|
|
Preset: "private_chat",
|
|
Preset: "private_chat",
|
|
- IsDirect: isPrivateChat,
|
|
|
|
|
|
+ IsDirect: portal.IsPrivateChat(),
|
|
InitialState: initialState,
|
|
InitialState: initialState,
|
|
})
|
|
})
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -784,6 +795,12 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|
}
|
|
}
|
|
portal.MXID = resp.RoomID
|
|
portal.MXID = resp.RoomID
|
|
portal.Update()
|
|
portal.Update()
|
|
|
|
+
|
|
|
|
+ // We set the memberships beforehand to make sure the encryption key exchange in initial backfill knows the users are here.
|
|
|
|
+ for _, user := range invite {
|
|
|
|
+ portal.bridge.StateStore.SetMembership(portal.MXID, user, event.MembershipInvite)
|
|
|
|
+ }
|
|
|
|
+
|
|
if metadata != nil {
|
|
if metadata != nil {
|
|
portal.SyncParticipants(metadata)
|
|
portal.SyncParticipants(metadata)
|
|
} else {
|
|
} else {
|
|
@@ -796,6 +813,13 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|
if portal.IsPrivateChat() {
|
|
if portal.IsPrivateChat() {
|
|
puppet := user.bridge.GetPuppetByJID(portal.Key.JID)
|
|
puppet := user.bridge.GetPuppetByJID(portal.Key.JID)
|
|
user.addPuppetToCommunity(puppet)
|
|
user.addPuppetToCommunity(puppet)
|
|
|
|
+
|
|
|
|
+ if portal.bridge.Config.Bridge.Encryption.Default {
|
|
|
|
+ err = portal.bridge.Bot.EnsureJoined(portal.MXID)
|
|
|
|
+ if err != nil {
|
|
|
|
+ portal.log.Errorln("Failed to join created portal with bridge bot for e2be:", err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
err = portal.FillInitialHistory(user)
|
|
err = portal.FillInitialHistory(user)
|
|
if err != nil {
|
|
if err != nil {
|