* Star/unstar post.
(postRef: DatabaseReference, uid: string)
| 152 | * Star/unstar post. |
| 153 | */ |
| 154 | function toggleStar(postRef: DatabaseReference, uid: string) { |
| 155 | runTransaction(postRef, function (post) { |
| 156 | if (post) { |
| 157 | if (post.stars && post.stars[uid]) { |
| 158 | post.starCount--; |
| 159 | post.stars[uid] = null; |
| 160 | } else { |
| 161 | post.starCount++; |
| 162 | if (!post.stars) { |
| 163 | post.stars = {}; |
| 164 | } |
| 165 | post.stars[uid] = true; |
| 166 | } |
| 167 | } |
| 168 | return post; |
| 169 | }); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Creates a post element. |