增加私聊置顶和按设备统计未读
This commit is contained in:
1 parent
7e165ba9b4
commit
ec2679b991
19 files changed
+312
-52
No files matched your search
@@ -17,6 +17,7 @@ type Contact struct {
|
||||
Alias string `json:"alias"`
|
||||
Category string `json:"category"`
|
||||
Muted bool `json:"muted"`
|
||||
Pinned bool `json:"pinned"`
|
||||
}
|
||||
|
||||
type Store struct{ db *pgxpool.Pool }
|
||||
@@ -30,7 +31,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.muted,false)
|
||||
COALESCE(p.alias,''), COALESCE(p.category,''), COALESCE(p.muted,false), COALESCE(p.pinned,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)
|
||||
@@ -43,7 +44,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, &c.Muted)
|
||||
Scan(&c.ID, &c.Username, &c.State, &c.Alias, &c.Category, &c.Muted, &c.Pinned)
|
||||
return c, err
|
||||
}
|
||||
|
||||
@@ -58,7 +59,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, &c.Muted); err != nil {
|
||||
if err := rows.Scan(&c.ID, &c.Username, &c.State, &c.Alias, &c.Category, &c.Muted, &c.Pinned); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, c)
|
||||
@@ -148,12 +149,16 @@ func (s *Store) Change(ctx context.Context, owner, target, action, alias, catego
|
||||
if err == nil && tag.RowsAffected() == 0 {
|
||||
return ErrUnavailable
|
||||
}
|
||||
case "mute", "unmute":
|
||||
case "mute", "unmute", "pin", "unpin":
|
||||
column, enabled := "muted", action == "mute"
|
||||
if action == "pin" || action == "unpin" {
|
||||
column, enabled = "pinned", action == "pin"
|
||||
}
|
||||
tag, writeErr := tx.Exec(ctx, `
|
||||
INSERT INTO contact_preferences(owner_id,contact_id,alias,category,muted)
|
||||
INSERT INTO contact_preferences(owner_id,contact_id,alias,category,`+column+`)
|
||||
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")
|
||||
ON CONFLICT (owner_id,contact_id) DO UPDATE SET `+column+`=EXCLUDED.`+column,
|
||||
owner, target, enabled)
|
||||
err = writeErr
|
||||
if err == nil && tag.RowsAffected() == 0 {
|
||||
return ErrUnavailable
|
||||
|
||||
Reference in new issue
Block a user