{"version":3,"file":"conversation_controller-CG1-HHJH.js","sources":["../../../app/javascript/controllers/inbox/conversation_controller.js"],"sourcesContent":["import ApplicationController from \"../application_controller\"\nimport {useUpdatableTimestamp} from \"../mixins/useUpdatableTimestamp\";\nimport {get} from \"@rails/request.js\";\n\nexport default class extends ApplicationController {\n static targets = [\"timestamp\", \"radio\", \"unreadCountContainer\", \"link\", \"checkbox\"]\n\n static values = {\n state: String,\n lastEventTimestamp: String,\n removeable: { type: Boolean, default: true }\n }\n\n initialize() {\n this.popStateListener = this.popStateListener.bind(this)\n this.url = this.element.dataset.url\n }\n\n connect() {\n window.addEventListener(\"popstate\", this.popStateListener)\n\n if(this.alreadyPresentInDOM && this.removeableValue) {\n // We want this element to be successfully shown for other clients, but,\n // for a client that already has the element and is already there, we don't to do anything with it.\n this.element.remove()\n } else {\n this.element.id = this.element.dataset.documentId\n }\n\n if(this.invisible) {\n this.dispatch(\"appended\", {\n target: document.getElementById(\"conversations-list\"),\n detail: {\n element: this.element,\n state: this.stateValue,\n }\n })\n\n this.syncLinkWithClientFilters()\n }\n\n useUpdatableTimestamp(this)\n\n this.updateTimestampEveryMinute()\n }\n\n disconnect() {\n clearInterval(this.timestampInterval)\n }\n\n popStateListener() {\n const parts = window.location.pathname.split(\"/\")\n const id = parts[parts.length - 1]\n\n if(id === this.element.dataset.id) {\n this.onClick()\n }\n }\n\n onClick() {\n if(document.querySelector('[data-conversations--inbox-target=\"checkAllContainer\"]').classList.contains('hidden')) {\n get(this.element.dataset.url, { responseKind: \"turbo-stream\" })\n\n this.changeBrowserUrl()\n this.activate()\n\n this.dispatch('show')\n } else {\n this.checkboxTarget.click()\n }\n }\n\n onCheckboxChange() {\n\n }\n\n changeBrowserUrl() {\n if(window.location.href === this.url) return\n\n const url = new URL(this.url)\n history.pushState({}, null, url.toString())\n\n this.activate()\n }\n\n activate() {\n document\n .querySelectorAll(`.inbox--conversation-card`)\n .forEach(card => card.removeAttribute('data-active'))\n\n this.element.setAttribute('data-active', true)\n }\n\n syncLinkWithClientFilters() {\n const clientFilters = new URL(window.location.href).searchParams\n\n const newLinkURL = new URL(this.url.split('?')[0])\n\n if(clientFilters.has(\"filter\")) {\n newLinkURL.searchParams.append(\"filter\", clientFilters.get(\"filter\"))\n }\n\n if(clientFilters.get(\"team\")) {\n newLinkURL.searchParams.append(\"team\", clientFilters.get(\"team\"))\n }\n\n clientFilters.getAll(\"member\").forEach((memberId) => {\n newLinkURL.searchParams.append(\"member[]\", memberId)\n })\n\n this.url = newLinkURL.toString()\n this.element.setAttribute(\"data-url\", this.url)\n }\n\n updateUnreadMessagesCount() {\n const newCount = parseInt(this.unreadCountContainerTarget.innerText) -1\n\n if(newCount > 0) {\n this.unreadCountContainerTarget.innerText = newCount\n } else {\n this.hide(this.unreadCountContainerTarget)\n }\n }\n\n // private\n\n updateTimestampEveryMinute() {\n if(this.lastEventTimestampValue) {\n this.timestampInterval = setInterval(() => {\n this.timestampTarget.innerHTML = this.timeAgoInWordsWithParsing(this.lastEventTimestampValue)\n }, 30000)\n }\n }\n\n get alreadyPresentInDOM() {\n // The reason we use data-document-id instead of id is because when broadcasting from the server\n // Turbo will replace any element that has the same id attribute automatically.\n return document.querySelectorAll(`[data-document-id='${this.element.dataset.documentId}']`).length > 1\n }\n}\n"],"names":["conversation_controller","ApplicationController","useUpdatableTimestamp","parts","get","url","card","clientFilters","newLinkURL","memberId","newCount","__publicField"],"mappings":"uTAIe,MAAKA,UAASC,CAAsB,CASjD,YAAa,CACX,KAAK,iBAAmB,KAAK,iBAAiB,KAAK,IAAI,EACvD,KAAK,IAAM,KAAK,QAAQ,QAAQ,GACpC,CAEE,SAAU,CACR,OAAO,iBAAiB,WAAY,KAAK,gBAAgB,EAEtD,KAAK,qBAAuB,KAAK,gBAGlC,KAAK,QAAQ,OAAM,EAEnB,KAAK,QAAQ,GAAK,KAAK,QAAQ,QAAQ,WAGtC,KAAK,YACN,KAAK,SAAS,WAAY,CACxB,OAAQ,SAAS,eAAe,oBAAoB,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