fix the issue that may duplicate create room on matrix side
This commit is contained in:
parent
1d58ca3270
commit
2d03904646
|
@ -1072,6 +1072,7 @@ func (handler *CommandHandler) CommandCreate(ce *CommandEvent) {
|
|||
HistoryDisclosed: "true",
|
||||
Topic: roomNameEvent.Name,
|
||||
}
|
||||
ce.User.currentCreateRoomName = roomNameEvent.Name
|
||||
handler.log.Debugln("Create Group", roomNameEvent.Name, "with", selfMembers, participants)
|
||||
err = ce.User.Conn.HandleGroupCreate(selfMembers)
|
||||
if err != nil {
|
||||
|
@ -1087,6 +1088,7 @@ func (handler *CommandHandler) CommandCreate(ce *CommandEvent) {
|
|||
})
|
||||
}
|
||||
conversationId, ok := <-ce.User.Conn.CreateChan
|
||||
handler.log.Debugln("Create Group: conversationId=", conversationId)
|
||||
if ok {
|
||||
portal := handler.bridge.GetPortalByJID(database.GroupPortalKey(conversationId))
|
||||
portal.roomCreateLock.Lock()
|
||||
|
@ -1105,9 +1107,11 @@ func (handler *CommandHandler) CommandCreate(ce *CommandEvent) {
|
|||
}
|
||||
portal.Encrypted = true
|
||||
}
|
||||
|
||||
handler.log.Debugln("Create Group: before update protal")
|
||||
portal.Update()
|
||||
portal.UpdateBridgeInfo()
|
||||
ce.User.currentCreateRoomName = ""
|
||||
handler.log.Debugln("Create Group: after update protal")
|
||||
|
||||
err = ce.User.Conn.AddMember(participantMembers, conversationId)
|
||||
ce.Reply("Successfully created Skype group %s", portal.Key.JID)
|
||||
|
|
12
portal.go
12
portal.go
|
@ -1101,10 +1101,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||
if err := intent.EnsureRegistered(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
portal.log.Infoln("Creating Matrix room. Info source user.MXID:", user.MXID)
|
||||
portal.log.Infoln("Creating Matrix room. Info source portal.Key.JID:", portal.Key.JID)
|
||||
|
||||
portal.log.Debugln("Creating Matrix room: user.MXID=%s, portal.Key.JID=%s", user.MXID, portal.Key.JID)
|
||||
var metadata *skypeExt.GroupInfo
|
||||
if portal.IsPrivateChat() {
|
||||
puppet := portal.bridge.GetPuppetByJID(portal.Key.JID + skypeExt.NewUserSuffix)
|
||||
|
@ -1134,9 +1131,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||
}
|
||||
if noRoomTopic {
|
||||
for index, participant := range metadata.Participants {
|
||||
fmt.Println()
|
||||
fmt.Printf("metadata.Participants2: %+v", participant)
|
||||
fmt.Println()
|
||||
portal.log.Debugfln("metadata.Participants2: %+v", participant)
|
||||
|
||||
if participant.JID == user.JID {
|
||||
continue
|
||||
|
@ -1157,6 +1152,9 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||
portal.Name = portalName
|
||||
} else {
|
||||
portal.Name = metadata.Name
|
||||
if (user.currentCreateRoomName == portal.Name && portal.Name != "") {
|
||||
return errors.New("It looks like a room is being created in the matrix using command 'create', so there is no need to create a new room here.")
|
||||
}
|
||||
}
|
||||
// portal.Topic = metadata.Topic
|
||||
portal.Topic = ""
|
||||
|
|
4
user.go
4
user.go
|
@ -57,6 +57,7 @@ type User struct {
|
|||
mgmtCreateLock sync.Mutex
|
||||
|
||||
contactsPresence map[string]*skypeExt.Presence
|
||||
currentCreateRoomName string
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetUserByMXID(userID id.UserID) *User {
|
||||
|
@ -873,9 +874,10 @@ func (user *User) HandleChatUpdate(cmd skype.Resource) {
|
|||
case skypeExt.ChatMemberAdd:
|
||||
user.log.Debugfln("chat member add")
|
||||
if len(portal.MXID) == 0 {
|
||||
user.log.Debugfln("seems no room for chat member add, start create a new matrix room")
|
||||
err := portal.CreateMatrixRoom(user)
|
||||
if err != nil {
|
||||
fmt.Println("create room failed")
|
||||
user.log.Debugln(err.Error())
|
||||
}
|
||||
}
|
||||
go portal.membershipAdd(cmd.Content)
|
||||
|
|
Loading…
Reference in New Issue