This reverts commit 5ea0436051
.
This commit is contained in:
parent
7e5ec7925c
commit
bc7bcc20b8
10 changed files with 24 additions and 202 deletions
|
@ -137,7 +137,6 @@ import messageFormatterMixin from 'shared/mixins/messageFormatterMixin';
|
|||
import { checkFileSizeLimit } from 'shared/helpers/FileHelper';
|
||||
import { MAXIMUM_FILE_UPLOAD_SIZE } from 'shared/constants/messages';
|
||||
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
||||
import { debounce } from 'shared/helpers/TimeHelpers';
|
||||
|
||||
import {
|
||||
isEscape,
|
||||
|
@ -150,8 +149,6 @@ import inboxMixin from 'shared/mixins/inboxMixin';
|
|||
import uiSettingsMixin from 'dashboard/mixins/uiSettings';
|
||||
import { DirectUpload } from 'activestorage';
|
||||
import { frontendURL } from '../../../helper/URLHelper';
|
||||
import { LocalStorage, LOCAL_STORAGE_KEYS } from '../../../helper/localStorage';
|
||||
import { trimMessage } from '../../../store/modules/conversations/helpers';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
|
@ -204,7 +201,6 @@ export default {
|
|||
hasSlashCommand: false,
|
||||
bccEmails: '',
|
||||
ccEmails: '',
|
||||
doAutoSaveDraft: () => {},
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -410,19 +406,10 @@ export default {
|
|||
profilePath() {
|
||||
return frontendURL(`accounts/${this.accountId}/profile/settings`);
|
||||
},
|
||||
conversationId() {
|
||||
return this.currentChat.id;
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
currentChat(conversation, oldConversation) {
|
||||
currentChat(conversation) {
|
||||
const { can_reply: canReply } = conversation;
|
||||
|
||||
if (oldConversation.id !== conversation.id) {
|
||||
this.setToDraft(oldConversation.id, this.replyType);
|
||||
this.getFromDraft();
|
||||
}
|
||||
|
||||
if (this.isOnPrivateNote) {
|
||||
return;
|
||||
}
|
||||
|
@ -447,87 +434,22 @@ export default {
|
|||
this.mentionSearchKey = '';
|
||||
this.showMentions = false;
|
||||
}
|
||||
this.doAutoSaveDraft();
|
||||
},
|
||||
replyType(updatedReplyType, oldReplyType) {
|
||||
this.setToDraft(this.conversationId, oldReplyType);
|
||||
this.getFromDraft();
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.getFromDraft();
|
||||
// Donot use the keyboard listener mixin here as the events here are supposed to be
|
||||
// working even if input/textarea is focussed.
|
||||
document.addEventListener('keydown', this.handleKeyEvents);
|
||||
document.addEventListener('paste', this.onPaste);
|
||||
|
||||
this.setCCEmailFromLastChat();
|
||||
this.doAutoSaveDraft = debounce(
|
||||
() => {
|
||||
this.saveDraft(this.conversationId, this.replyType);
|
||||
},
|
||||
5000,
|
||||
false
|
||||
);
|
||||
},
|
||||
destroyed() {
|
||||
document.removeEventListener('keydown', this.handleKeyEvents);
|
||||
document.removeEventListener('paste', this.onPaste);
|
||||
},
|
||||
methods: {
|
||||
getSavedDraftMessages() {
|
||||
return LocalStorage.get(LOCAL_STORAGE_KEYS.DRAFT_MESSAGES) || {};
|
||||
},
|
||||
saveDraft(conversationId, replyType) {
|
||||
if (this.message || this.message === '') {
|
||||
const savedDraftMessages = this.getSavedDraftMessages();
|
||||
const key = `draft-${conversationId}-${replyType}`;
|
||||
const draftToSave = trimMessage(this.message || '');
|
||||
const {
|
||||
[key]: currentDraft,
|
||||
...restOfDraftMessages
|
||||
} = savedDraftMessages;
|
||||
|
||||
const updatedDraftMessages = draftToSave
|
||||
? {
|
||||
...restOfDraftMessages,
|
||||
[key]: draftToSave,
|
||||
}
|
||||
: restOfDraftMessages;
|
||||
|
||||
LocalStorage.set(
|
||||
LOCAL_STORAGE_KEYS.DRAFT_MESSAGES,
|
||||
updatedDraftMessages
|
||||
);
|
||||
}
|
||||
},
|
||||
setToDraft(conversationId, replyType) {
|
||||
this.saveDraft(conversationId, replyType);
|
||||
this.message = '';
|
||||
},
|
||||
getFromDraft() {
|
||||
if (this.conversationId) {
|
||||
try {
|
||||
const key = `draft-${this.conversationId}-${this.replyType}`;
|
||||
const savedDraftMessages = this.getSavedDraftMessages();
|
||||
this.message = `${savedDraftMessages[key] || ''}`;
|
||||
} catch (error) {
|
||||
this.message = '';
|
||||
}
|
||||
}
|
||||
},
|
||||
removeFromDraft() {
|
||||
if (this.conversationId) {
|
||||
const key = `draft-${this.conversationId}-${this.replyType}`;
|
||||
const draftMessages = this.getSavedDraftMessages();
|
||||
const { [key]: toBeRemoved, ...updatedDraftMessages } = draftMessages;
|
||||
LocalStorage.set(
|
||||
LOCAL_STORAGE_KEYS.DRAFT_MESSAGES,
|
||||
updatedDraftMessages
|
||||
);
|
||||
}
|
||||
},
|
||||
onPaste(e) {
|
||||
const data = e.clipboardData.files;
|
||||
if (!this.showRichContentEditor && data.length !== 0) {
|
||||
|
@ -615,7 +537,6 @@ export default {
|
|||
messagePayload
|
||||
);
|
||||
bus.$emit(BUS_EVENTS.SCROLL_TO_MESSAGE);
|
||||
this.removeFromDraft();
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
error?.response?.data?.error ||
|
||||
|
@ -687,7 +608,6 @@ export default {
|
|||
},
|
||||
onBlur() {
|
||||
this.isFocused = false;
|
||||
this.saveDraft(this.conversationId, this.replyType);
|
||||
},
|
||||
onFocus() {
|
||||
this.isFocused = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue