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
- being able to redact local echos
- message removed by *display name*
- do action on last msg if none selected
- unselect before unfocusing
## Refactoring

View File

@ -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

View File

@ -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,16 +189,16 @@ 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,
@ -204,6 +206,11 @@ class NioCallbacks:
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 "",
)

View File

@ -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)

View File

@ -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 `<font color="${nameColor(name || userId.substring(1))}">` +
return `<font color="${nameColor(name || userId.substring(1), dim)}">`+
escapeHtml(displayText || name || userId) +
"</font>"
}
@ -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(
`<font color="${theme.chat.message.redactedBody}">` +
content +
"</font>"
)
}
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(
`<font color="${theme.chat.message.redactedBody}"><i>` +
escapeHtml(ev.content) +
"</i></font>"
)
}
return qsTr(ev.content).arg(sender)
}

View File

@ -33,10 +33,12 @@ colors:
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 dimColoredTextSaturation: saturation
real opacity: 0.7
@ -238,6 +240,8 @@ controls:
displayName:
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

View File

@ -33,10 +33,12 @@ colors:
real intensity: 1.0
real coloredTextIntensity: intensity * 71
real dimColoredTextIntensity: intensity * 60
int saturation: 60
int bgSaturation: saturation
int coloredTextSaturation: saturation + 20
int dimColoredTextSaturation: saturation
real opacity: 0.7
@ -244,6 +246,8 @@ controls:
displayName:
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