fix attachement with matrix v3

pull/1373/head
privacyfr3ak 2025-07-27 14:35:31 -04:00
parent 91faed0c6d
commit b673837f4e
No known key found for this signature in database
GPG Key ID: A8D8FC83B217A56A
1 changed files with 64 additions and 67 deletions

View File

@ -651,6 +651,9 @@ class NotifyMatrix(NotifyBase):
# Get our room # Get our room
room = rooms.pop(0) room = rooms.pop(0)
# Set method according to MatrixVersion
method = 'PUT' if self.version == MatrixVersion.V3 else 'POST'
# Get our room_id from our response # Get our room_id from our response
room_id = self._room_join(room) room_id = self._room_join(room)
if not room_id: if not room_id:
@ -677,10 +680,6 @@ class NotifyMatrix(NotifyBase):
path = '/rooms/{}/send/m.room.message'.format( path = '/rooms/{}/send/m.room.message'.format(
NotifyMatrix.quote(room_id)) NotifyMatrix.quote(room_id))
if self.version == MatrixVersion.V2:
#
# Attachments don't work beyond V2 at this time
#
if image_url: if image_url:
# Define our payload # Define our payload
image_payload = { image_payload = {
@ -704,7 +703,21 @@ class NotifyMatrix(NotifyBase):
attachment['type'] = 'm.room.message' attachment['type'] = 'm.room.message'
postokay, response = self._fetch( postokay, response = self._fetch(
path, payload=attachment) path, payload=attachment, method=method)
# Increment the transaction ID to avoid future messages
# being recognized as retransmissions and ignored
if self.version == MatrixVersion.V3 \
and self.access_token != self.password:
self.transaction_id += 1
self.store.set(
'transaction_id', self.transaction_id,
expires=self.default_cache_expiry_sec)
path = '/rooms/{}/send/m.room.message/{}'.format(
NotifyMatrix.quote(room_id),
self.transaction_id,
)
if not postokay: if not postokay:
# Mark our failure # Mark our failure
has_error = True has_error = True
@ -740,7 +753,6 @@ class NotifyMatrix(NotifyBase):
}) })
# Post our content # Post our content
method = 'PUT' if self.version == MatrixVersion.V3 else 'POST'
postokay, response = self._fetch( postokay, response = self._fetch(
path, payload=payload, method=method) path, payload=payload, method=method)
@ -770,10 +782,6 @@ class NotifyMatrix(NotifyBase):
""" """
payloads = [] payloads = []
if self.version != MatrixVersion.V2:
self.logger.warning(
'Add ?v=2 to Apprise URL to support Attachments')
return next((False for a in attach if not a), [])
for attachment in attach: for attachment in attach:
if not attachment: if not attachment:
@ -795,29 +803,19 @@ class NotifyMatrix(NotifyBase):
# "content_uri": "mxc://example.com/a-unique-key" # "content_uri": "mxc://example.com/a-unique-key"
# } # }
# FUTURE if self.version == MatrixVersion.V3: if self.version == MatrixVersion.V3:
# FUTURE # Prepare our payload # Prepare our payload
# FUTURE payloads.append({ payloads.append({
# FUTURE "body": attachment.name, "body": attachment.name,
# FUTURE "info": { "info": {
# FUTURE "mimetype": attachment.mimetype, "mimetype": attachment.mimetype,
# FUTURE "size": len(attachment), "size": len(attachment),
# FUTURE }, },
# FUTURE "msgtype": "m.image", "msgtype": "m.image",
# FUTURE "url": response.get('content_uri'), "url": response.get('content_uri'),
# FUTURE }) })
# FUTURE else:
# FUTURE # Prepare our payload
# FUTURE payloads.append({
# FUTURE "info": {
# FUTURE "mimetype": attachment.mimetype,
# FUTURE },
# FUTURE "msgtype": "m.image",
# FUTURE "body": "tta.webp",
# FUTURE "url": response.get('content_uri'),
# FUTURE })
else:
# Prepare our payload # Prepare our payload
payloads.append({ payloads.append({
"info": { "info": {
@ -1251,11 +1249,10 @@ class NotifyMatrix(NotifyBase):
status_code = requests.codes.internal_server_error status_code = requests.codes.internal_server_error
if path == '/upload': if path == '/upload':
# FUTURE if self.version == MatrixVersion.V3: if self.version == MatrixVersion.V3:
# FUTURE url += MATRIX_V3_MEDIA_PATH + path url += MATRIX_V3_MEDIA_PATH + path
# FUTURE else: else:
# FUTURE url += MATRIX_V2_MEDIA_PATH + path
url += MATRIX_V2_MEDIA_PATH + path url += MATRIX_V2_MEDIA_PATH + path
params.update({'filename': attachment.name}) params.update({'filename': attachment.name})