Fixed inbox id after add (#10609)

This commit is contained in:
Keith Holliday
2018-08-18 21:08:32 -05:00
committed by GitHub
parent 603fc8c4dd
commit d6514bce8b
4 changed files with 44 additions and 45 deletions

View File

@@ -14,23 +14,24 @@ div
p.time(v-b-tooltip="", :title="msg.timestamp | date") {{msg.timestamp | timeAgo}} p.time(v-b-tooltip="", :title="msg.timestamp | date") {{msg.timestamp | timeAgo}}
.text(v-markdown='msg.text') .text(v-markdown='msg.text')
hr hr
.action(@click='like()', v-if='!inbox && msg.likes', :class='{active: msg.likes[user._id]}') div(v-if='msg.id')
.svg-icon(v-html="icons.like") .action(@click='like()', v-if='!inbox && msg.likes', :class='{active: msg.likes[user._id]}')
span(v-if='!msg.likes[user._id]') {{ $t('like') }} .svg-icon(v-html="icons.like")
span(v-if='msg.likes[user._id]') {{ $t('liked') }} span(v-if='!msg.likes[user._id]') {{ $t('like') }}
span.action(v-if='!inbox', @click='copyAsTodo(msg)') span(v-if='msg.likes[user._id]') {{ $t('liked') }}
.svg-icon(v-html="icons.copy") span.action(v-if='!inbox', @click='copyAsTodo(msg)')
| {{$t('copyAsTodo')}} .svg-icon(v-html="icons.copy")
span.action(v-if='!inbox && user.flags.communityGuidelinesAccepted && msg.uuid !== "system"', @click='report(msg)') | {{$t('copyAsTodo')}}
.svg-icon(v-html="icons.report") span.action(v-if='!inbox && user.flags.communityGuidelinesAccepted && msg.uuid !== "system"', @click='report(msg)')
| {{$t('report')}} .svg-icon(v-html="icons.report")
// @TODO make flagging/reporting work in the inbox. NOTE: it must work even if the communityGuidelines are not accepted and it MUST work for messages that you have SENT as well as received. -- Alys | {{$t('report')}}
span.action(v-if='msg.uuid === user._id || inbox || user.contributor.admin', @click='remove()') // @TODO make flagging/reporting work in the inbox. NOTE: it must work even if the communityGuidelines are not accepted and it MUST work for messages that you have SENT as well as received. -- Alys
.svg-icon(v-html="icons.delete") span.action(v-if='msg.uuid === user._id || inbox || user.contributor.admin', @click='remove()')
| {{$t('delete')}} .svg-icon(v-html="icons.delete")
span.action.float-right.liked(v-if='likeCount > 0') | {{$t('delete')}}
.svg-icon(v-html="icons.liked") span.action.float-right.liked(v-if='likeCount > 0')
| + {{ likeCount }} .svg-icon(v-html="icons.liked")
| + {{ likeCount }}
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -7,11 +7,7 @@
.col-2 .col-2
.svg-icon.envelope(v-html="icons.messageIcon") .svg-icon.envelope(v-html="icons.messageIcon")
.col-6 .col-6
h2.text-center(v-once) {{$t('messages')}} h2.text-center(v-once) {{ $t('messages') }}
// @TODO: Implement this after we fix username bug
// .col-2.offset-1
// button.btn.btn-secondary(@click='toggleClick()') +
.col-4.offset-4
.svg-icon.close(v-html="icons.svgClose", @click='close()') .svg-icon.close(v-html="icons.svgClose", @click='close()')
toggle-switch.float-right( toggle-switch.float-right(
:label="optTextSet.switchDescription", :label="optTextSet.switchDescription",
@@ -19,9 +15,6 @@
:hoverText="optTextSet.popoverText", :hoverText="optTextSet.popoverText",
@change="toggleOpt()" @change="toggleOpt()"
) )
// .col-8.to-form(v-if='displayCreate')
// strong To:
// b-form-input
.row .row
.col-4.sidebar .col-4.sidebar
.search-section .search-section
@@ -48,9 +41,6 @@
.pm-disabled-caption.text-center(v-if="user.inbox.optOut && selectedConversation.key") .pm-disabled-caption.text-center(v-if="user.inbox.optOut && selectedConversation.key")
h4 {{$t('PMDisabledCaptionTitle')}} h4 {{$t('PMDisabledCaptionTitle')}}
p {{$t('PMDisabledCaptionText')}} p {{$t('PMDisabledCaptionText')}}
// @TODO: Implement new message header here when we fix the above
.new-message-row(v-if='selectedConversation.key && !user.flags.chatRevoked') .new-message-row(v-if='selectedConversation.key && !user.flags.chatRevoked')
textarea( textarea(
v-model='newMessage', v-model='newMessage',
@@ -211,6 +201,7 @@ import moment from 'moment';
import filter from 'lodash/filter'; import filter from 'lodash/filter';
import sortBy from 'lodash/sortBy'; import sortBy from 'lodash/sortBy';
import groupBy from 'lodash/groupBy'; import groupBy from 'lodash/groupBy';
import findIndex from 'lodash/findIndex';
import { mapState } from 'client/libs/store'; import { mapState } from 'client/libs/store';
import styleHelper from 'client/mixins/styleHelper'; import styleHelper from 'client/mixins/styleHelper';
import toggleSwitch from 'client/components/ui/toggleSwitch'; import toggleSwitch from 'client/components/ui/toggleSwitch';
@@ -386,15 +377,10 @@ export default {
sendPrivateMessage () { sendPrivateMessage () {
if (!this.newMessage) return; if (!this.newMessage) return;
let convoFound = this.conversations.find((conversation) => { const convoFound = this.conversations.find((conversation) => {
return conversation.key === this.selectedConversation.key; return conversation.key === this.selectedConversation.key;
}); });
this.$store.dispatch('members:sendPrivateMessage', {
toUserId: this.selectedConversation.key,
message: this.newMessage,
});
convoFound.messages.push({ convoFound.messages.push({
text: this.newMessage, text: this.newMessage,
timestamp: new Date(), timestamp: new Date(),
@@ -408,13 +394,22 @@ export default {
convoFound.lastMessageText = this.newMessage; convoFound.lastMessageText = this.newMessage;
convoFound.date = new Date(); convoFound.date = new Date();
this.newMessage = '';
Vue.nextTick(() => { Vue.nextTick(() => {
if (!this.$refs.chatscroll) return; if (!this.$refs.chatscroll) return;
let chatscroll = this.$refs.chatscroll.$el; let chatscroll = this.$refs.chatscroll.$el;
chatscroll.scrollTop = chatscroll.scrollHeight; chatscroll.scrollTop = chatscroll.scrollHeight;
}); });
this.$store.dispatch('members:sendPrivateMessage', {
toUserId: this.selectedConversation.key,
message: this.newMessage,
}).then(response => {
const newMessage = response.data.data.message;
const messageIndex = findIndex(convoFound.messages, msg => !msg.id);
convoFound.messages.splice(convoFound.messages.length - 1, messageIndex, newMessage);
});
this.newMessage = '';
}, },
close () { close () {
this.$root.$emit('bv::hide::modal', 'inbox-modal'); this.$root.$emit('bv::hide::modal', 'inbox-modal');

View File

@@ -478,25 +478,25 @@ api.sendPrivateMessage = {
req.checkBody('message', res.t('messageRequired')).notEmpty(); req.checkBody('message', res.t('messageRequired')).notEmpty();
req.checkBody('toUserId', res.t('toUserIDRequired')).notEmpty().isUUID(); req.checkBody('toUserId', res.t('toUserIDRequired')).notEmpty().isUUID();
let validationErrors = req.validationErrors(); const validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors; if (validationErrors) throw validationErrors;
let sender = res.locals.user; const sender = res.locals.user;
let message = req.body.message; const message = req.body.message;
let receiver = await User.findById(req.body.toUserId).exec(); const receiver = await User.findById(req.body.toUserId).exec();
if (!receiver) throw new NotFound(res.t('userNotFound')); if (!receiver) throw new NotFound(res.t('userNotFound'));
let objections = sender.getObjectionsToInteraction('send-private-message', receiver); const objections = sender.getObjectionsToInteraction('send-private-message', receiver);
if (objections.length > 0 && !sender.isAdmin()) throw new NotAuthorized(res.t(objections[0])); if (objections.length > 0 && !sender.isAdmin()) throw new NotAuthorized(res.t(objections[0]));
await sender.sendMessage(receiver, { receiverMsg: message }); const newMessage = await sender.sendMessage(receiver, { receiverMsg: message });
if (receiver.preferences.emailNotifications.newPM !== false) { if (receiver.preferences.emailNotifications.newPM !== false) {
sendTxnEmail(receiver, 'new-pm', [ sendTxnEmail(receiver, 'new-pm', [
{name: 'SENDER', content: getUserInfo(sender, ['name']).name}, {name: 'SENDER', content: getUserInfo(sender, ['name']).name},
]); ]);
} }
if (receiver.preferences.pushNotifications.newPM !== false) { if (receiver.preferences.pushNotifications.newPM !== false) {
sendPushNotification( sendPushNotification(
receiver, receiver,
@@ -510,7 +510,7 @@ api.sendPrivateMessage = {
); );
} }
res.respond(200, {}); res.respond(200, { message: newMessage });
}, },
}; };

View File

@@ -106,7 +106,8 @@ schema.methods.sendMessage = async function sendMessage (userToReceiveMessage, o
// whether to save users after sending the message, defaults to true // whether to save users after sending the message, defaults to true
let saveUsers = options.save === false ? false : true; let saveUsers = options.save === false ? false : true;
common.refPush(userToReceiveMessage.inbox.messages, chatDefaults(options.receiverMsg, sender)); const newMessage = chatDefaults(options.receiverMsg, sender);
common.refPush(userToReceiveMessage.inbox.messages, newMessage);
userToReceiveMessage.inbox.newMessages++; userToReceiveMessage.inbox.newMessages++;
userToReceiveMessage._v++; userToReceiveMessage._v++;
userToReceiveMessage.markModified('inbox.messages'); userToReceiveMessage.markModified('inbox.messages');
@@ -139,6 +140,8 @@ schema.methods.sendMessage = async function sendMessage (userToReceiveMessage, o
if (saveUsers) { if (saveUsers) {
await Promise.all([userToReceiveMessage.save(), sender.save()]); await Promise.all([userToReceiveMessage.save(), sender.save()]);
} }
return newMessage;
}; };
/** /**