Skip to content

Commit 4eef729

Browse files
get user token without chats
1 parent fc0c148 commit 4eef729

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/components/chat/index.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ export default {
119119
user: {
120120
type: String,
121121
default: ""
122+
},
123+
branchId: {
124+
type: [String, Number],
125+
default: ""
122126
}
123127
},
124128
data() {
@@ -146,7 +150,6 @@ export default {
146150
},
147151
methods: {
148152
async createClient(data) {
149-
console.time('initialLoad')
150153
const client = await Twilio.Client.create(data[this.tokenField], {
151154
logLevel: "info"
152155
});
@@ -161,7 +164,6 @@ export default {
161164
client.on("tokenAboutToExpire", this.onTokenAboutToExpire);
162165
this.loadChannelEvents(client);
163166
this.updateChannels();
164-
console.timeEnd('initialLoad')
165167
},
166168
167169
async loadChannel() {
@@ -195,18 +197,13 @@ export default {
195197
channel.join();
196198
}
197199
198-
if(!this.activeChannel && !this.showChannelList && !this.isLoading) {
199-
console.log("Hola Desde Dentro", `loaded: ${this.isLoaded}. Loading ${this.isLoading}`)
200-
}
201-
202200
if (!this.isLoading) {
203201
this.isLoading = true;
204202
if (!this.showChannelList) {
205203
await this.loadChannel();
206204
this.isLoaded = true;
207205
this.isLoading = false;
208206
} else {
209-
console.log("there", this.showChannelList)
210207
const subscribed = await this.client
211208
.getSubscribedChannels({ limit: 100 })
212209
.then(page => {
@@ -221,7 +218,7 @@ export default {
221218
},
222219
223220
async appendChannels(paginator, current) {
224-
current.push(...paginator.items);
221+
current.push(...paginator.items.filter((channel) => channel.attributes.branchId == this.branchId));
225222
if (paginator.hasNextPage) {
226223
return this.appendChannels(await paginator.nextPage(), current);
227224
} else {

src/components/chat/login.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ export default {
6262
},
6363
created() {
6464
if (this.receiver) {
65-
this.formData.identity = this.receiver;
66-
this.login();
65+
this.formData.identity = this.receiver;
66+
this.login();
67+
} else {
68+
this.getUserToken()
6769
}
6870
},
6971
methods: {
@@ -81,15 +83,27 @@ export default {
8183
this.$emit("logged", data);
8284
},
8385
86+
getUserToken() {
87+
axios
88+
.get("/users/0/chats-token", this.httpOptions)
89+
.then(({ data }) => {
90+
this.$emit("logged", {
91+
"channel_client_token": data
92+
});
93+
});
94+
},
95+
8496
getAccessToken(identity) {
97+
const url = `${this.endpoint}/${identity}`;
98+
8599
if (this.httpMethod) {
86-
this.httpMethod(`${this.endpoint}/${identity}`).then(({ data }) => {
100+
this.httpMethod(url).then(({ data }) => {
87101
this.setData(data);
88102
});
89103
return;
90104
} else {
91105
axios
92-
.get(`${this.endpoint}/${identity}`, this.httpOptions)
106+
.get(url, this.httpOptions)
93107
.then(({ data }) => {
94108
this.setData(data);
95109
});

0 commit comments

Comments
 (0)