Skip to content

Commit 4869ef1

Browse files
committed
fix(ui): conversation dropdown not populating
1 parent 768ecd6 commit 4869ef1

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

src/socketio/chatSocket.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ function register (socket) {
4444
function eventLoop () {
4545
updateUsers()
4646
updateOnlineBubbles()
47-
updateConversationsNotifications()
4847
}
4948

5049
events.onUpdateUsers = function (socket) {
5150
socket.on('updateUsers', updateUsers)
5251
}
52+
5353
events.onSetUserOnlineStatus = function (socket) {
5454
socket.on(socketEventConst.UI_ONLINE_STATUS_SET, data => {
5555
const state = data.state
@@ -186,45 +186,34 @@ events.updateOnlineBubbles = function (socket) {
186186
})
187187
}
188188

189-
async function updateConversationsNotifications () {
190-
return // TODO: Disable until we can fix the performance hit on this eventloop.
191-
const sockets = await io.fetchSockets()
192-
sockets.forEach(function (socket) {
193-
if (!socket.request && !socket.request.user) {
194-
return
195-
}
189+
async function updateConversationsNotifications (socket) {
190+
if (socket && socket.request && socket.request.user) {
191+
const user = socket.request.user
192+
const Message = require('../models/chat/message')
193+
const Conversation = require('../models/chat/conversation')
196194

197-
const userId = socket.request.user._id
198-
const messageSchema = require('../models/chat/message')
199-
const conversationSchema = require('../models/chat/conversation')
200-
conversationSchema.getConversationsWithLimit(userId, 10, function (err, conversations) {
195+
Conversation.getConversationsWithLimit(user._id, 10, (err, conversation) => {
201196
if (err) {
202197
winston.warn(err.message)
203198
return false
204199
}
205200

206201
const convos = []
207-
208202
async.eachSeries(
209-
conversations,
210-
function (convo, done) {
203+
conversation,
204+
(convo, done) => {
211205
const c = convo.toObject()
212206

213-
const userMeta =
214-
convo.userMeta[
215-
_.findIndex(convo.userMeta, function (item) {
216-
return item.userId.toString() === userId.toString()
217-
})
218-
]
207+
const userMeta = convo.userMeta[_.findIndex(convo.userMeta, i => i.userId.toString() === user._id.toString())]
219208
if (!_.isUndefined(userMeta) && !_.isUndefined(userMeta.deletedAt) && userMeta.deletedAt > convo.updatedAt) {
220209
return done()
221210
}
222211

223-
messageSchema.getMostRecentMessage(c._id, function (err, rm) {
212+
Message.getMostRecentMessage(c._id, (err, rm) => {
224213
if (err) return done(err)
225214

226-
_.each(c.participants, function (p) {
227-
if (p._id.toString() !== userId.toString()) {
215+
_.each(c.participants, p => {
216+
if (p._id.toString() !== user._id.toString()) {
228217
c.partner = p
229218
}
230219
})
@@ -248,15 +237,15 @@ async function updateConversationsNotifications () {
248237
return done()
249238
})
250239
},
251-
function (err) {
240+
err => {
252241
if (err) return false
253242
return utils.sendToSelf(socket, socketEventConst.MESSAGES_UPDATE_UI_CONVERSATION_NOTIFICATIONS, {
254243
conversations: convos
255244
})
256245
}
257246
)
258247
})
259-
})
248+
}
260249
}
261250

262251
events.updateConversationsNotifications = function (socket) {

0 commit comments

Comments
 (0)