(pds string, token string, targetActor string, my_did string)
| 1410 | } |
| 1411 | |
| 1412 | func UnfollowUser(pds string, token string, targetActor string, my_did string) (*User, error) { |
| 1413 | url := pds + "/xrpc/com.atproto.repo.deleteRecord" |
| 1414 | |
| 1415 | targetUser, err := GetUserInfoRaw(pds, token, targetActor) |
| 1416 | if err != nil { |
| 1417 | return nil, errors.New("failed to fetch post") |
| 1418 | } |
| 1419 | |
| 1420 | if targetUser.Viewer.Following == nil { |
| 1421 | return nil, errors.New("not following user") |
| 1422 | } |
| 1423 | |
| 1424 | payload := DeleteRecordPayload{ |
| 1425 | Collection: "app.bsky.graph.follow", |
| 1426 | Repo: my_did, |
| 1427 | RKey: strings.Split(*targetUser.Viewer.Following, "/app.bsky.graph.follow/")[1], |
| 1428 | } |
| 1429 | |
| 1430 | reqBody, err := json.Marshal(payload) |
| 1431 | if err != nil { |
| 1432 | return nil, errors.New("failed to marshal payload") |
| 1433 | } |
| 1434 | |
| 1435 | resp, err := SendRequest(&token, http.MethodPost, url, bytes.NewReader(reqBody)) |
| 1436 | if err != nil { |
| 1437 | return nil, err |
| 1438 | } |
| 1439 | defer resp.Body.Close() |
| 1440 | |
| 1441 | if resp.StatusCode != http.StatusOK { |
| 1442 | bodyBytes, _ := io.ReadAll(resp.Body) |
| 1443 | bodyString := string(bodyBytes) |
| 1444 | fmt.Println("Response Status:", resp.StatusCode) |
| 1445 | fmt.Println("Response Body:", bodyString) |
| 1446 | return nil, errors.New(bodyString) // return response |
| 1447 | } |
| 1448 | |
| 1449 | unfollowRes := CreateRecordResult{} |
| 1450 | if err := json.NewDecoder(resp.Body).Decode(&unfollowRes); err != nil { |
| 1451 | return nil, err |
| 1452 | } |
| 1453 | |
| 1454 | emptyString := "" |
| 1455 | targetUser.Viewer.Following = &emptyString |
| 1456 | |
| 1457 | return targetUser, nil |
| 1458 | } |
| 1459 | |
| 1460 | func GetPostLikes(pds string, token string, uri string, limit int) (*Likes, error) { |
| 1461 | url := fmt.Sprintf(pds+"/xrpc/app.bsky.feed.getLikes?limit=%d&uri=%s", limit, uri) |
nothing calls this directly
no test coverage detected