Skip to content

Commit

Permalink
Update tests and fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis committed Feb 6, 2025
1 parent b591fb7 commit d2ea62e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 40 deletions.
11 changes: 9 additions & 2 deletions service/chat/mam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
ORDER BY
mam_message.id DESC
LIMIT
50
LEAST(50, COALESCE(%(max)s, 50))
)
SELECT
*
Expand All @@ -118,6 +118,7 @@ class Query:
from_username: str
to_username: str
before: str | None
max: str | None


@dataclass(frozen=True)
Expand Down Expand Up @@ -148,14 +149,19 @@ def _process_query(
"string(.//*[local-name()='before'])"
)

max_value = parsed_xml.xpath(
"string(.//*[local-name()='max'])"
)

if not query_id or not to_username:
return None

return Query(
query_id=query_id,
from_username=to_bare_jid(from_username),
to_username=to_bare_jid(to_username),
before=before_value
before=before_value,
max=max_value,
)


Expand Down Expand Up @@ -286,6 +292,7 @@ async def _get_conversation(
from_username=from_username,
to_username=to_username,
before_id=before_id,
max=query.max,
)

async with asyncdatabase.chat_tx('read committed') as tx:
Expand Down
8 changes: 4 additions & 4 deletions test/functionality4/xmpp-inbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ expected_inbox_1=$(cat << EOF
<body>from user 3 to user 1</body>
<request xmlns="urn:xmpp:receipts"/>
</message></forwarded><read>false</read><box>inbox</box><archive>false</archive><mute>0</mute></result></message>
<iq id='$query_id_1' type='result'><fin/></iq>
<iq id="$query_id_1" type="result"><fin/></iq>
EOF
)

Expand All @@ -196,7 +196,7 @@ expected_inbox_2=$(cat << EOF
<body>from user 3 to user 2</body>
<request xmlns="urn:xmpp:receipts"/>
</message></forwarded><read>false</read><box>chats</box><archive>false</archive><mute>0</mute></result></message>
<iq id='$query_id_2' type='result'><fin/></iq>
<iq id="$query_id_2" type="result"><fin/></iq>
EOF
)

Expand All @@ -209,7 +209,7 @@ expected_inbox_3=$(cat << EOF
<body>from user 3 to user 2</body>
<request xmlns="urn:xmpp:receipts"/>
</message></forwarded><read>true</read><box>chats</box><archive>false</archive><mute>0</mute></result></message>
<iq id='$query_id_3' type='result'><fin/></iq>
<iq id="$query_id_3" type="result"><fin/></iq>
EOF
)

Expand All @@ -233,7 +233,7 @@ expected_inbox_1=$(cat << EOF
<body>from user 3 to user 1</body>
<request xmlns="urn:xmpp:receipts"/>
</message></forwarded><read>false</read><box>inbox</box><archive>false</archive><mute>0</mute></result></message>
<iq id='$query_id_1' type='result'><fin/></iq>
<iq id="$query_id_1" type="result"><fin/></iq>
EOF
)

Expand Down
Loading

0 comments on commit d2ea62e

Please sign in to comment.