PageRenderTime 62ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/assets/js/models.js

https://github.com/predominant/subway
JavaScript | 83 lines | 60 code | 11 blank | 12 comment | 11 complexity | 3c5cd1af809b0fa2c1c276c7348154b3 MD5 | raw file
  1. var Message = Backbone.Model.extend({
  2. defaults: {
  3. // expected properties:
  4. // - sender
  5. // - raw
  6. type: 'message'
  7. },
  8. initialize: function() {
  9. if (this.get('raw')) {
  10. this.set({text: this.get('raw')});
  11. }
  12. //Temporary solution to make unread mentions work again
  13. if (this.get('type') === 'message' && this.get('raw').search('\\b' + irc.me.get('nick') + '\\b') !== -1){
  14. this.set({mention: true});
  15. }
  16. },
  17. parse: function(text) {
  18. var nick = this.get('sender') || this.collection.channel.get('name');
  19. var result = utils.linkify(text);
  20. if (nick !== irc.me.get('nick')) {
  21. result = utils.mentions(result);
  22. }
  23. return result;
  24. },
  25. });
  26. // Represents any type of chat window -- a channel, private message,
  27. // or the status/console window.
  28. var ChatWindow = Backbone.Model.extend({
  29. // expected properties:
  30. // - name
  31. defaults: {
  32. type: 'channel',
  33. active: true,
  34. unread: 0,
  35. unreadMentions: 0
  36. },
  37. initialize: function() {
  38. console.log('chat window created');
  39. this.stream = new Stream();
  40. this.stream.bind('add', this.setUnread, this);
  41. //Backbone's collections don't support
  42. //attribute assignment in initizialization
  43. this.stream.channel = this;
  44. this.view = new ChatView({model: this});
  45. },
  46. part: function() {
  47. console.log('Leaving ' + this.get('name'));
  48. this.destroy();
  49. },
  50. setUnread: function(msg) {
  51. if (this.get('active')) return;
  52. var signal = false;
  53. // Increment unread messages
  54. if(msg.get('type') === 'message' || msg.get('type') === 'pm'){
  55. this.set({unread: this.get('unread') + 1});
  56. }
  57. if (this.get('type') === 'pm') signal = true;
  58. if (msg.get('mention')) {
  59. this.set({unreadMentions: this.get('unreadMentions') + 1});
  60. signal = true;
  61. }
  62. // All PMs & mentions
  63. if (signal) this.trigger('forMe', 'message');
  64. }
  65. });
  66. var User = Backbone.Model.extend({
  67. initialize: function() {
  68. },
  69. defaults: {
  70. opStatus: ''
  71. }
  72. });