|
113 | 113 | <template #list> |
114 | 114 | <li ref="container" class="left-sidebar__list" @scroll="debounceHandleScroll"> |
115 | 115 | <ul class="scroller"> |
116 | | - <NcListItem v-if="noMatchFound && searchText && canStartConversations" |
117 | | - :title="t('spreed', 'Create a new conversation')" |
118 | | - @click="createConversation(searchText)"> |
119 | | - <template #icon> |
120 | | - <ChatPlus :size="30" /> |
121 | | - </template> |
122 | | - <template #subtitle> |
123 | | - {{ searchText }} |
124 | | - </template> |
125 | | - </NcListItem> |
126 | | - |
127 | | - <NcAppNavigationCaption :class="{'hidden-visually': !isSearching}" |
128 | | - :title="t('spreed', 'Conversations')" /> |
129 | | - <Conversation v-for="item of conversationsList" |
130 | | - :key="item.id" |
131 | | - :ref="`conversation-${item.token}`" |
132 | | - :item="item" /> |
133 | | - <template v-if="!initialisedConversations"> |
134 | | - <LoadingPlaceholder type="conversations" /> |
| 116 | + <!-- Conversations List --> |
| 117 | + <template v-if="!isSearching"> |
| 118 | + <NcAppNavigationCaption :title="t('spreed', 'Conversations')" class="hidden-visually" /> |
| 119 | + <Conversation v-for="item of filteredConversationsList" |
| 120 | + :key="`conversation_${item.id}`" |
| 121 | + :ref="`conversation-${item.token}`" |
| 122 | + :item="item" /> |
| 123 | + <LoadingPlaceholder v-if="!initialisedConversations" type="conversations" /> |
| 124 | + <Hint v-else-if="filteredConversationsList.length === 0" :hint="t('spreed', 'No matches found')" /> |
135 | 125 | </template> |
136 | | - <Hint v-else-if="noMatchFound" |
137 | | - :hint="t('spreed', 'No matches found')" /> |
138 | | - <template v-if="isSearching"> |
139 | | - <template v-if="!listedConversationsLoading && searchResultsListedConversations.length > 0"> |
| 126 | + |
| 127 | + <!-- Search results --> |
| 128 | + <template v-else-if="isSearching"> |
| 129 | + <!-- Create a new conversation --> |
| 130 | + <NcListItem v-if="searchResultsConversationList.length === 0 && canStartConversations" |
| 131 | + :title="t('spreed', 'Create a new conversation')" |
| 132 | + @click="createConversation(searchText)"> |
| 133 | + <template #icon> |
| 134 | + <ChatPlus :size="30" /> |
| 135 | + </template> |
| 136 | + <template #subtitle> |
| 137 | + {{ searchText }} |
| 138 | + </template> |
| 139 | + </NcListItem> |
| 140 | + |
| 141 | + <!-- Search results: user's conversations --> |
| 142 | + <NcAppNavigationCaption :title="t('spreed', 'Conversations')" /> |
| 143 | + <Conversation v-for="item of searchResultsConversationList" |
| 144 | + :key="`conversation_${item.id}`" |
| 145 | + :ref="`conversation-${item.token}`" |
| 146 | + :item="item" /> |
| 147 | + <Hint v-if="searchResultsConversationList.length === 0" :hint="t('spreed', 'No matches found')" /> |
| 148 | + |
| 149 | + <!-- Search results: listed (open) conversations --> |
| 150 | + <template v-if="!listedConversationsLoading && searchResultsListedConversations.length !== 0"> |
140 | 151 | <NcAppNavigationCaption :title="t('spreed', 'Open conversations')" /> |
141 | 152 | <Conversation v-for="item of searchResultsListedConversations" |
142 | | - :key="item.id" |
| 153 | + :key="`open-conversation_${item.id}`" |
143 | 154 | :item="item" |
144 | 155 | is-search-result /> |
145 | 156 | </template> |
| 157 | + |
| 158 | + <!-- Search results: users --> |
146 | 159 | <template v-if="searchResultsUsers.length !== 0"> |
147 | 160 | <NcAppNavigationCaption :title="t('spreed', 'Users')" /> |
148 | 161 | <NcListItem v-for="item of searchResultsUsers" |
149 | | - :key="item.id" |
| 162 | + :key="`user_${item.id}`" |
150 | 163 | :title="item.label" |
151 | 164 | @click="createAndJoinConversation(item)"> |
152 | 165 | <template #icon> |
153 | | - <ConversationIcon :item="iconData(item)" |
154 | | - :disable-menu="true" /> |
155 | | - </template> |
156 | | - </NcListItem> |
157 | | - </template> |
158 | | - <template v-if="!showStartConversationsOptions"> |
159 | | - <NcAppNavigationCaption v-if="searchResultsUsers.length === 0" |
160 | | - :title="t('spreed', 'Users')" /> |
161 | | - <Hint v-if="contactsLoading" :hint="t('spreed', 'Loading')" /> |
162 | | - <Hint v-else :hint="t('spreed', 'No matches found')" /> |
163 | | - </template> |
164 | | - </template> |
165 | | - <template v-if="showStartConversationsOptions"> |
166 | | - <template v-if="searchResultsGroups.length !== 0"> |
167 | | - <NcAppNavigationCaption :title="t('spreed', 'Groups')" /> |
168 | | - <NcListItem v-for="item of searchResultsGroups" |
169 | | - :key="item.id" |
170 | | - :title="item.label" |
171 | | - @click="createAndJoinConversation(item)"> |
172 | | - <template #icon> |
173 | | - <ConversationIcon :item="iconData(item)" |
174 | | - :disable-menu="true" /> |
| 166 | + <ConversationIcon :item="iconData(item)" disable-menu /> |
175 | 167 | </template> |
176 | 168 | </NcListItem> |
177 | 169 | </template> |
178 | 170 |
|
179 | | - <template v-if="searchResultsCircles.length !== 0"> |
180 | | - <NcAppNavigationCaption :title="t('spreed', 'Circles')" /> |
181 | | - <NcListItem v-for="item of searchResultsCircles" |
182 | | - :key="item.id" |
183 | | - :title="item.label" |
184 | | - @click="createAndJoinConversation(item)"> |
185 | | - <template #icon> |
186 | | - <ConversationIcon :item="iconData(item)" |
187 | | - :disable-menu="true" /> |
188 | | - </template> |
189 | | - </NcListItem> |
| 171 | + <!-- Search results: new conversations --> |
| 172 | + <template v-if="canStartConversations"> |
| 173 | + <!-- New conversations: Groups --> |
| 174 | + <template v-if="searchResultsGroups.length !== 0"> |
| 175 | + <NcAppNavigationCaption :title="t('spreed', 'Groups')" /> |
| 176 | + <NcListItem v-for="item of searchResultsGroups" |
| 177 | + :key="`group_${item.id}`" |
| 178 | + :title="item.label" |
| 179 | + @click="createAndJoinConversation(item)"> |
| 180 | + <template #icon> |
| 181 | + <ConversationIcon :item="iconData(item)" disable-menu /> |
| 182 | + </template> |
| 183 | + </NcListItem> |
| 184 | + </template> |
| 185 | + |
| 186 | + <!-- New conversations: Circles --> |
| 187 | + <template v-if="searchResultsCircles.length !== 0"> |
| 188 | + <NcAppNavigationCaption :title="t('spreed', 'Circles')" /> |
| 189 | + <NcListItem v-for="item of searchResultsCircles" |
| 190 | + :key="`circle_${item.id}`" |
| 191 | + :title="item.label" |
| 192 | + @click="createAndJoinConversation(item)"> |
| 193 | + <template #icon> |
| 194 | + <ConversationIcon :item="iconData(item)" disable-menu /> |
| 195 | + </template> |
| 196 | + </NcListItem> |
| 197 | + </template> |
190 | 198 | </template> |
191 | 199 |
|
192 | | - <NcAppNavigationCaption v-if="sourcesWithoutResults" |
193 | | - :title="sourcesWithoutResultsList" /> |
| 200 | + <!-- Search results: no results (yet) --> |
| 201 | + <NcAppNavigationCaption v-if="sourcesWithoutResults" :title="sourcesWithoutResultsList" /> |
194 | 202 | <Hint v-if="contactsLoading" :hint="t('spreed', 'Loading')" /> |
195 | 203 | <Hint v-else :hint="t('spreed', 'No search results')" /> |
196 | 204 | </template> |
197 | 205 | </ul> |
198 | 206 | </li> |
| 207 | + |
199 | 208 | <NcButton v-if="!preventFindingUnread && unreadNum > 0" |
200 | 209 | class="unread-mention-button" |
201 | 210 | type="primary" |
@@ -337,37 +346,42 @@ export default { |
337 | 346 |
|
338 | 347 | computed: { |
339 | 348 | conversationsList() { |
340 | | - let conversations = this.$store.getters.conversationsList |
| 349 | + return this.$store.getters.conversationsList |
| 350 | + }, |
| 351 | +
|
| 352 | + searchResultsConversationList() { |
341 | 353 | if (this.searchText !== '' || this.isFocused) { |
342 | 354 | const lowerSearchText = this.searchText.toLowerCase() |
343 | | - conversations = conversations.filter(conversation => |
| 355 | + return this.conversationsList.filter(conversation => |
344 | 356 | conversation.displayName.toLowerCase().includes(lowerSearchText) |
345 | | - || conversation.name.toLowerCase().includes(lowerSearchText) |
| 357 | + || conversation.name.toLowerCase().includes(lowerSearchText) |
346 | 358 | ) |
347 | | - } else if (this.isFiltered === 'unread') { |
348 | | - conversations = conversations.filter(conversation => conversation.unreadMessages > 0) |
349 | | - } else if (this.isFiltered === 'mentions') { |
350 | | - conversations = conversations.filter(conversation => conversation.unreadMention || (conversation.unreadMessages > 0 |
| 359 | + } else { |
| 360 | + return [] |
| 361 | + } |
| 362 | + }, |
| 363 | +
|
| 364 | + filteredConversationsList() { |
| 365 | + if (this.isFocused) { |
| 366 | + return this.conversationsList |
| 367 | + } |
| 368 | +
|
| 369 | + if (this.isFiltered === 'unread') { |
| 370 | + return this.conversationsList.filter(conversation => conversation.unreadMessages > 0) |
| 371 | + } |
| 372 | +
|
| 373 | + if (this.isFiltered === 'mentions') { |
| 374 | + return this.conversationsList.filter(conversation => conversation.unreadMention || (conversation.unreadMessages > 0 |
351 | 375 | && (conversation.type === CONVERSATION.TYPE.ONE_TO_ONE || conversation.type === CONVERSATION.TYPE.ONE_TO_ONE_FORMER))) |
352 | 376 | } |
353 | 377 |
|
354 | | - // FIXME: this modifies the original array, |
355 | | - // maybe should act on a copy or sort already within the store ? |
356 | | - return conversations.sort(this.sortConversations) |
| 378 | + return this.conversationsList |
357 | 379 | }, |
358 | 380 |
|
359 | 381 | isSearching() { |
360 | 382 | return this.searchText !== '' |
361 | 383 | }, |
362 | 384 |
|
363 | | - noMatchFound() { |
364 | | - return (this.searchText || this.isFiltered) && !this.conversationsList.length |
365 | | - }, |
366 | | -
|
367 | | - showStartConversationsOptions() { |
368 | | - return this.isSearching && this.canStartConversations |
369 | | - }, |
370 | | -
|
371 | 385 | sourcesWithoutResults() { |
372 | 386 | return !this.searchResultsUsers.length |
373 | 387 | || !this.searchResultsGroups.length |
@@ -601,14 +615,6 @@ export default { |
601 | 615 | emit('show-settings') |
602 | 616 | }, |
603 | 617 |
|
604 | | - sortConversations(conversation1, conversation2) { |
605 | | - if (conversation1.isFavorite !== conversation2.isFavorite) { |
606 | | - return conversation1.isFavorite ? -1 : 1 |
607 | | - } |
608 | | -
|
609 | | - return conversation2.lastActivity - conversation1.lastActivity |
610 | | - }, |
611 | | -
|
612 | 618 | /** |
613 | 619 | * @param {object} [options] Options for conversation refreshing |
614 | 620 | * @param {string} [options.token] The conversation token that got update |
|
0 commit comments