db

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2026 License: GPL-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllDMInfo

type AllDMInfo struct {
	Channel      string
	Participants []string
}

AllDMInfo holds a DM channel with both participants' usernames.

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

type ChannelWithMembership struct {
	Channel
	Member bool
}

ChannelWithMembership extends Channel with membership status.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB wraps an SQLite database connection.

func Open

func Open(path string) (*DB, error)

Open opens an SQLite database and runs migrations.

func (*DB) AddChannelMember

func (d *DB) AddChannelMember(channelID, userID int64) error

AddChannelMember adds a user to a channel.

func (*DB) ChannelMemberUsernames

func (d *DB) ChannelMemberUsernames(channelID int64) ([]string, error)

ChannelMemberUsernames returns the usernames of all members of a channel.

func (*DB) Close

func (d *DB) Close() error

Close closes the database connection.

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

func (d *DB) CreateUser(username, password string) (int64, error)

CreateUser inserts a new user and returns its ID.

func (*DB) GetChannelByID

func (d *DB) GetChannelByID(id int64) (*Channel, error)

GetChannelByID returns a channel by its ID.

func (*DB) GetChannelByName

func (d *DB) GetChannelByName(name string) (*Channel, error)

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

func (d *DB) GetSetting(key string) (string, error)

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

func (d *DB) GetUserByUsername(username string) (*User, error)

GetUserByUsername returns a user by username.

func (*DB) IsChannelMember

func (d *DB) IsChannelMember(channelID, userID int64) (bool, error)

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

func (d *DB) ListAllDMs() ([]AllDMInfo, error)

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

func (d *DB) ListDMsForUser(userID int64) ([]DMInfo, error)

ListDMsForUser returns all DM channels the user is a member of, with the other participant's username.

func (*DB) ListSettings

func (d *DB) ListSettings() (map[string]string, error)

ListSettings returns all settings as a map.

func (*DB) ListUsers

func (d *DB) ListUsers() ([]User, error)

ListUsers returns all registered users.

func (*DB) MarkRead

func (d *DB) MarkRead(userID, channelID int64, messageID *int64) error

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

func (d *DB) OpenDM(userID, otherUserID int64, otherUsername string) (string, bool, error)

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

func (d *DB) SetSetting(key, value string) error

SetSetting sets a setting key to a value (upsert).

type DMInfo

type DMInfo struct {
	Channel     string
	Participant string
}

DMInfo holds a DM channel with the other participant's username.

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

type UnreadCount struct {
	ChannelName  string
	ChannelType  string
	UnreadCount  int
	MentionCount int
}

UnreadCount holds per-channel unread and mention counts.

type User

type User struct {
	ID        int64
	Username  string
	Password  string
	CreatedAt time.Time
}

User represents a registered user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL