(pds string, token string, id string, my_did string)
| 1264 | } |
| 1265 | |
| 1266 | func LikePost(pds string, token string, id string, my_did string) (*ThreadRoot, error) { |
| 1267 | url := pds + "/xrpc/com.atproto.repo.createRecord" |
| 1268 | |
| 1269 | thread, err := GetPost(pds, token, id, 0, 1) |
| 1270 | if err != nil { |
| 1271 | return nil, errors.New("failed to fetch post") |
| 1272 | } |
| 1273 | |
| 1274 | payload := CreateRecordPayload{ |
| 1275 | Collection: "app.bsky.feed.like", |
| 1276 | Repo: my_did, |
| 1277 | Record: PostInteractionRecord{ |
| 1278 | Type: "app.bsky.feed.like", |
| 1279 | CreatedAt: time.Now().UTC().Format(time.RFC3339), |
| 1280 | Subject: Subject{ |
| 1281 | URI: thread.Thread.Post.URI, |
| 1282 | CID: thread.Thread.Post.CID, |
| 1283 | }, |
| 1284 | }, |
| 1285 | } |
| 1286 | |
| 1287 | reqBody, err := json.Marshal(payload) |
| 1288 | if err != nil { |
| 1289 | return nil, errors.New("failed to marshal payload") |
| 1290 | } |
| 1291 | |
| 1292 | resp, err := SendRequest(&token, http.MethodPost, url, bytes.NewReader(reqBody)) |
| 1293 | if err != nil { |
| 1294 | return nil, err |
| 1295 | } |
| 1296 | defer resp.Body.Close() |
| 1297 | |
| 1298 | if resp.StatusCode != http.StatusOK { |
| 1299 | bodyBytes, _ := io.ReadAll(resp.Body) |
| 1300 | bodyString := string(bodyBytes) |
| 1301 | fmt.Println("Response Status:", resp.StatusCode) |
| 1302 | fmt.Println("Response Body:", bodyString) |
| 1303 | return nil, errors.New(bodyString) // return response |
| 1304 | } |
| 1305 | |
| 1306 | likeRes := CreateRecordResult{} |
| 1307 | if err := json.NewDecoder(resp.Body).Decode(&likeRes); err != nil { |
| 1308 | return nil, err |
| 1309 | } |
| 1310 | |
| 1311 | thread.Thread.Post.Viewer.Like = &strings.Split(likeRes.URI, "/app.bsky.feed.like/")[1] |
| 1312 | |
| 1313 | return thread, nil |
| 1314 | } |
| 1315 | |
| 1316 | func UnlikePost(pds string, token string, id string, my_did string) (*ThreadRoot, error) { |
| 1317 | url := pds + "/xrpc/com.atproto.repo.deleteRecord" |
nothing calls this directly
no test coverage detected