@@ -68,106 +68,106 @@ export default {
68
68
ChatMessager,
69
69
ChatSide,
70
70
ChatLogin,
71
- ChatLoading,
71
+ ChatLoading
72
72
},
73
73
props: {
74
74
tokenField: {
75
75
type: String ,
76
- default: " channel_owner_token" ,
76
+ default: " channel_owner_token"
77
77
},
78
78
displayFull: {
79
79
type: Boolean ,
80
- default: false ,
80
+ default: false
81
81
},
82
82
endpoint: {
83
83
type: String ,
84
- required: true ,
84
+ required: true
85
85
},
86
86
receiver: {
87
- type: String ,
87
+ type: String
88
88
},
89
89
showHeader: {
90
90
type: Boolean ,
91
- default: true ,
91
+ default: true
92
92
},
93
93
showChannelList: {
94
94
type: Boolean ,
95
- default: false ,
95
+ default: false
96
96
},
97
97
showSuggestButton: {
98
98
type: Boolean ,
99
- default: true ,
99
+ default: true
100
100
},
101
101
httpOptions: {
102
102
type: Object ,
103
103
default () {
104
104
return {};
105
- },
105
+ }
106
106
},
107
107
httpMethod: {
108
- type: Function ,
108
+ type: Function
109
109
},
110
110
isExpanded: {
111
111
type: Boolean ,
112
- default: false ,
112
+ default: false
113
113
},
114
114
externalChannelHandle: {
115
115
type: Boolean ,
116
- default: false ,
116
+ default: false
117
117
},
118
118
user: {
119
119
type: String ,
120
- default: " " ,
121
- },
120
+ default: " "
121
+ }
122
122
},
123
123
data () {
124
124
return {
125
125
client: null ,
126
126
channels: [],
127
127
activeChannel: null ,
128
- userContext: { identity: null },
128
+ userContext: { identity: null }
129
129
};
130
130
},
131
131
watch: {
132
132
receiver () {
133
133
this .unlistenEvents ();
134
- },
134
+ }
135
135
},
136
136
computed: {
137
137
isLoggedIn () {
138
138
return this .userContext .identity ;
139
- },
139
+ }
140
140
},
141
141
beforeDestroy () {
142
142
this .unlistenEvents ();
143
143
},
144
144
methods: {
145
- createClient (data ) {
146
- Twilio .Client .create (data[this .tokenField ], {
147
- logLevel: " info" ,
148
- }).then ((client ) => {
149
- this .userContext = {
150
- ... data,
151
- identity: client .user .identity ,
152
- user: client .user ,
153
- };
154
- this .client = client;
155
-
156
- client .on (" tokenAboutToExpire" , this .onTokenAboutToExpire );
157
- this .loadChannelEvents (client);
158
- this .updateChannels ();
145
+ async createClient (data ) {
146
+ const client = await Twilio .Client .create (data[this .tokenField ], {
147
+ logLevel: " info"
159
148
});
149
+
150
+ this .userContext = {
151
+ ... data,
152
+ identity: client .user .identity ,
153
+ user: client .user
154
+ };
155
+ this .client = client;
156
+
157
+ client .on (" tokenAboutToExpire" , this .onTokenAboutToExpire );
158
+ this .loadChannelEvents (client);
159
+ this .updateChannels ();
160
160
},
161
161
162
162
async loadChannel () {
163
163
if (! this .activeChannel && ! this .showChannelList ) {
164
- const channel = this .channels . find (( channel ) => {
165
- return channel . sid == this .userContext .channel_sid ;
166
- });
167
-
168
- if (channel) {
169
- this . joinChannel (channel);
170
- }
164
+ this .client
165
+ . getChannelBySid ( this .userContext .channel_sid )
166
+ . then ( channel => {
167
+ if (channel) {
168
+ this . joinChannel (channel);
169
+ }
170
+ });
171
171
}
172
172
},
173
173
@@ -193,13 +193,16 @@ export default {
193
193
channel .join ();
194
194
}
195
195
196
- const subscribed = await this .client
197
- .getSubscribedChannels ({ limit: 100 })
198
- .then ((page ) => {
199
- return this .appendChannels (page, []);
200
- });
201
- this .channels = subscribed;
202
- this .loadChannel ();
196
+ if (! this .showChannelList ) {
197
+ this .loadChannel ();
198
+ } else {
199
+ const subscribed = await this .client
200
+ .getSubscribedChannels ({ limit: 100 })
201
+ .then (page => {
202
+ return this .appendChannels (page, []);
203
+ });
204
+ this .channels = subscribed;
205
+ }
203
206
},
204
207
205
208
async appendChannels (paginator , current ) {
@@ -217,7 +220,7 @@ export default {
217
220
},
218
221
219
222
loadChannelEvents (client ) {
220
- client .on (" channelJoined" , ( channel ) => {
223
+ client .on (" channelJoined" , channel => {
221
224
channel .on (" messageAdded" , () => {
222
225
this .updateChannels ();
223
226
});
@@ -233,7 +236,7 @@ export default {
233
236
234
237
unlistenEvents () {
235
238
if (this .client ) {
236
- this .client .removeListener (" channelJoined" , ( channel ) => {
239
+ this .client .removeListener (" channelJoined" , channel => {
237
240
channel .removeListener (" messageAdded" , () => {
238
241
this .updateChannels ();
239
242
});
@@ -270,8 +273,8 @@ export default {
270
273
271
274
sendMessage (message , attributes ) {
272
275
this .$refs .messenger .sendMessage (message, attributes);
273
- },
274
- },
276
+ }
277
+ }
275
278
};
276
279
</script >
277
280
0 commit comments