Imrpove redacted events text

This commit is contained in:
miruka 2020-04-02 13:54:06 -04:00
parent 38cc0b1bc7
commit f8fe5d812b
7 changed files with 74 additions and 45 deletions

View File

@ -2,8 +2,6 @@
- redact local echo effect - redact local echo effect
- being able to redact local echos - being able to redact local echos
- message removed by *display name*
- do action on last msg if none selected
- unselect before unfocusing - unselect before unfocusing
## Refactoring ## Refactoring

View File

@ -187,6 +187,8 @@ class Event(ModelItem):
target_id: str = "" target_id: str = ""
target_name: str = "" target_name: str = ""
target_avatar: str = "" target_avatar: str = ""
redacter_id: str = ""
redacter_name: str = ""
is_local_echo: bool = False is_local_echo: bool = False
source: Optional[nio.Event] = None source: Optional[nio.Event] = None

View File

@ -28,8 +28,10 @@ class NioCallbacks:
automatically be registered in nio. automatically be registered in nio.
For room event content strings, the `%1` and `%2` placeholders For room event content strings, the `%1` and `%2` placeholders
refer to the event's sender and who this event targets (`state_key`). refer to the event's sender and who this event targets (`state_key`) or
These are processed from QML, to allow translations of the strings. the redactor of this event.
These are processed from QML, to allow for future translations of
the strings.
""" """
client: "MatrixClient" = field() client: "MatrixClient" = field()
@ -187,23 +189,28 @@ class NioCallbacks:
async def onRedactedEvent(self, room, ev, event_id: str = "") -> None: async def onRedactedEvent(self, room, ev, event_id: str = "") -> None:
kind = ev.source["type"] kind = ev.source["type"].split(".")[-1].replace("_", " ")
is_message = kind == "m.room.message"
kind = kind.split(".")[-1].capitalize().replace("_", " ")
co = "%s%s removed%s%s" % ( if kind != "message":
kind, kind = f"{kind} event"
"" if is_message else " event",
f" by {ev.redacter}" if ev.redacter != ev.sender else "", co = f"%1 removed this {kind}" if ev.redacter == ev.sender else \
f", reason: {ev.reason}." if ev.reason else "", f"%1's {kind} was removed by %2"
)
if ev.reason:
co = f"{co}, reason: {ev.reason}"
await self.client.register_nio_event( await self.client.register_nio_event(
room, room,
ev, ev,
event_id = event_id, event_id = event_id,
reason = ev.reason or "", reason = ev.reason or "",
content = co, 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 "",
) )

View File

@ -218,7 +218,6 @@ Rectangle {
} }
function canRedact(eventModel) { function canRedact(eventModel) {
print(eventModel)
return eventModel.event_type !== "RedactedEvent" && return eventModel.event_type !== "RedactedEvent" &&
(chat.roomInfo.can_redact_all || (chat.roomInfo.can_redact_all ||
eventModel.sender_id === chat.userId) eventModel.sender_id === chat.userId)

View File

@ -145,19 +145,26 @@ QtObject {
} }
function nameColor(name) { function nameColor(name, dim=false) {
return hsluv( return hsluv(
hueFrom(name), hueFrom(name),
dim ?
theme.controls.displayName.dimSaturation :
theme.controls.displayName.saturation, theme.controls.displayName.saturation,
dim ?
theme.controls.displayName.dimLightness :
theme.controls.displayName.lightness, theme.controls.displayName.lightness,
) )
} }
function coloredNameHtml(name, userId, displayText=null, function coloredNameHtml(
disambiguate=false) { name, userId, displayText=null, disambiguate=false, dim=false,
) {
// substring: remove leading @ // substring: remove leading @
return `<font color="${nameColor(name || userId.substring(1))}">` + return `<font color="${nameColor(name || userId.substring(1), dim)}">`+
escapeHtml(displayText || name || userId) + escapeHtml(displayText || name || userId) +
"</font>" "</font>"
} }
@ -195,19 +202,27 @@ QtObject {
if (type.startsWith("RoomEncrypted")) if (type.startsWith("RoomEncrypted"))
return ev.content 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(
`<font color="${theme.chat.message.redactedBody}">` +
content +
"</font>"
)
}
if (ev.content.includes("%2")) { if (ev.content.includes("%2")) {
const target = coloredNameHtml(ev.target_name, ev.target_id) const target = coloredNameHtml(ev.target_name, ev.target_id)
return qsTr(ev.content).arg(sender).arg(target) return qsTr(ev.content).arg(sender).arg(target)
} }
if (type === "RedactedEvent") {
return qsTr(
`<font color="${theme.chat.message.redactedBody}"><i>` +
escapeHtml(ev.content) +
"</i></font>"
)
}
return qsTr(ev.content).arg(sender) return qsTr(ev.content).arg(sender)
} }

View File

@ -31,12 +31,14 @@ fontFamily:
colors: colors:
int hue: 240 int hue: 240
real intensity: 1.0 real intensity: 1.0
real coloredTextIntensity: intensity * 71 real coloredTextIntensity: intensity * 71
real dimColoredTextIntensity: intensity * 60
int saturation: 60 int saturation: 60
int bgSaturation: saturation / 1.5 int bgSaturation: saturation / 1.5
int coloredTextSaturation: saturation + 20 int coloredTextSaturation: saturation + 20
int dimColoredTextSaturation: saturation
real opacity: 0.7 real opacity: 0.7
@ -236,8 +238,10 @@ controls:
real opacity: 1.0 real opacity: 1.0
displayName: displayName:
int saturation: colors.coloredTextSaturation int saturation: colors.coloredTextSaturation
int lightness: colors.coloredTextIntensity int lightness: colors.coloredTextIntensity
int dimSaturation: colors.dimColoredTextSaturation
int dimLightness: colors.dimColoredTextIntensity
// Specific interface parts // Specific interface parts
@ -353,7 +357,7 @@ chat:
color body: colors.text color body: colors.text
color date: colors.dimText color date: colors.dimText
color redactedBody: colors.halfDimText color redactedBody: colors.dimText
color noticeBody: colors.halfDimText color noticeBody: colors.halfDimText
int noticeLineWidth: 1 * uiScale int noticeLineWidth: 1 * uiScale

View File

@ -31,12 +31,14 @@ fontFamily:
colors: colors:
int hue: 240 int hue: 240
real intensity: 1.0 real intensity: 1.0
real coloredTextIntensity: intensity * 71 real coloredTextIntensity: intensity * 71
real dimColoredTextIntensity: intensity * 60
int saturation: 60 int saturation: 60
int bgSaturation: saturation int bgSaturation: saturation
int coloredTextSaturation: saturation + 20 int coloredTextSaturation: saturation + 20
int dimColoredTextSaturation: saturation
real opacity: 0.7 real opacity: 0.7
@ -242,8 +244,10 @@ controls:
real opacity: 1.0 real opacity: 1.0
displayName: displayName:
int saturation: colors.coloredTextSaturation int saturation: colors.coloredTextSaturation
int lightness: colors.coloredTextIntensity int lightness: colors.coloredTextIntensity
int dimSaturation: colors.dimColoredTextSaturation
int dimLightness: colors.dimColoredTextIntensity
// Specific interface parts // Specific interface parts
@ -366,7 +370,7 @@ chat:
color body: colors.text color body: colors.text
color date: colors.dimText color date: colors.dimText
color redactedBody: colors.halfDimText color redactedBody: colors.dimText
color noticeBody: colors.halfDimText color noticeBody: colors.halfDimText
int noticeLineWidth: 1 * uiScale int noticeLineWidth: 1 * uiScale