Skip to content

Commit fc0c148

Browse files
Improve chat performance
1 parent 7ffbaaf commit fc0c148

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

src/components/chat/index.vue

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default {
8585
required: true
8686
},
8787
receiver: {
88-
type: String
88+
type: [String, Number]
8989
},
9090
showHeader: {
9191
type: Boolean,
@@ -126,6 +126,7 @@ export default {
126126
client: null,
127127
channels: [],
128128
isLoaded: false,
129+
isLoading: false,
129130
activeChannel: null,
130131
userContext: { identity: null }
131132
};
@@ -160,7 +161,7 @@ export default {
160161
client.on("tokenAboutToExpire", this.onTokenAboutToExpire);
161162
this.loadChannelEvents(client);
162163
this.updateChannels();
163-
console.timeEnd('tnitialLoad')
164+
console.timeEnd('initialLoad')
164165
},
165166
166167
async loadChannel() {
@@ -194,18 +195,29 @@ export default {
194195
channel.join();
195196
}
196197
197-
if (!this.showChannelList) {
198-
await this.loadChannel();
199-
this.isLoaded = true;
200-
} else {
201-
const subscribed = await this.client
202-
.getSubscribedChannels({ limit: 100 })
203-
.then(page => {
204-
return this.appendChannels(page, []);
205-
});
206-
this.channels = subscribed;
207-
this.isLoaded = true;
198+
if(!this.activeChannel && !this.showChannelList && !this.isLoading) {
199+
console.log("Hola Desde Dentro", `loaded: ${this.isLoaded}. Loading ${this.isLoading}`)
208200
}
201+
202+
if (!this.isLoading) {
203+
this.isLoading = true;
204+
if (!this.showChannelList) {
205+
await this.loadChannel();
206+
this.isLoaded = true;
207+
this.isLoading = false;
208+
} else {
209+
console.log("there", this.showChannelList)
210+
const subscribed = await this.client
211+
.getSubscribedChannels({ limit: 100 })
212+
.then(page => {
213+
return this.appendChannels(page, []);
214+
});
215+
this.channels = subscribed;
216+
this.isLoaded = true;
217+
this.isLoading = false;
218+
}
219+
220+
}
209221
},
210222
211223
async appendChannels(paginator, current) {
@@ -229,7 +241,6 @@ export default {
229241
});
230242
this.updateChannels();
231243
});
232-
233244
client.on("channelInvited", this.updateChannels);
234245
client.on("channelAdded", this.updateChannels);
235246
client.on("channelUpdated", this.updateChannels);

src/components/chat/login.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ export default {
6161
};
6262
},
6363
created() {
64-
const loginData = this.getData();
65-
if (loginData) {
66-
this.$emit("logged", loginData);
67-
} else if (this.receiver) {
64+
if (this.receiver) {
6865
this.formData.identity = this.receiver;
6966
this.login();
7067
}
@@ -101,5 +98,3 @@ export default {
10198
}
10299
};
103100
</script>
104-
105-
<style></style>

src/components/chat/side-list-item.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,18 @@ export default {
7373
this.watchTime();
7474
},
7575
mounted() {
76+
this.$root.$on("leads:status-updated", (data) => {
77+
if (this.channel.attributes && data.id == this.channel.attributes.lead_id) {
78+
this.$set(this.channel.attributes, "status", data.status)
79+
}
80+
})
81+
7682
this.$root.$on("leads:stopwatch", (data) => {
7783
if (this.channel.attributes && data.lead_id == this.channel.attributes.lead_id) {
7884
this.$set(this.channel.attributes, "chrono_start_date", data.chrono_start_date);
7985
this.$set(this.channel.attributes, "is_chrono_running", data.is_chrono_running)
8086
this.$set(this.channel.attributes, "leads_visits_count", data.leads_visits_count)
87+
this.$set(this.channel.attributes, "status", data.status)
8188
this.watchTime();
8289
}
8390
});
@@ -114,9 +121,7 @@ export default {
114121
);
115122
},
116123
receiverImage() {
117-
return this.receiver && this.receiver.userAttributes
118-
? this.receiver.userAttributes.photoUrl
119-
: "";
124+
return this.channel.attributes.photoUrl;
120125
},
121126
sender() {
122127
return (

src/components/chat/side.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export default {
128128
selectedFilter: 'all',
129129
filters: {
130130
all: {
131-
value: '',
131+
value: 'all',
132132
label: "All Messages",
133133
field: ''
134134
},
@@ -187,7 +187,7 @@ export default {
187187
188188
visibleChannels() {
189189
const selectedFilter = this.filters[this.selectedFilter].value;
190-
return this.channels.filter(channel => channel.lastMessage && (!selectedFilter || channel.attributes.status == selectedFilter))
190+
return this.channels.filter(channel => channel.lastMessage && (selectedFilter == "all" || channel.attributes.status == selectedFilter))
191191
.sort((a, b) => {
192192
const dateCreatedA = a.lastMessage
193193
? a.lastMessage.dateCreated.toISOString()

0 commit comments

Comments
 (0)