github.com/decred/politeia@v1.4.0/politeiawww/legacy/user/mail.go (about) 1 // Copyright (c) 2021 The Decred developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package user 6 7 import "github.com/google/uuid" 8 9 // MailerDB describes the interface used to interact with the email histories 10 // table from the user database, used by the mail client. 11 type MailerDB interface { 12 // EmailHistoriesSave saves the provided email histories to the 13 // database. The histories map contains map[userid]EmailHistory. 14 EmailHistoriesSave(histories map[uuid.UUID]EmailHistory) error 15 16 // EmailHistoriesGet retrieves the email histories for the provided 17 // user IDs. The returned map[userid]EmailHistory will contain an 18 // entry for each of the provided user ID. If a provided user ID 19 // does not correspond to a user in the database then the entry will 20 // be skipped in the returned map. An error is not returned. 21 EmailHistoriesGet(users []uuid.UUID) (map[uuid.UUID]EmailHistory, error) 22 } 23 24 // EmailHistory keeps track of the received emails by each user. This is 25 // used to rate limit the amount of emails an user can receive in a 24h 26 // time window. This was not stored in the user object in order to avoid 27 // race conditions on db calls, since our user db currently does not support 28 // transactions, and email notifications run in a separate goroutine. This 29 // workaround won't be necessary once the user layer gets rewritten. 30 type EmailHistory struct { 31 Timestamps []int64 `json:"timestamps"` // Received email UNIX ts 32 33 // LimitWarningSent is used to track users that have hit the rate 34 // limit and have already been sent a notification email letting 35 // them know that they hit the rate limit. 36 LimitWarningSent bool `json:"limitwarningsent"` 37 } 38 39 // VersionEmailHistory is the version of the EmailHistory struct. 40 const VersionEmailHistory uint32 = 1