-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathworld.js
68 lines (54 loc) · 1.82 KB
/
world.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Signals = imports.signals;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const People = Me.imports.people;
const Timezone = Me.imports.timezone;
function _valuesToArray(obj) {
return Object.keys(obj).map(function (key) { return obj[key]; });
}
var World = new Lang.Class({
Name: 'World',
_init: function() {
this._people = new People.People;
this._peopleChangedSignalId = this._people.connect('changed', Lang.bind(this, function() {
this.emit('changed');
}));
},
destroy: function() {
this._people.disconnect(this._peopleChangedSignalId);
this.parent();
},
_sortByTimezone: function(a, b) {
let d = a.offset - b.offset;
if (d < 0)
return -1;
else if (d > 0)
return 1;
return 0;
},
_getTimezonesCB: function(people) {
if (people.error) {
this._getTimezonesOriginalCB(people);
return;
}
let localOffset = GLib.DateTime.new_now_local().get_utc_offset() / (3600*1000*1000);
let timezones = {};
people.forEach(function(person) {
if (timezones[person.offset] == undefined) {
timezones[person.offset] = new Timezone.Timezone(person);
}
timezones[person.offset].addPerson(person);
});
timezones = _valuesToArray(timezones);
timezones.sort(this._sortByTimezone);
this._timezones = timezones;
this._getTimezonesOriginalCB(this._timezones);
},
getTimezones: function(cb) {
this._getTimezonesOriginalCB = cb;
this._people.getPeople(Lang.bind(this, this._getTimezonesCB));
}
});
Signals.addSignalMethods(World.prototype);