Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding user to moderated list via listitem does not seem to work. #432

Closed
rayisbadat opened this issue Nov 16, 2024 · 2 comments
Closed
Labels
question Further information is requested

Comments

@rayisbadat
Copy link

Describe the bug
If I use client.app.bsky.graph.listitem.create() to try to add a user to a moderated list (Block list) it says its successful. But the user never gets added to the moderated list. If i use the same code to add a user to a normal list it seems to work just fine.

To Reproduce

  1. create a moderated list
  2. get the at:// for the moderated list
  3. create a models.AppBskyGraphListitem.Record
  4. run a client.app.bsky.graph.listitem.create(client.me.did,list_record)

Expected behavior

User gets added to list or atproto raises an exception of some kind.

Details
Python 3.12.7
pip modoles

pip freeze
annotated-types==0.7.0
anyio==4.6.2.post1
atproto==0.0.55
certifi==2024.8.30
cffi==1.17.1
click==8.1.7
cryptography==43.0.3
dnspython==2.7.0
h11==0.14.0
httpcore==1.0.6
httpx==0.27.2
idna==3.10
libipld==3.0.0
pycparser==2.22
pydantic==2.9.2
pydantic_core==2.23.4
sniffio==1.3.1
typing_extensions==4.12.2
websockets==13.1

Additional context
the relevant code chunk

def add_user_to_blocklist(client=None, tgtUserHandle=None, tgtUserDID=None, listURI=None, dryRun=False):
    # It only works for normal lists, not moderation lists
    list_record = models.AppBskyGraphListitem.Record(
        subject=tgtUserDID,
        created_at=client.get_current_time_iso(),
        list=listURI,
    )
    if not dryRun:
        try:
            client.app.bsky.graph.listitem.create(client.me.did,list_record)
            print( f'>> Added user: {tgtUserHandle} with DID: {tgtUserDID} to block list ${listURI}' )
        except Exception as e:
            print( f'ERROR: Somethign went wrong: {e}')
@MarshalX
Copy link
Owner

MarshalX commented Nov 17, 2024

I have tested. Everything works good. Verify what did do you pass; verify URIs; verify that you own this mod list; maybe you are logged in into wrong account and etc. Here is my coded that I used to test it:

def main() -> None:
    client = Client()
    client.login(os.environ['USERNAME'], os.environ['PASSWORD'])

    # https://bsky.app/profile/test.marshal.dev/lists/3k5z5k4k6qw2r
    mod_list_uri = 'at://did:plc:kvwvcn5iqfooopmyzvb4qzba/app.bsky.graph.list/3k5z5k4k6qw2r'
    mod_list_owner = AtUri.from_str(mod_list_uri).host
    user_to_add = IdResolver().handle.resolve('test.marshal.dev')

    print(f'Adding {user_to_add} to the list {mod_list_uri} (owned by {mod_list_owner})')

    created_list_item = client.app.bsky.graph.listitem.create(mod_list_owner, models.AppBskyGraphListitem.Record(
        list=mod_list_uri,
        subject=user_to_add,
        created_at=client.get_current_time_iso(),
    ))

    print(f'Created list item: CID={created_list_item.cid}; URI: {created_list_item.uri}')

    sleep(3)  # sleep for 3 sec because it takes some time to update the list for the backend

    mod_list = client.app.bsky.graph.get_list(models.AppBskyGraphGetList.Params(list=mod_list_uri))
    mod_list_users = [item.subject.did for item in mod_list.items]
    print(f'List users: {mod_list_users}')
    assert user_to_add in mod_list_users, f'User {user_to_add} not found in the list {mod_list_uri}'

    deleted_success = client.app.bsky.graph.listitem.delete(mod_list_owner, AtUri.from_str(created_list_item.uri).rkey)
    print(f'Deleted list item: {deleted_success}')

upd. added this code as SDK example #435

@MarshalX MarshalX added the question Further information is requested label Nov 17, 2024
@rayisbadat
Copy link
Author

sigh, i am sorry. I must have been passing the uri of a deleted list and not the current one.
:/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants