database

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Reminder itself
	MessageTypeReminderRequest = MessageType("REMINDER_REQUEST")
	MessageTypeReminderSuccess = MessageType("REMINDER_SUCCESS")
	MessageTypeReminderFail    = MessageType("REMINDER_FAIL")
	MessageTypeReminder        = MessageType("REMINDER")
	// Arbitrary actions
	MessageTypeActions          = MessageType("ACTIONS")
	MessageTypeReminderList     = MessageType("REMINDER_LIST")
	MessageTypeIcalLink         = MessageType("ICAL_LINK")
	MessageTypeIcalLinkRequest  = MessageType("ICAL_LINK_REQUEST")
	MessageTypeIcalRenew        = MessageType("ICAL_RENEW")
	MessageTypeIcalRenewRequest = MessageType("ICAL_RENEW_REQUEST")
	MessageTypeWelcome          = MessageType("WELCOME")
	// Reminder edits
	MessageTypeReminderUpdate           = MessageType("REMINDER_UPDATE")
	MessageTypeReminderUpdateFail       = MessageType("REMINDER_UPDATE_FAIL")
	MessageTypeReminderUpdateSuccess    = MessageType("REMINDER_UPDATE_SUCCESS")
	MessageTypeReminderDelete           = MessageType("REMINDER_DELETE")
	MessageTypeReminderDeleteSuccess    = MessageType("REMINDER_DELETE_SUCCESS")
	MessageTypeReminderDeleteFail       = MessageType("REMINDER_DELETE_Fail")
	MessageTypeReminderRecurringRequest = MessageType("REMINDER_RECURRING_REQUEST")
	MessageTypeReminderRecurringSuccess = MessageType("REMINDER_RECURRING_SUCCESS")
	MessageTypeReminderRecurringFail    = MessageType("REMINDER_RECURRING_FAIL")
	// Settings
	MessageTypeTimezoneChangeRequest        = MessageType("TIMEZONE_CHANGE")
	MessageTypeTimezoneChangeRequestSuccess = MessageType("TIMEZONE_CHANGE_SUCCESS")
	MessageTypeTimezoneChangeRequestFail    = MessageType("TIMEZONE_CHANGE_FAIL")
	// Daily Reminder
	MessageTypeDailyReminder              = MessageType("DAILY_REMINDER")
	MessageTypeDailyReminderUpdate        = MessageType("DAILY_REMINDER_UPDATE")
	MessageTypeDailyReminderUpdateFail    = MessageType("DAILY_REMINDER_UPDATE_FAIL")
	MessageTypeDailyReminderUpdateSuccess = MessageType("DAILY_REMINDER_UPDATE_SUCCESS")
	MessageTypeDailyReminderDelete        = MessageType("DAILY_REMINDER_DELETE")
	MessageTypeDailyReminderDeleteFail    = MessageType("DAILY_REMINDER_DELETE_FAIL")
	MessageTypeDailyReminderDeleteSuccess = MessageType("DAILY_REMINDER_DELETE_SUCCESS")
	// Do not save!
	MessageTypeDoNotSave = MessageType("")
)

Message types differentiate the context of a message

View Source
const (
	EventTypeMembership = EventType("MEMBERSHIP")
)

Variables

View Source
var (
	ErrThirdPartyResourceTypeUnknown = errors.New("third party resource type is not known")
)

List of errors the package might return

MessageTypesWithReminder message types with reminders

View Source
var (
	ThirdPartyResourceTypeIcal = ThirdPartyResourceType("ICAL")
)

List of available third party resource types

Functions

This section is empty.

Types

type Blocklist

type Blocklist struct {
	gorm.Model
	UserIdentifier string `gorm:"uniqueIndex,type:varchar(500)"`
	Reason         string `gorm:"type:text"`
}

Blocklist holds data about blocked users

type Channel

type Channel struct {
	gorm.Model
	Created           time.Time
	ChannelIdentifier string `gorm:"index;size:500"`
	UserIdentifier    string `gorm:"index;size:500"`
	TimeZone          string
	DailyReminder     *uint  // minutes from midnight when to send the daily reminder. Null to deactivate.
	CalendarSecret    string `gorm:"index"`
	Role              *roles.Role
	LastCryptoEvent   string `gorm:"type:text"`
}

Channel holds data about a messaging channel

func (*Channel) Timezone

func (c *Channel) Timezone() *time.Location

Timezone returns the timezone of the channel

type Database

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

Database holds all information for connecting to the database

func Create

func Create(config configuration.Database, debug bool) (*Database, error)

Create creates a database object

func (*Database) AddChannel

func (d *Database) AddChannel(userID, channelID string, role roles.Role) (*Channel, error)

AddChannel adds a channel to the database

func (*Database) AddEvent

func (d *Database) AddEvent(event *Event) (*Event, error)

AddEvent adds the given event to the database

func (*Database) AddMessage

func (d *Database) AddMessage(message *Message) (*Message, error)

AddMessage adds a message to the database

func (*Database) AddMessageFromMatrix

func (d *Database) AddMessageFromMatrix(id string, timestamp int64, content *event.MessageEventContent, reminder *Reminder, msgType MessageType, channel *Channel) (*Message, error)

AddMessageFromMatrix adds a message to the database

func (*Database) AddOrUpdateThirdPartyResourceReminder added in v1.8.4

func (d *Database) AddOrUpdateThirdPartyResourceReminder(remindTime time.Time, message string, channelID uint, thirdPartyResourceID uint, thirdPartyResourceIdentifier string) (*Reminder, error)

AddOrUpdateThirdPartyResourceReminder inserts a new reminder from a third party resource or updates an existing one if already present

func (*Database) AddReminder

func (d *Database) AddReminder(remindTime time.Time, message string, active bool, repeatInterval uint64, channel *Channel) (*Reminder, error)

AddReminder adds a reminder to the database

func (*Database) AddThirdPartyResource added in v1.8.4

func (d *Database) AddThirdPartyResource(resource *ThirdPartyResource) (*ThirdPartyResource, error)

AddThirdPartyResource adds a third party resource to the database

func (*Database) AddUserToBlocklist

func (d *Database) AddUserToBlocklist(userID string, reason string) error

AddUserToBlocklist blocks the given user with the given reason. The reason is only for internal usecases.

func (*Database) ChannelCount

func (d *Database) ChannelCount() (int64, error)

ChannelCount returns the amount of active channels

func (*Database) ChannelSaveChanges

func (d *Database) ChannelSaveChanges(channel *Channel) error

ChannelSaveChanges saves the changes in the given channel

func (*Database) CleanAdminChannels

func (d *Database) CleanAdminChannels(keep []*Channel) error

CleanAdminChannels removes all admin channels except the ones given in keep

func (*Database) DeleteChannel

func (d *Database) DeleteChannel(channel *Channel) error

DeleteChannel deletes the given channel

func (*Database) DeleteChannelsFromUser

func (d *Database) DeleteChannelsFromUser(userID string) error

DeleteChannelsFromUser removed all channels from the given matrix user

func (*Database) DeleteReminder

func (d *Database) DeleteReminder(reminderID uint) (*Reminder, error)

DeleteReminder deletes the given reminder

func (*Database) DeleteThirdPartyResource added in v1.8.4

func (d *Database) DeleteThirdPartyResource(id uint) error

DeleteThirdPartyResource deletes the third party resource with the given ID

func (*Database) GenerateNewCalendarSecret

func (d *Database) GenerateNewCalendarSecret(channel *Channel) error

GenerateNewCalendarSecret generates and sets a new calendar secret

func (*Database) GetBlockedUserList

func (d *Database) GetBlockedUserList() ([]Blocklist, error)

GetBlockedUserList lists all blocked users

func (*Database) GetChannel

func (d *Database) GetChannel(id uint) (*Channel, error)

GetChannel returns the channel

func (*Database) GetChannelByUserAndChannelIdentifier

func (d *Database) GetChannelByUserAndChannelIdentifier(userID string, channelID string) (*Channel, error)

GetChannelByUserAndChannelIdentifier returns the latest channel with the given user and channel id

func (*Database) GetChannelByUserIdentifier

func (d *Database) GetChannelByUserIdentifier(userID string) (*Channel, error)

GetChannelByUserIdentifier returns the latest channel with the given user

func (*Database) GetChannelList

func (d *Database) GetChannelList() ([]Channel, error)

GetChannelList returns all known channels

func (*Database) GetChannelsByChannelIdentifier

func (d *Database) GetChannelsByChannelIdentifier(channelID string) ([]Channel, error)

GetChannelsByChannelIdentifier returns all channels with the given channel identifier

func (*Database) GetChannelsByUserIdentifier

func (d *Database) GetChannelsByUserIdentifier(userID string) ([]Channel, error)

GetChannelsByUserIdentifier returns all channels with the given user

func (*Database) GetDailyReminder

func (d *Database) GetDailyReminder(channel *Channel) (*[]Reminder, error)

GetDailyReminder returns the reminders alerting in the next 24 hours

func (*Database) GetLastMessageByType

func (d *Database) GetLastMessageByType(msgType MessageType, channel *Channel) (*Message, error)

GetLastMessageByType returns the last message in the given channel with the given message type

func (*Database) GetLastMessageByTypeForReminder

func (d *Database) GetLastMessageByTypeForReminder(msgType MessageType, reminderID uint) (*Message, error)

GetLastMessageByTypeForReminder returns the last message of the specified type tied to the given reminder id

func (*Database) GetMessageByExternalID

func (d *Database) GetMessageByExternalID(externalID string) (*Message, error)

GetMessageByExternalID returns if found the message with the given external id

func (*Database) GetMessageFromReminder

func (d *Database) GetMessageFromReminder(reminderID uint, msgType MessageType) (*Message, error)

GetMessageFromReminder returns the message with the specified message type regarding the reminder

func (*Database) GetMessagesByReminderID

func (d *Database) GetMessagesByReminderID(id uint) ([]*Message, error)

GetMessagesByReminderID returns a list with all messages for the given reminder id

func (*Database) GetPendingReminder

func (d *Database) GetPendingReminder() ([]Reminder, error)

GetPendingReminder returns all reminders that are due

func (*Database) GetPendingReminders

func (d *Database) GetPendingReminders(channel *Channel) ([]Reminder, error)

GetPendingReminders returns a list with all pending reminders for the given channel

func (*Database) GetReminderForChannelIDByID

func (d *Database) GetReminderForChannelIDByID(channelID string, reminderID int) (*Reminder, error)

GetReminderForChannelIDByID returns the reminder with the given ID if it relates to the given channel ID

func (*Database) GetThirdPartyResources added in v1.8.4

func (d *Database) GetThirdPartyResources(resourceType ThirdPartyResourceType) ([]ThirdPartyResource, error)

GetThirdPartyResources lists all resources with the given type

func (*Database) GetThirdPartyResourcesByChannel added in v1.8.4

func (d *Database) GetThirdPartyResourcesByChannel(channelID uint) ([]ThirdPartyResource, error)

GetThirdPartyResourcesByChannel lists all resources in the given channel

func (*Database) IsEventKnown

func (d *Database) IsEventKnown(externalID string) (bool, error)

IsEventKnown returns if the given externalID of an event is already registered

func (*Database) IsUserBlocked

func (d *Database) IsUserBlocked(userID string) (bool, error)

IsUserBlocked checks if a user is on the blocklist

func (*Database) RemoveUserFromBlocklist

func (d *Database) RemoveUserFromBlocklist(userID string) error

RemoveUserFromBlocklist removes the given user from the blocklist

func (*Database) SQLDB

func (d *Database) SQLDB() (*sql.DB, error)

SQLDB returns the raw sql.DB

func (*Database) SetMatrixClient

func (d *Database) SetMatrixClient(matrixClient *mautrix.Client)

func (*Database) SetReminderDone

func (d *Database) SetReminderDone(reminder *Reminder) (*Reminder, error)

SetReminderDone sets a reminder as inactive

func (*Database) UpdateChannel

func (d *Database) UpdateChannel(channelID uint, timeZone string, dailyReminder *uint, role *roles.Role) (*Channel, error)

UpdateChannel updates the given channel with the given information

func (*Database) UpdateReminder

func (d *Database) UpdateReminder(reminderID uint, remindTime time.Time, repeatInterval uint64, repeatTimes uint64) (*Reminder, error)

UpdateReminder updates the reminder

type Event

type Event struct {
	gorm.Model
	ChannelID          *uint `gorm:"index"`
	Channel            Channel
	Timestamp          int64
	ExternalIdentifier string    `gorm:"uniqueIndex;size:500"`
	EventType          EventType `gorm:"index;size:250"`
	EventSubType       string    `gorm:"index;size:250"`
	AdditionalInfo     string
}

Event holds information about a matrix event

type EventType

type EventType string

EventType is the type of the event

type Message

type Message struct {
	gorm.Model
	Body               string
	BodyHTML           string
	ReminderID         *uint `gorm:"index"`
	Reminder           Reminder
	ResponseToMessage  string `gorm:"index"` // External identifier of parent message
	Type               MessageType
	ChannelID          uint `gorm:"index"`
	Channel            Channel
	Timestamp          int64
	ExternalIdentifier string `gorm:"index"`
}

Message holds information about a single message

type MessageType

type MessageType string

MessageType defines different types of messages

type Reminder

type Reminder struct {
	gorm.Model
	RemindTime                   time.Time `gorm:"index"`
	Message                      string
	Active                       bool `gorm:"index"`
	RepeatInterval               uint64
	RepeatMax                    uint64
	Repeated                     *uint64
	ChannelID                    uint `gorm:"index"`
	Channel                      Channel
	ThirdPartyResourceID         *uint              `gorm:"index"`
	ThirdPartyResource           ThirdPartyResource `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
	ThirdPartyResourceIdentifier string
}

Reminder is the database object for a reminder

func (*Reminder) GetReminderIcons added in v1.8.6

func (reminder *Reminder) GetReminderIcons() []string

type ThirdPartyResource added in v1.8.4

type ThirdPartyResource struct {
	gorm.Model
	Type        ThirdPartyResourceType
	ChannelID   uint `gorm:"index"`
	Channel     Channel
	ResourceURL string
}

type ThirdPartyResourceType added in v1.8.4

type ThirdPartyResourceType string

func ThirdPartyResourceTypeFromString added in v1.8.4

func ThirdPartyResourceTypeFromString(resourceType string) (ThirdPartyResourceType, error)

ThirdPartyResourceTypeFromString parses the resource type from a string

func (ThirdPartyResourceType) String added in v1.8.4

func (resourceType ThirdPartyResourceType) String() string

Jump to

Keyboard shortcuts

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