FreeDATA/gui/src/components/chat_conversations.vue

85 lines
2.5 KiB
Vue
Raw Normal View History

2023-09-12 15:52:16 +00:00
<script setup lang="ts">
2023-10-03 13:15:17 +00:00
import { setActivePinia } from "pinia";
import pinia from "../store/index";
2023-09-12 15:52:16 +00:00
setActivePinia(pinia);
2023-10-03 13:15:17 +00:00
import { useChatStore } from "../store/chatStore.js";
2023-09-12 15:52:16 +00:00
const chat = useChatStore(pinia);
2023-10-22 08:12:00 +00:00
import {
getNewMessagesByDXCallsign,
resetIsNewMessage,
} from "../js/chatHandler";
2023-09-12 15:52:16 +00:00
2023-10-03 13:15:17 +00:00
function chatSelected(callsign) {
chat.selectedCallsign = callsign.toUpperCase();
2023-09-20 04:46:37 +00:00
// scroll message container to bottom
var messageBody = document.getElementById("message-container");
2023-10-22 08:12:00 +00:00
if (messageBody != null) {
2023-10-04 21:34:36 +00:00
// needs sensible defaults
messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight;
}
2023-09-20 04:46:37 +00:00
2023-10-22 08:12:00 +00:00
if (getNewMessagesByDXCallsign(callsign)[1] > 0) {
let messageArray = getNewMessagesByDXCallsign(callsign)[2];
console.log(messageArray);
2023-10-20 17:02:40 +00:00
2023-10-22 08:12:00 +00:00
for (const key in messageArray) {
resetIsNewMessage(messageArray[key].uuid, false);
}
}
2023-10-03 13:15:17 +00:00
try {
chat.beaconLabelArray = Object.values(
chat.sorted_beacon_list[chat.selectedCallsign].timestamp,
);
chat.beaconDataArray = Object.values(
chat.sorted_beacon_list[chat.selectedCallsign].snr,
);
} catch (e) {
console.log("beacon data not fetched: " + e);
chat.beaconLabelArray = [];
chat.beaconDataArray = [];
}
2023-09-20 04:46:37 +00:00
}
2023-09-12 15:52:16 +00:00
</script>
<template>
2023-10-25 15:20:39 +00:00
<div class="list-group bg-body-tertiary m-0 p-1" id="chat-list-tab" role="chat-tablist">
2023-10-03 13:15:17 +00:00
<template v-for="(item, key) in chat.callsign_list" :key="item.dxcallsign">
<a
2023-10-25 15:20:39 +00:00
class="list-group-item list-group-item-action list-group-item-dark rounded-2 border-0 mb-2"
2023-10-22 08:12:00 +00:00
:class="{ active: key == 0 }"
2023-10-03 13:15:17 +00:00
:id="`list-chat-list-${item}`"
data-bs-toggle="list"
:href="`#list-${item}-messages`"
role="tab"
aria-controls="list-{{item}}-messages"
@click="chatSelected(item)"
>
<div class="row">
2023-10-22 08:12:00 +00:00
<div class="col-9">
2023-10-25 15:20:39 +00:00
<strong>{{ item }}</strong>
2023-10-22 08:12:00 +00:00
<span
class="badge rounded-pill bg-danger"
v-if="getNewMessagesByDXCallsign(item)[1] > 0"
>
{{ getNewMessagesByDXCallsign(item)[1] }} new messages
</span>
</div>
2023-10-03 13:15:17 +00:00
<div class="col-3">
<button
2023-10-15 06:25:58 +00:00
class="btn btn-sm btn-outline-secondary ms-2 border-0"
data-bs-target="#deleteChatModal"
data-bs-toggle="modal"
@click="chatSelected(item)"
2023-10-03 13:15:17 +00:00
>
2023-10-15 06:25:58 +00:00
<i class="bi bi-three-dots-vertical"></i>
2023-10-03 13:15:17 +00:00
</button>
</div>
</div>
</a>
</template>
</div>
2023-09-12 15:52:16 +00:00
</template>