Skip to content

Commit

Permalink
refactor(conversationsService): optimize functions, move error handli…
Browse files Browse the repository at this point in the history
…ng to store

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Feb 29, 2024
1 parent dc0edf8 commit 8d6e004
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 279 deletions.
10 changes: 7 additions & 3 deletions src/components/LeftSidebar/LeftSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,13 @@ export default {
},

async createConversation(name) {
const response = await createPrivateConversation(name)
const conversation = response.data.ocs.data
this.switchToConversation(conversation)
try {
const response = await createPrivateConversation(name)
const conversation = response.data.ocs.data
this.switchToConversation(conversation)
} catch (error) {
console.error('Error creating new private conversation: ', error)
}
},

async restoreNoteToSelfConversation() {
Expand Down
38 changes: 21 additions & 17 deletions src/components/NewConversationDialog/NewConversationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export default {
await this.createConversation(PRIVACY.PRIVATE)
}
} catch (exception) {
console.debug(exception)
console.error(exception)
this.isLoading = false
this.error = true
// Stop the execution of the method on exceptions.
Expand All @@ -321,7 +321,7 @@ export default {
listable: this.listable,
})
} catch (exception) {
console.debug(exception)
console.error(exception)
this.isLoading = false
this.error = true
// Stop the execution of the method on exceptions.
Expand All @@ -332,7 +332,7 @@ export default {
try {
await addParticipant(this.newConversation.token, participant.id, participant.source)
} catch (exception) {
console.debug(exception)
console.error(exception)
this.isLoading = false
this.error = true
// Stop the execution of the method on exceptions.
Expand Down Expand Up @@ -360,20 +360,24 @@ export default {
* @param {number} flag choose to send a request with private or public flag
*/
async createConversation(flag) {
let response
if (flag === PRIVACY.PRIVATE) {
response = await createPrivateConversation(this.conversationName)
} else if (flag === PRIVACY.PUBLIC) {
response = await createPublicConversation(this.conversationName)
}
const conversation = response.data.ocs.data
this.$store.dispatch('addConversation', conversation)
this.newConversation.token = conversation.token
if (this.isAvatarEdited) {
this.$refs.setupPage.$refs.conversationAvatar.saveAvatar()
}
if (this.newConversation.description) {
this.handleUpdateDescription()
try {
let response
if (flag === PRIVACY.PRIVATE) {
response = await createPrivateConversation(this.conversationName)
} else if (flag === PRIVACY.PUBLIC) {
response = await createPublicConversation(this.conversationName)
}
const conversation = response.data.ocs.data
this.$store.dispatch('addConversation', conversation)
this.newConversation.token = conversation.token
if (this.isAvatarEdited) {
this.$refs.setupPage.$refs.conversationAvatar.saveAvatar()
}
if (this.newConversation.description) {
this.handleUpdateDescription()
}
} catch (error) {
console.error('Error creating new conversation: ', error)
}
},
pushNewRoute() {
Expand Down
Loading

0 comments on commit 8d6e004

Please sign in to comment.