Merge branch 'main' of git.mstar.dev:mstar/linstrom
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Melody Becker 2025-04-05 12:23:38 +02:00
commit 9cca79ec4c
Signed by: mstar
SSH key fingerprint: SHA256:vkXfS9FG2pVNVfvDrzd1VW9n8VJzqqdKQGljxxX8uK8
25 changed files with 3882 additions and 55 deletions

View file

@ -7,10 +7,12 @@ var AllTypes = []any{
&MediaMetadata{},
&Note{},
&NoteToAttachment{},
&NoteToBoost{},
&NoteToEmote{},
&NoteToFeed{},
&NoteToPing{},
&NoteTag{},
&Notification{},
&Reaction{},
&RemoteServer{},
&Role{},

View file

@ -0,0 +1,13 @@
package models
import "time"
// Describes a user boosting one note
type NoteToBoost struct {
ID uint `gorm:"primarykey"`
CreatedAt time.Time
User User
UserId string
Note Note
NoteId string
}

View file

@ -0,0 +1,42 @@
package models
import (
"database/sql"
"gorm.io/gen"
"gorm.io/gorm"
)
// Notifications inform users of inbound events
// happening to their content
type Notification struct {
gorm.Model
ForUser User // The user the notification is for
ForUserId string
SourceNote *Note // The note where the notification originates from
SourceNoteId sql.NullString
SourceUser *User // The user causing the notification
SourceUserId sql.NullString
Cause NotificationCauseType // What the cause of the notification is
ViewedState NotificationViewedState // What the last known state of the notification is
}
type INotification interface {
// Update a given set of notifications to a given viewed state.
// State should be a [NotificationViewedStateType]
//
// UPDATE @@table SET viewed_state = @state WHERE id IN @ids
SetState(state uint8, ids ...uint) error
// Get the lastest count amount of notifications with a given offset for a user
//
// SELECT * FROM @@table WHERE for_user_id = @userId
// ORDER BY id DESC
// {{if count > 0 }}
// LIMIT @count
// {{else}}
// LIMIT 20
// {{end}}
// OFFSET @offset
GetLatestWithOffset(userId string, count uint, offset uint) ([]gen.T, error)
}

View file

@ -0,0 +1,22 @@
package models
import "database/sql/driver"
// What a notification is caused by
type NotificationCauseType uint8
const (
NotificationTypeReply NotificationCauseType = iota // A new reply
NotificationTypeReaction // A new reaction
NotificationTypeBoost // A note got boosted
NotificationTypeFollowRequest // Someone requested to follow
)
func (r *NotificationCauseType) Value() (driver.Value, error) {
return r, nil
}
func (ct *NotificationCauseType) Scan(value any) error {
*ct = NotificationCauseType(value.(uint8))
return nil
}

View file

@ -0,0 +1,21 @@
package models
import "database/sql/driver"
type NotificationViewedState uint8
const (
NotViewed NotificationViewedState = iota
Viewed
Accepted
Denied
)
func (r *NotificationViewedState) Value() (driver.Value, error) {
return r, nil
}
func (ct *NotificationViewedState) Scan(value any) error {
*ct = NotificationViewedState(value.(uint8))
return nil
}

View file

@ -2,6 +2,8 @@ package models
import (
"time"
"gorm.io/gen"
)
// AccessToken maps a unique token to one account.
@ -18,3 +20,10 @@ type AccessToken struct {
// at a point in the future this server should never reach
ExpiresAt time.Time `gorm:"default:TIMESTAMP WITH TIME ZONE '9999-12-30 23:59:59+00'"`
}
type IAccessToken interface {
// Get the data for a token
//
// SELECT * FROM @@table WHERE token = @token
GetTokenIfValid(token string) (*gen.T, error)
}

View file

@ -4,6 +4,7 @@ import (
"database/sql"
"time"
"gorm.io/gen"
"gorm.io/gorm"
"git.mstar.dev/mstar/linstrom/config"
@ -97,3 +98,10 @@ func BuildLinstromUser() *User {
BannerId: sql.NullString{Valid: false},
}
}
type IUser interface {
// Get a user by a username
//
// SELECT * FROM @@table WHERE username = @username LIMIT 1
GetByUsername(username string) (*gen.T, error)
}