feat: chat bootstrap, members and group sync

GET /_bm/api/v1/chat gives a chat-group member ogólny (the bm/1 group
conversation, adopted once as the system default channel under an
advisory lock), its unread and mention counts, the member's DMs newest
message first, the moderator flag and the composer limits. Every member
bootstrap syncs participants with the group: missing members join
ogólny, users no longer in the group lose their rows in every bm/1
conversation. A non-member gets only member:false and is pruned.

GET /_bm/api/v1/chat/members lists members (id, name, surname, handle,
is_bot from golem15.chatbots when active) and assigns missing handles;
non-members get 404.

The chatchannels access policy (ChatAccess) is installed from a
database hook: bm/1 for members only, nobody manages channels.
bm:chat-sync creates the groups when missing, syncs and assigns
handles. Migration 20261026130000_seed_jz_bm_chat_groups creates
studenci and moderatorzy without members; its rollback keeps them.
This commit is contained in:
2026-10-26 15:46:13 +01:00
parent 07d67be1e7
commit 0642fb1d08
9 changed files with 734 additions and 40 deletions

View File

@@ -0,0 +1,31 @@
package updates
import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)
// SeedChatGroups returns the 20261026130000_seed_jz_bm_chat_groups gormigrate
// entry: the user groups studenci (the chat's members) and moderatorzy (its
// moderators), each created only when no group with that code exists
// (user_groups.code is not unique). No user is put into either group;
// Jakub assigns members in the backend.
//
// Rollback leaves both groups in place: they may already carry memberships
// assigned in the backend, or have existed before this migration.
func SeedChatGroups() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "20261026130000_seed_jz_bm_chat_groups",
Migrate: func(tx *gorm.DB) error {
return execAll(tx, `INSERT INTO user_groups (name, code, description, created_at, updated_at)
SELECT 'Studenci', 'studenci', 'Czat BM (jz.bm)', NOW(), NOW()
WHERE NOT EXISTS (SELECT 1 FROM user_groups WHERE code = 'studenci');
INSERT INTO user_groups (name, code, description, created_at, updated_at)
SELECT 'Moderatorzy czatu', 'moderatorzy', 'Czat BM (jz.bm)', NOW(), NOW()
WHERE NOT EXISTS (SELECT 1 FROM user_groups WHERE code = 'moderatorzy')`)
},
Rollback: func(tx *gorm.DB) error {
return nil
},
}
}