Documentation
¶
Overview ¶
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-only
Index ¶
- type AllDMInfo
- type Channel
- type ChannelWithMembership
- type DB
- func (d *DB) AddChannelMember(channelID, userID int64) error
- func (d *DB) ChannelMemberUsernames(channelID int64) ([]string, error)
- func (d *DB) Close() error
- func (d *DB) CreateChannel(name string, public bool, memberIDs []int64, channelType string) (int64, error)
- func (d *DB) CreateUser(username, password string) (int64, error)
- func (d *DB) GetChannelByID(id int64) (*Channel, error)
- func (d *DB) GetChannelByName(name string) (*Channel, error)
- func (d *DB) GetMessages(channelID int64, before *int64, after *int64, limit int, threadID *int64) ([]Message, error)
- func (d *DB) GetSetting(key string) (string, error)
- func (d *DB) GetUnreadCounts(userID int64) ([]UnreadCount, error)
- func (d *DB) GetUnreadMessages(userID int64, channelID *int64, mentionsOnly bool, threadID *int64) ([]Message, error)
- func (d *DB) GetUserByUsername(username string) (*User, error)
- func (d *DB) IsChannelMember(channelID, userID int64) (bool, error)
- func (d *DB) ListAllChannelsWithMembership(userID int64) ([]ChannelWithMembership, error)
- func (d *DB) ListAllDMs() ([]AllDMInfo, error)
- func (d *DB) ListChannelsForUser(userID int64) ([]ChannelWithMembership, error)
- func (d *DB) ListDMsForUser(userID int64) ([]DMInfo, error)
- func (d *DB) ListSettings() (map[string]string, error)
- func (d *DB) ListUsers() ([]User, error)
- func (d *DB) MarkRead(userID, channelID int64, messageID *int64) error
- func (d *DB) OpenDM(userID, otherUserID int64, otherUsername string) (string, bool, error)
- func (d *DB) SendMessage(channelID, userID int64, body string, threadID *int64, mentionUserIDs []int64) (int64, error)
- func (d *DB) SetSetting(key, value string) error
- type DMInfo
- type Message
- type UnreadCount
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
ID int64
Name string
Public bool
Type string // "channel" or "dm"
CreatedAt time.Time
}
Channel represents a messaging channel.
type ChannelWithMembership ¶
ChannelWithMembership extends Channel with membership status.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps an SQLite database connection.
func (*DB) AddChannelMember ¶
AddChannelMember adds a user to a channel.
func (*DB) ChannelMemberUsernames ¶
ChannelMemberUsernames returns the usernames of all members of a channel.
func (*DB) CreateChannel ¶
func (d *DB) CreateChannel(name string, public bool, memberIDs []int64, channelType string) (int64, error)
CreateChannel creates a channel with the given members in a transaction. channelType should be "channel" or "dm".
func (*DB) CreateUser ¶
CreateUser inserts a new user and returns its ID.
func (*DB) GetChannelByID ¶
GetChannelByID returns a channel by its ID.
func (*DB) GetChannelByName ¶
GetChannelByName returns a channel by its name.
func (*DB) GetMessages ¶
func (d *DB) GetMessages(channelID int64, before *int64, after *int64, limit int, threadID *int64) ([]Message, error)
GetMessages returns messages for a channel with cursor-based pagination. If before is set, returns messages with id < before (most recent first up to limit, returned in ASC order). If after is set, returns messages with id > after in ASC order. If neither is set, returns the most recent `limit` messages in ASC order. If threadID is set, only returns replies to that parent message.
func (*DB) GetSetting ¶
GetSetting returns the value for a setting key.
func (*DB) GetUnreadCounts ¶
func (d *DB) GetUnreadCounts(userID int64) ([]UnreadCount, error)
GetUnreadCounts returns per-channel unread message and mention counts for a user. Only returns channels with >0 unreads. Excludes the user's own messages.
func (*DB) GetUnreadMessages ¶
func (d *DB) GetUnreadMessages(userID int64, channelID *int64, mentionsOnly bool, threadID *int64) ([]Message, error)
GetUnreadMessages returns unread messages for a user, optionally filtered by channel, mentions, or thread. Advances the read cursor only when no filters are active (a filtered read is partial and shouldn't mark everything as read).
func (*DB) GetUserByUsername ¶
GetUserByUsername returns a user by username.
func (*DB) IsChannelMember ¶
IsChannelMember returns true if the user is a member of the channel.
func (*DB) ListAllChannelsWithMembership ¶
func (d *DB) ListAllChannelsWithMembership(userID int64) ([]ChannelWithMembership, error)
ListAllChannelsWithMembership returns all non-DM channels with membership status for the given user.
func (*DB) ListAllDMs ¶
ListAllDMs returns all DM channels with their participants (admin view).
func (*DB) ListChannelsForUser ¶
func (d *DB) ListChannelsForUser(userID int64) ([]ChannelWithMembership, error)
ListChannelsForUser returns non-DM channels visible to a user: all public channels plus private channels where the user is a member. Each result includes whether the user is a member.
func (*DB) ListDMsForUser ¶
ListDMsForUser returns all DM channels the user is a member of, with the other participant's username.
func (*DB) ListSettings ¶
ListSettings returns all settings as a map.
func (*DB) MarkRead ¶
MarkRead advances the read cursor for a user in a channel. If messageID is nil, advances to the latest message. Forward-only: never moves the cursor backwards.
func (*DB) OpenDM ¶
OpenDM finds or creates a DM channel between two users. Returns the channel name and whether it was newly created.
func (*DB) SendMessage ¶
func (d *DB) SendMessage(channelID, userID int64, body string, threadID *int64, mentionUserIDs []int64) (int64, error)
SendMessage inserts a message into a channel with optional thread and mentions.
func (*DB) SetSetting ¶
SetSetting sets a setting key to a value (upsert).
type Message ¶
type Message struct {
ID int64
ChannelID int64
UserID int64
Body string
CreatedAt time.Time
Username string
ThreadID *int64
Mentions []string
}
Message represents a message in a channel.
type UnreadCount ¶
UnreadCount holds per-channel unread and mention counts.