summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/model/model_field_command.js
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2021-01-28 10:55:58 +0000
committerSébastien Theys <seb@odoo.com>2021-01-28 10:55:58 +0000
commitfa398ea291a72fa7752d382f85e6ef2ce7ac4c70 (patch)
tree2406dcb022d47409f8843ae03dbb1234398193bc /addons/mail/static/src/model/model_field_command.js
parent45544d024d5e4ad71285d70411b5109f4075b440 (diff)
[FIX] mail: make Inbox counters more reliable in mark as read flows
- Send the new Inbox counter when marking as read, to guarantee the JS has the correct value (instead of having to guess it which was impossible when an arbitrary domain was given to the method). NOTE: Manual increment is kept on receiving a new Inbox message because that one was reliable and it would have been more tricky to compute the new counter for each target partner (mark as read is one user doing an action for himself, whereas new message is from another user to potentially many different users). Generic counter for threads is also not sent on every change for similar reasons. - Refresh Inbox automatically when some messages are marked as read and there are more message on the server than currently loaded. - Remove confusing (and impossible to maintain) counter on non-origin threads (in particular channel followers). This behavior in JS was not consistent with the server which always counted only origin thread (model/res_id). task-2446302 closes odoo/odoo#65161 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/model/model_field_command.js')
-rw-r--r--addons/mail/static/src/model/model_field_command.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/addons/mail/static/src/model/model_field_command.js b/addons/mail/static/src/model/model_field_command.js
index 89f42651ad9..a6dadb7b983 100644
--- a/addons/mail/static/src/model/model_field_command.js
+++ b/addons/mail/static/src/model/model_field_command.js
@@ -35,11 +35,37 @@ function clear() {
);
}
+/**
+ * Returns a decrement command to give to the model manager at create/update.
+ *
+ * @param {number} [amount=1]
+ */
+function decrement(amount = 1) {
+ return new FieldCommand((field, record, options) => {
+ const oldValue = field.get(record);
+ field.set(record, oldValue - amount, options);
+ });
+}
+
+/**
+ * Returns a increment command to give to the model manager at create/update.
+ *
+ * @param {number} [amount=1]
+ */
+function increment(amount = 1) {
+ return new FieldCommand((field, record, options) => {
+ const oldValue = field.get(record);
+ field.set(record, oldValue + amount, options);
+ });
+}
+
return {
// class
FieldCommand,
// shortcuts
clear,
+ decrement,
+ increment,
};
});