Added avatars to chat (#8949)

This commit is contained in:
Keith Holliday
2017-08-14 15:44:09 -06:00
committed by GitHub
parent eb43f83c71
commit bd19b83db4
2 changed files with 45 additions and 14 deletions

View File

@@ -1,19 +1,20 @@
<template lang="pug"> <template lang="pug">
div .container
.row
.col-12
copy-as-todo-modal(:copying-message='copyingMessage', :group-name='groupName', :group-id='groupId') copy-as-todo-modal(:copying-message='copyingMessage', :group-name='groupName', :group-id='groupId')
report-flag-modal report-flag-modal
.row .row
// .col-md-2 .hr.col-12
// @TODO: Implement when we pull avatars .svg-icon(v-html="icons.like")
.hr .row(v-for="(msg, index) in chat", v-if='chat && Object.keys(cachedProfileData).length > 0')
.col-md-12(v-for="(msg, index) in chat", v-if='chat')
// @TODO: is there a different way to do these conditionals? This creates an infinite loop // @TODO: is there a different way to do these conditionals? This creates an infinite loop
//.hr(v-if='displayDivider(msg)') //.hr(v-if='displayDivider(msg)')
.hr-middle(v-once) {{ msg.timestamp }} .hr-middle(v-once) {{ msg.timestamp }}
.col-2
avatar(v-if='cachedProfileData[msg.uuid]', :member="cachedProfileData[msg.uuid]", :avatarOnly="true")
.card .card.col-10
.card-block .card-block
h3.leader {{msg.user}} h3.leader {{msg.user}}
p {{msg.timestamp | timeAgo}} p {{msg.timestamp | timeAgo}}
@@ -94,10 +95,13 @@ div
</style> </style>
<script> <script>
import axios from 'axios';
import Bluebird from 'bluebird';
import moment from 'moment'; import moment from 'moment';
import cloneDeep from 'lodash/cloneDeep'; import cloneDeep from 'lodash/cloneDeep';
import { mapState } from 'client/libs/store'; import { mapState } from 'client/libs/store';
import markdownDirective from 'client/directives/markdown'; import markdownDirective from 'client/directives/markdown';
import Avatar from '../avatar';
import copyAsTodoModal from './copyAsTodoModal'; import copyAsTodoModal from './copyAsTodoModal';
import reportFlagModal from './reportFlagModal'; import reportFlagModal from './reportFlagModal';
@@ -113,10 +117,14 @@ export default {
components: { components: {
copyAsTodoModal, copyAsTodoModal,
reportFlagModal, reportFlagModal,
Avatar,
}, },
directives: { directives: {
markdown: markdownDirective, markdown: markdownDirective,
}, },
mounted () {
this.loadProfileCache();
},
data () { data () {
return { return {
icons: Object.freeze({ icons: Object.freeze({
@@ -128,6 +136,7 @@ export default {
}), }),
copyingMessage: {}, copyingMessage: {},
currentDayDividerDisplay: moment().day(), currentDayDividerDisplay: moment().day(),
cachedProfileData: {},
}; };
}, },
filters: { filters: {
@@ -145,7 +154,29 @@ export default {
return this.chat; return this.chat;
}, },
}, },
watch: {
messages () {
// @TODO: MAybe we should watch insert and remove?
this.loadProfileCache();
},
},
methods: { methods: {
async loadProfileCache () {
let promises = [];
this.messages.forEach(message => {
let uuid = message.uuid;
if (!this.cachedProfileData[uuid]) {
promises.push(axios.get(`/api/v3/members/${uuid}`));
}
});
let results = await Bluebird.all(promises);
results.forEach(result => {
let userData = result.data.data;
this.$set(this.cachedProfileData, userData._id, userData);
});
},
displayDivider (message) { displayDivider (message) {
if (this.currentDayDividerDisplay !== moment(message.timestamp).day()) { if (this.currentDayDividerDisplay !== moment(message.timestamp).day()) {
this.currentDayDividerDisplay = moment(message.timestamp).day(); this.currentDayDividerDisplay = moment(message.timestamp).day();

View File

@@ -31,7 +31,7 @@
autocomplete(:text='newMessage', v-on:select="selectedAutocomplete", :coords='coords', :groupId='groupId') autocomplete(:text='newMessage', v-on:select="selectedAutocomplete", :coords='coords', :groupId='groupId')
button.btn.btn-secondary.send-chat.float-right(v-once, @click='sendMessage()') {{ $t('send') }} button.btn.btn-secondary.send-chat.float-right(v-once, @click='sendMessage()') {{ $t('send') }}
button.btn.btn-secondary.float-left(v-once, @click='fetchRecentMessages()') {{ $t('fetchRecentMessages') }} button.btn.btn-secondary.float-left(v-once, @click='fetchRecentMessages()') {{ $t('fetchRecentMessages') }}
.col-12
chat-message(:chat.sync='group.chat', :group-id='group._id', group-name='group.name') chat-message(:chat.sync='group.chat', :group-id='group._id', group-name='group.name')
.col-4.sidebar .col-4.sidebar