package models import ( "context" "time" ) // ChannelMember represents a user's membership in a channel. type ChannelMember struct { Base ChannelID string `json:"channelId"` UserID string `json:"userId"` Modes string `json:"modes"` JoinedAt time.Time `json:"joinedAt"` Nick string `json:"nick"` // denormalized from users table } // User returns the full User for this membership. func (cm *ChannelMember) User(ctx context.Context) (*User, error) { u := &User{} u.SetDB(cm.db) err := cm.GetDB().QueryRowContext(ctx, ` SELECT id, nick, password_hash, created_at, updated_at, last_seen_at FROM users WHERE id = ?`, cm.UserID, ).Scan( &u.ID, &u.Nick, &u.PasswordHash, &u.CreatedAt, &u.UpdatedAt, &u.LastSeenAt, ) if err != nil { return nil, err } return u, nil } // Channel returns the full Channel for this membership. func (cm *ChannelMember) Channel(ctx context.Context) (*Channel, error) { c := &Channel{} c.SetDB(cm.db) err := cm.GetDB().QueryRowContext(ctx, ` SELECT id, name, topic, modes, created_at, updated_at FROM channels WHERE id = ?`, cm.ChannelID, ).Scan( &c.ID, &c.Name, &c.Topic, &c.Modes, &c.CreatedAt, &c.UpdatedAt, ) if err != nil { return nil, err } return c, nil }