aboutsummaryrefslogtreecommitdiff
path: root/src/components/chat_new/chat_new.js
diff options
context:
space:
mode:
authorShpuld Shpludson <shp@cock.li>2020-08-27 14:45:03 +0000
committerShpuld Shpludson <shp@cock.li>2020-08-27 14:45:03 +0000
commite768ec1fca2f7580d111b0878a9695b0c8b9dbb1 (patch)
tree668ebbcd6818b3c7ad70a372c9f77fa9cffb6a3f /src/components/chat_new/chat_new.js
parent5d49edc823ba2ea3e34d4fd6c5efcc84ef9712f7 (diff)
parentd09f43ba7a179cdca9a2d808631f8ba213dd7710 (diff)
Merge branch '2.1.0-rc0' into 'master'
2.1.0 into master See merge request pleroma/pleroma-fe!1217
Diffstat (limited to 'src/components/chat_new/chat_new.js')
-rw-r--r--src/components/chat_new/chat_new.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/components/chat_new/chat_new.js b/src/components/chat_new/chat_new.js
new file mode 100644
index 00000000..d023efc0
--- /dev/null
+++ b/src/components/chat_new/chat_new.js
@@ -0,0 +1,73 @@
+import { mapState, mapGetters } from 'vuex'
+import BasicUserCard from '../basic_user_card/basic_user_card.vue'
+import UserAvatar from '../user_avatar/user_avatar.vue'
+
+const chatNew = {
+ components: {
+ BasicUserCard,
+ UserAvatar
+ },
+ data () {
+ return {
+ suggestions: [],
+ userIds: [],
+ loading: false,
+ query: ''
+ }
+ },
+ async created () {
+ const { chats } = await this.backendInteractor.chats()
+ chats.forEach(chat => this.suggestions.push(chat.account))
+ },
+ computed: {
+ users () {
+ return this.userIds.map(userId => this.findUser(userId))
+ },
+ availableUsers () {
+ if (this.query.length !== 0) {
+ return this.users
+ } else {
+ return this.suggestions
+ }
+ },
+ ...mapState({
+ currentUser: state => state.users.currentUser,
+ backendInteractor: state => state.api.backendInteractor
+ }),
+ ...mapGetters(['findUser'])
+ },
+ methods: {
+ goBack () {
+ this.$emit('cancel')
+ },
+ goToChat (user) {
+ this.$router.push({ name: 'chat', params: { recipient_id: user.id } })
+ },
+ onInput () {
+ this.search(this.query)
+ },
+ addUser (user) {
+ this.selectedUserIds.push(user.id)
+ this.query = ''
+ },
+ removeUser (userId) {
+ this.selectedUserIds = this.selectedUserIds.filter(id => id !== userId)
+ },
+ search (query) {
+ if (!query) {
+ this.loading = false
+ return
+ }
+
+ this.loading = true
+ this.userIds = []
+ this.$store.dispatch('search', { q: query, resolve: true, type: 'accounts' })
+ .then(data => {
+ this.loading = false
+ this.userIds = data.accounts.map(a => a.id)
+ })
+ }
+ }
+}
+
+export default chatNew