2018-02-13 12:06:35 +09:00
|
|
|
<template>
|
|
|
|
<div class="mk-messaging" :data-compact="compact">
|
2018-02-25 03:17:13 +09:00
|
|
|
<div class="search" v-if="!compact" :style="{ top: headerTop + 'px' }">
|
2018-02-13 12:06:35 +09:00
|
|
|
<div class="form">
|
2018-11-06 01:40:11 +09:00
|
|
|
<label for="search-input"><i><fa icon="search"/></i></label>
|
2018-11-09 13:47:22 +09:00
|
|
|
<input v-model="q" type="search" @input="search" @keydown="onSearchKeydown" :placeholder="$t('search-user')"/>
|
2018-02-13 12:06:35 +09:00
|
|
|
</div>
|
|
|
|
<div class="result">
|
2018-02-13 12:21:02 +09:00
|
|
|
<ol class="users" v-if="result.length > 0" ref="searchResult">
|
|
|
|
<li v-for="(user, i) in result"
|
2018-02-13 12:06:35 +09:00
|
|
|
@keydown.enter="navigate(user)"
|
2018-02-13 12:21:02 +09:00
|
|
|
@keydown="onSearchResultKeydown(i)"
|
|
|
|
@click="navigate(user)"
|
2018-02-13 12:06:35 +09:00
|
|
|
tabindex="-1"
|
|
|
|
>
|
2019-04-25 12:37:13 +09:00
|
|
|
<mk-avatar class="avatar" :user="user" :key="user.id"/>
|
|
|
|
<span class="name"><mk-user-name :user="user" :key="user.id"/></span>
|
2018-04-09 18:52:29 +09:00
|
|
|
<span class="username">@{{ user | acct }}</span>
|
2018-02-13 12:06:35 +09:00
|
|
|
</li>
|
|
|
|
</ol>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-02-13 12:21:02 +09:00
|
|
|
<div class="history" v-if="messages.length > 0">
|
2018-02-23 01:19:51 +09:00
|
|
|
<template>
|
2018-02-13 12:21:02 +09:00
|
|
|
<a v-for="message in messages"
|
|
|
|
class="user"
|
2018-04-09 19:52:17 +09:00
|
|
|
:href="`/i/messaging/${getAcct(isMe(message) ? message.recipient : message.user)}`"
|
2018-02-13 12:21:02 +09:00
|
|
|
:data-is-me="isMe(message)"
|
2018-03-29 14:48:47 +09:00
|
|
|
:data-is-read="message.isRead"
|
2018-02-23 01:19:51 +09:00
|
|
|
@click.prevent="navigate(isMe(message) ? message.recipient : message.user)"
|
2018-02-13 12:21:02 +09:00
|
|
|
:key="message.id"
|
|
|
|
>
|
2018-02-13 12:06:35 +09:00
|
|
|
<div>
|
2018-04-29 17:17:15 +09:00
|
|
|
<mk-avatar class="avatar" :user="isMe(message) ? message.recipient : message.user"/>
|
2018-02-13 12:06:35 +09:00
|
|
|
<header>
|
2018-12-07 11:29:49 +09:00
|
|
|
<span class="name"><mk-user-name :user="isMe(message) ? message.recipient : message.user"/></span>
|
2018-04-09 18:52:29 +09:00
|
|
|
<span class="username">@{{ isMe(message) ? message.recipient : message.user | acct }}</span>
|
2018-03-29 14:48:47 +09:00
|
|
|
<mk-time :time="message.createdAt"/>
|
2018-02-13 12:06:35 +09:00
|
|
|
</header>
|
|
|
|
<div class="body">
|
2018-11-09 03:44:35 +09:00
|
|
|
<p class="text"><span class="me" v-if="isMe(message)">{{ $t('you') }}:</span>{{ message.text }}</p>
|
2018-02-13 12:06:35 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
</div>
|
2018-11-09 03:44:35 +09:00
|
|
|
<p class="no-history" v-if="!fetching && messages.length == 0">{{ $t('no-history') }}</p>
|
2018-11-13 22:45:28 +09:00
|
|
|
<p class="fetching" v-if="fetching"><fa icon="spinner" pulse fixed-width/>{{ $t('@.loading') }}<mk-ellipsis/></p>
|
2018-02-13 12:06:35 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-11-09 03:44:35 +09:00
|
|
|
import i18n from '../../../i18n';
|
2018-07-07 19:19:00 +09:00
|
|
|
import getAcct from '../../../../../misc/acct/render';
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-11-09 03:44:35 +09:00
|
|
|
i18n: i18n('common/views/components/messaging.vue'),
|
2018-02-13 12:06:35 +09:00
|
|
|
props: {
|
|
|
|
compact: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2018-02-25 03:17:13 +09:00
|
|
|
},
|
|
|
|
headerTop: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
2018-02-13 12:06:35 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
|
|
|
moreFetching: false,
|
|
|
|
messages: [],
|
|
|
|
q: null,
|
|
|
|
result: [],
|
2018-10-07 11:06:17 +09:00
|
|
|
connection: null
|
2018-02-13 12:06:35 +09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2018-11-09 08:13:34 +09:00
|
|
|
this.connection = this.$root.stream.useSharedConnection('messagingIndex');
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
this.connection.on('message', this.onMessage);
|
|
|
|
this.connection.on('read', this.onRead);
|
|
|
|
|
2018-11-09 08:13:34 +09:00
|
|
|
this.$root.api('messaging/history').then(messages => {
|
2018-02-13 12:06:35 +09:00
|
|
|
this.messages = messages;
|
2018-02-19 23:37:09 +09:00
|
|
|
this.fetching = false;
|
2018-02-13 12:06:35 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2018-10-07 11:06:17 +09:00
|
|
|
this.connection.dispose();
|
2018-02-13 12:06:35 +09:00
|
|
|
},
|
|
|
|
methods: {
|
2018-04-09 19:52:17 +09:00
|
|
|
getAcct,
|
2018-02-13 12:06:35 +09:00
|
|
|
isMe(message) {
|
2018-05-27 13:49:09 +09:00
|
|
|
return message.userId == this.$store.state.i.id;
|
2018-02-13 12:06:35 +09:00
|
|
|
},
|
|
|
|
onMessage(message) {
|
|
|
|
this.messages = this.messages.filter(m => !(
|
2018-03-29 14:48:47 +09:00
|
|
|
(m.recipientId == message.recipientId && m.userId == message.userId) ||
|
|
|
|
(m.recipientId == message.userId && m.userId == message.recipientId)));
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
this.messages.unshift(message);
|
|
|
|
},
|
|
|
|
onRead(ids) {
|
2018-12-11 20:36:55 +09:00
|
|
|
for (const id of ids) {
|
2018-02-13 12:06:35 +09:00
|
|
|
const found = this.messages.find(m => m.id == id);
|
2018-03-29 14:48:47 +09:00
|
|
|
if (found) found.isRead = true;
|
2018-12-11 20:36:55 +09:00
|
|
|
}
|
2018-02-13 12:06:35 +09:00
|
|
|
},
|
|
|
|
search() {
|
|
|
|
if (this.q == '') {
|
|
|
|
this.result = [];
|
|
|
|
return;
|
|
|
|
}
|
2018-11-09 08:13:34 +09:00
|
|
|
this.$root.api('users/search', {
|
2018-02-13 12:06:35 +09:00
|
|
|
query: this.q,
|
2018-12-01 07:15:55 +09:00
|
|
|
localOnly: true,
|
2018-12-02 06:44:18 +09:00
|
|
|
limit: 10,
|
|
|
|
detail: false
|
2018-02-13 12:06:35 +09:00
|
|
|
}).then(users => {
|
2018-12-01 07:15:55 +09:00
|
|
|
this.result = users.filter(user => user.id != this.$store.state.i.id);
|
2018-02-13 12:06:35 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
navigate(user) {
|
|
|
|
this.$emit('navigate', user);
|
|
|
|
},
|
|
|
|
onSearchKeydown(e) {
|
|
|
|
switch (e.which) {
|
|
|
|
case 9: // [TAB]
|
|
|
|
case 40: // [↓]
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
(this.$refs.searchResult as any).childNodes[0].focus();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onSearchResultKeydown(i, e) {
|
2018-02-13 12:21:02 +09:00
|
|
|
const list = this.$refs.searchResult as any;
|
|
|
|
|
2018-02-13 12:06:35 +09:00
|
|
|
const cancel = () => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
};
|
2018-02-13 12:21:02 +09:00
|
|
|
|
2018-02-13 12:06:35 +09:00
|
|
|
switch (true) {
|
|
|
|
case e.which == 27: // [ESC]
|
|
|
|
cancel();
|
2018-02-13 12:21:02 +09:00
|
|
|
(this.$refs.search as any).focus();
|
2018-02-13 12:06:35 +09:00
|
|
|
break;
|
|
|
|
|
|
|
|
case e.which == 9 && e.shiftKey: // [TAB] + [Shift]
|
|
|
|
case e.which == 38: // [↑]
|
|
|
|
cancel();
|
2018-02-13 12:21:02 +09:00
|
|
|
(list.childNodes[i].previousElementSibling || list.childNodes[this.result.length - 1]).focus();
|
2018-02-13 12:06:35 +09:00
|
|
|
break;
|
|
|
|
|
|
|
|
case e.which == 9: // [TAB]
|
|
|
|
case e.which == 40: // [↓]
|
|
|
|
cancel();
|
2018-02-13 12:21:02 +09:00
|
|
|
(list.childNodes[i].nextElementSibling || list.childNodes[0]).focus();
|
2018-02-13 12:06:35 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-09-27 17:42:51 +09:00
|
|
|
.mk-messaging
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
&[data-compact]
|
|
|
|
font-size 0.8em
|
|
|
|
|
|
|
|
> .history
|
|
|
|
> a
|
|
|
|
&:last-child
|
|
|
|
border-bottom none
|
|
|
|
|
|
|
|
&:not([data-is-me]):not([data-is-read])
|
|
|
|
> div
|
|
|
|
background-image none
|
|
|
|
border-left solid 4px #3aa2dc
|
|
|
|
|
|
|
|
> div
|
|
|
|
padding 16px
|
|
|
|
|
|
|
|
> header
|
2018-02-17 03:01:00 +09:00
|
|
|
> .mk-time
|
2018-02-13 12:06:35 +09:00
|
|
|
font-size 1em
|
|
|
|
|
|
|
|
> .avatar
|
|
|
|
width 42px
|
|
|
|
height 42px
|
|
|
|
margin 0 12px 0 0
|
|
|
|
|
|
|
|
> .search
|
|
|
|
display block
|
|
|
|
position -webkit-sticky
|
|
|
|
position sticky
|
|
|
|
top 0
|
|
|
|
left 0
|
|
|
|
z-index 1
|
|
|
|
width 100%
|
2019-05-05 09:27:55 +09:00
|
|
|
box-shadow 0 0 2px rgba(#000, 0.2)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
> .form
|
2018-09-27 17:29:57 +09:00
|
|
|
background rgba(0, 0, 0, 0.02)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
> label
|
|
|
|
display block
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
left 8px
|
|
|
|
z-index 1
|
|
|
|
height 100%
|
|
|
|
width 38px
|
|
|
|
pointer-events none
|
|
|
|
|
2018-11-06 01:40:11 +09:00
|
|
|
> i
|
2018-02-13 12:06:35 +09:00
|
|
|
display block
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
right 0
|
|
|
|
bottom 0
|
|
|
|
left 0
|
|
|
|
width 1em
|
2018-09-27 17:29:57 +09:00
|
|
|
line-height 48px
|
2018-02-13 12:06:35 +09:00
|
|
|
margin auto
|
|
|
|
color #555
|
|
|
|
|
|
|
|
> input
|
|
|
|
margin 0
|
2018-09-27 17:29:57 +09:00
|
|
|
padding 0 0 0 42px
|
2018-02-13 12:06:35 +09:00
|
|
|
width 100%
|
|
|
|
font-size 1em
|
2018-09-27 17:29:57 +09:00
|
|
|
line-height 48px
|
|
|
|
color var(--faceText)
|
2018-02-13 12:06:35 +09:00
|
|
|
outline none
|
2018-09-27 17:29:57 +09:00
|
|
|
background transparent
|
|
|
|
border none
|
2018-02-13 12:06:35 +09:00
|
|
|
border-radius 5px
|
|
|
|
box-shadow none
|
|
|
|
|
|
|
|
> .result
|
|
|
|
display block
|
|
|
|
top 0
|
|
|
|
left 0
|
|
|
|
z-index 2
|
|
|
|
width 100%
|
|
|
|
margin 0
|
|
|
|
padding 0
|
|
|
|
background #fff
|
|
|
|
|
|
|
|
> .users
|
|
|
|
margin 0
|
|
|
|
padding 0
|
|
|
|
list-style none
|
|
|
|
|
|
|
|
> li
|
|
|
|
display inline-block
|
|
|
|
z-index 1
|
|
|
|
width 100%
|
|
|
|
padding 8px 32px
|
|
|
|
vertical-align top
|
|
|
|
white-space nowrap
|
|
|
|
overflow hidden
|
2018-04-29 08:51:17 +09:00
|
|
|
color rgba(#000, 0.8)
|
2018-02-13 12:06:35 +09:00
|
|
|
text-decoration none
|
|
|
|
transition none
|
|
|
|
cursor pointer
|
|
|
|
|
|
|
|
&:hover
|
|
|
|
&:focus
|
|
|
|
color #fff
|
2018-09-26 20:19:35 +09:00
|
|
|
background var(--primary)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
.name
|
|
|
|
color #fff
|
|
|
|
|
|
|
|
.username
|
|
|
|
color #fff
|
|
|
|
|
|
|
|
&:active
|
|
|
|
color #fff
|
2018-09-26 20:19:35 +09:00
|
|
|
background var(--primaryDarken10)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
.name
|
|
|
|
color #fff
|
|
|
|
|
|
|
|
.username
|
|
|
|
color #fff
|
|
|
|
|
|
|
|
.avatar
|
|
|
|
vertical-align middle
|
|
|
|
min-width 32px
|
|
|
|
min-height 32px
|
|
|
|
max-width 32px
|
|
|
|
max-height 32px
|
|
|
|
margin 0 8px 0 0
|
|
|
|
border-radius 6px
|
|
|
|
|
|
|
|
.name
|
|
|
|
margin 0 8px 0 0
|
|
|
|
/*font-weight bold*/
|
|
|
|
font-weight normal
|
2018-04-29 08:51:17 +09:00
|
|
|
color rgba(#000, 0.8)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
.username
|
|
|
|
font-weight normal
|
2018-04-29 08:51:17 +09:00
|
|
|
color rgba(#000, 0.3)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
> .history
|
|
|
|
|
|
|
|
> a
|
|
|
|
display block
|
|
|
|
text-decoration none
|
2018-09-26 20:28:13 +09:00
|
|
|
background var(--face)
|
2018-09-27 17:42:51 +09:00
|
|
|
border-bottom solid 1px var(--faceDivider)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
*
|
|
|
|
pointer-events none
|
|
|
|
user-select none
|
|
|
|
|
|
|
|
&:hover
|
2018-09-27 17:42:51 +09:00
|
|
|
box-shadow 0 0 0 100px inset rgba(0, 0, 0, 0.05)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
2018-09-27 17:42:51 +09:00
|
|
|
.avatar
|
2018-02-13 12:06:35 +09:00
|
|
|
filter saturate(200%)
|
|
|
|
|
|
|
|
&:active
|
2018-09-27 17:42:51 +09:00
|
|
|
box-shadow 0 0 0 100px inset rgba(0, 0, 0, 0.1)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
&[data-is-read]
|
|
|
|
&[data-is-me]
|
|
|
|
opacity 0.8
|
|
|
|
|
|
|
|
&:not([data-is-me]):not([data-is-read])
|
|
|
|
> div
|
|
|
|
background-image url("/assets/unread.svg")
|
|
|
|
background-repeat no-repeat
|
|
|
|
background-position 0 center
|
|
|
|
|
|
|
|
&:after
|
|
|
|
content ""
|
|
|
|
display block
|
|
|
|
clear both
|
|
|
|
|
|
|
|
> div
|
|
|
|
max-width 500px
|
|
|
|
margin 0 auto
|
|
|
|
padding 20px 30px
|
|
|
|
|
|
|
|
&:after
|
|
|
|
content ""
|
|
|
|
display block
|
|
|
|
clear both
|
|
|
|
|
|
|
|
> header
|
2018-03-03 16:27:07 +09:00
|
|
|
display flex
|
|
|
|
align-items center
|
2018-02-13 12:06:35 +09:00
|
|
|
margin-bottom 2px
|
|
|
|
white-space nowrap
|
2018-03-05 09:05:45 +09:00
|
|
|
overflow hidden
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
> .name
|
|
|
|
margin 0
|
|
|
|
padding 0
|
2018-03-03 16:27:07 +09:00
|
|
|
overflow hidden
|
|
|
|
text-overflow ellipsis
|
2018-02-13 12:06:35 +09:00
|
|
|
font-size 1em
|
2018-09-27 17:42:51 +09:00
|
|
|
color var(--noteHeaderName)
|
2018-02-13 12:06:35 +09:00
|
|
|
font-weight bold
|
|
|
|
transition all 0.1s ease
|
|
|
|
|
|
|
|
> .username
|
2018-03-03 17:01:41 +09:00
|
|
|
margin 0 8px
|
2018-09-27 17:42:51 +09:00
|
|
|
color var(--noteHeaderAcct)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
2018-02-17 03:01:00 +09:00
|
|
|
> .mk-time
|
2018-03-03 16:27:07 +09:00
|
|
|
margin 0 0 0 auto
|
2018-09-27 17:42:51 +09:00
|
|
|
color var(--noteHeaderInfo)
|
2018-02-13 12:06:35 +09:00
|
|
|
font-size 80%
|
|
|
|
|
|
|
|
> .avatar
|
|
|
|
float left
|
|
|
|
width 54px
|
|
|
|
height 54px
|
|
|
|
margin 0 16px 0 0
|
|
|
|
border-radius 8px
|
|
|
|
transition all 0.1s ease
|
|
|
|
|
|
|
|
> .body
|
|
|
|
|
|
|
|
> .text
|
|
|
|
display block
|
|
|
|
margin 0 0 0 0
|
|
|
|
padding 0
|
|
|
|
overflow hidden
|
|
|
|
overflow-wrap break-word
|
|
|
|
font-size 1.1em
|
2018-09-27 17:42:51 +09:00
|
|
|
color var(--faceText)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
.me
|
2018-09-27 17:42:51 +09:00
|
|
|
opacity 0.7
|
2018-02-13 12:06:35 +09:00
|
|
|
|
|
|
|
> .image
|
|
|
|
display block
|
|
|
|
max-width 100%
|
|
|
|
max-height 512px
|
|
|
|
|
|
|
|
> .no-history
|
|
|
|
margin 0
|
|
|
|
padding 2em 1em
|
|
|
|
text-align center
|
|
|
|
color #999
|
|
|
|
font-weight 500
|
|
|
|
|
|
|
|
> .fetching
|
|
|
|
margin 0
|
|
|
|
padding 16px
|
|
|
|
text-align center
|
2019-02-06 17:51:33 +09:00
|
|
|
color var(--text)
|
2018-02-13 12:06:35 +09:00
|
|
|
|
2018-11-06 01:40:11 +09:00
|
|
|
> [data-icon]
|
2018-02-13 12:06:35 +09:00
|
|
|
margin-right 4px
|
|
|
|
|
|
|
|
// TODO: element base media query
|
|
|
|
@media (max-width 400px)
|
|
|
|
> .search
|
|
|
|
> .result
|
|
|
|
> .users
|
|
|
|
> li
|
|
|
|
padding 8px 16px
|
|
|
|
|
|
|
|
> .history
|
|
|
|
> a
|
|
|
|
&:not([data-is-me]):not([data-is-read])
|
|
|
|
> div
|
|
|
|
background-image none
|
|
|
|
border-left solid 4px #3aa2dc
|
|
|
|
|
|
|
|
> div
|
|
|
|
padding 16px
|
|
|
|
font-size 14px
|
|
|
|
|
|
|
|
> .avatar
|
|
|
|
margin 0 12px 0 0
|
|
|
|
|
|
|
|
</style>
|