Documentation ¶
Index ¶
- Constants
- Variables
- type Blocklist
- type Channel
- type Database
- func (d *Database) AddChannel(userID, channelID string, role roles.Role) (*Channel, error)
- func (d *Database) AddEvent(event *Event) (*Event, error)
- func (d *Database) AddMessage(message *Message) (*Message, error)
- func (d *Database) AddMessageFromMatrix(id string, timestamp int64, content *event.MessageEventContent, ...) (*Message, error)
- func (d *Database) AddOrUpdateThirdPartyResourceReminder(remindTime time.Time, message string, channelID uint, ...) (*Reminder, error)
- func (d *Database) AddReminder(remindTime time.Time, message string, active bool, repeatInterval uint64, ...) (*Reminder, error)
- func (d *Database) AddThirdPartyResource(resource *ThirdPartyResource) (*ThirdPartyResource, error)
- func (d *Database) AddUserToBlocklist(userID string, reason string) error
- func (d *Database) ChannelCount() (int64, error)
- func (d *Database) ChannelSaveChanges(channel *Channel) error
- func (d *Database) CleanAdminChannels(keep []*Channel) error
- func (d *Database) DeleteChannel(channel *Channel) error
- func (d *Database) DeleteChannelsFromUser(userID string) error
- func (d *Database) DeleteReminder(reminderID uint) (*Reminder, error)
- func (d *Database) DeleteThirdPartyResource(id uint) error
- func (d *Database) GenerateNewCalendarSecret(channel *Channel) error
- func (d *Database) GetBlockedUserList() ([]Blocklist, error)
- func (d *Database) GetChannel(id uint) (*Channel, error)
- func (d *Database) GetChannelByUserAndChannelIdentifier(userID string, channelID string) (*Channel, error)
- func (d *Database) GetChannelByUserIdentifier(userID string) (*Channel, error)
- func (d *Database) GetChannelList() ([]Channel, error)
- func (d *Database) GetChannelsByChannelIdentifier(channelID string) ([]Channel, error)
- func (d *Database) GetChannelsByUserIdentifier(userID string) ([]Channel, error)
- func (d *Database) GetDailyReminder(channel *Channel) (*[]Reminder, error)
- func (d *Database) GetLastMessageByType(msgType MessageType, channel *Channel) (*Message, error)
- func (d *Database) GetLastMessageByTypeForReminder(msgType MessageType, reminderID uint) (*Message, error)
- func (d *Database) GetMessageByExternalID(externalID string) (*Message, error)
- func (d *Database) GetMessageFromReminder(reminderID uint, msgType MessageType) (*Message, error)
- func (d *Database) GetMessagesByReminderID(id uint) ([]*Message, error)
- func (d *Database) GetPendingReminder() ([]Reminder, error)
- func (d *Database) GetPendingReminders(channel *Channel) ([]Reminder, error)
- func (d *Database) GetReminderForChannelIDByID(channelID string, reminderID int) (*Reminder, error)
- func (d *Database) GetThirdPartyResources(resourceType ThirdPartyResourceType) ([]ThirdPartyResource, error)
- func (d *Database) GetThirdPartyResourcesByChannel(channelID uint) ([]ThirdPartyResource, error)
- func (d *Database) IsEventKnown(externalID string) (bool, error)
- func (d *Database) IsUserBlocked(userID string) (bool, error)
- func (d *Database) RemoveUserFromBlocklist(userID string) error
- func (d *Database) SQLDB() (*sql.DB, error)
- func (d *Database) SetMatrixClient(matrixClient *mautrix.Client)
- func (d *Database) SetReminderDone(reminder *Reminder) (*Reminder, error)
- func (d *Database) UpdateChannel(channelID uint, timeZone string, dailyReminder *uint, role *roles.Role) (*Channel, error)
- func (d *Database) UpdateReminder(reminderID uint, remindTime time.Time, repeatInterval uint64, ...) (*Reminder, error)
- type Event
- type EventType
- type Message
- type MessageType
- type Reminder
- type ThirdPartyResource
- type ThirdPartyResourceType
Constants ¶
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
const (
EventTypeMembership = EventType("MEMBERSHIP")
)
Variables ¶
var (
ErrThirdPartyResourceTypeUnknown = errors.New("third party resource type is not known")
)
List of errors the package might return
var MessageTypesWithReminder = []MessageType{MessageTypeReminderRequest, MessageTypeReminderSuccess, MessageTypeReminderUpdate, MessageTypeReminderUpdateSuccess, MessageTypeReminderRecurringRequest, MessageTypeReminderRecurringSuccess, MessageTypeReminderRecurringFail, MessageTypeReminderUpdateFail}
MessageTypesWithReminder message types with reminders
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
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 ¶
AddChannel adds a channel to the database
func (*Database) AddMessage ¶
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 ¶
AddUserToBlocklist blocks the given user with the given reason. The reason is only for internal usecases.
func (*Database) ChannelCount ¶
ChannelCount returns the amount of active channels
func (*Database) ChannelSaveChanges ¶
ChannelSaveChanges saves the changes in the given channel
func (*Database) CleanAdminChannels ¶
CleanAdminChannels removes all admin channels except the ones given in keep
func (*Database) DeleteChannel ¶
DeleteChannel deletes the given channel
func (*Database) DeleteChannelsFromUser ¶
DeleteChannelsFromUser removed all channels from the given matrix user
func (*Database) DeleteReminder ¶
DeleteReminder deletes the given reminder
func (*Database) DeleteThirdPartyResource ¶ added in v1.8.4
DeleteThirdPartyResource deletes the third party resource with the given ID
func (*Database) GenerateNewCalendarSecret ¶
GenerateNewCalendarSecret generates and sets a new calendar secret
func (*Database) GetBlockedUserList ¶
GetBlockedUserList lists all blocked users
func (*Database) GetChannel ¶
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 ¶
GetChannelByUserIdentifier returns the latest channel with the given user
func (*Database) GetChannelList ¶
GetChannelList returns all known channels
func (*Database) GetChannelsByChannelIdentifier ¶
GetChannelsByChannelIdentifier returns all channels with the given channel identifier
func (*Database) GetChannelsByUserIdentifier ¶
GetChannelsByUserIdentifier returns all channels with the given user
func (*Database) GetDailyReminder ¶
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 ¶
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 ¶
GetMessagesByReminderID returns a list with all messages for the given reminder id
func (*Database) GetPendingReminder ¶
GetPendingReminder returns all reminders that are due
func (*Database) GetPendingReminders ¶
GetPendingReminders returns a list with all pending reminders for the given channel
func (*Database) GetReminderForChannelIDByID ¶
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 ¶
IsEventKnown returns if the given externalID of an event is already registered
func (*Database) IsUserBlocked ¶
IsUserBlocked checks if a user is on the blocklist
func (*Database) RemoveUserFromBlocklist ¶
RemoveUserFromBlocklist removes the given user from the blocklist
func (*Database) SetMatrixClient ¶
func (*Database) SetReminderDone ¶
SetReminderDone sets a reminder as inactive
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 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 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
type ThirdPartyResource ¶ added in v1.8.4
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