Add in mark as reaad button to list view, use ajax to preform the action without page refresh.

This commit is contained in:
2025-11-02 09:11:48 +00:00
parent 61ad033520
commit f0fc70eac6
7 changed files with 212 additions and 27 deletions

View File

@@ -277,3 +277,25 @@ func (s *Service) Unarchive(userID, id int64) error {
}
return nil
}
func (s *Service) MarkRead(userID, id int64) error {
ctx, cancel := context.WithTimeout(context.Background(), s.Timeout)
defer cancel()
q := `
UPDATE user_messages
SET is_read = 1
WHERE id = ? AND recipientId = ?
`
q = s.bind(q)
res, err := s.DB.ExecContext(ctx, q, id, userID)
if err != nil {
return err
}
n, _ := res.RowsAffected()
if n == 0 {
return sql.ErrNoRows
}
return nil
}