Skip to content

Fix DM feature: deadlock on send, layout displacement, styling inconsistency#168

Merged
asim merged 2 commits intomainfrom
copilot/fix-messages-page-design
Mar 2, 2026
Merged

Fix DM feature: deadlock on send, layout displacement, styling inconsistency#168
asim merged 2 commits intomainfrom
copilot/fix-messages-page-design

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

The DM (direct messaging) feature had three critical issues: sending a message deadlocked the server, the link to DMs displaced the entire chat layout on desktop, and the DM pages used ad-hoc inline styles completely inconsistent with the rest of the app.

Deadlock fix

saveChatMessages() acquired chatMessagesMutex.RLock() while both SendChatMessage() and MarkChatMessageAsRead() already held the write lock — a classic reentrant deadlock on Go's non-reentrant sync.RWMutex. Removed the redundant lock from saveChatMessages() since callers already guarantee exclusive access.

// Before — deadlocks when called from SendChatMessage (which holds write lock)
func saveChatMessages() error {
    chatMessagesMutex.RLock()
    defer chatMessagesMutex.RUnlock()
    ...
}

// After — callers are responsible for holding the lock
func saveChatMessages() error {
    b, err := json.Marshal(chatMessages)
    ...
}

Layout displacement fix

The DMs link was injected as a standalone <div> before #topic-selector, adding a rogue flex item inside the body:has(#messages) #content flex column. Changed to append it as a tab inside the existing .topic-tabs container:

// Before — extra div breaks flex layout
messagesLink := `<div style="..."><a href="/chat?mode=messages">💬 Messages</a></div>`
tmpl = strings.Replace(tmpl, `<div id="topic-selector">`, messagesLink+`<div id="topic-selector">`, 1)

// After — DMs tab sits inline with other topic tabs
topicTabs := app.Head("chat", topicsData) + `<a href="/chat?mode=messages" class="head">DMs</a>`

DM pages restyled

Replaced all inline styles in messages.go with the app's design system classes (thread-preview card, thread-message, thread-message-header/author/time/body, card-list, unread-dot, btn, app.Page()). Pages now render consistently with mail and the rest of the app.

Renamed the feature from "Messages" to "DMs" throughout (tab, page titles, back links).


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…le pages

Co-authored-by: asim <17530+asim@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix design and functionality issues on messages page Fix DM feature: deadlock on send, layout displacement, styling inconsistency Mar 2, 2026
@asim asim marked this pull request as ready for review March 2, 2026 16:05
@asim asim merged commit e2ed335 into main Mar 2, 2026
Copilot finished work on behalf of asim March 2, 2026 16:05
@asim asim deleted the copilot/fix-messages-page-design branch March 2, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants