Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gitter-realtime-client

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitter-realtime-client - npm Package Compare versions

Comparing version 0.1.15 to 0.2.0

3

lib/index.js

@@ -8,3 +8,4 @@ 'use strict';

RoomModel: require('./room-model'),
filteredRooms: require('./filtered-rooms')
filteredRooms: require('./filtered-rooms'),
sortsFilters: require('./sorts-filters')
};

@@ -165,3 +165,3 @@ "use strict";

// add one by one
this.set(snapshot.concat(forKeeping), options);
this.set(forKeeping.concat(snapshot), options);
} else {

@@ -168,0 +168,0 @@ // trash it and add all in one go

@@ -24,23 +24,30 @@ "use strict";

if (time) {
this.set('lastAccessTimeNoSync', time.clone());
this.set('lastAccessTimeOnLoad', time.clone());
} else if(this.get('unreadItems')) {
// room has been added to the list but the user has never visited it.
// probably a fresh mention in a room.
// better escalate this room to be highest on the list.
this.set('escalationTime', moment());
}
if(this.get('unreadItems')) {
this.set('hasHadUnreadItemsAtSomePoint', true);
this.set('hadUnreadItemsOnLoad', true);
}
if(this.get('mentions')) {
this.set('hasHadMentionsAtSomePoint', true);
this.set('hadMentionsOnLoad', true);
}
}
this.listenTo(this, 'change:unreadItems', function (model, unreadItems) { // jshint unused:true
if(unreadItems) {
this.set('hasHadUnreadItemsAtSomePoint', true);
this.listenTo(this, 'change:mentions', function (model, mentions) { // jshint unused:true
if(!this.previous('mentions') && mentions) {
// changed from 0 mentions to 1+, so escalate this room to be highest on the list
this.set('escalationTime', moment());
}
});
this.listenTo(this, 'change:mentions', function(model, mentions) { // jshint unused:true
if(mentions) {
this.set('hasHadMentionsAtSomePoint', true);
this.listenTo(this, 'change:unreadItems', function (model, unreadItems) { // jshint unused:true
if(!this.previous('unreadItems') && unreadItems) {
// changed from 0 unread to 1+, so escalate this room to be highest on the list
this.set('escalationTime', moment());
}

@@ -47,0 +54,0 @@ });

@@ -37,5 +37,5 @@ 'use strict';

// hasHadMentionsAtSomePoint is not available on the server, so we have a failover.
if (room.hasHadMentionsAtSomePoint || room.mentions) {
if (room.hadMentionsOnLoad || room.mentions) {
return 0;
} else if (room.hasHadUnreadItemsAtSomePoint || room.unreadItems) {
} else if (room.hadUnreadItemsOnLoad || room.unreadItems) {
return 1;

@@ -51,18 +51,17 @@ } else {

// lastAccessTimeNoSync is not available on the server, so we have a failover.
var aDate = a.lastAccessTimeNoSync || a.lastAccessTime;
var bDate = b.lastAccessTimeNoSync || b.lastAccessTime;
// new Date(x).valueOf converts Moments, Dates, Strings and unixtime ints to unixtime ints.
var aTime = new Date(a.lastAccessTimeOnLoad || a.lastAccessTime || 0).valueOf();
var bTime = new Date(b.lastAccessTimeOnLoad || b.lastAccessTime || 0).valueOf();
if(!aDate && !bDate) {
return 0;
} else if(!aDate) {
// therefore bDate exists and is best
return 1;
} else if(!bDate) {
// therefore aDate exists and is best
return -1;
} else {
return new Date(bDate).valueOf() - new Date(aDate).valueOf();
}
return bTime - aTime;
}
function escalationDifference(a, b) {
var aTime = a.escalationTime && a.escalationTime.valueOf() || 0;
var bTime = b.escalationTime && b.escalationTime.valueOf() || 0;
// most recently escalated is better
return bTime - aTime;
}
var favouritesSort = nullsLast(function(a, b) {

@@ -82,10 +81,14 @@ var isDifferent = natural(a.favourite, b.favourite);

var recentsSort = nullsLast(function(a, b) {
var aRank = getRank(a);
var bRank = getRank(b);
var escDiff = escalationDifference(a, b);
if (aRank === bRank) {
return timeDifference(a, b, aRank);
} else {
return aRank - bRank;
}
if (escDiff) return escDiff;
var aRank = getRank(a);
var bRank = getRank(b);
if (aRank === bRank) {
return timeDifference(a, b);
} else {
return aRank - bRank;
}
});

@@ -92,0 +95,0 @@

{
"name": "gitter-realtime-client",
"version": "0.1.15",
"version": "0.2.0",
"description": "Gitter Realtime Client",

@@ -28,3 +28,6 @@ "main": "lib/index.js",

"mocha": "^2.1.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
}
}

@@ -100,6 +100,6 @@ /*jslint node:true, unused:true*/

mentions: 3,
hasHadUnreadItemsAtSomePoint: true,
hasHadMentionsAtSomePoint: true,
hadUnreadItemsOnLoad: true,
hadMentionsOnLoad: true,
lastAccessTime: OLD,
lastAccessTimeNoSync: OLD
lastAccessTimeOnLoad: OLD
});

@@ -110,6 +110,6 @@ var roomToUpdate = new Backbone.Model({

mentions: 1,
hasHadUnreadItemsAtSomePoint: true,
hasHadMentionsAtSomePoint: true,
hadUnreadItemsOnLoad: true,
hadMentionsOnLoad: true,
lastAccessTime: VERY_OLD,
lastAccessTimeNoSync: VERY_OLD
lastAccessTimeOnLoad: VERY_OLD
});

@@ -133,6 +133,6 @@ var collection = new RecentsCollection([room, roomToUpdate]);

mentions: 1,
hasHadUnreadItemsAtSomePoint: true,
hasHadMentionsAtSomePoint: true,
hadUnreadItemsOnLoad: true,
hadMentionsOnLoad: true,
lastAccessTime: OLD,
lastAccessTimeNoSync: OLD
lastAccessTimeOnLoad: OLD
});

@@ -143,6 +143,6 @@ var roomToUpdate = new Backbone.Model({

mentions: 1,
hasHadUnreadItemsAtSomePoint: true,
hasHadMentionsAtSomePoint: true,
hadUnreadItemsOnLoad: true,
hadMentionsOnLoad: true,
lastAccessTime: VERY_OLD,
lastAccessTimeNoSync: VERY_OLD
lastAccessTimeOnLoad: VERY_OLD
});

@@ -153,6 +153,6 @@ var veryVeryOldRoom = new Backbone.Model({

mentions: 1,
hasHadUnreadItemsAtSomePoint: true,
hasHadMentionsAtSomePoint: true,
hadUnreadItemsOnLoad: true,
hadMentionsOnLoad: true,
lastAccessTime: VERY_VERY_OLD,
lastAccessTimeNoSync: VERY_VERY_OLD
lastAccessTimeOnLoad: VERY_VERY_OLD
});

@@ -186,2 +186,14 @@ var collection = new RecentsCollection([room, roomToUpdate, veryVeryOldRoom]);

it('puts new unreads above rooms that had unreads (issue troupe/gitter-webapp#368)', function() {
var collection = new RecentsCollection([
{ id: 'regular' },
{ id: 'was_unread', hadUnreadItemsOnLoad: true, lastAccessTime: OLD },
{ id: 'unread', unreadItems: 1, escalationTime: NEW }
]);
collection.sort();
assert.deepEqual(id(collection), ['unread', 'was_unread', 'regular']);
});
it('sorts multiple unread rooms by time of last access', function() {

@@ -213,5 +225,5 @@ var collection = new RecentsCollection([

unreadItems: 5,
hasHadUnreadItemsAtSomePoint: true,
hadUnreadItemsOnLoad: true,
lastAccessTime: OLD,
lastAccessTimeNoSync: OLD
lastAccessTimeOnLoad: OLD
});

@@ -221,5 +233,5 @@ var roomToUpdate = new Backbone.Model({

unreadItems: 3,
hasHadUnreadItemsAtSomePoint: true,
hadUnreadItemsOnLoad: true,
lastAccessTime: VERY_OLD,
lastAccessTimeNoSync: VERY_OLD
lastAccessTimeOnLoad: VERY_OLD
});

@@ -242,5 +254,5 @@ var collection = new RecentsCollection([room, roomToUpdate]);

unreadItems: 1,
hasHadUnreadItemsAtSomePoint: true,
hadUnreadItemsOnLoad: true,
lastAccessTime: OLD,
lastAccessTimeNoSync: OLD
lastAccessTimeOnLoad: OLD
});

@@ -250,5 +262,5 @@ var roomToUpdate = new Backbone.Model({

unreadItems: 1,
hasHadUnreadItemsAtSomePoint: true,
hadUnreadItemsOnLoad: true,
lastAccessTime: VERY_OLD,
lastAccessTimeNoSync: VERY_OLD
lastAccessTimeOnLoad: VERY_OLD
});

@@ -258,5 +270,5 @@ var veryVeryOldRoom = new Backbone.Model({

unreadItems: 1,
hasHadUnreadItemsAtSomePoint: true,
hadUnreadItemsOnLoad: true,
lastAccessTime: VERY_VERY_OLD,
lastAccessTimeNoSync: VERY_VERY_OLD
lastAccessTimeOnLoad: VERY_VERY_OLD
});

@@ -303,4 +315,4 @@ var collection = new RecentsCollection([room, roomToUpdate, veryVeryOldRoom]);

it('doesnt move rooms if they are later accessed', function() {
var room = new Backbone.Model({ id: 'room', lastAccessTime: OLD, lastAccessTimeNoSync: OLD });
var roomToUpdate = new Backbone.Model({ id: 'room_to_update', lastAccessTime: VERY_OLD, lastAccessTimeNoSync: VERY_OLD });
var room = new Backbone.Model({ id: 'room', lastAccessTime: OLD, lastAccessTimeOnLoad: OLD });
var roomToUpdate = new Backbone.Model({ id: 'room_to_update', lastAccessTime: VERY_OLD, lastAccessTimeOnLoad: VERY_OLD });
var collection = new RecentsCollection([room, roomToUpdate]);

@@ -307,0 +319,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc