接入私聊消息通知和联系人免打扰
This commit is contained in:
1 parent
5c882ac855
commit
7e165ba9b4
23 files changed
+286
-97
No files matched your search
@@ -16,6 +16,7 @@ type Contact struct {
|
||||
State string `json:"state"`
|
||||
Alias string `json:"alias"`
|
||||
Category string `json:"category"`
|
||||
Muted bool `json:"muted"`
|
||||
}
|
||||
|
||||
type Store struct{ db *pgxpool.Pool }
|
||||
@@ -29,7 +30,7 @@ const selectContact = `
|
||||
WHEN r.requested_by = $1 THEN 'outgoing'
|
||||
WHEN r.status = 'pending' THEN 'incoming'
|
||||
ELSE 'none' END,
|
||||
COALESCE(p.alias,''), COALESCE(p.category,'')
|
||||
COALESCE(p.alias,''), COALESCE(p.category,''), COALESCE(p.muted,false)
|
||||
FROM users u
|
||||
LEFT JOIN contact_relationships r ON r.first_user = LEAST($1::uuid, u.id)
|
||||
AND r.second_user = GREATEST($1::uuid, u.id)
|
||||
@@ -42,7 +43,7 @@ const selectContact = `
|
||||
func (s *Store) Search(ctx context.Context, owner, username string) (Contact, error) {
|
||||
var c Contact
|
||||
err := s.db.QueryRow(ctx, selectContact+" AND u.username=$2", owner, username).
|
||||
Scan(&c.ID, &c.Username, &c.State, &c.Alias, &c.Category)
|
||||
Scan(&c.ID, &c.Username, &c.State, &c.Alias, &c.Category, &c.Muted)
|
||||
return c, err
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ func (s *Store) List(ctx context.Context, owner string) ([]Contact, error) {
|
||||
result := make([]Contact, 0)
|
||||
for rows.Next() {
|
||||
var c Contact
|
||||
if err := rows.Scan(&c.ID, &c.Username, &c.State, &c.Alias, &c.Category); err != nil {
|
||||
if err := rows.Scan(&c.ID, &c.Username, &c.State, &c.Alias, &c.Category, &c.Muted); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, c)
|
||||
@@ -147,6 +148,16 @@ func (s *Store) Change(ctx context.Context, owner, target, action, alias, catego
|
||||
if err == nil && tag.RowsAffected() == 0 {
|
||||
return ErrUnavailable
|
||||
}
|
||||
case "mute", "unmute":
|
||||
tag, writeErr := tx.Exec(ctx, `
|
||||
INSERT INTO contact_preferences(owner_id,contact_id,alias,category,muted)
|
||||
SELECT $1::uuid,$2::uuid,'','',$3::boolean FROM contact_relationships WHERE `+pair+` AND status='accepted'
|
||||
ON CONFLICT (owner_id,contact_id) DO UPDATE SET muted=EXCLUDED.muted
|
||||
`, owner, target, action == "mute")
|
||||
err = writeErr
|
||||
if err == nil && tag.RowsAffected() == 0 {
|
||||
return ErrUnavailable
|
||||
}
|
||||
default:
|
||||
return ErrUnavailable
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user