Skip to content

Commit c7ecb3c

Browse files
committed
(refacto) replace methods by computed
1 parent 34cabda commit c7ecb3c

File tree

1 file changed

+38
-40
lines changed

1 file changed

+38
-40
lines changed

src/ChatWindow/RoomsList/RoomContent.vue

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
room.lastMessage && room.lastMessage.new && !typingUsers
2828
}"
2929
>
30-
<span v-if="isMessageCheckmarkVisible(room)">
30+
<span v-if="isMessageCheckmarkVisible">
3131
<slot name="checkmark-icon" v-bind="room.lastMessage">
3232
<svg-icon
3333
:name="
@@ -52,11 +52,11 @@
5252
<slot name="microphone-icon">
5353
<svg-icon name="microphone" class="vac-icon-microphone" />
5454
</slot>
55-
{{ formattedDuration(room.lastMessage.file.duration) }}
55+
{{ formattedDuration }}
5656
</div>
5757
<format-message
5858
v-else-if="room.lastMessage"
59-
:content="getLastMessage(room)"
59+
:content="getLastMessage"
6060
:deleted="!!room.lastMessage.deleted && !typingUsers"
6161
:users="room.users"
6262
:linkify="false"
@@ -97,7 +97,7 @@
9797
<div v-for="action in roomActions" :key="action.name">
9898
<div
9999
class="vac-menu-item"
100-
@click.stop="roomActionHandler(action, room)"
100+
@click.stop="roomActionHandler(action)"
101101
>
102102
{{ action.title }}
103103
</div>
@@ -147,64 +147,62 @@ export default {
147147
},
148148
149149
computed: {
150-
userStatus() {
151-
if (!this.room.users || this.room.users.length !== 2) return
152-
153-
const user = this.room.users.find(u => u._id !== this.currentUserId)
154-
if (user.status) return user.status.state
155-
156-
return null
157-
},
158-
typingUsers() {
159-
return typingText(this.room, this.currentUserId, this.textMessages)
160-
}
161-
},
162-
163-
watch: {},
164-
165-
methods: {
166-
getLastMessage(room) {
150+
getLastMessage() {
167151
const isTyping = this.typingUsers
168152
if (isTyping) return isTyping
169153
170-
const content = room.lastMessage.deleted
154+
const content = this.room.lastMessage.deleted
171155
? this.textMessages.MESSAGE_DELETED
172-
: room.lastMessage.content
156+
: this.room.lastMessage.content
173157
174-
if (room.users.length <= 2) {
158+
if (this.room.users.length <= 2) {
175159
return content
176160
}
177161
178-
const user = room.users.find(
179-
user => user._id === room.lastMessage.sender_id
162+
const user = this.room.users.find(
163+
user => user._id === this.room.lastMessage.sender_id
180164
)
181165
182-
if (room.lastMessage.username) {
183-
return `${room.lastMessage.username} - ${content}`
166+
if (this.room.lastMessage.username) {
167+
return `${this.room.lastMessage.username} - ${content}`
184168
} else if (!user || user._id === this.currentUserId) {
185169
return content
186170
}
187171
188172
return `${user.username} - ${content}`
189173
},
190-
formattedDuration(s) {
191-
s = Math.round(s)
192-
return (s - (s %= 60)) / 60 + (s > 9 ? ':' : ':0') + s
174+
userStatus() {
175+
if (!this.room.users || this.room.users.length !== 2) return
176+
177+
const user = this.room.users.find(u => u._id !== this.currentUserId)
178+
if (user.status) return user.status.state
179+
180+
return null
193181
},
194-
isMessageCheckmarkVisible(room) {
182+
typingUsers() {
183+
return typingText(this.room, this.currentUserId, this.textMessages)
184+
},
185+
isMessageCheckmarkVisible() {
195186
return (
196187
!this.typingUsers &&
197-
room.lastMessage &&
198-
!room.lastMessage.deleted &&
199-
room.lastMessage.sender_id === this.currentUserId &&
200-
(room.lastMessage.saved ||
201-
room.lastMessage.distributed ||
202-
room.lastMessage.seen)
188+
this.room.lastMessage &&
189+
!this.room.lastMessage.deleted &&
190+
this.room.lastMessage.sender_id === this.currentUserId &&
191+
(this.room.lastMessage.saved ||
192+
this.room.lastMessage.distributed ||
193+
this.room.lastMessage.seen)
203194
)
204195
},
205-
roomActionHandler(action, room) {
196+
formattedDuration() {
197+
let s = Math.round(this.room.lastMessage.file.duration)
198+
return (s - (s %= 60)) / 60 + (s > 9 ? ':' : ':0') + s
199+
}
200+
},
201+
202+
methods: {
203+
roomActionHandler(action) {
206204
this.closeRoomMenu()
207-
this.$emit('room-action-handler', { action, roomId: room.roomId })
205+
this.$emit('room-action-handler', { action, roomId: this.room.roomId })
208206
},
209207
closeRoomMenu() {
210208
this.roomMenuOpened = null

0 commit comments

Comments
 (0)