Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
$scope.$digest();
};
const invitedHandler = (payload, conversation) => {
if (conversation.transient) {
// 暂态对话
if ($scope.transConvs.indexOf(conversation) === -1) {
$scope.transConvs.push(conversation);
}
} else if ($scope.normalConvs.indexOf(conversation) === -1) {
$scope.normalConvs.push(conversation);
}
$scope.$digest();
};
const client = $scope.imClient;
client.on(Event.MESSAGE, messageHandler);
client.on(Event.INVITED, invitedHandler);
client.on(Event.UNREAD_MESSAGES_COUNT_UPDATE, () => {
$scope.$emit('unreadCountUpdate', getTotalUnreadCount());
});
client.on(Event.DISCONNECT, () => {
$scope.networkError = '连接已断开';
$scope.networkErrorIcon = 'sync_problem';
$scope.$digest();
});
client.on(Event.OFFLINE, () => {
$scope.networkError = '网络不可用,请检查网络设置';
$scope.networkErrorIcon = 'signal_wifi_off';
$scope.networkShowRetry = false;
$scope.$digest();
});
client.on(Event.ONLINE, () => {
$scope.$on("$destroy", () => {
conversation.off(Event.MEMBERS_JOINED, membersJoinedHandler);
conversation.off(Event.MEMBERS_LEFT, membersLeftHandler);
conversation.off(Event.KICKED, kickedHandler);
conversation.off(Event.INFO_UPDATED, infoUpdatedHandler);
conversation.off(Event.MEMBER_INFO_UPDATED, memberInfoUpdateHandler);
conversation.off(Event.MESSAGE, readMarker);
conversation.off(Event.MESSAGE, messageUpdater);
conversation.off(Event.LAST_DELIVERED_AT_UPDATE, receiptUpdateHandler);
conversation.off(Event.LAST_READ_AT_UPDATE, receiptUpdateHandler);
conversation.off('lastreadtimestampsupdate', receiptUpdateHandler);
conversation.off(Event.MESSAGE_RECALL, replaceRecalledMessage);
$scope.typingIndicator.off('change');
document.removeEventListener("visibilitychange", handleVisibilityChange);
});
$scope.$on("$destroy", () => {
client.off(Event.MESSAGE, messageHandler);
client.off(Event.INVITED, invitedHandler);
[
Event.UNREAD_MESSAGES_COUNT_UPDATE,
Event.DISCONNECT,
Event.OFFLINE,
Event.ONLINE,
Event.SCHEDULE,
Event.RETRY,
Event.RECONNECT,
Event.RECONNECT_ERROR
].forEach(event => client.off(event));
});
const receiptUpdateHandler = () => {
$scope.$digest();
};
const handleVisibilityChange = () => {
if (!document.hidden && conversation.unreadMessagesCount) {
conversation.read();
}
};
conversation.on(Event.MEMBERS_JOINED, membersJoinedHandler);
conversation.on(Event.MEMBERS_LEFT, membersLeftHandler);
conversation.on(Event.KICKED, kickedHandler);
conversation.on(Event.INFO_UPDATED, infoUpdatedHandler);
conversation.on(Event.MEMBER_INFO_UPDATED, memberInfoUpdateHandler);
conversation.on(Event.MESSAGE, readMarker);
conversation.on(Event.MESSAGE, messageUpdater);
conversation.on(Event.LAST_DELIVERED_AT_UPDATE, receiptUpdateHandler);
conversation.on(Event.LAST_READ_AT_UPDATE, receiptUpdateHandler);
conversation.on('lastreadtimestampsupdate', receiptUpdateHandler);
conversation.on(Event.MESSAGE_RECALL, replaceRecalledMessage);
document.addEventListener("visibilitychange", handleVisibilityChange);
$scope.$on("$destroy", () => {
conversation.off(Event.MEMBERS_JOINED, membersJoinedHandler);
conversation.off(Event.MEMBERS_LEFT, membersLeftHandler);
conversation.off(Event.KICKED, kickedHandler);
conversation.off(Event.INFO_UPDATED, infoUpdatedHandler);
conversation.off(Event.MEMBER_INFO_UPDATED, memberInfoUpdateHandler);
conversation.off(Event.MESSAGE, readMarker);
conversation.off(Event.MESSAGE, messageUpdater);
conversation.off(Event.LAST_DELIVERED_AT_UPDATE, receiptUpdateHandler);