Changeset 0.23.2 (#155)

This commit is contained in:
2026-03-06 23:17:03 +00:00
parent 4c6555cb06
commit 2dc4514a57
36 changed files with 2784 additions and 192 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/gin-gonic/gin"
"git.gobha.me/xcaliber/chat-switchboard/database"
"git.gobha.me/xcaliber/chat-switchboard/models"
"git.gobha.me/xcaliber/chat-switchboard/store"
)
@@ -258,6 +259,37 @@ func (h *ParticipantHandler) Remove(c *gin.Context) {
}
}
// v0.23.2: DM guard — cannot drop below 2 human participants
var channelType string
_ = database.DB.QueryRowContext(c.Request.Context(), database.Q(`
SELECT COALESCE(type, 'direct') FROM channels WHERE id = $1
`), channelID).Scan(&channelType)
if channelType == "dm" && p.ParticipantType == "user" {
var userCount int
_ = database.DB.QueryRowContext(c.Request.Context(), database.Q(`
SELECT COUNT(*) FROM channel_participants
WHERE channel_id = $1 AND participant_type = 'user'
`), channelID).Scan(&userCount)
if userCount <= 2 {
c.JSON(http.StatusConflict, gin.H{"error": "DMs require at least 2 participants"})
return
}
}
// v0.23.2: Group guard — cannot remove the last persona
if channelType == "group" && p.ParticipantType == "persona" {
var personaCount int
_ = database.DB.QueryRowContext(c.Request.Context(), database.Q(`
SELECT COUNT(*) FROM channel_participants
WHERE channel_id = $1 AND participant_type = 'persona'
`), channelID).Scan(&personaCount)
if personaCount <= 1 {
c.JSON(http.StatusConflict, gin.H{"error": "group chats require at least 1 persona"})
return
}
}
// If removing a persona, also remove its auto-created model roster entry
if p.ParticipantType == "persona" {
_ = h.stores.Channels.DeleteModelByPersona(c.Request.Context(), channelID, p.ParticipantID)