Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.0 - Unreleased

- Added coherent conversation organization and attention tools: topic selection and filtered timelines, per-channel all/mentions/muted notification preferences, and resolved mention highlighting whose current-user emphasis follows that preference across timelines, threads, embeds, and agent preambles. Thanks @PollyBot13 and @jjjhenriksen.

## 0.2.2 - 2026-08-01

- Updated Go, web, desktop, Cloudflare, CI action, package-manager, and container-base dependencies.
Expand Down
4 changes: 4 additions & 0 deletions apps/api/internal/httpapi/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func TestHTTPUnauthorizedRoutes(t *testing.T) {
{http.MethodPost, "/api/messages/msg_missing/thread/replies", `{"body":"x"}`},
{http.MethodPost, "/api/messages/msg_missing/reactions", `{"emoji":"x"}`},
{http.MethodDelete, "/api/messages/msg_missing/reactions/x", ""},
{http.MethodGet, "/api/channels/chn_missing/notification-settings", ""},
{http.MethodPatch, "/api/channels/chn_missing/notification-settings", `{"preference":"muted"}`},
{http.MethodGet, "/api/realtime/events?workspace_id=wsp_missing", ""},
{http.MethodGet, "/api/realtime/ws?workspace_id=wsp_missing", ""},
{http.MethodGet, "/api/search?workspace_id=wsp_missing&q=x", ""},
Expand Down Expand Up @@ -229,6 +231,8 @@ func TestHTTPBotTokenWorkspaceIsolation(t *testing.T) {
expectStatusWithBearer(t, token.Token, http.MethodGet, server.URL+"/api/routes/"+otherWorkspace.RouteID+"/"+otherChannel.RouteID, nil, http.StatusForbidden)
expectStatusWithBearer(t, token.Token, http.MethodGet, server.URL+"/api/channels/"+otherChannel.ID+"/messages", nil, http.StatusForbidden)
expectStatusWithBearer(t, token.Token, http.MethodPost, server.URL+"/api/channels/"+otherChannel.ID+"/messages", strings.NewReader(`{"body":"nope"}`), http.StatusForbidden)
expectStatusWithBearer(t, token.Token, http.MethodGet, server.URL+"/api/channels/"+otherChannel.ID+"/notification-settings", nil, http.StatusForbidden)
expectStatusWithBearer(t, token.Token, http.MethodPatch, server.URL+"/api/channels/"+otherChannel.ID+"/notification-settings", strings.NewReader(`{"preference":"muted"}`), http.StatusForbidden)
expectStatusWithBearer(t, token.Token, http.MethodPost, server.URL+"/api/channels/"+otherChannel.ID+"/read", strings.NewReader(`{"seq":1}`), http.StatusForbidden)
expectStatusWithBearer(t, token.Token, http.MethodPost, server.URL+"/api/hooks/mattermost/"+otherChannel.ID, strings.NewReader(`{"text":"nope"}`), http.StatusForbidden)
expectStatusWithBearer(t, token.Token, http.MethodPost, server.URL+"/api/hooks/slash/"+otherChannel.ID, strings.NewReader(`command=/nope`), http.StatusForbidden)
Expand Down
73 changes: 73 additions & 0 deletions apps/api/internal/httpapi/channel_notifications.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package httpapi

import (
"errors"
"net/http"

"github.com/go-chi/chi/v5"
"github.com/openclaw/clickclack/apps/api/internal/store"
)

func (s *Server) getChannelNotificationSettings(w http.ResponseWriter, r *http.Request) {
actor, err := s.currentActor(r)
if err != nil {
writeError(w, http.StatusUnauthorized, err)
return
}
if err := actor.requireScope("messages:read"); err != nil {
writeError(w, http.StatusForbidden, err)
return
}
channelID := chi.URLParam(r, "channel_id")
if !s.requireBotChannelWorkspace(w, r, actor, channelID) {
return
}
preference, err := s.store.GetChannelNotificationPreference(
r.Context(),
channelID,
actor.user.ID,
)
if err != nil {
writeStoreError(w, err)
return
}
writeJSON(w, http.StatusOK, map[string]string{"preference": preference})
}

func (s *Server) updateChannelNotificationSettings(w http.ResponseWriter, r *http.Request) {
actor, err := s.currentActor(r)
if err != nil {
writeError(w, http.StatusUnauthorized, err)
return
}
if err := actor.requireScope("messages:write"); err != nil {
writeError(w, http.StatusForbidden, err)
return
}
channelID := chi.URLParam(r, "channel_id")
if !s.requireBotChannelWorkspace(w, r, actor, channelID) {
return
}
var body struct {
Preference string `json:"preference"`
}
if err := readJSON(w, r, &body); err != nil {
writeError(w, http.StatusBadRequest, err)
return
}
if body.Preference != store.ChannelNotifyAll &&
body.Preference != store.ChannelNotifyMentions &&
body.Preference != store.ChannelNotifyMuted {
writeError(w, http.StatusBadRequest, errors.New("preference must be all, mentions, or muted"))
return
}
if err := s.store.UpsertChannelNotificationSettings(r.Context(), store.ChannelNotificationInput{
ChannelID: channelID,
UserID: actor.user.ID,
Preference: body.Preference,
}); err != nil {
writeStoreError(w, err)
return
}
writeJSON(w, http.StatusOK, map[string]string{"preference": body.Preference})
}
48 changes: 48 additions & 0 deletions apps/api/internal/httpapi/channel_notifications_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package httpapi

import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/openclaw/clickclack/apps/api/internal/realtime"
"github.com/openclaw/clickclack/apps/api/internal/store"
)

func TestChannelNotificationSettingsHTTP(t *testing.T) {
t.Parallel()
ctx := context.Background()
st := newEmptyHTTPStore(t)
owner, err := st.EnsureBootstrap(ctx, "Owner", "channel-notifications@example.com")
if err != nil {
t.Fatal(err)
}
workspaces, err := st.ListWorkspaces(ctx, owner.ID)
if err != nil {
t.Fatal(err)
}
channels, err := st.ListChannels(ctx, workspaces[0].ID, owner.ID)
if err != nil {
t.Fatal(err)
}
server := httptest.NewServer(New(st, realtime.NewHub(), Options{}).Handler())
t.Cleanup(server.Close)
endpoint := server.URL + "/api/channels/" + channels[0].ID + "/notification-settings"

initial := getJSON[map[string]string](t, endpoint)
if initial["preference"] != store.ChannelNotifyAll {
t.Fatalf("expected all as the default preference, got %#v", initial)
}
updated := patchJSON[map[string]string](t, endpoint, map[string]string{"preference": store.ChannelNotifyMentions})
if updated["preference"] != store.ChannelNotifyMentions {
t.Fatalf("expected mentions preference, got %#v", updated)
}
loaded := getJSON[map[string]string](t, endpoint)
if loaded["preference"] != store.ChannelNotifyMentions {
t.Fatalf("expected persisted mentions preference, got %#v", loaded)
}
expectStatus(t, http.MethodPatch, endpoint, strings.NewReader(`{"preference":"invalid"}`), http.StatusBadRequest)
expectStatus(t, http.MethodPatch, endpoint, strings.NewReader(`{"preference":`), http.StatusBadRequest)
}
1 change: 1 addition & 0 deletions apps/api/internal/httpapi/correlation_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestMessageEventCorrelationSurvivesResponseRealtimeAndRetrieval(t *testing.
replyEvent := eventByType(t, replyResult.Events, "thread.reply_created")
stateEvent := eventByType(t, replyResult.Events, "thread.state_updated")
assertAPIEventPayloadValue(t, replyEvent, "correlation_id", "corr-api-reply")
assertAPIEventPayloadMissing(t, replyEvent, "author_id")
assertAPIEventPayloadMissing(t, replyEvent, "body")
assertAPIEventPayloadMissing(t, stateEvent, "correlation_id")
liveReply := readEventType(t, conn, "thread.reply_created")
Expand Down
8 changes: 4 additions & 4 deletions apps/api/internal/httpapi/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ func (s *Server) createDirectMessage(w http.ResponseWriter, r *http.Request) {
if err == nil && event.ID != "" {
s.publishEvent(r.Context(), event)
if !store.IsActivityMessageKind(message.Kind) {
s.notifyMessageCreated(r.Context(), message)
s.notifyMessageCreated(r.Context(), message, event.MentionedUserIDs)
}
}
writeMessageCreateResult(w, message, event, err)
Expand Down Expand Up @@ -1546,7 +1546,7 @@ func (s *Server) mattermostWebhook(w http.ResponseWriter, r *http.Request) {
message, event, err := s.store.CreateMessage(r.Context(), store.CreateMessageInput{ChannelID: chi.URLParam(r, "channel_id"), AuthorID: act.user.ID, Body: body.Text})
if err == nil {
s.publishEvent(r.Context(), event)
s.notifyMessageCreated(r.Context(), message)
s.notifyMessageCreated(r.Context(), message, event.MentionedUserIDs)
}
writeResultStatus(w, http.StatusCreated, map[string]any{"message": message, "event": event}, err)
}
Expand Down Expand Up @@ -1587,7 +1587,7 @@ func (s *Server) slashCommand(w http.ResponseWriter, r *http.Request) {
message, event, err := s.store.CreateMessage(r.Context(), store.CreateMessageInput{ChannelID: chi.URLParam(r, "channel_id"), AuthorID: act.user.ID, Body: body})
if err == nil {
s.publishEvent(r.Context(), event)
s.notifyMessageCreated(r.Context(), message)
s.notifyMessageCreated(r.Context(), message, event.MentionedUserIDs)
}
writeResultStatus(w, http.StatusCreated, map[string]any{
"response_type": "in_channel",
Expand Down Expand Up @@ -1661,7 +1661,7 @@ func (s *Server) invokeRegisteredSlashCommand(w http.ResponseWriter, r *http.Req
return
}
s.publishEvent(r.Context(), event)
s.notifyMessageCreated(r.Context(), message)
s.notifyMessageCreated(r.Context(), message, event.MentionedUserIDs)
}
writeJSON(w, http.StatusOK, map[string]any{
"response_type": callback.ResponseType,
Expand Down
6 changes: 3 additions & 3 deletions apps/api/internal/httpapi/mutations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,15 +659,15 @@ func TestPushNotificationsRespectModerationVisibility(t *testing.T) {
if err != nil {
t.Fatal(err)
}
server.notifyMessageCreated(ctx, hidden)
server.notifyMessageCreated(ctx, hidden, nil)
if len(notifier.notifications) != 0 {
t.Fatalf("guest should not receive hidden channel push notifications: %#v", notifier.notifications)
}
visible, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: guestChannelID, AuthorID: moderator.ID, Body: "visible"})
if err != nil {
t.Fatal(err)
}
server.notifyMessageCreated(ctx, visible)
server.notifyMessageCreated(ctx, visible, nil)
if len(notifier.notifications) != 1 || notifier.notifications[0].RecipientKey != "g12345678901234567890123456789" {
t.Fatalf("guest should receive guest channel push notification, got %#v", notifier.notifications)
}
Expand Down Expand Up @@ -698,7 +698,7 @@ func TestPushNotificationsRespectModerationVisibility(t *testing.T) {
if err != nil {
t.Fatal(err)
}
server.notifyMessageCreated(ctx, dmMessage)
server.notifyMessageCreated(ctx, dmMessage, nil)
if len(notifier.notifications) != 0 {
t.Fatalf("demoted guest should not receive DM push notifications: %#v", notifier.notifications)
}
Expand Down
13 changes: 11 additions & 2 deletions apps/api/internal/httpapi/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type PushNotifier interface {
Notify(ctx context.Context, notification PushNotification) error
}

func (s *Server) notifyMessageCreated(ctx context.Context, message store.Message) {
func (s *Server) notifyMessageCreated(ctx context.Context, message store.Message, mentionedUserIDs []string) {
if s.pushNotifier == nil {
return
}
recipients, err := s.store.ListPushNotificationRecipients(ctx, message.ID)
recipients, err := s.store.ListPushNotificationRecipients(ctx, message.ID, mentionedUserIDs)
if err != nil {
log.Printf("push notification recipient lookup failed: %v", err)
return
Expand All @@ -43,6 +43,15 @@ func (s *Server) notifyMessageCreated(ctx context.Context, message store.Message
}
}

func messageEventMentionedUserIDs(events []store.Event) []string {
for _, event := range events {
if event.Type == "message.created" || event.Type == "thread.reply_created" {
return event.MentionedUserIDs
}
}
return nil
}

func (s *Server) canNotifyMessageRecipient(ctx context.Context, message store.Message, userID string) bool {
_, err := s.store.GetMessage(ctx, message.ID, userID)
return err == nil
Expand Down
13 changes: 11 additions & 2 deletions apps/api/internal/httpapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ func (s *Server) Handler() http.Handler {
r.Patch("/channels/{channel_id}", s.updateChannel)
r.Get("/channels/{channel_id}/messages", s.listMessages)
r.Post("/channels/{channel_id}/messages", s.createMessage)
r.Get("/channels/{channel_id}/notification-settings", s.getChannelNotificationSettings)
r.Patch("/channels/{channel_id}/notification-settings", s.updateChannelNotificationSettings)
r.Post("/channels/{channel_id}/read", s.markChannelRead)
r.Get("/messages/by-nonce", s.getMessageByNonce)
r.Get("/messages/{message_id}", s.getMessage)
Expand Down Expand Up @@ -952,6 +954,13 @@ func (s *Server) listMessages(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusBadRequest, err)
return
}
if values, ok := r.URL.Query()["topic_id"]; ok {
if len(values) == 0 || strings.TrimSpace(values[0]) == "" {
writeError(w, http.StatusBadRequest, fmt.Errorf("%w: topic_id is required", store.ErrInvalidMessagePage))
return
}
page.TopicID = strings.TrimSpace(values[0])
}
if !s.requireBotChannelWorkspace(w, r, act, chi.URLParam(r, "channel_id")) {
return
}
Expand Down Expand Up @@ -992,7 +1001,7 @@ func (s *Server) createMessage(w http.ResponseWriter, r *http.Request) {
if err == nil && event.ID != "" {
s.publishEvent(r.Context(), event)
if !store.IsActivityMessageKind(message.Kind) {
s.notifyMessageCreated(r.Context(), message)
s.notifyMessageCreated(r.Context(), message, event.MentionedUserIDs)
}
}
writeMessageCreateResult(w, message, event, err)
Expand Down Expand Up @@ -1157,7 +1166,7 @@ func (s *Server) createThreadReply(w http.ResponseWriter, r *http.Request) {
message, state, events, err := s.store.CreateThreadReply(r.Context(), store.CreateThreadReplyInput{RootMessageID: chi.URLParam(r, "message_id"), AuthorID: act.user.ID, Body: body.Body, QuotedMessageID: optionalString(body.QuotedMessageID), Nonce: body.Nonce})
if err == nil && len(events) > 0 {
s.publishEvents(r.Context(), events)
s.notifyMessageCreated(r.Context(), message)
s.notifyMessageCreated(r.Context(), message, messageEventMentionedUserIDs(events))
}
writeThreadReplyCreateResult(w, message, state, events, err)
}
Expand Down
Loading