feat: notes to self via self-DM
Backend: - Removed self-DM restriction in conversation Create - Added duplicate check for self-DMs (returns existing one) Frontend: - ConversationList: [📝] button creates/opens notes to self - Self-DMs show as 'Notes' with 📝 icon in sidebar - DMChat header shows 'Notes' for self-DMs
This commit is contained in:
+19
-5
@@ -82,10 +82,7 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
memberSet[uid] = struct{}{}
|
||||
}
|
||||
}
|
||||
if len(memberSet) == 1 {
|
||||
http.Error(w, `{"error":"cannot create conversation with yourself"}`, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// ponytail: allow self-DM (notes to self) — len(memberSet)==1 is fine
|
||||
|
||||
memberIDs := make([]string, 0, len(memberSet))
|
||||
for uid := range memberSet {
|
||||
@@ -94,7 +91,24 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
sort.Strings(memberIDs)
|
||||
|
||||
// For a 1:1 DM, check if it already exists.
|
||||
if len(memberIDs) == 2 {
|
||||
if len(memberIDs) == 1 {
|
||||
var existingID string
|
||||
err := h.db.QueryRowContext(r.Context(), `
|
||||
SELECT c.id FROM conversations c
|
||||
WHERE c.type = 'dm'
|
||||
AND (SELECT COUNT(*) FROM conversation_members cm WHERE cm.conversation_id = c.id) = 1
|
||||
AND EXISTS (SELECT 1 FROM conversation_members cm2 WHERE cm2.conversation_id = c.id AND cm2.user_id = $1)
|
||||
LIMIT 1
|
||||
`, memberIDs[0]).Scan(&existingID)
|
||||
if err == nil {
|
||||
h.getByID(w, r, existingID)
|
||||
return
|
||||
}
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
http.Error(w, `{"error":"server error"}`, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
} else if len(memberIDs) == 2 {
|
||||
var existingID string
|
||||
err := h.db.QueryRowContext(r.Context(), `
|
||||
SELECT c.id FROM conversations c
|
||||
|
||||
Reference in New Issue
Block a user