hopefully this fixed chat updates

This commit is contained in:
cutestnekoaqua 2023-01-12 20:19:12 +01:00
parent 5948b2b74c
commit bbbfbc1061
No known key found for this signature in database
GPG key ID: 6BF0964A5069C1E0
2 changed files with 10 additions and 2 deletions

View file

@ -64,6 +64,7 @@ const props = withDefaults(defineProps<{
pagination: Paging; pagination: Paging;
disableAutoLoad?: boolean; disableAutoLoad?: boolean;
displayLimit?: number; displayLimit?: number;
reloadKey?: number;
}>(), { }>(), {
displayLimit: 30, displayLimit: 30,
}); });

View file

@ -37,7 +37,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { markRaw, onMounted, onUnmounted, watch } from 'vue'; import { markRaw, onMounted, onUnmounted, watch, ref } from 'vue';
import * as Acct from 'calckey-js/built/acct'; import * as Acct from 'calckey-js/built/acct';
import { Virtual } from 'swiper'; import { Virtual } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue'; import { Swiper, SwiperSlide } from 'swiper/vue';
@ -59,11 +59,16 @@ const router = useRouter();
let messages = $ref([]); let messages = $ref([]);
let connection = $ref(null); let connection = $ref(null);
const reloadingKey = ref(0);
const tabs = ['dms', 'groups']; const tabs = ['dms', 'groups'];
let tab = $ref(tabs[0]); let tab = $ref(tabs[0]);
watch($$(tab), () => (syncSlide(tabs.indexOf(tab)))); watch($$(tab), () => (syncSlide(tabs.indexOf(tab))));
const forceRerender = () => {
reloadingKey.value += 1;
};
const headerActions = $computed(() => [{ const headerActions = $computed(() => [{
asFullButton: true, asFullButton: true,
icon: 'ph-plus-bold ph-lg', icon: 'ph-plus-bold ph-lg',
@ -112,6 +117,7 @@ function onMessage(message): void {
messages = messages.filter(m => m.groupId !== message.groupId); messages = messages.filter(m => m.groupId !== message.groupId);
messages.unshift(message); messages.unshift(message);
} }
forceRerender();
} }
function onRead(ids): void { function onRead(ids): void {
@ -183,11 +189,12 @@ function syncSlide(index) {
} }
onMounted(() => { onMounted(() => {
syncSlide(tabs.indexOf(swiperRef.activeIndex)); syncSlide(tabs.indexOf(swiperRef?.activeIndex));
connection = markRaw(stream.useChannel('messagingIndex')); connection = markRaw(stream.useChannel('messagingIndex'));
connection.on('message', onMessage); connection.on('message', onMessage);
connection.on('messagingMessage', onMessage);
connection.on('read', onRead); connection.on('read', onRead);
os.api('messaging/history', { group: false, limit: 5 }).then(userMessages => { os.api('messaging/history', { group: false, limit: 5 }).then(userMessages => {