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

Features/prevent messages removal #84

Merged
merged 2 commits into from
Jun 1, 2015
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
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