expiring_messages.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * vim: ts=4:sw=4:expandtab
  3. */
  4. ;(function() {
  5. 'use strict';
  6. window.Whisper = window.Whisper || {};
  7. Whisper.ExpiringMessages = new (Whisper.MessageCollection.extend({
  8. initialize: function() {
  9. this.on('expired', this.remove);
  10. this.fetchExpiring();
  11. }
  12. }))();
  13. var TimerOption = Backbone.Model.extend({
  14. getName: function() {
  15. return i18n([
  16. 'timerOption', this.get('time'), this.get('unit'),
  17. ].join('_')) || moment.duration(this.get('time'), this.get('unit')).humanize();
  18. },
  19. getAbbreviated: function() {
  20. return i18n([
  21. 'timerOption', this.get('time'), this.get('unit'), 'abbreviated'
  22. ].join('_'));
  23. }
  24. });
  25. Whisper.ExpirationTimerOptions = new (Backbone.Collection.extend({
  26. model: TimerOption,
  27. getName: function(seconds) {
  28. if (!seconds) {
  29. seconds = 0;
  30. }
  31. var o = this.findWhere({seconds: seconds});
  32. if (o) { return o.getName(); }
  33. },
  34. getAbbreviated: function(seconds) {
  35. if (!seconds) {
  36. seconds = 0;
  37. }
  38. var o = this.findWhere({seconds: seconds});
  39. if (o) { return o.getAbbreviated(); }
  40. }
  41. }))([
  42. [ 0, 'seconds' ],
  43. [ 5, 'seconds' ],
  44. [ 10, 'seconds' ],
  45. [ 30, 'seconds' ],
  46. [ 1, 'minute' ],
  47. [ 5, 'minutes' ],
  48. [ 30, 'minutes' ],
  49. [ 1, 'hour' ],
  50. [ 6, 'hours' ],
  51. [ 12, 'hours' ],
  52. [ 1, 'day' ],
  53. [ 1, 'week' ],
  54. ].map(function(o) {
  55. var duration = moment.duration(o[0], o[1]); // 5, 'seconds'
  56. return {
  57. time: o[0],
  58. unit: o[1],
  59. seconds: duration.asSeconds()
  60. };
  61. }));
  62. })();