summaryrefslogtreecommitdiff
path: root/shrine/models
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-03-13 18:25:44 +0530
committerBobby <[email protected]>2026-03-13 18:25:44 +0530
commit344d02a7feddefb5c08f88dbe5f3a3f7e7da385f (patch)
tree94deed23d82d7f868721cc00b5550f5c27e8b8f7 /shrine/models
parent9f808807a557fc10a38a44cb52be6bfcdfda68b2 (diff)
downloadpagoda-main.tar.xz
pagoda-main.zip
feat: add letters feature with detail view and listingHEADmain
- Introduced new routes for letters and their details. - Created pages for displaying letter details and listing letters. - Added new types for letters, including participants, messages, and attachments. - Implemented API calls for fetching letters and managing messages (reply, edit, delete). - Enhanced stats to include unread letters and pending districts for staff users. - Updated styles for letters and their components. - Added privacy settings for letters (public and friends). - Modified user model to include letter privacy settings. - Improved error handling and user feedback in the UI.
Diffstat (limited to 'shrine/models')
-rw-r--r--shrine/models/user.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/shrine/models/user.go b/shrine/models/user.go
index 503c61a..8846aa4 100644
--- a/shrine/models/user.go
+++ b/shrine/models/user.go
@@ -45,6 +45,7 @@ type User struct {
DisabledBy *uint `gorm:"index"`
DisabledUntil *time.Time
WarningCount uint `gorm:"not null;default:0"`
+ LetterPrivacy enums.LetterPrivacy `gorm:"size:20;not null;default:public"`
LastSeenAt *time.Time
IP string `gorm:"size:45"`
}
@@ -194,20 +195,27 @@ func (self *User) BeforeCreate(tx *gorm.DB) error {
}
func (self *User) BeforeUpdate(tx *gorm.DB) error {
- if !validators.IsValidEmail(self.Email) {
- return errors.New(messages.InvalidEmail)
+ if self.Email == "" && self.DisplayName == "" {
+ return nil
}
- if len(strings.TrimSpace(self.DisplayName)) < 1 || len(strings.TrimSpace(self.DisplayName)) > 50 {
- return errors.New(messages.InvalidDisplayName)
+ if self.Email != "" {
+ if !validators.IsValidEmail(self.Email) {
+ return errors.New(messages.InvalidEmail)
+ }
+ self.Email = strings.ToLower(strings.TrimSpace(self.Email))
+ }
+
+ if self.DisplayName != "" {
+ if len(strings.TrimSpace(self.DisplayName)) < 1 || len(strings.TrimSpace(self.DisplayName)) > 50 {
+ return errors.New(messages.InvalidDisplayName)
+ }
+ self.DisplayName = strings.TrimSpace(self.DisplayName)
}
if self.Jade > validators.MaxJade {
return errors.New(messages.JadeExceedsMax)
}
- self.Email = strings.ToLower(strings.TrimSpace(self.Email))
- self.DisplayName = strings.TrimSpace(self.DisplayName)
-
return nil
} \ No newline at end of file