Merge branch 'PM_opt-in-out' of https://github.com/pengfluf/habitica into pengfluf-PM_opt-in-out

This commit is contained in:
Matteo Pagliazzi
2018-05-25 12:44:44 +02:00
3 changed files with 91 additions and 14 deletions

View File

@@ -1,9 +1,9 @@
<template lang="pug"> <template lang="pug">
b-modal#inbox-modal(title="", :hide-footer="true", size='lg') b-modal#inbox-modal(title="", :hide-footer="true", size='lg')
.header-wrap.container(slot="modal-header") .header-wrap.container.align-items-center(slot="modal-header")
.row .row.align-items-center
.col-4 .col-4
.row .row.align-items-center
.col-2 .col-2
.svg-icon.envelope(v-html="icons.messageIcon") .svg-icon.envelope(v-html="icons.messageIcon")
.col-6 .col-6
@@ -13,6 +13,12 @@
// button.btn.btn-secondary(@click='toggleClick()') + // button.btn.btn-secondary(@click='toggleClick()') +
.col-4.offset-4 .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(
:label="optTextSet.switchDescription",
:checked="!this.user.inbox.optOut"
:hoverText="optTextSet.popoverText",
@change="toggleOpt()"
)
// .col-8.to-form(v-if='displayCreate') // .col-8.to-form(v-if='displayCreate')
// strong To: // strong To:
// b-form-input // b-form-input
@@ -31,14 +37,17 @@
span(:class="userLevelStyle(conversation)") {{conversation.name}} span(:class="userLevelStyle(conversation)") {{conversation.name}}
span.timeago {{conversation.date | timeAgo}} span.timeago {{conversation.date | timeAgo}}
div {{conversation.lastMessageText ? conversation.lastMessageText.substring(0, 30) : ''}} div {{conversation.lastMessageText ? conversation.lastMessageText.substring(0, 30) : ''}}
.col-8.messages .col-8.messages.d-flex.flex-column.justify-content-between
.empty-messages.text-center(v-if='activeChat.length === 0 && !selectedConversation.key') .empty-messages.text-center(v-if='activeChat.length === 0 && !selectedConversation.key')
.svg-icon.envelope(v-html="icons.messageIcon") .svg-icon.envelope(v-html="icons.messageIcon")
h4 {{placeholderTexts.title}} h4 {{placeholderTexts.title}}
p(v-html="placeholderTexts.description") p(v-html="placeholderTexts.description")
.empty-messages.text-center(v-if='activeChat.length === 0 && selectedConversation.key') .empty-messages.text-center(v-if='activeChat.length === 0 && selectedConversation.key')
p {{ $t('beginningOfConversation', {userName: selectedConversation.name})}} p {{ $t('beginningOfConversation', {userName: selectedConversation.name})}}
chat-message.message-scroll(:chat.sync='activeChat', :inbox='true', ref="chatscroll") chat-message.message-scroll(v-if="activeChat.length > 0", :chat.sync='activeChat', :inbox='true', ref="chatscroll")
.pm-disabled-caption.text-center(v-if="user.inbox.optOut && selectedConversation.key")
h4 {{$t('PMDisabledCaptionTitle')}}
p {{$t('PMDisabledCaptionText')}}
// @TODO: Implement new message header here when we fix the above // @TODO: Implement new message header here when we fix the above
@@ -50,18 +59,26 @@
<style lang="scss" scoped> <style lang="scss" scoped>
@import '~client/assets/scss/colors.scss'; @import '~client/assets/scss/colors.scss';
.header-wrap {
padding: 0.5em;
h2 {
margin: 0;
line-height: 1;
}
}
.envelope { .envelope {
color: $gray-400 !important; color: $gray-400 !important;
margin-top: 1em; margin: 0;
} }
.close { .close {
margin-top: .5em; margin-top: .5em;
width: 15px; width: 15px;
} position: absolute;
top: -1.9em;
h2 { right: 0.3em;
margin-top: .5em;
} }
.sidebar { .sidebar {
@@ -83,7 +100,12 @@
.message-scroll { .message-scroll {
max-height: 500px; max-height: 500px;
overflow: scroll; overflow-x: scroll;
@media (min-width: 992px) {
overflow-x: hidden;
overflow-y: scroll;
}
} }
.to-form input { .to-form input {
@@ -108,6 +130,27 @@
} }
} }
.pm-disabled-caption {
padding-top: 1em;
background-color: $gray-700;
z-index: 2;
h4, p {
color: $gray-300;
}
h4 {
margin-top: 0;
margin-bottom: 0.4em;
}
p {
font-size: 12px;
margin-bottom: 0;
}
}
.new-message-row { .new-message-row {
background-color: $gray-700; background-color: $gray-700;
position: absolute; position: absolute;
@@ -133,7 +176,8 @@
.conversations { .conversations {
max-height: 400px; max-height: 400px;
overflow: scroll; overflow-x: hidden;
overflow-y: scroll;
} }
.conversation { .conversation {
@@ -163,6 +207,7 @@ import sortBy from 'lodash/sortBy';
import groupBy from 'lodash/groupBy'; import groupBy from 'lodash/groupBy';
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 messageIcon from 'assets/svg/message.svg'; import messageIcon from 'assets/svg/message.svg';
import chatMessage from '../chat/chatMessages'; import chatMessage from '../chat/chatMessages';
@@ -172,6 +217,7 @@ export default {
mixins: [styleHelper], mixins: [styleHelper],
components: { components: {
chatMessage, chatMessage,
toggleSwitch,
}, },
mounted () { mounted () {
this.$root.$on('habitica::new-inbox-message', (data) => { this.$root.$on('habitica::new-inbox-message', (data) => {
@@ -211,6 +257,7 @@ export default {
search: '', search: '',
newMessage: '', newMessage: '',
activeChat: [], activeChat: [],
showPopover: false,
}; };
}, },
filters: { filters: {
@@ -287,11 +334,26 @@ export default {
description: this.$t('PMPlaceholderDescription'), description: this.$t('PMPlaceholderDescription'),
}; };
}, },
optTextSet () {
if (!this.user.inbox.optOut) {
return {
switchDescription: this.$t('PMDisable'),
popoverText: this.$t('PMEnabledOptPopoverText'),
};
}
return {
switchDescription: this.$t('PMEnable'),
popoverText: this.$t('PMDisabledOptPopoverText'),
};
},
}, },
methods: { methods: {
toggleClick () { toggleClick () {
this.displayCreate = !this.displayCreate; this.displayCreate = !this.displayCreate;
}, },
toggleOpt () {
this.$store.dispatch('user:togglePrivateMessagesOpt');
},
selectConversation (key) { selectConversation (key) {
let convoFound = this.conversations.find((conversation) => { let convoFound = this.conversations.find((conversation) => {
return conversation.key === key; return conversation.key === key;

View File

@@ -143,3 +143,13 @@ export async function rebirth () {
return result; return result;
} }
export async function togglePrivateMessagesOpt (store) {
let response = await axios.put('/api/v3/user',
{
'inbox.optOut': !store.state.user.data.inbox.optOut,
}
);
store.state.user.data.inbox.optOut = !store.state.user.data.inbox.optOut;
return response;
}

View File

@@ -128,15 +128,20 @@
"send": "Send", "send": "Send",
"messageSentAlert": "Message sent", "messageSentAlert": "Message sent",
"pmHeading": "Private message to <%= name %>", "pmHeading": "Private message to <%= name %>",
"pmsMarkedRead": "Your private messages have been marked as read", "pmsMarkedRead": "Your Private Messages have been marked as read",
"possessiveParty": "<%= name %>'s Party", "possessiveParty": "<%= name %>'s Party",
"clearAll": "Delete All Messages", "clearAll": "Delete All Messages",
"confirmDeleteAllMessages": "Are you sure you want to delete all messages in your inbox? Other users will still see messages you have sent to them.", "confirmDeleteAllMessages": "Are you sure you want to delete all messages in your inbox? Other users will still see messages you have sent to them.",
"optOutPopover": "Don't like private messages? Click to completely opt out",
"PMPlaceholderTitle": "Nothing Here Yet", "PMPlaceholderTitle": "Nothing Here Yet",
"PMPlaceholderDescription": "Select a conversation on the left", "PMPlaceholderDescription": "Select a conversation on the left",
"PMPlaceholderTitleRevoked": "Your chat privileges have been revoked", "PMPlaceholderTitleRevoked": "Your chat privileges have been revoked",
"PMPlaceholderDescriptionRevoked": "You are not able to send private messages because your chat privileges have been revoked. If you have questions or concerns about this, please email <a href=\"mailto:admin@habitica.com\">admin@habitica.com</a> to discuss it with the staff.", "PMPlaceholderDescriptionRevoked": "You are not able to send private messages because your chat privileges have been revoked. If you have questions or concerns about this, please email <a href=\"mailto:admin@habitica.com\">admin@habitica.com</a> to discuss it with the staff.",
"PMEnable": "Enable Private Messages",
"PMDisable": "Disable Private Messages",
"PMEnabledOptPopoverText": "When Private Messages are disabled, you still can send messages, but no one can send them to you.",
"PMDisabledOptPopoverText": "Enable this option to be able to receive messages.",
"PMDisabledCaptionTitle": "Private Messages are disabled",
"PMDisabledCaptionText": "You still can send messages, but no one can send them to you.",
"block": "Block", "block": "Block",
"unblock": "Un-block", "unblock": "Un-block",
"pm-reply": "Send a reply", "pm-reply": "Send a reply",