Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/views/app/sideNav/channels.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Template.channels.helpers
return t('chatRooms.Members_placeholder')

rooms: ->
return ChatSubscription.find { 'u._id': Meteor.userId(), t: { $in: ['c']}, f: { $ne: true } }, { sort: 't': 1, 'rn': 1 }
return ChatSubscription.find { 'u._id': Meteor.userId(), t: { $in: ['c']}, f: { $ne: true } }, { sort: 't': 1, 'name': 1 }

total: ->
return ChatSubscription.find({ 'u._id': Meteor.userId(), t: { $in: ['c']}, f: { $ne: true } }, { sort: 't': 1, 'rn': 1 }).count()
return ChatSubscription.find({ 'u._id': Meteor.userId(), t: { $in: ['c']}, f: { $ne: true } }, { sort: 't': 1, 'name': 1 }).count()

Template.channels.events
'click .add-room': (e, instance) ->
Expand Down
2 changes: 1 addition & 1 deletion client/views/app/sideNav/chatRoomItem.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Template.chatRoomItem.helpers
else return ''

name: ->
return this.rn
return this.name

roomIcon: ->
switch this.t
Expand Down
4 changes: 2 additions & 2 deletions client/views/app/sideNav/directMessages.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Template.directMessages.helpers
rooms: ->
return ChatSubscription.find { 'u._id': Meteor.userId(), t: { $in: ['d']}, f: { $ne: true } }, { sort: 't': 1, 'rn': 1 }
return ChatSubscription.find { 'u._id': Meteor.userId(), t: { $in: ['d']}, f: { $ne: true } }, { sort: 't': 1, 'name': 1 }
total: ->
return ChatSubscription.find({ 'u._id': Meteor.userId(), t: { $in: ['d']}, f: { $ne: true } }, { sort: 't': 1, 'rn': 1 }).fetch().length
return ChatSubscription.find({ 'u._id': Meteor.userId(), t: { $in: ['d']}, f: { $ne: true } }, { sort: 't': 1, 'name': 1 }).fetch().length
4 changes: 2 additions & 2 deletions client/views/app/sideNav/privateGroups.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Template.privateGroups.helpers
tRoomMembers: ->
return t('chatRooms.Members_placeholder')
rooms: ->
return ChatSubscription.find { 'u._id': Meteor.userId(), t: { $in: ['p']}, f: { $ne: true } }, { sort: 't': 1, 'rn': 1 }
return ChatSubscription.find { 'u._id': Meteor.userId(), t: { $in: ['p']}, f: { $ne: true } }, { sort: 't': 1, 'name': 1 }
total: ->
return ChatSubscription.find({ 'u._id': Meteor.userId(), t: { $in: ['p']}, f: { $ne: true } }, { sort: 't': 1, 'rn': 1 }).fetch().length
return ChatSubscription.find({ 'u._id': Meteor.userId(), t: { $in: ['p']}, f: { $ne: true } }, { sort: 't': 1, 'name': 1 }).fetch().length

Template.privateGroups.events
'click .add-room': (e, instance) ->
Expand Down
4 changes: 2 additions & 2 deletions client/views/app/sideNav/starredRooms.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Template.starredRooms.helpers
rooms: ->
return ChatSubscription.find { 'u._id': Meteor.userId(), f: true }, { sort: 't': 1, 'rn': 1 }
return ChatSubscription.find { 'u._id': Meteor.userId(), f: true }, { sort: 't': 1, 'name': 1 }
total: ->
return ChatSubscription.find({ 'u._id': Meteor.userId(), f: true }, { sort: 't': 1, 'rn': 1 }).fetch().length
return ChatSubscription.find({ 'u._id': Meteor.userId(), f: true }, { sort: 't': 1, 'name': 1 }).fetch().length
2 changes: 1 addition & 1 deletion server/methods/addUserToRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Meteor.methods
username: data.username
rid: data.rid
ts: (new Date())
rn: room.name
name: room.name
t: room.t
unread: 0

Expand Down
2 changes: 1 addition & 1 deletion server/methods/canAccessRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Meteor.methods
ChatSubscription.upsert { rid: roomId, $and: [{'u._id': Meteor.userId()}] },
$setOnInsert:
'u._id': Meteor.userId()
rn: room.name
name: room.name
t: room.t
unread: 0
$set:
Expand Down
4 changes: 2 additions & 2 deletions server/methods/createChannel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ Meteor.methods
continue

sub =
u:
u:
_id: member._id
username: username
rid: roomId
ts: now
rn: name
name: name
t: 'c'
unread: 0

Expand Down
4 changes: 2 additions & 2 deletions server/methods/createDirectRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ Meteor.methods
$set:
ts: now
ls: now
rn: userTo.name
name: userTo.name
$setOnInsert:
t: 'd'
unread: 0
'u._id': userTo._id

ChatSubscription.upsert { $and: [{'u._id': userTo._id}], rid: roomId },
$set:
rn: me.name
name: me.name
$setOnInsert:
t: 'd'
unread: 0
Expand Down
4 changes: 2 additions & 2 deletions server/methods/createPrivateGroup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Meteor.methods
continue

sub =
u:
u:
_id: member._id
username: username
rid: roomId
ts: now
rn: name
name: name
t: 'p'
unread: 0

Expand Down
2 changes: 1 addition & 1 deletion server/methods/leaveRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Meteor.methods

ChatSubscription.update { rid: roomId },
$set:
rn: room.name
name: room.name
,
multi: true

Expand Down
2 changes: 1 addition & 1 deletion server/methods/saveRoomName.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Meteor.methods

ChatSubscription.update { rid: data.rid },
$set:
rn: newName
name: newName
,
multi: true

Expand Down
2 changes: 1 addition & 1 deletion server/methods/setUsername.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Meteor.methods
_id: user._id
username: username
ls: new Date()
rn: 'general'
name: 'general'
t: 'c'
f: true
ts: new Date()
Expand Down
18 changes: 12 additions & 6 deletions server/startup/indexes.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
Meteor.startup ->
Meteor.defer ->
ChatMessage._ensureIndex({ 'expireAt': 1 }, { expireAfterSeconds: 0 })
ChatMessage._ensureIndex({ 'rid': 1 })
ChatMessage._ensureIndex({ 'rid': 1, 'ts': 1 })
ChatSubscription._ensureIndex({ 'u._id': 1 })
ChatSubscription._ensureIndex({ 'ts': 1 })
ChatSubscription._ensureIndex({ 'rid': 1, 'u._id': 1 }, {unique: true})
try ChatRoom._ensureIndex { 'name': 1 }, { unique: 1, sparse: 1 } catch e then console.log e
try ChatRoom._ensureIndex { 'u._id': 1 } catch e then console.log e

try ChatSubscription._ensureIndex { 'rid': 1, 'u._id': 1 }, { unique: 1 } catch e then console.log e
try ChatSubscription._ensureIndex { 'u._id': 1, 'name': 1, 't': 1 }, { unique: 1 } catch e then console.log e
try ChatSubscription._ensureIndex { 'open': 1 } catch e then console.log e
try ChatSubscription._ensureIndex { 'alert': 1 } catch e then console.log e
try ChatSubscription._ensureIndex { 'unread': 1 } catch e then console.log e
try ChatSubscription._ensureIndex { 'ts': 1 } catch e then console.log e

try ChatMessage._ensureIndex { 'rid': 1, 'ts': 1 } catch e then console.log e
try ChatMessage._ensureIndex { 'expireAt': 1 }, { expireAfterSeconds: 0 } catch e then console.log e
36 changes: 36 additions & 0 deletions server/startup/migrations/v4.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Meteor.startup ->
Migrations.add
version: 4
up: ->

try ChatMessage._dropIndex 'rid_1'
try ChatSubscription._dropIndex 'u._id_1'


console.log 'Rename rn to name'
ChatSubscription.update({rn: {$exists: true}}, {$rename: {rn: 'name'}}, {multi: true})


console.log 'Adding names to rooms without name'
ChatRoom.find({name: ''}).forEach (item) ->
name = Random.id().toLowerCase()
ChatRoom.update item._id, {$set: {name: name}}
ChatSubscription.update {rid: item._id}, {$set: {name: name}}, {multi: true}


console.log 'Making room names unique'
ChatRoom.find().forEach (room) ->
ChatRoom.find({name: room.name, _id: {$ne: room._id}}).forEach (item) ->
name = room.name + '-' + Random.id(2).toLowerCase()
ChatRoom.update item._id, {$set: {name: name}}
ChatSubscription.update {rid: item._id}, {$set: {name: name}}, {multi: true}


console.log 'Dropping test rooms with less than 10 messages'
ChatRoom.find({msgs: {'$lt': 10}}).forEach (room) ->
ChatRoom.remove room._id
ChatMessage.remove {rid: room._id}
ChatSubscription.remove {rid: room._id}


console.log 'End'