castle-chat-lib
Advanced tools
Comparing version 2.4.0 to 2.5.0
{ | ||
"name": "castle-chat-lib", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -124,2 +124,79 @@ import _ from 'lodash'; | ||
async joinChannelAsync(channelId) { | ||
try { | ||
let joinResult = await this._api.graphqlAsync( | ||
` | ||
mutation($channelId: ID!) { | ||
joinChatChannel(channelId: $channelId) { | ||
channelId | ||
} | ||
} | ||
`, | ||
{ | ||
channelId, | ||
} | ||
); | ||
if (joinResult.errors && joinResult.errors.length) { | ||
throw new Error(joinResult.errors); | ||
} | ||
this._socket.emit('join-channels', { | ||
channels: [channelId], | ||
}); | ||
let recentMessagesResult = await this._api.graphqlAsync( | ||
` | ||
query($channelId: ID!) { | ||
recentChannelChatMessages(channelId: $channelId) { | ||
chatMessageId | ||
channelId | ||
fromUserId | ||
body | ||
createdTime | ||
} | ||
} | ||
`, | ||
{ | ||
channelId, | ||
} | ||
); | ||
if (recentMessagesResult.data && recentMessagesResult.data.recentChannelChatMessages) { | ||
this._handleMessages(recentMessagesResult.data.recentChannelChatMessages); | ||
} | ||
} catch (e) { | ||
console.log('join channel error'); | ||
console.log(JSON.stringify(e)); | ||
} | ||
} | ||
async leaveChannelAsync(channelId) { | ||
try { | ||
let result = await this._api.graphqlAsync( | ||
` | ||
mutation($channelId: ID!) { | ||
leaveChatChannel(channelId: $channelId) { | ||
channelId | ||
} | ||
} | ||
`, | ||
{ | ||
channelId, | ||
} | ||
); | ||
this._socket.emit('leave-channels', { | ||
channels: [channelId], | ||
}); | ||
if (result.errors && result.errors.length) { | ||
throw new Error(result.errors); | ||
} | ||
} catch (e) { | ||
console.log('leave channel error'); | ||
console.log(JSON.stringify(e)); | ||
} | ||
} | ||
async sendMessageAsync(channel, message, postId) { | ||
@@ -126,0 +203,0 @@ try { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6859
233