|
@@ -38,6 +38,7 @@ from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, Mess
|
|
MessageEvent, EncryptedEvent, ContentURI, MediaMessageEventContent,
|
|
MessageEvent, EncryptedEvent, ContentURI, MediaMessageEventContent,
|
|
TextMessageEventContent, ImageInfo, VideoInfo, FileInfo, AudioInfo,
|
|
TextMessageEventContent, ImageInfo, VideoInfo, FileInfo, AudioInfo,
|
|
PowerLevelStateEventContent, UserID, SingleReceiptEventContent)
|
|
PowerLevelStateEventContent, UserID, SingleReceiptEventContent)
|
|
|
|
+from mautrix.util.format_duration import format_duration
|
|
from mautrix.util.bridge_state import BridgeStateEvent
|
|
from mautrix.util.bridge_state import BridgeStateEvent
|
|
from mautrix.util.message_send_checkpoint import MessageSendCheckpointStatus
|
|
from mautrix.util.message_send_checkpoint import MessageSendCheckpointStatus
|
|
from mautrix.errors import MatrixError, MForbidden, IntentError
|
|
from mautrix.errors import MatrixError, MForbidden, IntentError
|
|
@@ -940,38 +941,16 @@ class Portal(DBPortal, BasePortal):
|
|
if self.expiration_time == expires_in_seconds:
|
|
if self.expiration_time == expires_in_seconds:
|
|
return
|
|
return
|
|
|
|
|
|
- def format_time(seconds) -> str:
|
|
|
|
- if seconds is None:
|
|
|
|
- return "Off"
|
|
|
|
-
|
|
|
|
- # Technique from https://stackoverflow.com/a/24542445
|
|
|
|
- intervals = (
|
|
|
|
- ("weeks", 604800), # 60 * 60 * 24 * 7
|
|
|
|
- ("days", 86400), # 60 * 60 * 24
|
|
|
|
- ("hours", 3600), # 60 * 60
|
|
|
|
- ("minutes", 60),
|
|
|
|
- ("seconds", 1),
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- result = []
|
|
|
|
- for name, count in intervals:
|
|
|
|
- value = seconds // count
|
|
|
|
- if value:
|
|
|
|
- seconds -= value * count
|
|
|
|
- if value == 1:
|
|
|
|
- name = name[:-1]
|
|
|
|
- result.append(f"{value} {name}")
|
|
|
|
- return ", ".join(result)
|
|
|
|
-
|
|
|
|
assert self.mxid
|
|
assert self.mxid
|
|
self.expiration_time = expires_in_seconds
|
|
self.expiration_time = expires_in_seconds
|
|
await self.update()
|
|
await self.update()
|
|
|
|
|
|
|
|
+ time_str = format_duration(expires_in_seconds)
|
|
await self.main_intent.send_notice(
|
|
await self.main_intent.send_notice(
|
|
self.mxid,
|
|
self.mxid,
|
|
- text=None,
|
|
|
|
|
|
+ text=f'{sender.name} set the disappearing message timer to {time_str}.',
|
|
html=f'<a href="https://matrix.to/#/{sender.mxid}">{sender.name}</a> set the '
|
|
html=f'<a href="https://matrix.to/#/{sender.mxid}">{sender.name}</a> set the '
|
|
- f'disappearing message timer to {format_time(expires_in_seconds)}.'
|
|
|
|
|
|
+ f'disappearing message timer to {time_str}.'
|
|
)
|
|
)
|
|
|
|
|
|
async def update_puppet_avatar(self, new_hash: str, avatar_url: ContentURI) -> None:
|
|
async def update_puppet_avatar(self, new_hash: str, avatar_url: ContentURI) -> None:
|