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>
|
|
|
|
|
|
|
|
<script>
|
2019-11-16 17:24:03 +00:00
|
|
|
import constants from "../js/constants";
|
2018-07-09 12:14:44 +00:00
|
|
|
import Message from "./Message.vue";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "MessageCondensed",
|
|
|
|
components: {
|
2018-07-09 13:21:14 +00:00
|
|
|
Message,
|
2018-07-09 12:14:44 +00:00
|
|
|
},
|
|
|
|
props: {
|
2018-07-19 17:44:24 +00:00
|
|
|
network: Object,
|
2018-07-09 12:14:44 +00:00
|
|
|
messages: Array,
|
2018-09-23 17:51:43 +00:00
|
|
|
keepScrollPosition: Function,
|
2018-07-09 12:14:44 +00:00
|
|
|
},
|
2018-07-09 13:21:14 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isCollapsed: true,
|
|
|
|
};
|
|
|
|
},
|
2018-07-09 12:14:44 +00:00
|
|
|
computed: {
|
|
|
|
condensedText() {
|
|
|
|
const obj = {};
|
|
|
|
|
|
|
|
constants.condensedTypes.forEach((type) => {
|
|
|
|
obj[type] = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const message of this.messages) {
|
|
|
|
obj[message.type]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count quits as parts in condensed messages to reduce information density
|
|
|
|
obj.part += obj.quit;
|
|
|
|
|
|
|
|
const strings = [];
|
|
|
|
constants.condensedTypes.forEach((type) => {
|
|
|
|
if (obj[type]) {
|
|
|
|
switch (type) {
|
2019-07-17 09:33:59 +00:00
|
|
|
case "chghost":
|
|
|
|
strings.push(
|
|
|
|
obj[type] +
|
|
|
|
(obj[type] > 1
|
|
|
|
? " users have changed hostname"
|
|
|
|
: " user has changed hostname")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "join":
|
|
|
|
strings.push(
|
|
|
|
obj[type] +
|
|
|
|
(obj[type] > 1 ? " users have joined" : " user has joined")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "part":
|
|
|
|
strings.push(
|
|
|
|
obj[type] + (obj[type] > 1 ? " users have left" : " user has left")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "nick":
|
|
|
|
strings.push(
|
|
|
|
obj[type] +
|
|
|
|
(obj[type] > 1
|
|
|
|
? " users have changed nick"
|
|
|
|
: " user has changed nick")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "kick":
|
|
|
|
strings.push(
|
|
|
|
obj[type] +
|
|
|
|
(obj[type] > 1 ? " users were kicked" : " user was kicked")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "mode":
|
|
|
|
strings.push(
|
|
|
|
obj[type] + (obj[type] > 1 ? " modes were set" : " mode was set")
|
|
|
|
);
|
|
|
|
break;
|
2018-07-09 12:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let text = strings.pop();
|
|
|
|
|
|
|
|
if (strings.length) {
|
|
|
|
text = strings.join(", ") + ", and " + text;
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
},
|
|
|
|
},
|
2018-09-23 17:51:43 +00:00
|
|
|
methods: {
|
|
|
|
onCollapseClick() {
|
|
|
|
this.isCollapsed = !this.isCollapsed;
|
|
|
|
this.keepScrollPosition();
|
|
|
|
},
|
|
|
|
},
|
2018-07-09 12:14:44 +00:00
|
|
|
};
|
|
|
|
</script>
|