Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(chat): remove unnecessary code and fix intellisense #3072

Merged
merged 2 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion components/views/chat/chatbar/Chatbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<div class="control-wrap file-upload-wrap">
<FilesUpload
v-if="recipient"
:editable="recipient ? true : false"
:recipient="recipient"
type="quick"
ref="file-upload"
Expand Down
51 changes: 16 additions & 35 deletions components/views/chat/chatbar/Chatbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ import { Config } from '~/config'
import { Peer2Peer } from '~/libraries/WebRTC/Libp2p'
import { UploadDropItemType } from '~/types/files/file'

declare module 'vue/types/vue' {
interface Vue {
sendMessage: Function
text: string
updateText: Function
handleUpload: Function
throttleTyping: Function
typingNotifHandler: Function
smartTypingStart: Function
clearChatbar: Function
handleChatBorderRadius: Function
files: UploadDropItemType[]
onRecipientChangeResetUploadState: Function
}
}
export default Vue.extend({
components: {
TerminalIcon,
Expand All @@ -58,19 +43,16 @@ export default Vue.extend({
computed: {
...mapState(['ui', 'friends', 'webrtc', 'chat', 'textile']),
...mapGetters('chat', ['getFiles']),
activeFriend() {
activeFriend(): Friend | undefined {
return this.$Hounddog.getActiveFriend(this.friends)
},
/**
* Computes the amount of characters left
*/
/**
* @method charlimit DocsTODO
* @description Checks if current text is longer than the max character limit
* @returns Boolean based on if the current text length is longer than the max character limit
* @example
*/
charlimit() {
charlimit(): boolean {
return this.text.length > this.$Config.chat.maxChars
},
/**
Expand All @@ -79,7 +61,7 @@ export default Vue.extend({
* @returns
* @example
*/
hasCommand() {
hasCommand(): boolean {
const parsedCommand = parseCommand(this.ui.chatbarContent)
const currentCommand = commands.find(
(cmd) => cmd.name === parsedCommand.name.toLowerCase(),
Expand All @@ -94,7 +76,7 @@ export default Vue.extend({
* @returns
* @example
*/
commandPreview() {
commandPreview(): boolean {
// Hide commands for early access
// return hasCommandPreview(this.ui.chatbarContent)
return false
Expand All @@ -105,7 +87,7 @@ export default Vue.extend({
* @returns
* @example
*/
isValidCommand() {
isValidCommand(): boolean {
const currentText = parseCommand(
this.ui.chatbarContent,
).name.toLowerCase()
Expand All @@ -122,7 +104,7 @@ export default Vue.extend({
* @returns String of chatbars current text
* @example const currText = this.get()
*/
get() {
get(): string {
return this.ui.chatbarContent
},
/**
Expand All @@ -134,23 +116,22 @@ export default Vue.extend({
set(value: string) {
this.$store.dispatch('ui/setChatbarContent', {
content: value,
userId: this.$props.recipient?.address,
userId: this.recipient?.address,
})
},
},
placeholder() {
if (!this.hasCommand && this.$data.text === '') {
return this.$t('ui.talk')
}
return ''
placeholder(): string {
return !this.hasCommand && this.text === ''
? (this.$t('ui.talk') as string)
: ''
},
},
watch: {
'friends.all': {
handler() {
const activeFriend = this.$Hounddog.getActiveFriend(this.friends)
if (activeFriend)
this.$data.recipientTyping =
this.recipientTyping =
activeFriend.typingState === PropCommonEnum.TYPING
},
deep: true,
Expand Down Expand Up @@ -184,13 +165,13 @@ export default Vue.extend({
mutation.type === 'chat/setFiles'
) {
if (this.recipient) {
this.$data.files = this.getFiles(this.recipient?.address)
this.files = this.getFiles(this.recipient?.address)
}
}

if (mutation.type === 'chat/deleteFiles') {
if (this.recipient) {
this.$data.files = []
this.files = []
}
}
})
Expand Down Expand Up @@ -335,7 +316,7 @@ export default Vue.extend({
text: value,
})
}
this.$data.nsfwUploadError = false
this.nsfwUploadError = false
}
},
/**
Expand Down Expand Up @@ -384,7 +365,7 @@ export default Vue.extend({
this.$store.commit('chat/setCountError', false)
},
onRecipientChangeResetUploadState(recipient: string) {
this.$data.files = this.getFiles(recipient)
this.files = this.getFiles(recipient)
this.$store.commit('chat/setContainsNsfw', false)
this.$store.commit('chat/setCountError', false)
this.$store.commit('chat/setAlertNsfw', false)
Expand Down
4 changes: 2 additions & 2 deletions components/views/files/upload/Upload.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div id="file-upload">
<input
:type="editable ? `file` : `hidden`"
:type="recipient ? `file` : `hidden`"
id="quick-upload"
ref="quickUpload"
@change="handleFile"
Expand All @@ -10,7 +10,7 @@
v-if="type == 'quick'"
@click="handleFileClick"
:data-tooltip="$t('global.upload')"
:class="`has-tooltip has-tooltip-top has-tooltip-primary upload-label ${editable ? 'active' : 'inactive'}`"
:class="`has-tooltip has-tooltip-top has-tooltip-primary upload-label ${recipient ? 'active' : 'inactive'}`"
>
<plus-icon size="1.2x" class="control-icon" />
</label>
Expand Down
18 changes: 6 additions & 12 deletions components/views/files/upload/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isHeic } from '~/utilities/FileType'
import { UploadDropItemType } from '~/types/files/file'
import { Friend } from '~/types/ui/friends'
import { SettingsRoutes } from '~/store/ui/types'
import { RootState } from '~/types/store/store'
const converter = require('heic-convert')

export default Vue.extend({
Expand All @@ -22,9 +23,6 @@ export default Vue.extend({
type: String,
default: '',
},
editable: {
type: Boolean,
},
recipient: {
type: Object as PropType<Friend>,
default: null,
Expand All @@ -36,17 +34,13 @@ export default Vue.extend({
},
data() {
return {
progress: 0,
ipfsHash: false,
selectedFile: false,
imageURL: '',
fileClass: false,
aiScanning: false,
fileAmount: 0,
}
},
computed: {
...mapState(['settings']),
...mapState({
consentScan: (state) => (state as RootState).settings.consentScan,
}),
activeFriend(): Friend | undefined {
return this.$Hounddog.getActiveFriend(this.$store.state.friends)
},
Expand All @@ -63,7 +57,7 @@ export default Vue.extend({
},
handleFileClick() {
this.resetFileUpload()
if (!this.settings.consentScan) {
if (!this.consentScan) {
this.$toast.error(
this.$t('pages.files.errors.enable_consent') as string,
{
Expand Down Expand Up @@ -91,7 +85,7 @@ export default Vue.extend({
async handleFile(event: any) {
this.$store.dispatch('textile/clearUploadStatus')
this.$store.dispatch('ui/setChatbarFocus')
if (this.editable) {
if (this.recipient) {
const newFiles: File[] = [...event.target.files]

if (newFiles.length + this.files.length > 8) {
Expand Down