diff --git a/TODO.md b/TODO.md index e30c4a9d..c4fb1e53 100644 --- a/TODO.md +++ b/TODO.md @@ -2,8 +2,6 @@ - redact local echo effect - being able to redact local echos -- message removed by *display name* -- do action on last msg if none selected - unselect before unfocusing ## Refactoring diff --git a/src/backend/models/items.py b/src/backend/models/items.py index 3428075e..11b31156 100644 --- a/src/backend/models/items.py +++ b/src/backend/models/items.py @@ -187,6 +187,8 @@ class Event(ModelItem): target_id: str = "" target_name: str = "" target_avatar: str = "" + redacter_id: str = "" + redacter_name: str = "" is_local_echo: bool = False source: Optional[nio.Event] = None diff --git a/src/backend/nio_callbacks.py b/src/backend/nio_callbacks.py index ea484a1d..f09dbacd 100644 --- a/src/backend/nio_callbacks.py +++ b/src/backend/nio_callbacks.py @@ -28,8 +28,10 @@ class NioCallbacks: automatically be registered in nio. For room event content strings, the `%1` and `%2` placeholders - refer to the event's sender and who this event targets (`state_key`). - These are processed from QML, to allow translations of the strings. + refer to the event's sender and who this event targets (`state_key`) or + the redactor of this event. + These are processed from QML, to allow for future translations of + the strings. """ client: "MatrixClient" = field() @@ -187,23 +189,28 @@ class NioCallbacks: async def onRedactedEvent(self, room, ev, event_id: str = "") -> None: - kind = ev.source["type"] - is_message = kind == "m.room.message" - kind = kind.split(".")[-1].capitalize().replace("_", " ") + kind = ev.source["type"].split(".")[-1].replace("_", " ") - co = "%s%s removed%s%s" % ( - kind, - "" if is_message else " event", - f" by {ev.redacter}" if ev.redacter != ev.sender else "", - f", reason: {ev.reason}." if ev.reason else "", - ) + if kind != "message": + kind = f"{kind} event" + + co = f"%1 removed this {kind}" if ev.redacter == ev.sender else \ + f"%1's {kind} was removed by %2" + + if ev.reason: + co = f"{co}, reason: {ev.reason}" await self.client.register_nio_event( room, ev, - event_id = event_id, - reason = ev.reason or "", - content = co, + event_id = event_id, + reason = ev.reason or "", + content = co, + redacter_id = ev.redacter or "", + redacter_name = + (await self.client.get_member_name_avatar( + room.room_id, ev.redacter, + ))[0] if ev.redacter else "", ) diff --git a/src/gui/Pages/Chat/Timeline/EventList.qml b/src/gui/Pages/Chat/Timeline/EventList.qml index 4a47d53b..d0385cd9 100644 --- a/src/gui/Pages/Chat/Timeline/EventList.qml +++ b/src/gui/Pages/Chat/Timeline/EventList.qml @@ -218,7 +218,6 @@ Rectangle { } function canRedact(eventModel) { - print(eventModel) return eventModel.event_type !== "RedactedEvent" && (chat.roomInfo.can_redact_all || eventModel.sender_id === chat.userId) diff --git a/src/gui/Utils.qml b/src/gui/Utils.qml index 389eb1d3..aae2e955 100644 --- a/src/gui/Utils.qml +++ b/src/gui/Utils.qml @@ -145,19 +145,26 @@ QtObject { } - function nameColor(name) { + function nameColor(name, dim=false) { return hsluv( hueFrom(name), + + dim ? + theme.controls.displayName.dimSaturation : theme.controls.displayName.saturation, + + dim ? + theme.controls.displayName.dimLightness : theme.controls.displayName.lightness, ) } - function coloredNameHtml(name, userId, displayText=null, - disambiguate=false) { + function coloredNameHtml( + name, userId, displayText=null, disambiguate=false, dim=false, + ) { // substring: remove leading @ - return `` + + return ``+ escapeHtml(displayText || name || userId) + "" } @@ -195,19 +202,27 @@ QtObject { if (type.startsWith("RoomEncrypted")) return ev.content + if (type === "RedactedEvent") { + print("c", ev.content) + let content = qsTr(escapeHtml(ev.content)).arg(sender) + + if (ev.content.includes("%2")) + content = content.arg(coloredNameHtml( + ev.redacter_name, ev.redacter_id, "", false, true, + )) + + return qsTr( + `` + + content + + "" + ) + } + if (ev.content.includes("%2")) { const target = coloredNameHtml(ev.target_name, ev.target_id) return qsTr(ev.content).arg(sender).arg(target) } - if (type === "RedactedEvent") { - return qsTr( - `` + - escapeHtml(ev.content) + - "" - ) - } - return qsTr(ev.content).arg(sender) } diff --git a/src/themes/Glass.qpl b/src/themes/Glass.qpl index cc93aaee..77803e52 100644 --- a/src/themes/Glass.qpl +++ b/src/themes/Glass.qpl @@ -31,12 +31,14 @@ fontFamily: colors: int hue: 240 - real intensity: 1.0 - real coloredTextIntensity: intensity * 71 + real intensity: 1.0 + real coloredTextIntensity: intensity * 71 + real dimColoredTextIntensity: intensity * 60 - int saturation: 60 - int bgSaturation: saturation / 1.5 - int coloredTextSaturation: saturation + 20 + int saturation: 60 + int bgSaturation: saturation / 1.5 + int coloredTextSaturation: saturation + 20 + int dimColoredTextSaturation: saturation real opacity: 0.7 @@ -236,8 +238,10 @@ controls: real opacity: 1.0 displayName: - int saturation: colors.coloredTextSaturation - int lightness: colors.coloredTextIntensity + int saturation: colors.coloredTextSaturation + int lightness: colors.coloredTextIntensity + int dimSaturation: colors.dimColoredTextSaturation + int dimLightness: colors.dimColoredTextIntensity // Specific interface parts @@ -353,7 +357,7 @@ chat: color body: colors.text color date: colors.dimText - color redactedBody: colors.halfDimText + color redactedBody: colors.dimText color noticeBody: colors.halfDimText int noticeLineWidth: 1 * uiScale diff --git a/src/themes/Midnight.qpl b/src/themes/Midnight.qpl index e2fe3c70..dffd41df 100644 --- a/src/themes/Midnight.qpl +++ b/src/themes/Midnight.qpl @@ -31,12 +31,14 @@ fontFamily: colors: int hue: 240 - real intensity: 1.0 - real coloredTextIntensity: intensity * 71 + real intensity: 1.0 + real coloredTextIntensity: intensity * 71 + real dimColoredTextIntensity: intensity * 60 - int saturation: 60 - int bgSaturation: saturation - int coloredTextSaturation: saturation + 20 + int saturation: 60 + int bgSaturation: saturation + int coloredTextSaturation: saturation + 20 + int dimColoredTextSaturation: saturation real opacity: 0.7 @@ -242,8 +244,10 @@ controls: real opacity: 1.0 displayName: - int saturation: colors.coloredTextSaturation - int lightness: colors.coloredTextIntensity + int saturation: colors.coloredTextSaturation + int lightness: colors.coloredTextIntensity + int dimSaturation: colors.dimColoredTextSaturation + int dimLightness: colors.dimColoredTextIntensity // Specific interface parts @@ -366,7 +370,7 @@ chat: color body: colors.text color date: colors.dimText - color redactedBody: colors.halfDimText + color redactedBody: colors.dimText color noticeBody: colors.halfDimText int noticeLineWidth: 1 * uiScale