Skip to content
Snippets Groups Projects
Commit a91f639c authored by Gabriel Engel's avatar Gabriel Engel
Browse files

Merge pull request #156 from RocketChat/better-urls

Better urls
parents cb539025 e0852271
No related branches found
No related tags found
No related merge requests found
Showing
with 68 additions and 26 deletions
......@@ -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) ->
......
......@@ -17,7 +17,7 @@ Template.chatRoomItem.helpers
else return ''
name: ->
return this.rn
return this.name
roomIcon: ->
switch this.t
......
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
......@@ -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) ->
......
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
\ No newline at end of file
return ChatSubscription.find({ 'u._id': Meteor.userId(), f: true }, { sort: 't': 1, 'name': 1 }).fetch().length
......@@ -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
......
......@@ -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:
......
......@@ -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
......
......@@ -28,7 +28,7 @@ Meteor.methods
$set:
ts: now
ls: now
rn: userTo.name
name: userTo.name
$setOnInsert:
t: 'd'
unread: 0
......@@ -36,7 +36,7 @@ Meteor.methods
ChatSubscription.upsert { $and: [{'u._id': userTo._id}], rid: roomId },
$set:
rn: me.name
name: me.name
$setOnInsert:
t: 'd'
unread: 0
......
......@@ -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
......
......@@ -14,7 +14,7 @@ Meteor.methods
ChatSubscription.update { rid: roomId },
$set:
rn: room.name
name: room.name
,
multi: true
......
......@@ -20,7 +20,7 @@ Meteor.methods
ChatSubscription.update { rid: data.rid },
$set:
rn: newName
name: newName
,
multi: true
......
......@@ -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()
......
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
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'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment