New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bulbul-chat

Package Overview
Dependencies
Maintainers
2
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bulbul-chat - npm Package Compare versions

Comparing version 2.3.2 to 2.3.3

2

dist/src/ChatService.d.ts

@@ -15,3 +15,3 @@ import ChannelMessageStorage from './ChannelMessageStorage';

start(): void;
setCurrentChannel(channel: ChatChannel): void;
setCurrentChannel(channel: ChatChannel | null): void;
channelMessageStorage(channelId: string): ChannelMessageStorage;

@@ -18,0 +18,0 @@ getChannelStorage(): ChannelsStorage;

@@ -79,38 +79,40 @@ "use strict";

this.chatClient.onAllNewMessage(function (message) { return __awaiter(_this, void 0, void 0, function () {
var channelMessageStorage, currentUser, channel, updatedChannel;
var channelMessageStorage;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
if (message.channelId) {
channelMessageStorage = this.channelMessageStorage(message.channelId);
if (channelMessageStorage.initialMessagesLoaded &&
((_a = this.currentChannel) === null || _a === void 0 ? void 0 : _a.id) !== message.channelId) {
channelMessageStorage.addLiveMessage([message]);
}
}
return [2 /*return*/];
});
}); });
this.chatClient.onChannelUpdate(function (channel) { return __awaiter(_this, void 0, void 0, function () {
var currentUser, updatedChannel;
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!message.channelId) return [3 /*break*/, 5];
channelMessageStorage = this.channelMessageStorage(message.channelId);
if (channelMessageStorage.initialMessagesLoaded) {
channelMessageStorage.addLiveMessage([message]);
}
if (!channel) return [3 /*break*/, 4];
return [4 /*yield*/, this.currentUser()];
case 1:
currentUser = _b.sent();
if (!(message.channelId !== ((_a = this.currentChannel) === null || _a === void 0 ? void 0 : _a.id))) return [3 /*break*/, 4];
return [4 /*yield*/, this.channelsStorage.get(message.channelId, this.chatClient)];
currentUser = _c.sent();
updatedChannel = __assign({}, channel);
if (!(((_a = this.currentChannel) === null || _a === void 0 ? void 0 : _a.id) !== channel.id &&
((_b = channel.lastMessage) === null || _b === void 0 ? void 0 : _b.senderId) !== currentUser.id)) return [3 /*break*/, 3];
return [4 /*yield*/, this.chatClient.getUnreadMessageCount(channel)];
case 2:
channel = _b.sent();
return [4 /*yield*/, this.chatClient.getUnreadMessageCount(channel)];
// if the channel is open then mark this message as read
updatedChannel = _c.sent();
_c.label = 3;
case 3:
updatedChannel = _b.sent();
this.channelsStorage.update(updatedChannel);
return [3 /*break*/, 5];
case 4:
if (message.senderId !== currentUser.id) {
// if the channel is open but the sender is not me then mark this message as read
this.markAllAsRead(message.channelId);
}
_b.label = 5;
case 5: return [2 /*return*/];
_c.label = 4;
case 4: return [2 /*return*/];
}
});
}); });
this.chatClient.onChannelUpdate(function (channel) {
if (channel)
_this.channelsStorage.update(channel);
});
this.chatClient.onChannelUpsert(function (data) { return __awaiter(_this, void 0, void 0, function () {

@@ -258,36 +260,50 @@ var channel, _a, channelMembership, rest, nChannel;

.get(channelId, this.chatClient)
.then(function (channel) {
if (unsubscribed) {
return;
}
//Check if we need to join channel socket or the user channel is enough
//FIXME channel does not have listed & watching. Those property are from ChannelMembership.
if (channel.listed || channel.watching) {
if (!channelMessageStorage.latestDate()) {
//first time opening the channel. Load some messages
channelMessageStorage.loadEarlier(_this.chatClient);
.then(function (channel) { return __awaiter(_this, void 0, void 0, function () {
var currentUser, removeOnNewMessage, removeOnConnect;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (unsubscribed) {
return [2 /*return*/];
}
return [4 /*yield*/, this.currentUser()];
case 1:
currentUser = _a.sent();
//Check if we need to join channel socket or the user channel is enough
//FIXME channel does not have listed & watching. Those property are from ChannelMembership.
if (channel.listed || channel.watching) {
if (!channelMessageStorage.latestDate()) {
//first time opening the channel. Load some messages
channelMessageStorage.loadEarlier(this.chatClient);
}
return [2 /*return*/, function () { }];
}
this.chatClient.joinChannel(channel.id);
unsubscribeList.push(function () {
_this.chatClient.leaveChannel(channel.id);
});
//if channel was previously opened and some messages are loaded then load the reset
if (channelMessageStorage.latestDate() &&
!channelMessageStorage.initialMessagesLoaded) {
channelMessageStorage.loadAllLater(this.chatClient);
}
else {
channelMessageStorage.loadEarlier(this.chatClient);
}
removeOnNewMessage = this.chatClient.onNewMessage(channelId, function (message) {
channelMessageStorage.addLiveMessage([message]);
if (message.senderId !== currentUser.id) {
_this.markAllAsRead(channelId);
}
});
removeOnConnect = this.chatClient.onConnect(function () {
channelMessageStorage.loadAllLater(_this.chatClient);
});
unsubscribeList.push(removeOnNewMessage);
unsubscribeList.push(removeOnConnect);
return [2 /*return*/];
}
return function () { };
}
_this.chatClient.joinChannel(channel.id);
unsubscribeList.push(function () {
_this.chatClient.leaveChannel(channel.id);
});
//if channel was previously opened and some messages are loaded then load the reset
if (channelMessageStorage.latestDate() &&
!channelMessageStorage.initialMessagesLoaded) {
channelMessageStorage.loadAllLater(_this.chatClient);
}
else {
channelMessageStorage.loadEarlier(_this.chatClient);
}
var removeOnNewMessage = _this.chatClient.onNewMessage(channelId, function (message) {
channelMessageStorage.addLiveMessage([message]);
});
var removeOnConnect = _this.chatClient.onConnect(function () {
channelMessageStorage.loadAllLater(_this.chatClient);
});
unsubscribeList.push(removeOnNewMessage);
unsubscribeList.push(removeOnConnect);
})
}); })
.catch(function (_error) {

@@ -294,0 +310,0 @@ //throw error

@@ -189,5 +189,9 @@ "use strict";

});
chatService.setCurrentChannel(data.channel);
}
});
return function () { return removeListener(); };
return function () {
chatService.setCurrentChannel(null);
removeListener();
};
}, [channelExternalId, chatService]);

@@ -194,0 +198,0 @@ react_1.default.useEffect(function () {

{
"name": "bulbul-chat",
"version": "2.3.2",
"version": "2.3.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -53,27 +53,26 @@ import { diffInSeconds } from './utils';

);
if (channelMessageStorage.initialMessagesLoaded) {
if (
channelMessageStorage.initialMessagesLoaded &&
this.currentChannel?.id !== message.channelId
) {
channelMessageStorage.addLiveMessage([message]);
}
}
});
this.chatClient.onChannelUpdate(async (channel: ChatChannel) => {
if (channel) {
const currentUser = await this.currentUser();
if (message.channelId !== this.currentChannel?.id) {
// if the channel is not open and received a new message then update the unread messages
const channel = await this.channelsStorage.get(
message.channelId,
this.chatClient
);
const updatedChannel = await this.chatClient.getUnreadMessageCount(
channel
);
this.channelsStorage.update(updatedChannel);
} else if (message.senderId !== currentUser.id) {
// if the channel is open but the sender is not me then mark this message as read
this.markAllAsRead(message.channelId);
let updatedChannel = { ...channel };
if (
this.currentChannel?.id !== channel.id &&
channel.lastMessage?.senderId !== currentUser.id
) {
// if the channel is open then mark this message as read
updatedChannel = await this.chatClient.getUnreadMessageCount(channel);
}
this.channelsStorage.update(updatedChannel);
}
});
this.chatClient.onChannelUpdate((channel: ChatChannel) => {
if (channel) this.channelsStorage.update(channel);
});
this.chatClient.onChannelUpsert(async (data) => {

@@ -162,3 +161,3 @@ const channel = await this.channelsStorage.get(

setCurrentChannel(channel: ChatChannel) {
setCurrentChannel(channel: ChatChannel | null) {
this.currentChannel = channel;

@@ -201,6 +200,7 @@ }

.get(channelId, this.chatClient)
.then((channel) => {
.then(async (channel) => {
if (unsubscribed) {
return;
}
const currentUser = await this.currentUser();

@@ -236,2 +236,5 @@ //Check if we need to join channel socket or the user channel is enough

channelMessageStorage.addLiveMessage([message]);
if (message.senderId !== currentUser.id) {
this.markAllAsRead(channelId);
}
}

@@ -238,0 +241,0 @@ );

@@ -153,5 +153,9 @@ import { diffInSeconds } from './utils';

});
chatService.setCurrentChannel(data.channel);
}
});
return () => removeListener();
return () => {
chatService.setCurrentChannel(null);
removeListener();
};
}, [channelExternalId, chatService]);

@@ -158,0 +162,0 @@ React.useEffect(() => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc