Skip to content

Commit

Permalink
fix(settings): missing values when moving to react
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jul 11, 2022
1 parent 2de92f8 commit 24993c9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 72 deletions.
4 changes: 2 additions & 2 deletions src/client/containers/Settings/General/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class GeneralSettings extends React.Component {
title='Site Url'
subtitle={
<div>
Publicly accessible URL of this site. <i>ex: {this.props.viewdata.hosturl}</i>
Publicly accessible URL of this site. <i>ex: {this.props.viewdata.get('hosturl')}</i>
</div>
}
component={SiteUrl}
Expand Down Expand Up @@ -186,7 +186,7 @@ GeneralSettings.propTypes = {
}

const mapStateToProps = state => ({
viewdata: state.common,
viewdata: state.common.viewdata,
settings: state.settings.settings
})

Expand Down
4 changes: 2 additions & 2 deletions src/client/containers/Settings/Tickets/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class TicketsSettings extends React.Component {
subtitle={
<div>
Allow the creation of tickets by users that are unregistered. (
<a href={viewdata.hosturl + '/newissue'}>{viewdata.hosturl + '/newissue'}</a>)
<a href={viewdata.get('hosturl') + '/newissue'}>{viewdata.get('hosturl') + '/newissue'}</a>)
</div>
}
component={
Expand Down Expand Up @@ -514,7 +514,7 @@ TicketsSettings.propTypes = {
}

const mapStateToProps = state => ({
viewdata: state.common,
viewdata: state.common.viewdata,
settings: state.settings.settings,
tagsSettings: state.tagsSettings
})
Expand Down
15 changes: 14 additions & 1 deletion src/client/containers/Topbar/conversationsDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ConversationsDropdownPartial extends React.Component {
}

onUpdateConversationsNotifications (data) {
helpers.setupScrollers()
if (!helpers.arrayIsEqual(this.conversations, data.conversations)) this.conversations = data.conversations
}

Expand Down Expand Up @@ -72,8 +73,20 @@ class ConversationsDropdownPartial extends React.Component {
Start Conversation
</a>
}
footerComponent={
<div className={'uk-text-center' + (this.conversations.length < 1 ? ' hide' : '')}>
<a
className={'no-ajaxy hoverUnderline'}
onClick={() => {
History.pushState(null, null, '/messages')
}}
>
View All Conversations
</a>
</div>
}
>
<div className={'items close-on-click'}>
<div className={'items scrollable close-on-click'}>
<ul>
{this.conversations.map(conversation => {
const profilePic = conversation.partner.image || 'defaultProfile.jpg'
Expand Down
64 changes: 0 additions & 64 deletions src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
8 changes: 5 additions & 3 deletions src/socketio/chatSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
})
}
)
Expand Down

0 comments on commit 24993c9

Please sign in to comment.