!JiiOHXrIUCtcOJsZCa:matrix.org

nio

342 Members
The nio matrix python library | Latest stable release 0.25.2 | https://pypi.org/project/matrix-nio/ | Documentation: https://matrix-nio.readthedocs.io/en/stable/133 Servers

Load older messages


SenderMessageTime
18 Oct 2024
@ifiguero:matrix.orgifiguero
In reply to @winduu:matrix.org

Question About Power Levels

To modify power levels in nio, we need to use room_put_state event_type = "m.room.power_levels".

AFAIK: Synapse requires sending the full power level dictionary to the server when making modifications. Otherwise, values that are not explicitly set might get overwritten (or deleted). Is that correct?

I can’t seem to find a straightforward way to access this information in the correct schema structure, other than by fetching room events and modifying the last power level event as a base. The clients (rooms) have a PowerLevels object, but it doesn’t seem to fully represent the server schema.

It would be helpful to have a function that returns the server schema from here, perhaps something like a to_dict or to_json function. (Easy to implement, happy to do it)

Additionally, it appears that power levels in the object aren’t synced correctly; they seem to get updated only partially (this might be a separate issue).

Am I on the wrong track here? I’d appreciate clarification before opening a ticket. ;)

I was trying to figure out that also on myself. I think the only way to really know is to look in the synapse codebase (as the documentation don't say much) about what happens with values missing on modification. Other bots seems to "overwrite" the whole allow,deny field, but I'm unsure that can scale to the sizes required for the amount of home-servers you can find on a room.

I was thinking on just sending the "changes" with this method, but I haven't properly test it. Nor that I have any custom homeserver to try. Now to be able to do that, your software need to keep the "true state" stored on its own, and probably query the "room state" to see what keys needs to get updated. So your code can send an event and sync the "room state" to the "true state" desired.

Another way is just to blindly craft the event from your "true state" without any regard of the "room state" trying to overwrite it completely. My only worry is that you could (eventually) get an event size too large if the list of homeservers grow beyond a threshold.

15:24:35
@nex:nexy7574.co.uknex (she/it)
In reply to@winduu:matrix.org
I certainly could, but that is an extra request, for data that already is or should be available - thus not straightforward. The web clients don't do it either. - This why I thought I'm maybe doing something wrong.
you could probably pull it from sync(), but I see what you mean
13:17:26
22 Oct 2024
@mtrnord:midnightthoughts.spaceMTRNord (they/them)

Hi :) I am kinda new to python matrix nio and I am getting AttributeError: 'dict' object has no attribute 'type' for events returned using await client.room_get_state(room_id.room_id).

I am doing a for ... in loop over state.events where the dict in the error is the event out of the events list. On which I am trying to compare the type with a string.

13:11:12
@mtrnord:midnightthoughts.spaceMTRNord (they/them)Any ideas why that happens?13:11:18
@mtrnord:midnightthoughts.spaceMTRNord (they/them)printing the event shows the type being present13:11:26
@mtrnord:midnightthoughts.spaceMTRNord (they/them) * printing the event shows the type key being present 13:11:32
@mtrnord:midnightthoughts.spaceMTRNord (they/them) I am doing if event.type == "event type": 13:11:56
@mtrnord:midnightthoughts.spaceMTRNord (they/them)
state = await client.room_get_state(room_id.room_id)

for event in state.events:
    if event.type == "m.room.message":
        ....
13:12:37
@mtrnord:midnightthoughts.spaceMTRNord (they/them) *
state = await client.room_get_state(room_id.room_id)

for event in state.events:
    if event.type == "state_event_type_here":
        ....
13:12:59
@tulir:maunium.nettulirpython doesn't allow dict access with dots like javascript does13:13:40
@mtrnord:midnightthoughts.spaceMTRNord (they/them) Ah. So its event["type"]? 13:14:17
@tulir:maunium.nettuliryes, looks like nio doesn't parse the events into dataclasses or anything like that, so they're just raw dicts13:15:09
@mtrnord:midnightthoughts.spaceMTRNord (they/them)Ok even pycharm assumed dot notation here :D but maybe it is confusing it with some other type13:15:41
@mtrnord:midnightthoughts.spaceMTRNord (they/them)ah it seems like there is an Event class which exists and it might have thought this applies here13:16:08
@nex:nexy7574.co.uknex (she/it)
In reply to@tulir:maunium.net
yes, looks like nio doesn't parse the events into dataclasses or anything like that, so they're just raw dicts
Events usually yes, but iirc state values don't have any dataclasses at all
13:20:10
@mtrnord:midnightthoughts.spaceMTRNord (they/them)

Another thing for room messages which are redacted I am getting lots of:

Failed validating 'required' in schema['properties']['content']:
    {'type': 'object',
     'properties': {'msgtype': {'type': 'string'}},
     'required': ['msgtype']}

On instance['content']:
    {}
Error validating event: 'msgtype' is a required property

when going backwards using await client.room_messages.

I dont care about the content but I do care about the message existing in the resulting list of events. Will they still exist or does this error cause them to disappear? 🤔

17:46:27
26 Oct 2024
@ifiguero:matrix.orgifiguero

I'm familiar with the error message, and I was tracking it to: https://matrix-nio.readthedocs.io/en/latest/_modules/nio/events/misc.html

def validate_or_badevent(
    parsed_dict: Dict[Any, Any],
    schema: Dict[Any, Any],
) -> Optional[Union[BadEvent, UnknownBadEvent]]:
    try:
        validate_json(parsed_dict, schema)
    except (ValidationError, SchemaError) as e:
        logger.warning(f"Error validating event: {str(e)}")
        try:
            return BadEvent.from_dict(parsed_dict)
        except KeyError:
            return UnknownBadEvent(parsed_dict)

    return None
01:51:48
23 Oct 2024
@nex:nexy7574.co.uknex (she/it) changed their profile picture.18:46:39
26 Oct 2024
@ifiguero:matrix.orgifigueroit happens most likely happen on events that have the `event.source['type']=='m.room.message' value, and for some reason don't have a valid payload. 01:55:26
23 Oct 2024
@nex:nexy7574.co.uknex (she/it) removed their profile picture.19:03:18
26 Oct 2024
@ifiguero:matrix.orgifiguero * it happens most likely happen on events that have the event.source\['type'\]=='m.room.message' value, and for some reason don't have a valid payload. 01:55:41
23 Oct 2024
@nex:nexy7574.co.uknex (she/it) set a profile picture.19:04:45
26 Oct 2024
@ifiguero:matrix.orgifiguero * it happens most likely happen on events that have the event.source['type']=='m.room.message' value, and for some reason don't have a valid payload. 01:55:55
24 Oct 2024
@nex:nexy7574.co.uknex (she/it)Is there an easy way to get each state update from each SyncResponse?23:40:01
26 Oct 2024
@ifiguero:matrix.orgifiguerothere is several custom events, and malformed ones, as not all clients behave properly. 01:58:51
24 Oct 2024
@nex:nexy7574.co.uknex (she/it)I don't want the events in this case, just state changes23:40:12
26 Oct 2024
@ifiguero:matrix.orgifiguero IIRC there is m.room.member for changes in the user and ['m.room'. ('name' | 'topic' | 'avatar' | 'aliases' | 'canonical_alias' | 'encryption' | 'create' | 'join_rules' | 'history_visibility' | 'guest_access' | 'power_levels' | 'server_acl' | 'tombstone' | 'pinned_events')] seem to be room state changes. 02:30:11
@ifiguero:matrix.orgifiguero

they are all events. You get a copy of the current value if you query:

res = await client.room_get_state(room_id)
02:34:38
@ifiguero:matrix.orgifiguero *

they are all events. You get a copy of the current value if you query:

res = await client.room_get_state(room_id)

but also they get relayed by normal sync as they come by.

02:35:11
@d3v1l-h4cker:4d2.org-=D3V1L=- joined the room.08:18:48

Show newer messages


Back to Room ListRoom Version: 4