| 
									
										
										
										
											2020-03-26 17:31:57 -03:00
										 |  |  | // SPDX-License-Identifier: LGPL-3.0-or-later
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import QtQuick 2.12 | 
					
						
							|  |  |  | import QtQuick.Layouts 1.12 | 
					
						
							|  |  |  | import "../Base" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BoxPopup { | 
					
						
							|  |  |  |     summary.text: | 
					
						
							| 
									
										
										
										
											2020-04-02 10:19:43 -04:00
										 |  |  |         isLast ? | 
					
						
							|  |  |  |         qsTr("Remove your last message?") : | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 06:13:45 -04:00
										 |  |  |         eventSenderAndIds.length > 1 ? | 
					
						
							|  |  |  |         qsTr("Remove %1 messages?").arg(eventSenderAndIds.length) : | 
					
						
							| 
									
										
										
										
											2020-04-02 10:19:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         qsTr("Remove this message?") | 
					
						
							| 
									
										
										
										
											2020-03-26 17:31:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 14:33:19 -03:00
										 |  |  |     details.color: theme.colors.warningText | 
					
						
							| 
									
										
										
										
											2020-04-01 15:15:49 -04:00
										 |  |  |     details.text: | 
					
						
							|  |  |  |         onlyOwnMessageWarning ? | 
					
						
							| 
									
										
										
										
											2020-04-02 10:19:43 -04:00
										 |  |  |         qsTr("Only your messages can be removed") : | 
					
						
							| 
									
										
										
										
											2020-04-01 15:15:49 -04:00
										 |  |  |         "" | 
					
						
							| 
									
										
										
										
											2020-04-01 14:33:19 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 17:31:57 -03:00
										 |  |  |     okText: qsTr("Remove") | 
					
						
							| 
									
										
										
										
											2020-04-03 07:53:16 -04:00
										 |  |  |     // box.focusButton: "ok"
 | 
					
						
							| 
									
										
										
										
											2020-03-26 17:31:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 20:14:55 -04:00
										 |  |  |     onOpened: reasonField.item.forceActiveFocus() | 
					
						
							| 
									
										
										
										
											2020-04-03 06:13:45 -04:00
										 |  |  |     onOk: { | 
					
						
							| 
									
										
										
										
											2020-04-03 06:50:24 -04:00
										 |  |  |         const idsForSender = {}  // {senderId: [event.id, ...]}
 | 
					
						
							| 
									
										
										
										
											2020-03-26 17:31:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 06:50:24 -04:00
										 |  |  |         for (const [senderId, eventClientId] of eventSenderAndIds) { | 
					
						
							| 
									
										
										
										
											2020-04-03 06:13:45 -04:00
										 |  |  |             if (! idsForSender[senderId]) | 
					
						
							|  |  |  |                 idsForSender[senderId] = [] | 
					
						
							| 
									
										
										
										
											2020-04-02 10:19:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 06:50:24 -04:00
										 |  |  |             idsForSender[senderId].push(eventClientId) | 
					
						
							| 
									
										
										
										
											2020-04-03 06:13:45 -04:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 06:50:24 -04:00
										 |  |  |         for (const [senderId, eventClientIds] of Object.entries(idsForSender)) | 
					
						
							| 
									
										
										
										
											2020-04-03 06:13:45 -04:00
										 |  |  |             py.callClientCoro( | 
					
						
							|  |  |  |                 mainUI.accountIds.includes(senderId) ? senderId : preferUserId, | 
					
						
							|  |  |  |                 "room_mass_redact", | 
					
						
							| 
									
										
										
										
											2020-06-02 20:14:55 -04:00
										 |  |  |                 [roomId, reasonField.item.text, ...eventClientIds] | 
					
						
							| 
									
										
										
										
											2020-04-03 06:13:45 -04:00
										 |  |  |             ) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     property string preferUserId: "" | 
					
						
							| 
									
										
										
										
											2020-03-26 17:31:57 -03:00
										 |  |  |     property string roomId: "" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 06:50:24 -04:00
										 |  |  |     property var eventSenderAndIds: []  // [[senderId, event.id], ...]
 | 
					
						
							| 
									
										
										
										
											2020-04-01 15:15:49 -04:00
										 |  |  |     property bool onlyOwnMessageWarning: false | 
					
						
							| 
									
										
										
										
											2020-04-02 10:19:43 -04:00
										 |  |  |     property bool isLast: false | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 20:14:55 -04:00
										 |  |  |     HLabeledItem { | 
					
						
							| 
									
										
										
										
											2020-04-02 10:19:43 -04:00
										 |  |  |         id: reasonField | 
					
						
							|  |  |  |         label.text: qsTr("Optional reason:") | 
					
						
							| 
									
										
										
										
											2020-04-03 07:53:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 10:19:43 -04:00
										 |  |  |         Layout.fillWidth: true | 
					
						
							| 
									
										
										
										
											2020-06-02 20:14:55 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         HTextField { | 
					
						
							|  |  |  |             width: parent.width | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-04-02 10:19:43 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-26 17:31:57 -03:00
										 |  |  | } |