Copyright 2015-2016 GetSocial B.V.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
var ChatViewBuilder = require('./ChatViewBuilder');
var ChatListViewBuilder = require('./ChatListViewBuilder');
NATIVE_BRIDGE_NAME = "GetSocialChatCordova";
var GetSocialChat = function() {
this.instance = null;
this.onErrorPlugin = function(err) {
console.log(err);
}
}
/// <summary>
/// Return GetSocialChat instance
/// </summary>
GetSocialChat.getInstance = function () {
if (!this.instance) {
this.instance = new GetSocialChat();
}
return this.instance;
}
/// <summary>
/// Gets the number of unread chat conversations.
/// </summary>
GetSocialChat.prototype.unreadConversationsCount = function(onSuccess, onFailure) {
cordova.exec(onSuccess, onFailure, NATIVE_BRIDGE_NAME, "unreadConversationsCount", []);
}
/// <summary>
/// Check if chat feature is enabled on a GetSocial Developer Portal
/// </summary>
/// <value><c>true</c> if chat feature is enabled; otherwise, <c>false</c>.</value>
GetSocialChat.prototype.isEnabled = function(onSuccess, onFailure) {
cordova.exec(function(value) {
if(value == 1) {
onSuccess(true);
} else {
onSuccess(false);
}
}, onFailure, NATIVE_BRIDGE_NAME, "isEnable", []);
}
/// <summary>
/// Unread conversations listener.
/// </summary>
GetSocialChat.prototype.setOnUnreadConversationsCountChangeListener = function(onUnreadConversationsCountChangeListener) {
cordova.exec(onUnreadConversationsCountChangeListener, this.onErrorPlugin, NATIVE_BRIDGE_NAME, "setOnUnreadConversationsCountChangeListener", []);
}
/// <summary>
/// Creates the chat list view.
/// </summary>
/// <returns><see cref="ChatListViewBuilder"/> instance.</returns>
GetSocialChat.prototype.createChatListView = function() {
var chatListViewBuilder = new ChatListViewBuilder();
return chatListViewBuilder;
}
/// <summary>
/// Creates <see cref="ChatViewBuilder"/> used to open the Chat View.
/// </summary>
/// <param name="userId">The id of the user to chat with</param>
/// <returns><see cref="ChatViewBuilder"/> instance.</returns>
GetSocialChat.prototype.createChatViewForUserId = function(userId) {
var chatViewBuilder = new ChatViewBuilder.constructWithUserId(userId);
return chatViewBuilder;
}
/// <summary>
/// Creates <see cref="ChatViewBuilder"/> used to open the Chat View.
/// </summary>
/// <param name="userId">The id of the user to chat with</param>
/// <param name="providerId">The id of the external provider</param>
/// <returns><see cref="ChatViewBuilder"/> instance.</returns>
GetSocialChat.prototype.createChatViewForUserIdOnProvider = function(userId, providerId) {
var chatViewBuilder = new ChatViewBuilder.constructWithUserIdAndProviderId(userId, providerId);
return chatViewBuilder;
}
/// <summary>
/// Creates <see cref="ChatViewBuilder"/> used to open the Chat View.
/// </summary>
/// <param name="conversationId">The id of the chat conversation</param>
/// <returns><see cref="ChatViewBuilder"/> instance.</returns>-
GetSocialChat.prototype.createChatViewForConversationId = function(conversationId) {
var chatViewBuilder = new ChatViewBuilder.constructWithConversationId(conversationId);
return chatViewBuilder;
}
/// <summary>
/// Creates <see cref="ChatViewBuilder"/> used to open the Chat View.
/// </summary>
/// <param name="roomName">The name of the chat room</param>
/// <returns><see cref="ChatViewBuilder"/> instance.</returns>
GetSocialChat.prototype.createChatViewForRoomName = function(roomName) {
var chatViewBuilder = new ChatViewBuilder.constructWithRoomName(roomName);
return chatViewBuilder;
}
module.exports = GetSocialChat;