Imrpove redacted events text
This commit is contained in:
parent
38cc0b1bc7
commit
f8fe5d812b
2
TODO.md
2
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 "",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user