You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.0 KiB

  1. odoo.define("mail_archives.archives", function(require) {
  2. "use strict";
  3. var core = require("web.core");
  4. var session = require("web.session");
  5. var Manager = require("mail.Manager");
  6. var Mailbox = require("mail.model.Mailbox");
  7. var SearchableThread = require("mail.model.SearchableThread");
  8. var _t = core._t;
  9. Manager.include({
  10. _updateMailboxesFromServer: function(data) {
  11. this._super(data);
  12. if (
  13. !_.find(this.getThreads(), function(th) {
  14. return th.getID() === "mailbox_channel_archive";
  15. })
  16. ) {
  17. this._addMailbox({
  18. id: "channel_archive",
  19. name: _t("Archive"),
  20. mailboxCounter: 0,
  21. });
  22. }
  23. },
  24. });
  25. SearchableThread.include({
  26. _fetchMessages: function(pDomain, loadMore) {
  27. var self = this;
  28. if (this._id !== "mailbox_channel_archive") {
  29. return this._super(pDomain, loadMore);
  30. }
  31. // This is a copy-paste from super method
  32. var domain = this._getThreadDomain();
  33. var cache = this._getCache(pDomain);
  34. if (pDomain) {
  35. domain = domain.concat(pDomain || []);
  36. }
  37. if (loadMore) {
  38. var minMessageID = cache.messages[0].getID();
  39. domain = [["id", "<", minMessageID]].concat(domain);
  40. }
  41. return this._rpc({
  42. model: "mail.message",
  43. method: "message_fetch",
  44. args: [domain],
  45. kwargs: this._getFetchMessagesKwargs(),
  46. }).then(function(messages) {
  47. // Except this function. It adds the required thread to downloaded messages
  48. _.each(messages, function(m) {
  49. m.channel_ids.push("mailbox_channel_archive");
  50. });
  51. if (!cache.allHistoryLoaded) {
  52. cache.allHistoryLoaded = messages.length < self._FETCH_LIMIT;
  53. }
  54. cache.loaded = true;
  55. _.each(messages, function(message) {
  56. self.call("mail_service", "addMessage", message, {
  57. silent: true,
  58. domain: pDomain,
  59. });
  60. });
  61. cache = self._getCache(pDomain || []);
  62. return cache.messages;
  63. });
  64. },
  65. });
  66. Mailbox.include({
  67. _getThreadDomain: function() {
  68. if (this._id === "mailbox_channel_archive") {
  69. return [
  70. "|",
  71. "|",
  72. ["partner_ids", "in", [session.partner_id]],
  73. ["author_id", "in", [session.partner_id]],
  74. ["channel_ids.channel_partner_ids", "in", [session.partner_id]],
  75. ];
  76. }
  77. return this._super();
  78. },
  79. });
  80. return {
  81. Manager: Manager,
  82. Mailbox: Mailbox,
  83. };
  84. });