commentmodel.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2016
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. (function(OC, OCA) {
  11. _.extend(OC.Files.Client, {
  12. PROPERTY_FILEID: '{' + OC.Files.Client.NS_OWNCLOUD + '}id',
  13. PROPERTY_MESSAGE: '{' + OC.Files.Client.NS_OWNCLOUD + '}message',
  14. PROPERTY_ACTORTYPE: '{' + OC.Files.Client.NS_OWNCLOUD + '}actorType',
  15. PROPERTY_ACTORID: '{' + OC.Files.Client.NS_OWNCLOUD + '}actorId',
  16. PROPERTY_ISUNREAD: '{' + OC.Files.Client.NS_OWNCLOUD + '}isUnread',
  17. PROPERTY_OBJECTID: '{' + OC.Files.Client.NS_OWNCLOUD + '}objectId',
  18. PROPERTY_OBJECTTYPE: '{' + OC.Files.Client.NS_OWNCLOUD + '}objectType',
  19. PROPERTY_ACTORDISPLAYNAME: '{' + OC.Files.Client.NS_OWNCLOUD + '}actorDisplayName',
  20. PROPERTY_CREATIONDATETIME: '{' + OC.Files.Client.NS_OWNCLOUD + '}creationDateTime',
  21. PROPERTY_MENTIONS: '{' + OC.Files.Client.NS_OWNCLOUD + '}mentions'
  22. });
  23. /**
  24. * @class OCA.Comments.CommentModel
  25. * @classdesc
  26. *
  27. * Comment
  28. *
  29. */
  30. var CommentModel = OC.Backbone.Model.extend(
  31. /** @lends OCA.Comments.CommentModel.prototype */ {
  32. sync: OC.Backbone.davSync,
  33. defaults: {
  34. actorType: 'users',
  35. objectType: 'files'
  36. },
  37. davProperties: {
  38. 'id': OC.Files.Client.PROPERTY_FILEID,
  39. 'message': OC.Files.Client.PROPERTY_MESSAGE,
  40. 'actorType': OC.Files.Client.PROPERTY_ACTORTYPE,
  41. 'actorId': OC.Files.Client.PROPERTY_ACTORID,
  42. 'actorDisplayName': OC.Files.Client.PROPERTY_ACTORDISPLAYNAME,
  43. 'creationDateTime': OC.Files.Client.PROPERTY_CREATIONDATETIME,
  44. 'objectType': OC.Files.Client.PROPERTY_OBJECTTYPE,
  45. 'objectId': OC.Files.Client.PROPERTY_OBJECTID,
  46. 'isUnread': OC.Files.Client.PROPERTY_ISUNREAD,
  47. 'mentions': OC.Files.Client.PROPERTY_MENTIONS
  48. },
  49. parse: function(data) {
  50. return {
  51. id: data.id,
  52. message: data.message,
  53. actorType: data.actorType,
  54. actorId: data.actorId,
  55. actorDisplayName: data.actorDisplayName,
  56. creationDateTime: data.creationDateTime,
  57. objectType: data.objectType,
  58. objectId: data.objectId,
  59. isUnread: (data.isUnread === 'true'),
  60. mentions: this._parseMentions(data.mentions)
  61. };
  62. },
  63. _parseMentions: function(mentions) {
  64. if(_.isUndefined(mentions)) {
  65. return {};
  66. }
  67. var result = {};
  68. for(var i in mentions) {
  69. var mention = mentions[i];
  70. if(_.isUndefined(mention.localName) || mention.localName !== 'mention') {
  71. continue;
  72. }
  73. result[i] = {};
  74. for (var child = mention.firstChild; child; child = child.nextSibling) {
  75. if(_.isUndefined(child.localName) || !child.localName.startsWith('mention')) {
  76. continue;
  77. }
  78. result[i][child.localName] = child.textContent;
  79. }
  80. }
  81. return result;
  82. }
  83. });
  84. OCA.Comments.CommentModel = CommentModel;
  85. })(OC, OCA);