2018-07-09 12:14:44 +00:00
|
|
|
<template>
|
2019-12-15 11:46:43 +00:00
|
|
|
<div :class="['msg', {closed: isCollapsed}]" data-type="condensed">
|
2018-07-13 07:43:31 +00:00
|
|
|
<div class="condensed-summary">
|
2018-07-29 17:57:14 +00:00
|
|
|
<span class="time" />
|
|
|
|
<span class="from" />
|
2019-07-17 09:33:59 +00:00
|
|
|
<span class="content" @click="onCollapseClick"
|
|
|
|
>{{ condensedText
|
|
|
|
}}<button class="toggle-button" aria-label="Toggle status messages"
|
2019-02-25 05:38:13 +00:00
|
|
|
/></span>
|
2018-07-09 12:14:44 +00:00
|
|
|
</div>
|
|
|
|
<Message
|
|
|
|
v-for="message in messages"
|
2018-07-29 17:57:14 +00:00
|
|
|
:key="message.id"
|
2018-07-19 17:44:24 +00:00
|
|
|
:network="network"
|
2019-02-25 05:38:13 +00:00
|
|
|
:message="message"
|
|
|
|
/>
|
2018-07-09 12:14:44 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import {computed, defineComponent, PropType, ref} from "vue";
|
2023-01-29 22:16:55 +00:00
|
|
|
import {condensedTypes} from "../../shared/irc";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {ClientMessage, ClientNetwork} from "../js/types";
|
2018-07-09 12:14:44 +00:00
|
|
|
import Message from "./Message.vue";
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2018-07-09 12:14:44 +00:00
|
|
|
name: "MessageCondensed",
|
|
|
|
components: {
|
2018-07-09 13:21:14 +00:00
|
|
|
Message,
|
2018-07-09 12:14:44 +00:00
|
|
|
},
|
|
|
|
props: {
|
2022-06-19 00:25:21 +00:00
|
|
|
network: {type: Object as PropType<ClientNetwork>, required: true},
|
|
|
|
messages: {
|
|
|
|
type: Array as PropType<ClientMessage[]>,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
keepScrollPosition: {
|
|
|
|
type: Function as PropType<() => void>,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-01-26 22:51:22 +00:00
|
|
|
focused: Boolean,
|
2018-07-09 12:14:44 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
setup(props) {
|
|
|
|
const isCollapsed = ref(true);
|
|
|
|
|
|
|
|
const onCollapseClick = () => {
|
|
|
|
isCollapsed.value = !isCollapsed.value;
|
|
|
|
props.keepScrollPosition();
|
2018-07-09 13:21:14 +00:00
|
|
|
};
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
const condensedText = computed(() => {
|
|
|
|
const obj: Record<string, number> = {};
|
2018-07-09 12:14:44 +00:00
|
|
|
|
2023-01-29 22:16:55 +00:00
|
|
|
condensedTypes.forEach((type) => {
|
2018-07-09 12:14:44 +00:00
|
|
|
obj[type] = 0;
|
|
|
|
});
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
for (const message of props.messages) {
|
2021-12-31 21:24:29 +00:00
|
|
|
// special case since one MODE message can change multiple modes
|
|
|
|
if (message.type === "mode") {
|
|
|
|
// syntax: +vv-t maybe-some targets
|
|
|
|
// we want the number of mode changes in the message, so count the
|
|
|
|
// number of chars other than + and - before the first space
|
|
|
|
const modeChangesCount = message.text
|
|
|
|
.split(" ")[0]
|
|
|
|
.split("")
|
|
|
|
.filter((char) => char !== "+" && char !== "-").length;
|
|
|
|
obj[message.type] += modeChangesCount;
|
|
|
|
} else {
|
|
|
|
obj[message.type]++;
|
|
|
|
}
|
2018-07-09 12:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Count quits as parts in condensed messages to reduce information density
|
|
|
|
obj.part += obj.quit;
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const strings: string[] = [];
|
2023-01-29 22:16:55 +00:00
|
|
|
condensedTypes.forEach((type) => {
|
2018-07-09 12:14:44 +00:00
|
|
|
if (obj[type]) {
|
|
|
|
switch (type) {
|
2019-07-17 09:33:59 +00:00
|
|
|
case "chghost":
|
|
|
|
strings.push(
|
2022-06-19 00:25:21 +00:00
|
|
|
String(obj[type]) +
|
2019-07-17 09:33:59 +00:00
|
|
|
(obj[type] > 1
|
|
|
|
? " users have changed hostname"
|
|
|
|
: " user has changed hostname")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "join":
|
|
|
|
strings.push(
|
2022-06-19 00:25:21 +00:00
|
|
|
String(obj[type]) +
|
2019-07-17 09:33:59 +00:00
|
|
|
(obj[type] > 1 ? " users have joined" : " user has joined")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "part":
|
|
|
|
strings.push(
|
2022-06-19 00:25:21 +00:00
|
|
|
String(obj[type]) +
|
|
|
|
(obj[type] > 1 ? " users have left" : " user has left")
|
2019-07-17 09:33:59 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "nick":
|
|
|
|
strings.push(
|
2022-06-19 00:25:21 +00:00
|
|
|
String(obj[type]) +
|
2019-07-17 09:33:59 +00:00
|
|
|
(obj[type] > 1
|
|
|
|
? " users have changed nick"
|
|
|
|
: " user has changed nick")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "kick":
|
|
|
|
strings.push(
|
2022-06-19 00:25:21 +00:00
|
|
|
String(obj[type]) +
|
2019-07-17 09:33:59 +00:00
|
|
|
(obj[type] > 1 ? " users were kicked" : " user was kicked")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "mode":
|
|
|
|
strings.push(
|
2022-06-19 00:25:21 +00:00
|
|
|
String(obj[type]) +
|
|
|
|
(obj[type] > 1 ? " modes were set" : " mode was set")
|
2019-07-17 09:33:59 +00:00
|
|
|
);
|
|
|
|
break;
|
2022-12-29 15:06:54 +00:00
|
|
|
case "away":
|
|
|
|
strings.push(
|
|
|
|
"marked away " +
|
|
|
|
(obj[type] > 1 ? String(obj[type]) + " times" : "once")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "back":
|
|
|
|
strings.push(
|
|
|
|
"marked back " +
|
|
|
|
(obj[type] > 1 ? String(obj[type]) + " times" : "once")
|
|
|
|
);
|
|
|
|
break;
|
2018-07-09 12:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (strings.length) {
|
2022-06-19 00:25:21 +00:00
|
|
|
let text = strings.pop();
|
|
|
|
|
|
|
|
if (strings.length) {
|
|
|
|
text = strings.join(", ") + ", and " + text!;
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
2018-07-09 12:14:44 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
return "";
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
isCollapsed,
|
|
|
|
condensedText,
|
|
|
|
onCollapseClick,
|
|
|
|
};
|
2018-09-23 17:51:43 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2018-07-09 12:14:44 +00:00
|
|
|
</script>
|