From 24993c99e95aa61be9a084c7c1b5832491c7a8a4 Mon Sep 17 00:00:00 2001 From: Chris Brame Date: Mon, 11 Jul 2022 17:12:39 -0400 Subject: [PATCH] fix(settings): missing values when moving to react --- .../containers/Settings/General/index.jsx | 4 +- .../containers/Settings/Tickets/index.jsx | 4 +- .../Topbar/conversationsDropdown.jsx | 15 ++++- src/models/user.js | 64 ------------------- src/socketio/chatSocket.js | 8 ++- 5 files changed, 23 insertions(+), 72 deletions(-) diff --git a/src/client/containers/Settings/General/index.jsx b/src/client/containers/Settings/General/index.jsx index 8e753f167..f85ac57ea 100644 --- a/src/client/containers/Settings/General/index.jsx +++ b/src/client/containers/Settings/General/index.jsx @@ -109,7 +109,7 @@ class GeneralSettings extends React.Component { title='Site Url' subtitle={
- Publicly accessible URL of this site. ex: {this.props.viewdata.hosturl} + Publicly accessible URL of this site. ex: {this.props.viewdata.get('hosturl')}
} component={SiteUrl} @@ -186,7 +186,7 @@ GeneralSettings.propTypes = { } const mapStateToProps = state => ({ - viewdata: state.common, + viewdata: state.common.viewdata, settings: state.settings.settings }) diff --git a/src/client/containers/Settings/Tickets/index.jsx b/src/client/containers/Settings/Tickets/index.jsx index 0e43b6572..7f6b7ec36 100644 --- a/src/client/containers/Settings/Tickets/index.jsx +++ b/src/client/containers/Settings/Tickets/index.jsx @@ -242,7 +242,7 @@ class TicketsSettings extends React.Component { subtitle={
Allow the creation of tickets by users that are unregistered. ( - {viewdata.hosturl + '/newissue'}) + {viewdata.get('hosturl') + '/newissue'})
} component={ @@ -514,7 +514,7 @@ TicketsSettings.propTypes = { } const mapStateToProps = state => ({ - viewdata: state.common, + viewdata: state.common.viewdata, settings: state.settings.settings, tagsSettings: state.tagsSettings }) diff --git a/src/client/containers/Topbar/conversationsDropdown.jsx b/src/client/containers/Topbar/conversationsDropdown.jsx index 45b09ce40..dfcda92a2 100644 --- a/src/client/containers/Topbar/conversationsDropdown.jsx +++ b/src/client/containers/Topbar/conversationsDropdown.jsx @@ -44,6 +44,7 @@ class ConversationsDropdownPartial extends React.Component { } onUpdateConversationsNotifications (data) { + helpers.setupScrollers() if (!helpers.arrayIsEqual(this.conversations, data.conversations)) this.conversations = data.conversations } @@ -72,8 +73,20 @@ class ConversationsDropdownPartial extends React.Component { Start Conversation } + footerComponent={ +
+ { + History.pushState(null, null, '/messages') + }} + > + View All Conversations + +
+ } > -
+
    {this.conversations.map(conversation => { const profilePic = conversation.partner.image || 'defaultProfile.jpg' diff --git a/src/models/user.js b/src/models/user.js index df820ae72..50d2838fd 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -45,7 +45,6 @@ const COLLECTION = 'accounts' * @property {String} tOTPKey One Time Password Secret Key * @property {Number} tOTPPeriod One Time Password Key Length (Time) - Default 30 Seconds * @property {String} accessToken API Access Token - * @property {Array} iOSDeviceTokens Array of String based device Ids for Apple iOS devices. *push notifications* * @property {Object} preferences Object to hold user preferences * @property {Boolean} preferences.autoRefreshTicketGrid Enable the auto refresh of the ticket grid. * @property {Boolean} deleted Account Deleted @@ -190,38 +189,6 @@ userSchema.methods.removeL2Auth = function (callback) { }) } -userSchema.methods.addDeviceToken = function (token, type, callback) { - if (_.isUndefined(token)) return callback('Invalid token') - var user = this - // type 1 = iOS - // type 2 = Android - if (type === 1) { - if (hasDeviceToken(user, token, type)) return callback(null, token) - - user.iOSDeviceTokens.push(token) - user.save(function (err) { - if (err) return callback(err, null) - - callback(null, token) - }) - } -} - -userSchema.methods.removeDeviceToken = function (token, type, callback) { - var user = this - if (type === 1) { - if (!hasDeviceToken(user, token, type)) return callback() - - winston.debug('Removing Device: ' + token) - user.iOSDeviceTokens.splice(_.indexOf(this.iOSDeviceTokens, token), 1) - user.save(function (err, u) { - if (err) return callback(err, null) - - return callback(null, u.iOSDeviceTokens) - }) - } -} - userSchema.methods.addOpenChatWindow = function (convoId, callback) { if (convoId === undefined) { if (!_.isFunction(callback)) return false @@ -731,35 +698,4 @@ userSchema.statics.getAdmins = function (obj, callback) { }) } -/** - * Checks if a user has device token already - * - * @memberof User - * @instance - * @method hasDeviceToken - * - * @param {User} user User to check against - * @param {String} token token to check for in given user - * @param {Number} type Type of Device token to check. - * @return {Boolean} - * @example - * type: - * 1: iOS - * 2: Android - * 3: Windows - */ -function hasDeviceToken (user, token, type) { - if (type === 1) { - var matches = _.filter(user.iOSDeviceTokens, function (value) { - if (value === token) { - return value - } - }) - - return matches.length > 0 - } - - return false -} - module.exports = mongoose.model(COLLECTION, userSchema) diff --git a/src/socketio/chatSocket.js b/src/socketio/chatSocket.js index 817483240..8f19d46bc 100644 --- a/src/socketio/chatSocket.js +++ b/src/socketio/chatSocket.js @@ -192,15 +192,16 @@ async function updateConversationsNotifications (socket) { const Message = require('../models/chat/message') const Conversation = require('../models/chat/conversation') - Conversation.getConversationsWithLimit(user._id, 10, (err, conversation) => { + Conversation.getConversationsWithLimit(user._id, null, (err, conversations) => { if (err) { winston.warn(err.message) return false } const convos = [] + async.eachSeries( - conversation, + conversations, (convo, done) => { const c = convo.toObject() @@ -239,8 +240,9 @@ async function updateConversationsNotifications (socket) { }, err => { if (err) return false + return utils.sendToSelf(socket, socketEventConst.MESSAGES_UPDATE_UI_CONVERSATION_NOTIFICATIONS, { - conversations: convos + conversations: convos.length >= 10 ? convos.slice(0, 9) : convos }) } )