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 # TODO
- redact local echo effect
- being able to redact local echos
## Refactoring ## Refactoring
- Rewrite account settings using `HTabbedContainer` - Rewrite account settings using `HTabbedContainer`

View File

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

View File

@ -70,7 +70,7 @@ class Room(ModelItem):
guests_allowed: bool = True guests_allowed: bool = True
can_invite: bool = False can_invite: bool = False
can_redact: bool = False can_redact_all: bool = False
can_send_messages: bool = False can_send_messages: bool = False
can_set_name: bool = False can_set_name: bool = False
can_set_topic: 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"] model = self.client.models[self.client.user_id, room.room_id, "events"]
event = None event = None
for evt in model._sorted_data: for existing in model._sorted_data:
if evt.event_id == ev.redacts: if existing.event_id == ev.redacts:
event = evt event = existing
break break
if not (event and event.event_type is not nio.RedactedEvent): 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: async def onRedactedEvent(self, room, ev, event_id: str = "") -> None:
# There is no way to know which kind of event was redacted in an kind = ev.source["type"]
# encrypted room. is_message = kind == "m.room.message"
kind = "Message" if ev.type == "m.room.encrypted" \ kind = kind.split(".")[-1].capitalize().replace("_", " ")
else ev.type.split(".")[-1].capitalize() \
.replace("_", " ")
co = "%s event removed%s.%s" % ( co = "%s%s removed%s%s" % (
kind, kind,
"" if is_message else " event",
f" by {ev.redacter}" if ev.redacter != ev.sender else "", 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( 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 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import Clipboard 0.1 import Clipboard 0.1
@ -222,27 +224,31 @@ HColumnLayout {
text: qsTr("Remove") text: qsTr("Remove")
enabled: properties.eventIds.length enabled: properties.eventIds.length
popup: "Popups/RedactEvents.qml" popup: "Popups/RedactPopup.qml"
popupParent: chat popupParent: chat
properties: ({ properties: ({
userId: chat.userId, userId: chat.userId,
roomId: chat.roomId, roomId: chat.roomId,
eventIds: 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.selectedCount ?
eventList.getSortedChecked() : eventList.getSortedChecked() :
[model] [model]
).filter(ev => ).filter(ev =>
(
ev.sender_id === chat.userId || ev.sender_id === chat.userId ||
chat.roomInfo.can_redact chat.roomInfo.can_redact_all
) && ! isRedacted )
).map(ev => ev.event_id),
"details.text":
(! chat.roomInfo.can_redact && eventList.selectedCount) ?
qsTr("Only your messages will be removed") :
""
})
} }
HMenuItem { HMenuItem {

View File

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

View File

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

View File

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

View File

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