[Client] Implement more messages fetching of messaging
This commit is contained in:
parent
c7af2bc885
commit
0039f42a09
|
@ -45,6 +45,8 @@ common:
|
||||||
|
|
||||||
mk-messaging-room:
|
mk-messaging-room:
|
||||||
empty: "No conversations"
|
empty: "No conversations"
|
||||||
|
more: "More"
|
||||||
|
no-history: "There is no more history"
|
||||||
resize-form: "Drag to resize"
|
resize-form: "Drag to resize"
|
||||||
new-message: "New message"
|
new-message: "New message"
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ common:
|
||||||
|
|
||||||
mk-messaging-room:
|
mk-messaging-room:
|
||||||
empty: "このユーザーと話したことはありません"
|
empty: "このユーザーと話したことはありません"
|
||||||
|
more: "もっと読む"
|
||||||
|
no-history: "これより過去の履歴はありません"
|
||||||
resize-form: "ドラッグしてフォームの広さを調整"
|
resize-form: "ドラッグしてフォームの広さを調整"
|
||||||
new-message: "新しいメッセージがあります"
|
new-message: "新しいメッセージがあります"
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
<div class="stream">
|
<div class="stream">
|
||||||
<p class="init" if={ init }><i class="fa fa-spinner fa-spin"></i>%i18n:common.loading%</p>
|
<p class="init" if={ init }><i class="fa fa-spinner fa-spin"></i>%i18n:common.loading%</p>
|
||||||
<p class="empty" if={ !init && messages.length == 0 }><i class="fa fa-info-circle"></i>%i18n:common.tags.mk-messaging-room.empty%</p>
|
<p class="empty" if={ !init && messages.length == 0 }><i class="fa fa-info-circle"></i>%i18n:common.tags.mk-messaging-room.empty%</p>
|
||||||
|
<p class="no-history" if={ !init && messages.length > 0 && !moreMessagesIsInStock }><i class="fa fa-flag"></i>%i18n:common.tags.mk-messaging-room.no-history%</p>
|
||||||
|
<button class="more { fetching: fetchingMoreMessages }" if={ moreMessagesIsInStock } onclick={ fetchMoreMessages } disabled={ fetchingMoreMessages }>
|
||||||
|
<i class="fa fa-spinner fa-pulse fa-fw" if={ fetchingMoreMessages }></i>{ fetchingMoreMessages ? '%i18n:common.loading%' : '%i18n:common.tags.mk-messaging-room.more%' }
|
||||||
|
</button>
|
||||||
<virtual each={ message, i in messages }>
|
<virtual each={ message, i in messages }>
|
||||||
<mk-messaging-message message={ message }/>
|
<mk-messaging-message message={ message }/>
|
||||||
<p class="date" if={ i != messages.length - 1 && message._date != messages[i + 1]._date }><span>{ messages[i + 1]._datetext }</span></p>
|
<p class="date" if={ i != messages.length - 1 && message._date != messages[i + 1]._date }><span>{ messages[i + 1]._datetext }</span></p>
|
||||||
|
@ -42,6 +46,27 @@
|
||||||
i
|
i
|
||||||
margin-right 4px
|
margin-right 4px
|
||||||
|
|
||||||
|
> .more
|
||||||
|
display block
|
||||||
|
margin 16px auto
|
||||||
|
padding 0 12px
|
||||||
|
line-height 24px
|
||||||
|
color #fff
|
||||||
|
background rgba(0, 0, 0, 0.3)
|
||||||
|
border-radius 12px
|
||||||
|
|
||||||
|
&:hover
|
||||||
|
background rgba(0, 0, 0, 0.4)
|
||||||
|
|
||||||
|
&:active
|
||||||
|
background rgba(0, 0, 0, 0.5)
|
||||||
|
|
||||||
|
&.fetching
|
||||||
|
cursor wait
|
||||||
|
|
||||||
|
> i
|
||||||
|
margin-right 4px
|
||||||
|
|
||||||
> .message
|
> .message
|
||||||
// something
|
// something
|
||||||
|
|
||||||
|
@ -142,11 +167,8 @@
|
||||||
|
|
||||||
document.addEventListener('visibilitychange', this.onVisibilitychange);
|
document.addEventListener('visibilitychange', this.onVisibilitychange);
|
||||||
|
|
||||||
this.api('messaging/messages', {
|
this.fetchMessages().then(() => {
|
||||||
user_id: this.user.id
|
|
||||||
}).then(messages => {
|
|
||||||
this.init = false;
|
this.init = false;
|
||||||
this.messages = messages.reverse();
|
|
||||||
this.update();
|
this.update();
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
});
|
});
|
||||||
|
@ -201,6 +223,39 @@
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.fetchMoreMessages = () => {
|
||||||
|
this.update({
|
||||||
|
fetchingMoreMessages: true
|
||||||
|
});
|
||||||
|
this.fetchMessages().then(() => {
|
||||||
|
this.update({
|
||||||
|
fetchingMoreMessages: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.fetchMessages = () => new Promise((resolve, reject) => {
|
||||||
|
const max = this.moreMessagesIsInStock ? 20 : 10;
|
||||||
|
|
||||||
|
this.api('messaging/messages', {
|
||||||
|
user_id: this.user.id,
|
||||||
|
limit: max + 1,
|
||||||
|
max_id: this.moreMessagesIsInStock ? this.messages[0].id : undefined
|
||||||
|
}).then(messages => {
|
||||||
|
if (messages.length == max + 1) {
|
||||||
|
this.moreMessagesIsInStock = true;
|
||||||
|
messages.pop();
|
||||||
|
} else {
|
||||||
|
this.moreMessagesIsInStock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.messages.unshift.apply(this.messages, messages.reverse());
|
||||||
|
this.update();
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
this.isBottom = () => {
|
this.isBottom = () => {
|
||||||
const asobi = 32;
|
const asobi = 32;
|
||||||
const current = this.isNaked
|
const current = this.isNaked
|
||||||
|
|
Loading…
Reference in New Issue