Skip to content

Commit

Permalink
Merge pull request #84 from RocketChat/features/prevent-messages-removal
Browse files Browse the repository at this point in the history
Features/prevent messages removal
  • Loading branch information
engelgabriel committed Jun 1, 2015
2 parents 6f7c002 + a2135f6 commit 32c5efc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
12 changes: 10 additions & 2 deletions client/lib/RoomHistoryManager.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@RoomHistoryManager = new class
defaultLimit = 30
defaultLimit = 20

histories = {}

Expand Down Expand Up @@ -27,7 +27,15 @@

$('.messages-box .wrapper').data('previous-height', $('.messages-box .wrapper').get(0)?.scrollHeight - $('.messages-box .wrapper').get(0)?.scrollTop)

Meteor.call 'loadHistory', roomId, room.from, limit, room.loaded, (err, result) ->
lastMessage = ChatMessageHistory.findOne({rid: roomId}, {sort: {ts: 1}})
lastMessage ?= ChatMessage.findOne({rid: roomId}, {sort: {ts: 1}})

if lastMessage?
ts = lastMessage.ts
else
ts = new Date

Meteor.call 'loadHistory', roomId, ts, limit, 0, (err, result) ->
ChatMessageHistory.insert item for item in result

room.isLoading.set false
Expand Down
5 changes: 5 additions & 0 deletions client/lib/collections.coffee
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
@UserAndRoom = new Meteor.Collection null
@ChatMessageHistory = new Meteor.Collection null

Meteor.startup ->
ChatMessage.find().observe
removed: (record) ->
ChatMessageHistory.insert record
2 changes: 1 addition & 1 deletion server/methods/loadHistory.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meteor.methods
query =
rid: rid
ts:
$lte: end
$lt: end

options =
sort:
Expand Down

0 comments on commit 32c5efc

Please sign in to comment.