Pārlūkot izejas kodu

Subscribe to the todo list after creating it

JC Brand 4 nedēļas atpakaļ
vecāks
revīzija
56748fc70d
1 mainītis faili ar 14 papildinājumiem un 2 dzēšanām
  1. 14 2
      src/plugins/todo/modals/add-todo-modal.js

+ 14 - 2
src/plugins/todo/modals/add-todo-modal.js

@@ -66,13 +66,25 @@ export default class AddTodoModal extends BaseModal {
             return;
         }
 
+        const service_jid = entities[0].get('jid');
+        const node = `${Strophe.NS.TODO}/${u.getUniqueId()}`;
+
+        try {
+            await api.pubsub.create(service_jid, node, { title: name });
+        } catch (e) {
+            const err = await parsers.parseErrorStanza(e);
+            this.alert(__('Sorry, an error occurred while trying to create the todo list: %s', err.message), 'danger');
+            return;
+        }
+
         try {
-            await api.pubsub.create(entities[0].get('jid'), `${Strophe.NS.TODO}/${u.getUniqueId()}`, { title: name });
+            await api.pubsub.subscribe(service_jid, node);
         } catch (e) {
             const err = await parsers.parseErrorStanza(e);
-            this.alert(__('Sorry, an error occurred: %s', err.message), 'danger');
+            this.alert(__('Sorry, an error occurred while trying to subscribe to updates %s', err.message), 'danger');
             return;
         }
+
         form.reset();
         this.modal.hide();
     }