This commit is contained in:
eugenijm 2020-05-11 17:04:28 +03:00
parent 5fdb5c554d
commit d48b7a7d58
3 changed files with 17 additions and 5 deletions

View file

@ -1,4 +1,4 @@
import { throttle } from 'lodash' import _ from 'lodash'
import { mapGetters, mapState } from 'vuex' import { mapGetters, mapState } from 'vuex'
import ChatMessage from '../chat_message/chat_message.vue' import ChatMessage from '../chat_message/chat_message.vue'
import ChatAvatar from '../chat_avatar/chat_avatar.vue' import ChatAvatar from '../chat_avatar/chat_avatar.vue'
@ -78,7 +78,8 @@ const Chat = {
...mapState({ ...mapState({
backendInteractor: state => state.api.backendInteractor, backendInteractor: state => state.api.backendInteractor,
currentUser: state => state.users.currentUser, currentUser: state => state.users.currentUser,
isMobileLayout: state => state.interface.mobileLayout isMobileLayout: state => state.interface.mobileLayout,
openedChats: state => state.chats.openedChats
}) })
}, },
watch: { watch: {
@ -288,7 +289,9 @@ const Chat = {
return res return res
}, },
handleScroll: throttle(function () { handleScroll: _.throttle(function () {
if (!this.currentChat) { return }
if (this.reachedTop(0)) { if (this.reachedTop(0)) {
this.fetchChat(false, this.currentChat.id, { this.fetchChat(false, this.currentChat.id, {
maxId: this.currentChatMessageService.minId maxId: this.currentChatMessageService.minId
@ -351,12 +354,19 @@ const Chat = {
}) })
}, },
readChat () { readChat () {
if (!this.currentChat.id) { return } if (!(this.currentChat && this.currentChat.id)) { return }
this.$store.dispatch('readChat', { id: this.currentChat.id }) this.$store.dispatch('readChat', { id: this.currentChat.id })
this.newMessageCount = this.currentChatMessageService.newMessageCount this.newMessageCount = this.currentChatMessageService.newMessageCount
}, },
async startFetching () { async startFetching () {
const chat = await this.backendInteractor.getOrCreateChat({ accountId: this.recipientId }) let chat = _.find(this.openedChats, c => c.account.id === this.recipientId)
if (!chat) {
chat = await this.backendInteractor.getOrCreateChat({ accountId: this.recipientId })
}
this.$nextTick(() => {
this.scrollDown({ forceRead: true })
})
this.$store.dispatch('addOpenedChat', { chat }) this.$store.dispatch('addOpenedChat', { chat })
this.doStartFetching() this.doStartFetching()
}, },

View file

@ -45,6 +45,7 @@
position: sticky; position: sticky;
.button-icon { .button-icon {
cursor: pointer;
display: flex; display: flex;
align-content: center; align-content: center;
align-items: center; align-items: center;

View file

@ -176,6 +176,7 @@ export const parseUser = (data) => {
output.deactivated = data.pleroma.deactivated output.deactivated = data.pleroma.deactivated
output.notification_settings = data.pleroma.notification_settings output.notification_settings = data.pleroma.notification_settings
output.unread_chat_count = data.pleroma.unread_chat_count
} }
output.tags = output.tags || [] output.tags = output.tags || []