Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including tab for listing room uploaded files #955

Merged
merged 10 commits into from
Oct 3, 2015
Merged
1 change: 1 addition & 0 deletions client/routes/roomRoute.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ openRoom = (type, name) ->
RocketChat.TabBar.addButton({ id: 'members-list', title: t('User_Info'), icon: 'icon-user', template: 'membersList', order: 2 })
else
RocketChat.TabBar.addButton({ id: 'members-list', title: t('Members_List'), icon: 'icon-users', template: 'membersList', order: 2 })
RocketChat.TabBar.addButton({ id: 'uploaded-files-list', title: t('Room_uploaded_file_list'), icon: 'icon-download', template: 'uploadedFilesList', order: 3 })

# update user's room subscription
if ChatSubscription.findOne({rid: room._id})?.open is false
Expand Down
19 changes: 19 additions & 0 deletions client/views/app/tabBar/uploadedFilesList.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
roomFiles = new Mongo.Collection 'room_files'

Template.uploadedFilesList.helpers
files: ->
return roomFiles.find().fetch()

hasFiles: ->
return roomFiles.find().count() > 0

getFileIcon: (type) ->
if type.match(/^image\/.+$/)
return 'icon-picture'

return 'icon-docs'

Template.uploadedFilesList.onCreated ->
instance = this
this.autorun ->
instance.subscribe 'roomFiles', Session.get('openedRoom')
25 changes: 25 additions & 0 deletions client/views/app/tabBar/uploadedFilesList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template name="uploadedFilesList">
<div class="content">
<div class="list-view">
<div class="status">
<h2>{{_ "Room_uploaded_file_list"}}</h2>
</div>
{{#if Template.subscriptionsReady}}
{{#if hasFiles }}
<ul class='list clearfix lines'>
{{#each files}}
<li>
<i class="{{getFileIcon type}}"></i>
<a title="{{name}}" href="{{url}}" target="_blank">{{name}}</a>
</li>
{{/each}}
</ul>
{{else}}
<h2>{{_ "Room_uploaded_file_list_empty"}}</h2>
{{/if}}
{{else}}
<span>{{_ "Loading..."}}</span>
{{/if}}
</div>
</div>
</template>
2 changes: 2 additions & 0 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@
"Room_name_changed" : "Room name changed to: <em>__room_name__</em> by <em>__user_by__</em>",
"Room_name_changed_successfully" : "Room name changed successfully",
"Room_not_found" : "Room not found",
"Room_uploaded_file_list" : "Files list",
"Room_uploaded_file_list_empty" : "No files available.",
"room_user_count" : "%s users",
"Rooms" : "Rooms",
"Save" : "Save",
Expand Down
2 changes: 2 additions & 0 deletions i18n/pt.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@
"Room_name_changed" : "Nome da sala alterado para: <em>__room_name__</em> por <em>__user_by__</em>",
"Room_name_changed_successfully" : "Nome da sala alterado com sucesso",
"Room_not_found" : "Sala não encontrada",
"Room_uploaded_file_list" : "Lista de arquivos",
"Room_uploaded_file_list_empty" : "Nenhum arquivo disponível",
"room_user_count" : "%s usuários",
"Rooms" : "Salas",
"Save" : "Salvar",
Expand Down
59 changes: 59 additions & 0 deletions server/publications/roomFiles.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Meteor.publish 'roomFiles', (rid) ->
unless this.userId
return this.ready()

console.log '[publish] roomFiles'.green, rid

# list of channel messages which were created after uploading a file
msgQuery =
rid: rid
'file._id': { $exists: true }
msgOptions =
fields:
_id: 1
'file._id': 1
limit: 50
cursorFileMessages = RocketChat.models.Messages.find(msgQuery, msgOptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to use a named query, like RocketChat.models.Messages.findMessagesWithFilesByRoomId?

uploadedFilesMessages = cursorFileMessages.fetch()
unless uploadedFilesMessages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as i know the fetch always returns an array, so probably this unless will not work, right?

return this.ready()

uploadIdList = _.map(uploadedFilesMessages, (doc) -> return doc?.file?._id)
unless uploadIdList
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem here, _.map always returns an array

return this.ready()

fileQuery =
_id: { $in : uploadIdList }
complete: true
uploading: false

fileOptions =
fields:
_id: 1
name: 1
type: 1
url: 1

cursorFileList = fileCollection.find(fileQuery, fileOptions)

# observe whether a new file was sent to the room and notifies subscribers
pub = this
cursorFileMessagesHandle = cursorFileMessages.observeChanges
added: (_id, record) ->
unless record?.file?._id
return pub.ready()

data = fileCollection.findOne({ _id: record.file._id }, fileOptions)

data.rid = rid
pub.added('room_files', record.file._id, data)

cursorFileListHandle = cursorFileList.observeChanges
added: (_id, record) ->
record.rid = rid
pub.added('room_files', _id, record)

this.ready()
this.onStop ->
cursorFileListHandle.stop()
cursorFileMessagesHandle.stop()