Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 | 92x 125x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 16x 16x 16x 16x 91x 92x 91x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 95x 95x 91x 90x 90x 91x 91x 91x 92x 16x 16x 16x 16x 16x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 121x 121x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 92x 49x 47x 49x 49x 49x 49x 42x 42x 42x 42x 42x 42x 42x 42x 235x 235x 235x 235x 218x 42x 42x 42x 42x 42x 40x 40x 40x 40x 40x 42x 42x 42x 42x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 49x 49x 49x 49x 49x 49x 49x 15x 15x 15x 49x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 1x 1x 1x 35x 35x 35x 35x 35x 35x 1x 1x 1x 1x 1x 92x 270x 270x 270x 270x 92x 270x 270x 270x 270x 270x 92x 389x 389x 389x 389x 389x 41x 389x 385x 223x 389x 389x 389x 389x 130x 389x 389x 389x 389x 389x 24x 24x 324x 360x 276x 276x 389x 348x 48x 48x 92x 41x 41x 41x 41x 187x 187x 187x 187x 187x 159x 187x 187x 154x 154x 154x 154x 154x 154x 154x 154x 154x 154x 154x 154x 9x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 187x 19x 19x 19x 19x 14x 14x 14x 14x 14x 14x 14x 41x 41x 41x 41x 41x 41x 41x 41x 235x 235x 235x 235x 235x 235x 235x 235x 187x 187x 187x 187x 187x 187x 12x 12x 235x 235x 41x 41x 41x 41x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 92x 92x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x 6x 1x 92x 92x 92x 251x 251x 178x 178x 251x 251x 92x 251x 251x 251x 251x 251x 251x 251x 251x 251x 251x 208x 208x 251x 251x 251x 251x 176x 176x 176x 251x 251x 251x 251x 251x 251x 251x 251x 251x 251x 251x 251x 251x 251x 251x 206x 206x 206x 251x 16x 16x 16x 16x 16x 1x 1x 16x 251x 251x 251x 3x 3x 3x 3x 3x 3x 251x 251x 315x 315x 315x 315x 315x 315x 315x 315x 315x 80x 80x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 315x 3x 3x 3x 3x 3x 3x 3x 315x 315x 315x 315x 315x 315x 315x 251x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 144x 144x 144x 144x 251x 251x 251x 251x 92x 92x 92x 92x 92x 91x 220x 89x 89x 89x 89x 269x 269x 89x 89x 89x 89x 89x 92x 92x 92x 92x 92x 92x 92x 98x 92x 92x 92x 92x 105x 105x 92x 92x 92x 91x 91x 92x 92x 92x 89x 92x 92x 92x 92x 92x 92x 116x 116x 116x 92x 91x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 234x 90x 90x 90x 90x 90x 218x 234x 234x 90x 90x 90x 90x 90x 90x 90x 90x 90x 90x 90x 90x 225x 92x 105x 90x 90x 90x 90x 90x 90x 90x 90x 105x 105x 105x 105x 105x 92x 92x 92x 92x 92x | import { TemplateResult, html, nothing, PropertyValueMap, css } from 'lit';
import { property } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
import { RapidElement } from '../RapidElement';
import { CustomEventType } from '../interfaces';
import { DEFAULT_AVATAR } from '../webchat/assets';
const BATCH_TIME_WINDOW = 60 * 60 * 1000;
const SCROLL_FETCH_BUFFER = 200; // pixels from top
const MIN_FETCH_TIME = 250;
const getUnsendableReasonMessage = (reason: string): string => {
switch (reason) {
case 'no_route':
return 'No channel available to send message';
case 'contact_blocked':
return 'Contact has been blocked';
case 'contact_stopped':
return 'Contact has been stopped';
case 'contact_archived':
return 'Contact is archived';
case 'org_suspended':
return 'Workspace is suspended';
case 'looping':
return 'Message loop detected';
default:
return 'Unable to send message';
}
};
const getStatusReasonMessage = (reason: string): string => {
switch (reason) {
case 'error_limit':
return 'Error limit reached';
case 'too_old':
return 'Message is too old to send';
case 'channel_removed':
return 'Channel was removed';
default:
return 'Message failed to send';
}
};
export enum MessageType {
Inline = 'inline',
Error = 'error',
Collapse = 'collapse',
Note = 'note'
}
export type GroupReason =
| 'time_elapsed'
| 'new_author'
| 'new_type'
| 'initial';
export interface MessageGroup {
messages: string[];
reason: GroupReason;
}
export interface ObjectReference {
uuid: string;
name: string;
}
interface User extends ObjectReference {
avatar?: string;
email: string;
}
export interface Msg {
text: string;
channel: ObjectReference;
quick_replies: string[];
urn: string;
direction: string;
type: string;
attachments: string[];
unsendable_reason?:
| 'no_route'
| 'contact_blocked'
| 'contact_stopped'
| 'contact_archived'
| 'org_suspended'
| 'looping';
}
export interface ContactEvent {
uuid?: string;
type: string;
created_on: Date;
_user?: User;
_rendered?: { html: TemplateResult; type: MessageType };
}
export interface MsgEvent extends ContactEvent {
msg: Msg;
optin?: ObjectReference;
_status?: {
created_on: string;
status: 'wired' | 'sent' | 'delivered' | 'read' | 'errored' | 'failed';
reason: 'error_limit' | 'too_old' | 'channel_removed';
};
_deleted?: {
created_on: string;
by_contact: boolean;
user?: { name: string; uuid: string };
};
_logs_url?: string;
}
const TIME_FORMAT = { hour: 'numeric', minute: '2-digit' } as any;
const VERBOSE_FORMAT = {
weekday: undefined,
year: undefined,
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit'
} as any;
const VERBOSE_FORMAT_WITH_YEAR = {
weekday: undefined,
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit'
} as any;
export class Chat extends RapidElement {
static get styles() {
return css`
:host {
display: flex;
flex-direction: column;
flex-grow: 1;
position: relative;
z-index: 1;
}
slot[name='header'] {
position: absolute;
top: 0;
left: 0;
right: 0;
display: block;
}
slot[name='footer'] {
position: absolute;
bottom: 0;
left: 0;
right: 0;
display: block;
}
.block {
margin-bottom: 1em;
display: flex;
flex-direction: row;
}
.block.outgoing {
flex-direction: row-reverse;
}
.block.collapse {
margin: 0;
align-items: center;
display: flex;
flex-direction: column;
margin-bottom: 0.5em;
}
.block.collapse .messsage {
transform: scaleY(0);
margin: 0;
padding: 0;
line-height: 0;
}
.time {
text-align: center;
font-size: 0.8em;
color: #999;
margin-bottom: 2em;
margin-top: 1em;
border-top: 1px solid #e9e9e9;
padding: 1em;
margin-left: 10%;
margin-right: 10%;
}
.time.first {
border-top: none;
margin-top: 0;
border-bottom: 1px solid #e9e9e9;
margin-bottom: 2em;
}
.first .time {
margin-top: 0;
border-top: none;
padding-top: 0;
}
.group-reason {
text-align: center;
font-size: 0.75em;
color: #999;
margin-bottom: 1em;
margin-top: 0.5em;
padding: 0.5em 1em;
font-style: italic;
}
.row {
display: flex;
flex-direction: row;
align-items: flex-start;
margin-bottom: 8px;
}
.row.is-event {
margin-bottom: 2px;
margin-left: 0px !important;
margin-right: 4px !important;
}
.input-panel {
padding: 1em;
background: #fff;
}
temba-user {
margin-right: 0.6em;
margin-left: 0.6em;
width: 2em;
align-self: flex-end;
}
.toggle {
flex-shrink: 0;
width: 4em;
height: 4em;
overflow: hidden;
border-radius: 100%;
box-shadow:
rgba(0, 0, 0, 0.1) 0px 0px 1em 0.7em,
rgba(0, 0, 0, 0.2) 0px 1px 2px 0px,
inset 0 0 0 0.25em rgba(0, 0, 0, 0.1);
cursor: pointer;
transition: box-shadow var(--toggle-speed, 200ms) ease-out;
position: absolute;
bottom: 1em;
right: 1em;
}
.toggle:hover {
box-shadow:
rgba(0, 0, 0, 0.1) 0px 0px 1em 0.7em,
rgba(0, 0, 0, 0.4) 0px 1px 2px 0px,
inset 0 0 0 0.25em rgba(0, 0, 0, 0.2);
}
.incoming .row {
flex-direction: row-reverse;
margin-left: 1em;
}
.bubble {
padding: 10px 14px;
background: var(--color-chat-in, #e5e5ea);
border-radius: 18px;
border: var(--chat-border-in, none);
}
.bubble .name {
font-size: 0.95em;
font-weight: 400;
color: rgba(0, 0, 0, 0.4);
margin-bottom: 0.25em;
}
.outgoing .latest .bubble {
border-bottom-left-radius: 4px;
}
.incoming .bubble-wrap {
align-items: flex-end;
}
.incoming .bubble {
background: var(--color-chat-out, #007aff);
border: var(--chat-border-out, none);
color: white;
}
.incoming .latest .bubble {
border-bottom-right-radius: 4px;
}
.incoming .bubble .name {
color: rgba(255, 255, 255, 0.7);
}
.note .bubble {
background: #fffac3;
color: rgba(0, 0, 0, 0.7);
}
.note .bubble .name {
color: rgba(0, 0, 0, 0.5);
}
.warning .bubble {
background: #fef3c7;
color: rgba(125, 87, 18, 0.8);
border: none;
}
.warning .bubble .name {
color: rgba(125, 87, 18, 0.6);
}
.failed .bubble,
.error .bubble {
border: none;
background: #fee3e3;
color: #c01829;
}
.error .bubble .name,
.failed .bubble .name {
color: rgba(192, 24, 41, 0.6);
}
.deleted .bubble {
background: #fff;
color: #999;
border: 1px solid #e0e0e0;
}
.deleted .bubble .name {
color: #aaa;
}
.message-text {
white-space: pre-wrap;
margin-bottom: 0;
line-height: 1.2;
word-break: break-word;
font-size: 13px;
}
.message-deleted {
font-style: italic;
margin-bottom: 0;
line-height: 1.2;
font-size: 13px;
}
.quick-replies {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 6px;
padding: 8px 0;
margin: 0 auto;
max-width: 90%;
}
.quick-reply-btn {
padding: 4px 8px;
border-radius: 18px;
border: 1px solid var(--color-chat-out, #007aff);
background: white;
color: var(--color-chat-out, #007aff);
font-size: 11px;
cursor: pointer;
transition: all 0.2s ease;
}
.quick-reply-btn:hover:not(:disabled) {
background: var(--color-chat-out, #007aff);
color: white;
}
.quick-reply-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.chat {
width: 28rem;
border-radius: var(--curvature);
overflow: hidden;
box-shadow:
rgba(0, 0, 0, 0.1) 0px 3px 7px 0px,
rgba(0, 0, 0, 0.2) 0px 1px 2px 0px,
rgba(0, 0, 0, 0.1) 5em 5em 5em 5em;
position: absolute;
bottom: 3em;
right: 1em;
transition: all var(--toggle-speed, 200ms) ease-out;
transform: scale(0.9);
pointer-events: none;
opacity: 0;
}
.chat.open {
bottom: 6em;
opacity: 1;
transform: scale(1);
pointer-events: initial;
}
.messages {
position: relative;
flex-grow: 1;
overflow: hidden;
}
.scroll {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
overflow-y: auto;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
overflow-scrolling: touch;
padding: var(--chat-top-padding, 1em) 1em
var(--chat-bottom-padding, 2.5em) 1em;
display: flex;
flex-direction: column-reverse;
}
:host(.phone-screen) .scroll {
scrollbar-width: none;
-ms-overflow-style: none;
}
:host(.phone-screen) .scroll::-webkit-scrollbar {
display: none;
}
.messages:before {
content: '';
background: radial-gradient(
farthest-side at 50% 0,
rgba(0, 0, 0, 0.2),
rgba(0, 0, 0, 0)
)
center top;
height: 10px;
display: block;
position: absolute;
width: 100%;
transition: opacity var(--toggle-speed, 200ms) ease-out;
z-index: 1;
}
.messages:after {
content: '';
background: radial-gradient(
farthest-side at 50% 100%,
rgba(0, 0, 0, 0.2),
rgba(0, 0, 0, 0)
)
center bottom;
height: 10px;
display: block;
position: absolute;
bottom: 0;
margin-top: -10px;
width: 100%;
margin-right: 5em;
transition: opacity var(--toggle-speed, 200ms) ease-out;
z-index: 1;
}
.bubble-wrap {
position: relative;
max-width: 70%;
display: flex;
flex-direction: column;
align-items: flex-start;
}
.scroll-at-top.messages:before {
opacity: 0;
}
.scroll-at-bottom.messages:after {
opacity: 0;
}
.input {
border: none;
flex-grow: 1;
color: #333;
font-size: 1em;
}
.input:focus {
outline: none;
}
input::placeholder {
opacity: 0.3;
}
.input.inactive {
// pointer-events: none;
// opacity: 0.3;
}
.active {
}
.send-icon {
color: #eee;
pointer-events: none;
transform: rotate(-45deg);
transition: transform 0.2s ease-out;
}
.pending .send-icon {
color: var(--color-primary-dark);
pointer-events: initial;
transform: rotate(0deg);
}
.notice {
padding: 1em;
background: #f8f8f8;
color: #666;
text-align: center;
cursor: pointer;
}
.connecting .notice {
display: flex;
justify-content: center;
}
.connecting .notice temba-icon {
margin-left: 0.5em;
}
.reconnect {
color: var(--color-primary-dark);
text-decoration: underline;
font-size: 0.9em;
}
.input:disabled {
background: transparent !important;
}
temba-loading {
justify-content: center;
margin: 0.5em auto;
margin-bottom: 2em;
}
temba-loading.hidden {
display: none;
}
.inline {
}
.event {
flex-grow: 1;
align-self: center;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
font-size: 11px;
color: #8e8e93;
max-width: 100%;
overflow: hidden;
}
.event .webhook-event {
display: inline-flex;
align-items: flex-start;
gap: 6px;
max-width: 100%;
min-width: 0;
}
.event .webhook-event-text {
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
word-break: break-all;
min-width: 0;
padding: 4px 0;
}
.event .webhook-event-url {
color: inherit;
text-decoration: underline;
cursor: pointer;
}
.event .webhook-event-url:hover {
text-decoration: none;
}
.event p {
margin: 0;
padding: 0;
}
.collapse {
}
a {
color: var(--color-primary-dark);
}
.attachments {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
align-self: flex-start;
}
.incoming .attachments {
align-self: flex-end;
}
temba-thumbnail {
margin: 0.4em;
border-radius: var(--curvature);
}
.failed temba-thumbnail,
.error temba-thumbnail {
--thumb-background: #ffe6e6;
--thumb-border: var(--color-error);
border: 1px solid var(--color-error);
color: #ad4747a8;
}
.outgoing .popup {
justify-content: left;
}
.incoming .popup {
justify-content: right;
}
.popup {
display: flex;
position: absolute;
background: #fff;
margin: 0;
padding: 0.5em 1em;
border-radius: var(--curvature);
box-shadow:
rgba(0, 0, 0, 0.05) 0px 3px 7px 0px,
rgba(0, 0, 0, 0.2) 0px 1px 2px 0px;
border: 1px solid #f3f3f3;
opacity: 0;
z-index: 2;
}
.popup .arrow {
z-index: 1;
text-shadow: 0px 3px 3px rgba(0, 0, 0, 0.1);
position: absolute;
justify-content: center;
text-align: center;
font-size: 1.3em;
transform: translateY(0.7em) scale(1);
color: #fff;
bottom: 0;
}
.bubble-wrap:hover .popup {
opacity: 1;
transition-delay: 1s;
top: -35px;
}
.new-message-notification {
position: absolute;
bottom: 1em;
left: 50%;
transform: translateX(-50%) translateY(100px);
background: var(--color-primary-dark, #3c92dd);
color: white;
padding: 0.75em 1.5em;
border-radius: var(--curvature);
box-shadow:
rgba(0, 0, 0, 0.2) 0px 3px 7px 0px,
rgba(0, 0, 0, 0.3) 0px 1px 2px 0px;
cursor: pointer;
opacity: 0;
transition: all 0.3s ease-out;
z-index: 100;
font-weight: 500;
pointer-events: none;
}
.new-message-notification.visible {
transform: translateX(-50%) translateY(0);
opacity: 1;
pointer-events: auto;
}
.new-message-notification:hover {
background: var(--color-primary-darker, #2b7ac4);
box-shadow:
rgba(0, 0, 0, 0.3) 0px 4px 10px 0px,
rgba(0, 0, 0, 0.4) 0px 2px 4px 0px;
}
mark {
background: #fef08a;
color: #1a1a1a;
padding: 0.1em 0.3em;
margin: 0 0.1em;
border-radius: 3px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.search-match .bubble {
box-shadow: 0 0 0 2px #fef08a;
}
@keyframes search-pulse {
0% {
box-shadow: 0 0 0 2px #fef08a;
}
50% {
box-shadow: 0 0 0 4px #fef08a;
}
100% {
box-shadow: 0 0 0 2px #fef08a;
}
}
.search-match .bubble {
animation: search-pulse 1s ease-in-out 2;
}
`;
}
@property({ type: Array })
messageGroups: MessageGroup[] = [];
@property({ type: Boolean })
fetching = false;
@property({ type: Boolean, attribute: false })
hideTopScroll = true;
@property({ type: Boolean, attribute: false })
hideBottomScroll = true;
@property({ type: String, attribute: 'avatar' })
defaultAvatar = DEFAULT_AVATAR;
@property({ type: Boolean })
agent = false;
@property({ type: Boolean })
avatars = false;
@property({ type: Boolean, attribute: false })
endOfHistory = false;
@property({ type: Object, attribute: false })
oldestEventDate: Date = null;
@property({ type: Boolean, attribute: false })
showNewMessageNotification = false;
@property({ type: Object })
showMessageLogsAfter: Date = null;
@property({ type: Boolean })
hasFooter = false;
@property({ type: Boolean })
showTimestamps = true;
@property({ type: String, attribute: false })
searchHighlight: string = null;
@property({ type: String, attribute: false })
highlightMessageUuid: string = null;
private msgMap = new Map<string, ContactEvent>();
private metadataCache = new Map<string, ContactEvent>();
public firstUpdated(
changed: PropertyValueMap<any> | Map<PropertyKey, unknown>
): void {
super.firstUpdated(changed);
const scroll = this.shadowRoot.querySelector('.scroll');
const hasScroll = scroll.scrollHeight > scroll.clientHeight;
this.hideBottomScroll = true;
this.hideTopScroll = !hasScroll;
}
public addMessages(
messages: ContactEvent[],
startTime: Date = null,
append = false,
maintainScroll = false
) {
if (!startTime) {
startTime = new Date();
}
const elapsed = new Date().getTime() - startTime.getTime();
window.setTimeout(
() => {
this.fetching = false;
// first add messages to the map
const newMessages = [];
for (const m of messages) {
// filter out metadata events - they aren't rendered but cached for later reference
if (m.type === 'msg_deleted' || m.type === 'msg_status_changed') {
const msgUuid = (m as any).msg_uuid;
if (msgUuid) {
this.metadataCache.set(msgUuid, m);
}
continue;
}
if (this.addMessage(m)) {
newMessages.push(m.uuid);
}
}
if (newMessages.length === 0) {
return;
}
const ele = this.shadowRoot.querySelector('.scroll');
const prevTop = ele.scrollTop;
const prevScrollHeight = ele.scrollHeight;
const scrollableHeight = ele.scrollHeight - ele.clientHeight;
const isScrolledAway =
scrollableHeight > 0 && Math.abs(ele.scrollTop) > 50;
const grouped = this.groupMessages(newMessages);
this.insertGroups(grouped, append);
// show notification if new messages are appended and user is scrolled away from bottom
// but not during search (searchHighlight is set)
if (
append &&
isScrolledAway &&
newMessages.length > 0 &&
!this.searchHighlight
) {
this.showNewMessageNotification = true;
}
window.setTimeout(() => {
// when appending (new messages at bottom), adjust scroll to maintain visible content
// with column-reverse, new content at bottom increases scrollHeight
if (append && (isScrolledAway || maintainScroll)) {
const heightDiff = ele.scrollHeight - prevScrollHeight;
ele.scrollTop = prevTop - heightDiff;
} else {
ele.scrollTop = prevTop;
}
// recalculate shadow visibility after content change
const scrollableHeight = ele.scrollHeight - ele.clientHeight;
const absScrollTop = Math.abs(ele.scrollTop);
this.hideTopScroll = absScrollTop >= scrollableHeight - 1;
this.hideBottomScroll = absScrollTop <= 1;
this.fireCustomEvent(CustomEventType.FetchComplete);
}, 100);
},
// if it's the first load don't wait, otherwise wait a minimum amount of time
this.messageGroups.length === 0
? 0
: Math.max(0, MIN_FETCH_TIME - elapsed)
);
}
/**
* Synchronously loads messages into the chat without any timeouts or scroll
* adjustments. Use this when the caller controls visibility and scroll
* positioning (e.g. search result navigation).
*/
public loadMessages(messages: ContactEvent[]) {
const newMessageIds: string[] = [];
for (const m of messages) {
if (m.type === 'msg_deleted' || m.type === 'msg_status_changed') {
const msgUuid = (m as any).msg_uuid;
if (msgUuid) {
this.metadataCache.set(msgUuid, m);
}
continue;
}
if (this.addMessage(m)) {
newMessageIds.push(m.uuid);
}
}
if (newMessageIds.length > 0) {
const grouped = this.groupMessages(newMessageIds);
this.insertGroups(grouped, false);
}
}
private addMessage(msg: ContactEvent): boolean {
const isNew = !this.messageExists(msg);
this.msgMap.set(msg.uuid, msg);
return isNew;
}
public messageExists(msg: ContactEvent): boolean {
return this.msgMap.has(msg.uuid);
}
private isSameGroup(
msg1: ContactEvent,
msg2: ContactEvent,
lastTimeElapsedDate?: Date
): { same: boolean; reason?: GroupReason } {
if (!msg1 || !msg2) {
return { same: true };
}
// for type equivalence, treat all non-message types as the same
const isMsg1 =
msg1.type === 'msg_created' ||
msg1.type === 'msg_received' ||
msg1.type === 'ivr_created';
const isMsg2 =
msg2.type === 'msg_created' ||
msg2.type === 'msg_received' ||
msg2.type === 'ivr_created';
const typeMatch =
isMsg1 && isMsg2 ? msg1.type === msg2.type : isMsg1 === isMsg2;
// check time first - if BATCH_TIME_WINDOW has passed since last time_elapsed reason
// compare the current message (msg1) against the last break point to detect
// when messages have drifted far enough to warrant a new time group
const timeToCheck = lastTimeElapsedDate || msg2.created_on;
if (
Math.abs(msg1.created_on.getTime() - timeToCheck.getTime()) >=
BATCH_TIME_WINDOW
) {
return { same: false, reason: 'time_elapsed' };
}
if (!typeMatch) {
return { same: false, reason: 'new_type' };
}
// only check author for message types
if (isMsg1 && isMsg2 && msg1._user?.name !== msg2._user?.name) {
return { same: false, reason: 'new_author' };
}
return { same: true };
}
private insertGroups(newGroups: MessageGroup[], append = false) {
if (!append) {
newGroups.reverse();
}
for (const newGroup of newGroups) {
// see if our new group belongs to the most recent group
const group =
this.messageGroups[append ? 0 : this.messageGroups.length - 1];
if (group) {
const lastMsgId = group.messages[group.messages.length - 1];
const lastMsg = this.msgMap.get(lastMsgId);
const newMsg = this.msgMap.get(newGroup.messages[0]);
// if our message belongs to the previous group, in we go
const groupCheck = this.isSameGroup(lastMsg, newMsg);
if (groupCheck.same) {
if (append) {
group.messages.push(...newGroup.messages);
} else {
// historical messages are older, prepend to maintain chronological order
group.messages.unshift(...newGroup.messages);
}
} else {
// otherwise, just add our entire group as a new one
if (append) {
this.messageGroups.splice(0, 0, newGroup);
} else {
// update the boundary group's reason to reflect the new adjacency
if (groupCheck.reason) {
group.reason = groupCheck.reason;
}
this.messageGroups.push(newGroup);
}
}
} else {
if (append) {
this.messageGroups.splice(0, 0, newGroup);
} else {
this.messageGroups.push(newGroup);
}
}
}
this.requestUpdate('messageGroups');
}
private groupMessages(msgIds: string[]): MessageGroup[] {
// group our messages by origin and user
const groups: MessageGroup[] = [];
let lastGroup: MessageGroup = null;
let lastMsg: ContactEvent = null;
let lastTimeElapsedDate: Date = null;
for (const msgId of msgIds) {
const msg = this.msgMap.get(msgId);
const groupCheck = this.isSameGroup(msg, lastMsg, lastTimeElapsedDate);
if (!groupCheck.same || !lastGroup) {
lastGroup = {
messages: [],
reason: groupCheck.reason || 'initial'
};
groups.push(lastGroup);
// track when we last broke for time_elapsed
if (groupCheck.reason === 'time_elapsed') {
lastTimeElapsedDate = msg.created_on;
}
}
lastGroup.messages.push(msgId);
lastMsg = msg;
}
return groups;
}
private handleScroll(event: any) {
const ele = event.target;
const scrollableHeight = ele.scrollHeight - ele.clientHeight;
if (scrollableHeight <= 0) {
return;
}
// with column-reverse, scrollTop behavior depends on the browser
// check if scrollTop is negative (some browsers) or positive (others)
const absScrollTop = Math.abs(ele.scrollTop);
// when scrolling up to older messages, absScrollTop increases
// trigger when we're close to the maximum scroll (oldest messages)
const shouldFetch = absScrollTop >= scrollableHeight - SCROLL_FETCH_BUFFER;
this.hideTopScroll = absScrollTop >= scrollableHeight - 1;
this.hideBottomScroll = absScrollTop <= 1;
// hide notification when scrolled to bottom
if (absScrollTop <= 10) {
this.showNewMessageNotification = false;
}
if (shouldFetch) {
this.fireCustomEvent(CustomEventType.ScrollThreshold);
}
// trigger when scrolling near the bottom (newest messages) in column-reverse
if (absScrollTop <= SCROLL_FETCH_BUFFER * 3 && scrollableHeight > 0) {
this.fireCustomEvent(CustomEventType.ScrollThresholdBottom);
}
}
public scrollToBottom() {
const scroll = this.shadowRoot.querySelector('.scroll');
if (scroll) {
scroll.scrollTop = 0;
this.hideBottomScroll = true;
this.showNewMessageNotification = false;
}
}
public scrollToMessage(
uuid: string,
animate = true,
onComplete?: () => void
) {
this.highlightMessageUuid = uuid;
window.setTimeout(() => {
const scroll = this.shadowRoot.querySelector('.scroll') as HTMLElement;
const row = this.shadowRoot.querySelector(
`.row[data-uuid="${uuid}"]`
) as HTMLElement;
if (scroll && row) {
// manually set scrollTop to center the row within the scroll area
// this avoids scrollIntoView which can move ancestor containers
const scrollRect = scroll.getBoundingClientRect();
const rowRect = row.getBoundingClientRect();
const rowCenter = rowRect.top + rowRect.height / 2;
const scrollCenter = scrollRect.top + scrollRect.height / 2;
const offset = rowCenter - scrollCenter;
if (animate) {
scroll.scrollBy({ top: offset, behavior: 'smooth' });
} else {
scroll.scrollTop = scroll.scrollTop + offset;
}
}
if (onComplete) {
// wait one frame for the browser to finish the scroll
requestAnimationFrame(() => onComplete());
}
}, 150);
}
private highlightText(text: string, search: string): TemplateResult | string {
if (!search || !text) {
return text;
}
const escaped = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const regex = new RegExp(`(${escaped})`, 'gi');
const parts = text.split(regex);
if (parts.length === 1) {
return text;
}
return html`${parts.map((part, index) =>
index % 2 === 1 ? html`<mark>${part}</mark>` : part
)}`;
}
private handleNewMessageClick() {
this.scrollToBottom();
}
private getReasonLabel(reason: GroupReason): string {
switch (reason) {
case 'new_author':
return '👤 Different author';
case 'new_type':
return '🔄 Message type changed';
case 'time_elapsed':
case 'initial':
default:
return '';
}
}
private renderMessageGroup(
group: MessageGroup,
idx: number,
lastShownTimestamp: Date | null
): { html: TemplateResult; timestamp: Date | null } {
const today = new Date();
const msgIds = group.messages;
const mostRecentId = msgIds[msgIds.length - 1];
const currentMsg = this.msgMap.get(mostRecentId);
const incoming = this.agent
? currentMsg.type !== 'msg_received'
: currentMsg.type === 'msg_received';
const name = currentMsg._user?.name;
const isMessageType =
currentMsg.type === 'msg_received' ||
currentMsg.type === 'msg_created' ||
currentMsg.type === 'ivr_created';
const showAvatar =
this.avatars && ((isMessageType && this.agent) || !incoming);
const isSystem = !currentMsg._user?.uuid;
const reasonLabel = this.getReasonLabel(group.reason);
const showReason = false; // reasonLabel && idx > 0;
// determine if we should show a timestamp
// use the first message in the group (oldest) for the timestamp
const firstMsgId = msgIds[0];
const firstMsg = this.msgMap.get(firstMsgId);
// check if we should show a timestamp based on the last shown timestamp
let showTimeForReason = false;
let newLastShownTimestamp = lastShownTimestamp;
if (idx > 0) {
if (lastShownTimestamp) {
const timeSinceLastShown = Math.abs(
firstMsg.created_on.getTime() - lastShownTimestamp.getTime()
);
showTimeForReason = timeSinceLastShown >= BATCH_TIME_WINDOW;
} else {
showTimeForReason = group.reason === 'time_elapsed';
}
}
let timeForReason = null;
if (showTimeForReason) {
newLastShownTimestamp = firstMsg.created_on;
const isDifferentYear =
today.getFullYear() !== firstMsg.created_on.getFullYear();
const format = isDifferentYear
? VERBOSE_FORMAT_WITH_YEAR
: today.getDate() !== firstMsg.created_on.getDate()
? VERBOSE_FORMAT
: TIME_FORMAT;
timeForReason = html`<div class="time time-elapsed">
${firstMsg.created_on.toLocaleTimeString(undefined, format)}
</div>`;
}
const resultHtml = html`
<div class="block ${incoming ? 'incoming' : 'outgoing'}">
<div class="group-messages" style="flex-grow:1">
${repeat(
msgIds,
(msgId) => msgId,
(msgId, index) => {
const msg = this.msgMap.get(msgId);
const msgEvent = msg as MsgEvent;
const statusClass = (msg as any)._status
? (msg as any)._status.status
: '';
const hasError =
msgEvent.msg?.unsendable_reason ||
(msgEvent._status?.reason &&
(statusClass === 'failed' || statusClass === 'errored'));
const unsendableClass = hasError ? 'error' : '';
const deletedClass = msgEvent._deleted ? 'deleted' : '';
const latestClass = index === msgIds.length - 1 ? 'latest' : '';
const eventClass = msg._rendered ? 'is-event' : '';
const matchClass =
this.highlightMessageUuid === msg.uuid ? 'search-match' : '';
return html`<div
class="row message ${statusClass} ${unsendableClass} ${deletedClass} ${latestClass} ${eventClass} ${matchClass}"
data-uuid=${msg.uuid || nothing}
>
${this.renderMessage(msg, index == 0 ? name : null)}
</div>`;
}
)}
</div>
${showAvatar
? html`<div class="avatar" style="align-self:flex-end">
<temba-user
uuid=${currentMsg._user?.uuid}
name=${name}
avatar=${currentMsg._user?.avatar}
?system=${isSystem}
>
</temba-user>
</div>`
: null}
</div>
${showReason
? html`<div class="group-reason">${reasonLabel}</div>`
: null}
${timeForReason}
`;
return { html: resultHtml, timestamp: newLastShownTimestamp };
}
private renderMessage(event: ContactEvent, name = null): TemplateResult {
if (event._rendered) {
return html`<div class="event">${event._rendered.html}</div>`;
}
const message = event as MsgEvent;
// safety check: if msg doesn't exist, return nothing
if (!message.msg) {
return html``;
}
const unsendableReason = message.msg?.unsendable_reason;
const statusReason = message._status?.reason;
const errorMessage = unsendableReason
? getUnsendableReasonMessage(unsendableReason)
: statusReason
? getStatusReasonMessage(statusReason)
: null;
const logsURL =
this.showMessageLogsAfter &&
message.created_on >= this.showMessageLogsAfter &&
message.msg.channel
? `/channels/channel/logs/${message.msg.channel.uuid}/msg/${event.uuid}/`
: null;
// handle deleted messages
const isDeleted = message._deleted;
const deletedByText = isDeleted
? message._deleted.by_contact
? 'contact'
: message._deleted.user?.name || 'user'
: null;
// check if message has location attachment and text is just coordinates
const hasLocationAttachment = message.msg.attachments?.some((att) =>
att.startsWith('geo:')
);
const textIsCoordinates =
hasLocationAttachment &&
message.msg.text &&
/^-?\d+\.?\d*\s*,\s*-?\d+\.?\d*$/.test(message.msg.text.trim());
// Keep the text interpolation itself whitespace-free: this element uses
// pre-wrap, so formatter-inserted newlines become visible in screenshots.
const messageText =
this.searchHighlight && this.highlightMessageUuid === message.uuid
? this.highlightText(message.msg.text, this.searchHighlight)
: message.msg.text;
return html`
<div class="bubble-wrap">
${this.showTimestamps
? html`<div class="popup" style="white-space: nowrap;">
${errorMessage
? html`<div
style="color: var(--color-error); margin-right: 1em;"
>
${errorMessage}
</div>`
: null}
<temba-date
value="${message.created_on.toISOString()}"
display="relative"
></temba-date>
${logsURL
? html`<a
style="margin-left: 1em; color: var(--color-primary-dark);"
href="${logsURL}"
target="_blank"
rel="noopener noreferrer"
><temba-icon name="log"></temba-icon
></a>`
: null}
<div class="arrow">â–¼</div>
</div>`
: null}
${isDeleted
? html`<div class="bubble">
${name ? html`<div class="name">${name}</div>` : null}
<div class="message-deleted">
Message deleted by ${deletedByText}
</div>
</div>`
: message.msg.text && !textIsCoordinates
? html`<div class="bubble">
${name ? html`<div class="name">${name}</div>` : null}
<div class="message-text">${messageText}</div>
</div>`
: null}
<div class="attachments">
${(message.msg.attachments || []).map(
(attachment) =>
html`<temba-thumbnail
attachment="${attachment}"
></temba-thumbnail>`
)}
</div>
</div>
`;
}
public reset() {
this.msgMap.clear();
this.messageGroups = [];
this.hideBottomScroll = true;
this.hideTopScroll = true;
this.endOfHistory = false;
this.oldestEventDate = null;
}
public setEndOfHistory(oldestDate: Date) {
this.endOfHistory = true;
this.oldestEventDate = oldestDate;
}
public render(): TemplateResult {
return html` <div
class="
messages
${this.hideBottomScroll ? 'scroll-at-bottom' : ''}
${this.hideTopScroll ? 'scroll-at-top' : ''}"
>
<div class="scroll" @scroll=${this.handleScroll}>
${this.messageGroups
? (() => {
let lastTimestamp: Date | null = null;
// process from oldest to newest (high index to low index)
// to establish logical time groupings going forward in time
const results = [];
for (let idx = this.messageGroups.length - 1; idx >= 0; idx--) {
const msgGroup = this.messageGroups[idx];
const result = this.renderMessageGroup(
msgGroup,
idx,
lastTimestamp
);
lastTimestamp = result.timestamp;
results.unshift(result.html); // add to front since we're going backwards
}
return results;
})()
: null}
<temba-loading
class="${!this.fetching ? 'hidden' : ''}"
></temba-loading>
${this.endOfHistory && this.oldestEventDate
? html`<div class="time first">
${this.oldestEventDate.toLocaleTimeString(
undefined,
VERBOSE_FORMAT
)}
</div>`
: null}
</div>
${!this.hasFooter
? html`<div
class="new-message-notification ${this.showNewMessageNotification
? 'visible'
: ''}"
@click=${this.handleNewMessageClick}
>
New Messages
</div>`
: null}
<slot class="header" name="header"></slot>
<slot class="footer" name="footer"></slot>
</div>`;
}
}
|