fix(collab): fix self-lockout, stuck live sessions, block locking propagation and reactive hashtags
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 58s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 58s
This commit is contained in:
1 parent
0e06cc5577
commit
996f27133c
6 files changed
+303
-89
No files matched your search
+37
-8
@@ -1490,9 +1490,20 @@ func (s *Server) handleLockBlock(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
s.wsHub.BroadcastRoom("doc:"+docID, "DOC_BLOCK_LOCKED", lockInfo, nil)
|
||||
if users, err := s.store.GetAuthorizedDocUsers(docID); err == nil {
|
||||
for _, uid := range users {
|
||||
s.wsHub.BroadcastToUser(uid, "DOC_BLOCK_LOCKED", lockInfo)
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]interface{}{
|
||||
"success": true,
|
||||
"lock": lockInfo,
|
||||
"success": true,
|
||||
"lock": lockInfo,
|
||||
"docId": lockInfo.DocID,
|
||||
"blockId": lockInfo.BlockID,
|
||||
"userId": lockInfo.UserID,
|
||||
"userName": lockInfo.UserName,
|
||||
"userColor": lockInfo.UserColor,
|
||||
"expiresAt": lockInfo.ExpiresAt,
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -1506,11 +1517,17 @@ func (s *Server) handleUnlockBlock(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if s.wsHub != nil {
|
||||
s.wsHub.ReleaseBlockLock(docID, blockID, userID)
|
||||
s.wsHub.BroadcastRoom("doc:"+docID, "DOC_BLOCK_UNLOCKED", map[string]string{
|
||||
evt := map[string]string{
|
||||
"docId": docID,
|
||||
"blockId": blockID,
|
||||
"userId": userID,
|
||||
}, nil)
|
||||
}
|
||||
s.wsHub.BroadcastRoom("doc:"+docID, "DOC_BLOCK_UNLOCKED", evt, nil)
|
||||
if users, err := s.store.GetAuthorizedDocUsers(docID); err == nil {
|
||||
for _, uid := range users {
|
||||
s.wsHub.BroadcastToUser(uid, "DOC_BLOCK_UNLOCKED", evt)
|
||||
}
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]bool{"success": true})
|
||||
}
|
||||
@@ -1529,7 +1546,7 @@ func (s *Server) handleStartLiveSession(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
}
|
||||
|
||||
ttl := 120 * time.Second // 2 min lease with heartbeat while active
|
||||
ttl := 60 * time.Second // 1 min lease with heartbeat while active
|
||||
if s.wsHub != nil {
|
||||
info, ok, existing := s.wsHub.StartLiveSession(docID, userID, userName, ttl)
|
||||
if !ok && existing != nil {
|
||||
@@ -1549,8 +1566,13 @@ func (s *Server) handleStartLiveSession(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]interface{}{
|
||||
"success": true,
|
||||
"session": info,
|
||||
"success": true,
|
||||
"session": info,
|
||||
"docId": info.DocID,
|
||||
"initiatorId": info.InitiatorID,
|
||||
"initiatorName": info.InitiatorName,
|
||||
"startedAt": info.StartedAt,
|
||||
"expiresAt": info.ExpiresAt,
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -1561,8 +1583,15 @@ func (s *Server) handleEndLiveSession(w http.ResponseWriter, r *http.Request) {
|
||||
userID := auth.GetUserID(r.Context())
|
||||
docID := chi.URLParam(r, "id")
|
||||
|
||||
doc, _ := s.store.GetDocumentByID(userID, docID)
|
||||
isOwner := doc != nil && (doc.IsOwner || doc.Permission == "owner" || doc.UserID == userID)
|
||||
|
||||
if s.wsHub != nil {
|
||||
s.wsHub.EndLiveSession(docID, userID)
|
||||
if isOwner {
|
||||
s.wsHub.ForceEndLiveSession(docID)
|
||||
} else {
|
||||
s.wsHub.EndLiveSession(docID, userID)
|
||||
}
|
||||
evt := map[string]string{
|
||||
"docId": docID,
|
||||
"userId": userID,
|
||||
|
||||
Reference in new issue
Block a user