增加私聊置顶和按设备统计未读
This commit is contained in:
1 parent
7e165ba9b4
commit
ec2679b991
19 files changed
+312
-52
No files matched your search
@@ -27,7 +27,7 @@ type Store struct{ db *pgxpool.Pool }
|
||||
|
||||
func New(db *pgxpool.Pool) *Store { return &Store{db: db} }
|
||||
|
||||
func (s *Store) Send(ctx context.Context, sender, recipient, message string, ciphertext []byte, requestNotice bool) (string, bool, error) {
|
||||
func (s *Store) Send(ctx context.Context, sender, recipient, message string, ciphertext []byte, countAsUnread bool) (string, bool, error) {
|
||||
tx, err := s.db.Begin(ctx)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
@@ -40,13 +40,13 @@ func (s *Store) Send(ctx context.Context, sender, recipient, message string, cip
|
||||
|
||||
var seq string
|
||||
err = tx.QueryRow(ctx, `
|
||||
INSERT INTO device_envelopes(message_id, sender_device, recipient_device, ciphertext)
|
||||
VALUES ($1,$2,$3,$4)
|
||||
INSERT INTO device_envelopes(message_id, sender_device, recipient_device, ciphertext, counts_as_unread)
|
||||
VALUES ($1,$2,$3,$4,$5)
|
||||
ON CONFLICT (sender_device, recipient_device, message_id) DO NOTHING
|
||||
RETURNING sequence::text
|
||||
`, message, sender, recipient, ciphertext).Scan(&seq)
|
||||
`, message, sender, recipient, ciphertext, countAsUnread).Scan(&seq)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
requestNotice = false
|
||||
countAsUnread = false
|
||||
var previous []byte
|
||||
err = tx.QueryRow(ctx, `
|
||||
SELECT sequence::text,ciphertext FROM device_envelopes
|
||||
@@ -60,7 +60,7 @@ func (s *Store) Send(ctx context.Context, sender, recipient, message string, cip
|
||||
return "", false, err
|
||||
}
|
||||
var notify bool
|
||||
if requestNotice {
|
||||
if countAsUnread {
|
||||
err = tx.QueryRow(ctx, `
|
||||
SELECT NOT EXISTS (
|
||||
SELECT 1 FROM contact_preferences p
|
||||
|
||||
Reference in new issue
Block a user