Browse Source

Don't sleep for 5 seconds when creating portal for join via link

Tulir Asokan 2 years ago
parent
commit
5c5633548f
2 changed files with 10 additions and 2 deletions
  1. 6 0
      provisioning.go
  2. 4 2
      user.go

+ 6 - 0
provisioning.go

@@ -566,6 +566,12 @@ func (prov *ProvisioningAPI) JoinGroup(w http.ResponseWriter, r *http.Request) {
 	if info == nil {
 	if info == nil {
 		return
 		return
 	}
 	}
+	user.groupJoinLock.Lock()
+	user.skipGroupCreateDelay = info.JID
+	defer func() {
+		user.skipGroupCreateDelay = types.EmptyJID
+		user.groupJoinLock.Unlock()
+	}()
 	inviteCode, _ := mux.Vars(r)["inviteCode"]
 	inviteCode, _ := mux.Vars(r)["inviteCode"]
 	if jid, err := user.Client.JoinGroupWithLink(inviteCode); err != nil {
 	if jid, err := user.Client.JoinGroupWithLink(inviteCode); err != nil {
 		jsonResponse(w, http.StatusInternalServerError, Error{
 		jsonResponse(w, http.StatusInternalServerError, Error{

+ 4 - 2
user.go

@@ -95,7 +95,9 @@ type User struct {
 	resyncQueueLock sync.Mutex
 	resyncQueueLock sync.Mutex
 	nextResync      time.Time
 	nextResync      time.Time
 
 
-	createKeyDedup string
+	createKeyDedup       string
+	skipGroupCreateDelay types.JID
+	groupJoinLock        sync.Mutex
 }
 }
 
 
 type resyncQueueItem struct {
 type resyncQueueItem struct {
@@ -1304,7 +1306,7 @@ func (user *User) markUnread(portal *Portal, unread bool) {
 
 
 func (user *User) handleGroupCreate(evt *events.JoinedGroup) {
 func (user *User) handleGroupCreate(evt *events.JoinedGroup) {
 	portal := user.GetPortalByJID(evt.JID)
 	portal := user.GetPortalByJID(evt.JID)
-	if evt.CreateKey == "" && len(portal.MXID) == 0 {
+	if evt.CreateKey == "" && len(portal.MXID) == 0 && portal.Key.JID != user.skipGroupCreateDelay {
 		user.log.Debugfln("Delaying handling group create with empty key to avoid race conditions")
 		user.log.Debugfln("Delaying handling group create with empty key to avoid race conditions")
 		time.Sleep(5 * time.Second)
 		time.Sleep(5 * time.Second)
 	}
 	}