1// SPDX-FileCopyrightText: 2021 Nheko Contributors 2// 3// SPDX-License-Identifier: GPL-3.0-or-later 4 5import QtQuick 2.6 6import QtQuick.Controls 2.1 7import QtQuick.Layouts 1.2 8import im.nheko 1.0 9 10Item { 11 id: d 12 13 required property bool isReply 14 property alias child: chooser.child 15 property real implicitWidth: (chooser.child && chooser.child.implicitWidth) ? chooser.child.implicitWidth : width 16 required property double proportionalHeight 17 required property int type 18 required property string typeString 19 required property int originalWidth 20 required property string blurhash 21 required property string body 22 required property string formattedBody 23 required property string eventId 24 required property string filename 25 required property string filesize 26 required property string url 27 required property string thumbnailUrl 28 required property bool isOnlyEmoji 29 required property string userId 30 required property string userName 31 required property string roomTopic 32 required property string roomName 33 required property string callType 34 required property int encryptionError 35 required property int relatedEventCacheBuster 36 37 height: chooser.child ? chooser.child.height : Nheko.paddingLarge 38 39 DelegateChooser { 40 id: chooser 41 42 //role: "type" //< not supported in our custom implementation, have to use roleValue 43 roleValue: type 44 anchors.fill: parent 45 46 DelegateChoice { 47 roleValue: MtxEvent.UnknownMessage 48 49 Placeholder { 50 typeString: d.typeString 51 text: "Unretrieved event" 52 } 53 54 } 55 56 DelegateChoice { 57 roleValue: MtxEvent.TextMessage 58 59 TextMessage { 60 formatted: d.formattedBody 61 body: d.body 62 isOnlyEmoji: d.isOnlyEmoji 63 isReply: d.isReply 64 } 65 66 } 67 68 DelegateChoice { 69 roleValue: MtxEvent.NoticeMessage 70 71 NoticeMessage { 72 formatted: d.formattedBody 73 body: d.body 74 isOnlyEmoji: d.isOnlyEmoji 75 isReply: d.isReply 76 } 77 78 } 79 80 DelegateChoice { 81 roleValue: MtxEvent.EmoteMessage 82 83 NoticeMessage { 84 formatted: TimelineManager.escapeEmoji(d.userName) + " " + d.formattedBody 85 color: TimelineManager.userColor(d.userId, Nheko.colors.window) 86 body: d.body 87 isOnlyEmoji: d.isOnlyEmoji 88 isReply: d.isReply 89 } 90 91 } 92 93 DelegateChoice { 94 roleValue: MtxEvent.ImageMessage 95 96 ImageMessage { 97 type: d.type 98 originalWidth: d.originalWidth 99 proportionalHeight: d.proportionalHeight 100 url: d.url 101 blurhash: d.blurhash 102 body: d.body 103 filename: d.filename 104 isReply: d.isReply 105 eventId: d.eventId 106 } 107 108 } 109 110 DelegateChoice { 111 roleValue: MtxEvent.Sticker 112 113 ImageMessage { 114 type: d.type 115 originalWidth: d.originalWidth 116 proportionalHeight: d.proportionalHeight 117 url: d.url 118 blurhash: d.blurhash 119 body: d.body 120 filename: d.filename 121 isReply: d.isReply 122 eventId: d.eventId 123 } 124 125 } 126 127 DelegateChoice { 128 roleValue: MtxEvent.FileMessage 129 130 FileMessage { 131 eventId: d.eventId 132 filename: d.filename 133 filesize: d.filesize 134 } 135 136 } 137 138 DelegateChoice { 139 roleValue: MtxEvent.VideoMessage 140 141 PlayableMediaMessage { 142 proportionalHeight: d.proportionalHeight 143 type: d.type 144 originalWidth: d.originalWidth 145 thumbnailUrl: d.thumbnailUrl 146 eventId: d.eventId 147 url: d.url 148 body: d.body 149 filesize: d.filesize 150 } 151 152 } 153 154 DelegateChoice { 155 roleValue: MtxEvent.AudioMessage 156 157 PlayableMediaMessage { 158 proportionalHeight: d.proportionalHeight 159 type: d.type 160 originalWidth: d.originalWidth 161 thumbnailUrl: d.thumbnailUrl 162 eventId: d.eventId 163 url: d.url 164 body: d.body 165 filesize: d.filesize 166 } 167 168 } 169 170 DelegateChoice { 171 roleValue: MtxEvent.Redacted 172 173 Pill { 174 text: qsTr("removed") 175 } 176 177 } 178 179 DelegateChoice { 180 roleValue: MtxEvent.Redaction 181 182 Pill { 183 text: qsTr("removed") 184 } 185 186 } 187 188 DelegateChoice { 189 roleValue: MtxEvent.Encryption 190 191 Pill { 192 text: qsTr("Encryption enabled") 193 } 194 195 } 196 197 DelegateChoice { 198 roleValue: MtxEvent.Encrypted 199 200 Encrypted { 201 encryptionError: d.encryptionError 202 eventId: d.eventId 203 } 204 205 } 206 207 DelegateChoice { 208 roleValue: MtxEvent.Name 209 210 NoticeMessage { 211 body: formatted 212 isOnlyEmoji: false 213 isReply: d.isReply 214 formatted: d.roomName ? qsTr("room name changed to: %1").arg(d.roomName) : qsTr("removed room name") 215 } 216 217 } 218 219 DelegateChoice { 220 roleValue: MtxEvent.Topic 221 222 NoticeMessage { 223 body: formatted 224 isOnlyEmoji: false 225 isReply: d.isReply 226 formatted: d.roomTopic ? qsTr("topic changed to: %1").arg(d.roomTopic) : qsTr("removed topic") 227 } 228 229 } 230 231 DelegateChoice { 232 roleValue: MtxEvent.Avatar 233 234 NoticeMessage { 235 body: formatted 236 isOnlyEmoji: false 237 isReply: d.isReply 238 formatted: qsTr("%1 changed the room avatar").arg(d.userName) 239 } 240 241 } 242 243 DelegateChoice { 244 roleValue: MtxEvent.RoomCreate 245 246 NoticeMessage { 247 body: formatted 248 isOnlyEmoji: false 249 isReply: d.isReply 250 formatted: qsTr("%1 created and configured room: %2").arg(d.userName).arg(room.roomId) 251 } 252 253 } 254 255 DelegateChoice { 256 roleValue: MtxEvent.CallInvite 257 258 NoticeMessage { 259 body: formatted 260 isOnlyEmoji: false 261 isReply: d.isReply 262 formatted: { 263 switch (d.callType) { 264 case "voice": 265 return qsTr("%1 placed a voice call.").arg(d.userName); 266 case "video": 267 return qsTr("%1 placed a video call.").arg(d.userName); 268 default: 269 return qsTr("%1 placed a call.").arg(d.userName); 270 } 271 } 272 } 273 274 } 275 276 DelegateChoice { 277 roleValue: MtxEvent.CallAnswer 278 279 NoticeMessage { 280 body: formatted 281 isOnlyEmoji: false 282 isReply: d.isReply 283 formatted: qsTr("%1 answered the call.").arg(d.userName) 284 } 285 286 } 287 288 DelegateChoice { 289 roleValue: MtxEvent.CallHangUp 290 291 NoticeMessage { 292 body: formatted 293 isOnlyEmoji: false 294 isReply: d.isReply 295 formatted: qsTr("%1 ended the call.").arg(d.userName) 296 } 297 298 } 299 300 DelegateChoice { 301 roleValue: MtxEvent.CallCandidates 302 303 NoticeMessage { 304 body: formatted 305 isOnlyEmoji: false 306 isReply: d.isReply 307 formatted: qsTr("Negotiating call...") 308 } 309 310 } 311 312 DelegateChoice { 313 // TODO: make a more complex formatter for the power levels. 314 roleValue: MtxEvent.PowerLevels 315 316 NoticeMessage { 317 body: formatted 318 isOnlyEmoji: false 319 isReply: d.isReply 320 formatted: d.relatedEventCacheBuster, room.formatPowerLevelEvent(d.eventId) 321 } 322 323 } 324 325 DelegateChoice { 326 roleValue: MtxEvent.RoomJoinRules 327 328 NoticeMessage { 329 body: formatted 330 isOnlyEmoji: false 331 isReply: d.isReply 332 formatted: d.relatedEventCacheBuster, room.formatJoinRuleEvent(d.eventId) 333 } 334 335 } 336 337 DelegateChoice { 338 roleValue: MtxEvent.RoomHistoryVisibility 339 340 NoticeMessage { 341 body: formatted 342 isOnlyEmoji: false 343 isReply: d.isReply 344 formatted: d.relatedEventCacheBuster, room.formatHistoryVisibilityEvent(d.eventId) 345 } 346 347 } 348 349 DelegateChoice { 350 roleValue: MtxEvent.RoomGuestAccess 351 352 NoticeMessage { 353 body: formatted 354 isOnlyEmoji: false 355 isReply: d.isReply 356 formatted: d.relatedEventCacheBuster, room.formatGuestAccessEvent(d.eventId) 357 } 358 359 } 360 361 DelegateChoice { 362 roleValue: MtxEvent.Member 363 364 ColumnLayout { 365 width: parent ? parent.width : undefined 366 367 NoticeMessage { 368 body: formatted 369 isOnlyEmoji: false 370 isReply: d.isReply 371 formatted: d.relatedEventCacheBuster, room.formatMemberEvent(d.eventId) 372 } 373 374 Button { 375 visible: d.relatedEventCacheBuster, room.showAcceptKnockButton(d.eventId) 376 palette: Nheko.colors 377 text: qsTr("Allow them in") 378 onClicked: room.acceptKnock(eventId) 379 } 380 381 } 382 383 } 384 385 DelegateChoice { 386 roleValue: MtxEvent.KeyVerificationRequest 387 388 NoticeMessage { 389 body: formatted 390 isOnlyEmoji: false 391 isReply: d.isReply 392 formatted: "KeyVerificationRequest" 393 } 394 395 } 396 397 DelegateChoice { 398 roleValue: MtxEvent.KeyVerificationStart 399 400 NoticeMessage { 401 body: formatted 402 isOnlyEmoji: false 403 isReply: d.isReply 404 formatted: "KeyVerificationStart" 405 } 406 407 } 408 409 DelegateChoice { 410 roleValue: MtxEvent.KeyVerificationReady 411 412 NoticeMessage { 413 body: formatted 414 isOnlyEmoji: false 415 isReply: d.isReply 416 formatted: "KeyVerificationReady" 417 } 418 419 } 420 421 DelegateChoice { 422 roleValue: MtxEvent.KeyVerificationCancel 423 424 NoticeMessage { 425 body: formatted 426 isOnlyEmoji: false 427 isReply: d.isReply 428 formatted: "KeyVerificationCancel" 429 } 430 431 } 432 433 DelegateChoice { 434 roleValue: MtxEvent.KeyVerificationKey 435 436 NoticeMessage { 437 body: formatted 438 isOnlyEmoji: false 439 isReply: d.isReply 440 formatted: "KeyVerificationKey" 441 } 442 443 } 444 445 DelegateChoice { 446 roleValue: MtxEvent.KeyVerificationMac 447 448 NoticeMessage { 449 body: formatted 450 isOnlyEmoji: false 451 isReply: d.isReply 452 formatted: "KeyVerificationMac" 453 } 454 455 } 456 457 DelegateChoice { 458 roleValue: MtxEvent.KeyVerificationDone 459 460 NoticeMessage { 461 body: formatted 462 isOnlyEmoji: false 463 isReply: d.isReply 464 formatted: "KeyVerificationDone" 465 } 466 467 } 468 469 DelegateChoice { 470 roleValue: MtxEvent.KeyVerificationDone 471 472 NoticeMessage { 473 body: formatted 474 isOnlyEmoji: false 475 isReply: d.isReply 476 formatted: "KeyVerificationDone" 477 } 478 479 } 480 481 DelegateChoice { 482 roleValue: MtxEvent.KeyVerificationAccept 483 484 NoticeMessage { 485 body: formatted 486 isOnlyEmoji: false 487 isReply: d.isReply 488 formatted: "KeyVerificationAccept" 489 } 490 491 } 492 493 DelegateChoice { 494 Placeholder { 495 typeString: d.typeString 496 } 497 498 } 499 500 } 501 502} 503