Merge branch 'main' of git.mstar.dev:mstar/linstrom
Some checks are pending
/ test (push) Waiting to run
Some checks are pending
/ test (push) Waiting to run
This commit is contained in:
commit
9cca79ec4c
25 changed files with 3882 additions and 55 deletions
|
@ -7,10 +7,12 @@ var AllTypes = []any{
|
|||
&MediaMetadata{},
|
||||
&Note{},
|
||||
&NoteToAttachment{},
|
||||
&NoteToBoost{},
|
||||
&NoteToEmote{},
|
||||
&NoteToFeed{},
|
||||
&NoteToPing{},
|
||||
&NoteTag{},
|
||||
&Notification{},
|
||||
&Reaction{},
|
||||
&RemoteServer{},
|
||||
&Role{},
|
||||
|
|
13
storage-new/models/NoteToBoost.go
Normal file
13
storage-new/models/NoteToBoost.go
Normal 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
|
||||
}
|
42
storage-new/models/Notification.go
Normal file
42
storage-new/models/Notification.go
Normal 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)
|
||||
}
|
22
storage-new/models/NotificationType.go
Normal file
22
storage-new/models/NotificationType.go
Normal 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
|
||||
}
|
21
storage-new/models/NotificationViewedStateType.go
Normal file
21
storage-new/models/NotificationViewedStateType.go
Normal 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
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue