tangled
alpha
login
or
join now
yoten.app
/
yoten
17
fork
atom
Yōten: A social tracker for your language learning journey built on the atproto.
17
fork
atom
overview
issues
pulls
pipelines
fix: follow status
brookjeynes.dev
6 months ago
6ccbe4bd
bbfbd817
verified
This commit was signed with the committer's
known signature
.
brookjeynes.dev
SSH Key Fingerprint:
SHA256:N3n3PCBSiXfS6EHlmGdx+LMEruJMj6FS2hqaXyfsw0s=
+28
-8
1 changed file
expand all
collapse all
unified
split
internal
db
follow.go
+28
-8
internal/db/follow.go
···
1
1
package db
2
2
3
3
import (
4
4
+
"database/sql"
4
5
"fmt"
6
6
+
"log"
5
7
"strings"
6
8
"time"
7
9
)
···
76
78
return IsSelf
77
79
}
78
80
79
79
-
var follows, isFollowed bool
80
81
query := `
81
81
-
select
82
82
-
exists(select 1 from follows where user_did = ? and subject_did = ?),
83
83
-
exists(select 1 from follows where user_did = ? and subject_did = ?)
84
84
-
`
85
85
-
err := e.QueryRow(query, userDid, subjectDid, subjectDid, userDid).Scan(&follows, &isFollowed)
82
82
+
SELECT
83
83
+
-- Count of rows where the user follows the subject
84
84
+
COUNT(CASE WHEN user_did = ? AND subject_did = ? THEN 1 END),
85
85
+
-- Count of rows where the subject follows the user
86
86
+
COUNT(CASE WHEN user_did = ? AND subject_did = ? THEN 1 END)
87
87
+
FROM
88
88
+
follows
89
89
+
WHERE
90
90
+
(user_did = ? AND subject_did = ?) OR (user_did = ? AND subject_did = ?);
91
91
+
`
92
92
+
93
93
+
var userFollowsSubject, subjectFollowsUser int
94
94
+
err := e.QueryRow(
95
95
+
query,
96
96
+
userDid, subjectDid,
97
97
+
subjectDid, userDid,
98
98
+
userDid, subjectDid,
99
99
+
subjectDid, userDid,
100
100
+
).Scan(&userFollowsSubject, &subjectFollowsUser)
101
101
+
86
102
if err != nil {
103
103
+
if err == sql.ErrNoRows {
104
104
+
return IsNotFollowing
105
105
+
}
106
106
+
log.Printf("failed to query follow status: %v", err)
87
107
return IsNotFollowing
88
108
}
89
109
90
90
-
if follows && isFollowed {
110
110
+
if userFollowsSubject > 0 && subjectFollowsUser > 0 {
91
111
return IsMutual
92
92
-
} else if follows {
112
112
+
} else if userFollowsSubject > 0 {
93
113
return IsFollowing
94
114
} else {
95
115
return IsNotFollowing