mirror of
https://github.com/owncast/owncast.git
synced 2024-11-25 22:31:09 +03:00
4a17f30da8
* First pass at browser, discord, twilio notifications * Commit updated Javascript packages * Remove twilio notification support * Email notifications/smtp support * Fix Firefox notification support, remove chrome checks * WIP more email work * Add support for twitter notifications * Add stream title to discord and twitter notifications * Update notification registration modal * Fix hide/show email section * Commit updated API documentation * Commit updated Javascript packages * Fix post-rebase missing var * Remove unused var * Handle unsubscribe errors for browser push * Standardize email config prop names * Allow overriding go live email template * Some notifications cleanup * Commit updated Javascript packages * Remove email/smtp/mailjet support * Remove more references to email notifications Co-authored-by: Owncast <owncast@owncast.online>
60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package notifications
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/owncast/owncast/core/data"
|
|
"github.com/owncast/owncast/db"
|
|
"github.com/pkg/errors"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func createNotificationsTable(db *sql.DB) {
|
|
log.Traceln("Creating federation followers table...")
|
|
|
|
createTableSQL := `CREATE TABLE IF NOT EXISTS notifications (
|
|
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
"channel" TEXT NOT NULL,
|
|
"destination" TEXT NOT NULL,
|
|
"created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
|
CREATE INDEX channel_index ON notifications (channel);`
|
|
|
|
stmt, err := db.Prepare(createTableSQL)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer stmt.Close()
|
|
_, err = stmt.Exec()
|
|
if err != nil {
|
|
log.Warnln("error executing sql creating followers table", createTableSQL, err)
|
|
}
|
|
}
|
|
|
|
// AddNotification saves a new user notification destination.
|
|
func AddNotification(channel, destination string) error {
|
|
return data.GetDatastore().GetQueries().AddNotification(context.Background(), db.AddNotificationParams{
|
|
Channel: channel,
|
|
Destination: destination,
|
|
})
|
|
}
|
|
|
|
// RemoveNotificationForChannel removes a notification destination..
|
|
func RemoveNotificationForChannel(channel, destination string) error {
|
|
log.Println("Removing notification for channel", channel)
|
|
return data.GetDatastore().GetQueries().RemoveNotificationDestinationForChannel(context.Background(), db.RemoveNotificationDestinationForChannelParams{
|
|
Channel: channel,
|
|
Destination: destination,
|
|
})
|
|
}
|
|
|
|
// GetNotificationDestinationsForChannel will return a collection of
|
|
// destinations to notify for a given channel.
|
|
func GetNotificationDestinationsForChannel(channel string) ([]string, error) {
|
|
result, err := data.GetDatastore().GetQueries().GetNotificationDestinationsForChannel(context.Background(), channel)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "unable to query notification destinations for channel "+channel)
|
|
}
|
|
|
|
return result, nil
|
|
}
|