Redaction code adjustments + theme addition

This commit is contained in:
miruka 2020-04-01 15:15:49 -04:00
parent e60a7f6dac
commit 05319af858
9 changed files with 50 additions and 33 deletions

View File

@ -1,5 +1,8 @@
# TODO
- redact local echo effect
- being able to redact local echos
## Refactoring
- Rewrite account settings using `HTabbedContainer`

View File

@ -885,8 +885,8 @@ class MatrixClient(nio.AsyncClient):
"""
return await asyncio.gather(*[
self.room_redact(room_id, evt_id, reason)
for evt_id in event_ids
self.room_redact(room_id, ev_id, reason)
for ev_id in event_ids
])
@ -1119,7 +1119,7 @@ class MatrixClient(nio.AsyncClient):
guests_allowed = room.guest_access == "can_join",
can_invite = levels.can_user_invite(self.user),
can_redact = levels.can_user_redact(self.user),
can_redact_all = levels.can_user_redact(self.user),
can_send_messages = can_send_msg(),
can_set_name = can_send_state("m.room.name"),
can_set_topic = can_send_state("m.room.topic"),

View File

@ -70,7 +70,7 @@ class Room(ModelItem):
guests_allowed: bool = True
can_invite: bool = False
can_redact: bool = False
can_redact_all: bool = False
can_send_messages: bool = False
can_set_name: bool = False
can_set_topic: bool = False

View File

@ -165,9 +165,9 @@ class NioCallbacks:
model = self.client.models[self.client.user_id, room.room_id, "events"]
event = None
for evt in model._sorted_data:
if evt.event_id == ev.redacts:
event = evt
for existing in model._sorted_data:
if existing.event_id == ev.redacts:
event = existing
break
if not (event and event.event_type is not nio.RedactedEvent):
@ -187,16 +187,15 @@ class NioCallbacks:
async def onRedactedEvent(self, room, ev, event_id: str = "") -> None:
# There is no way to know which kind of event was redacted in an
# encrypted room.
kind = "Message" if ev.type == "m.room.encrypted" \
else ev.type.split(".")[-1].capitalize() \
.replace("_", " ")
kind = ev.source["type"]
is_message = kind == "m.room.message"
kind = kind.split(".")[-1].capitalize().replace("_", " ")
co = "%s event removed%s.%s" % (
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 "",
f", reason: {ev.reason}." if ev.reason else "",
)
await self.client.register_nio_event(

View File

@ -1,3 +1,5 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Layouts 1.12
import Clipboard 0.1
@ -222,27 +224,31 @@ HColumnLayout {
text: qsTr("Remove")
enabled: properties.eventIds.length
popup: "Popups/RedactEvents.qml"
popup: "Popups/RedactPopup.qml"
popupParent: chat
properties: ({
userId: chat.userId,
roomId: chat.roomId,
eventIds:
redactableEvents
.filter(ev => ev.event_type !== "RedactedEvent")
.map(ev => ev.event_id),
onlyOwnMessageWarning:
! chat.roomInfo.can_redact_all &&
redactableEvents.length < eventList.selectedCount
})
readonly property var redactableEvents:
(
eventList.selectedCount ?
eventList.getSortedChecked() :
[model]
).filter(ev =>
(
ev.sender_id === chat.userId ||
chat.roomInfo.can_redact
) && ! isRedacted
).map(ev => ev.event_id),
"details.text":
(! chat.roomInfo.can_redact && eventList.selectedCount) ?
qsTr("Only your messages will be removed") :
""
})
chat.roomInfo.can_redact_all
)
}
HMenuItem {

View File

@ -11,6 +11,10 @@ BoxPopup {
qsTr("Remove selected message?")
details.color: theme.colors.warningText
details.text:
onlyOwnMessageWarning ?
qsTr("Only your messages will be removed") :
""
HLabeledTextField {
id: reasonField
@ -31,4 +35,5 @@ BoxPopup {
property string userId: ""
property var eventIds: []
property bool onlyOwnMessageWarning: false
}

View File

@ -202,7 +202,7 @@ QtObject {
if (type === "RedactedEvent") {
return qsTr(
`<font color="${theme.colors.dimText}"><i>` +
`<font color="${theme.chat.message.redactedBody}"><i>` +
escapeHtml(ev.content) +
"</i></font>"
)

View File

@ -353,6 +353,8 @@ chat:
color body: colors.text
color date: colors.dimText
color redactedBody: colors.halfDimText
color noticeBody: colors.halfDimText
int noticeLineWidth: 1 * uiScale

View File

@ -366,6 +366,8 @@ chat:
color body: colors.text
color date: colors.dimText
color redactedBody: colors.halfDimText
color noticeBody: colors.halfDimText
int noticeLineWidth: 1 * uiScale