|
5 | 5 | :class="{ 'app-mobile': isDevice, 'app-mobile-dark': theme === 'dark' }"
|
6 | 6 | >
|
7 | 7 | <!-- <div>
|
8 |
| - <button @click="resetData">Clear Data</button> |
9 |
| - <button @click="addData" :disabled="updatingData">Add Data</button> |
| 8 | + <button @click="resetData"> |
| 9 | + Clear Data |
| 10 | + </button> |
| 11 | + <button :disabled="updatingData" @click="addData"> |
| 12 | + Add Data |
| 13 | + </button> |
10 | 14 | </div> -->
|
11 | 15 | <span
|
12 | 16 | v-if="showOptions"
|
|
51 | 55 | </template>
|
52 | 56 |
|
53 | 57 | <script>
|
54 |
| -import { roomsRef, usersRef } from '@/firestore' |
| 58 | +import * as firestoreService from '@/database/firestore' |
| 59 | +import * as storageService from '@/database/storage' |
| 60 | +
|
55 | 61 | import ChatContainer from './ChatContainer'
|
56 | 62 |
|
57 | 63 | export default {
|
@@ -110,50 +116,58 @@ export default {
|
110 | 116 |
|
111 | 117 | methods: {
|
112 | 118 | resetData() {
|
113 |
| - roomsRef.get().then(val => { |
114 |
| - val.forEach(async val => { |
115 |
| - const ref = roomsRef.doc(val.id).collection('messages') |
116 |
| -
|
117 |
| - await ref.get().then(res => { |
118 |
| - if (res.empty) return |
119 |
| - res.docs.map(doc => ref.doc(doc.id).delete()) |
| 119 | + firestoreService.getAllRooms().then(rooms => { |
| 120 | + rooms.forEach(async room => { |
| 121 | + await firestoreService.getMessages(room.id).then(messages => { |
| 122 | + messages.forEach(message => { |
| 123 | + firestoreService.deleteMessage(room.id, message.id) |
| 124 | + if (message.data().files) { |
| 125 | + message.data().files.forEach(file => { |
| 126 | + storageService.deleteFile( |
| 127 | + this.currentUserId, |
| 128 | + message.id, |
| 129 | + file |
| 130 | + ) |
| 131 | + }) |
| 132 | + } |
| 133 | + }) |
120 | 134 | })
|
121 | 135 |
|
122 |
| - roomsRef.doc(val.id).delete() |
| 136 | + firestoreService.deleteRoom(room.id) |
123 | 137 | })
|
124 | 138 | })
|
125 | 139 |
|
126 |
| - usersRef.get().then(val => { |
127 |
| - val.forEach(val => { |
128 |
| - usersRef.doc(val.id).delete() |
| 140 | + firestoreService.getAllUsers().then(users => { |
| 141 | + users.forEach(user => { |
| 142 | + firestoreService.deleteUser(user.id) |
129 | 143 | })
|
130 | 144 | })
|
131 | 145 | },
|
132 | 146 | async addData() {
|
133 | 147 | this.updatingData = true
|
134 | 148 |
|
135 | 149 | const user1 = this.users[0]
|
136 |
| - await usersRef.doc(user1._id).set(user1) |
| 150 | + await firestoreService.addIdentifiedUser(user1._id, user1) |
137 | 151 |
|
138 | 152 | const user2 = this.users[1]
|
139 |
| - await usersRef.doc(user2._id).set(user2) |
| 153 | + await firestoreService.addIdentifiedUser(user2._id, user2) |
140 | 154 |
|
141 | 155 | const user3 = this.users[2]
|
142 |
| - await usersRef.doc(user3._id).set(user3) |
| 156 | + await firestoreService.addIdentifiedUser(user3._id, user3) |
143 | 157 |
|
144 |
| - await roomsRef.add({ |
| 158 | + await firestoreService.addRoom({ |
145 | 159 | users: [user1._id, user2._id],
|
146 | 160 | lastUpdated: new Date()
|
147 | 161 | })
|
148 |
| - await roomsRef.add({ |
| 162 | + await firestoreService.addRoom({ |
149 | 163 | users: [user1._id, user3._id],
|
150 | 164 | lastUpdated: new Date()
|
151 | 165 | })
|
152 |
| - await roomsRef.add({ |
| 166 | + await firestoreService.addRoom({ |
153 | 167 | users: [user2._id, user3._id],
|
154 | 168 | lastUpdated: new Date()
|
155 | 169 | })
|
156 |
| - await roomsRef.add({ |
| 170 | + await firestoreService.addRoom({ |
157 | 171 | users: [user1._id, user2._id, user3._id],
|
158 | 172 | lastUpdated: new Date()
|
159 | 173 | })
|
|
0 commit comments