mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 17:30:59 +01:00
4bc561f17b
Summary: Ref T4083. This needs some work (mostly in the Conpherence JS itself), but is sort of functional. In particular: - On thread pages, add the thread as a `pageObject`. - After updating a thread, send a new "message" event to the server. - Share a little more event posting code. - In the browser, use event dispatch to respond to events. - Add a listener for the new event type. - Update conpherence threads (this part is really yucky). Test Plan: With multiple browser windows / browsers open, posted a message to a thread, and saw it update everywhere. Reviewers: joshuaspence Reviewed By: joshuaspence Subscribers: chad, epriestley Maniphest Tasks: T4083 Differential Revision: https://secure.phabricator.com/D9486
112 lines
3 KiB
JavaScript
112 lines
3 KiB
JavaScript
/**
|
|
* @provides javelin-behavior-conpherence-pontificate
|
|
* @requires javelin-behavior
|
|
* javelin-dom
|
|
* javelin-util
|
|
* javelin-workflow
|
|
* javelin-stratcom
|
|
*/
|
|
|
|
JX.behavior('conpherence-pontificate', function(config) {
|
|
|
|
JX.Stratcom.listen('aphlict-receive-message', null, function(e) {
|
|
var message = e.getData();
|
|
|
|
if (message.type != 'message') {
|
|
// Not a message event.
|
|
return;
|
|
}
|
|
|
|
// TODO: This is really, really gross.
|
|
var infonode = JX.DOM.find(document, 'input', 'latest-transaction-id');
|
|
var data = JX.Stratcom.getData(infonode);
|
|
|
|
var latest_id = infonode.value;
|
|
var thread_phid = data.threadPHID;
|
|
var thread_id = data.threadID;
|
|
|
|
if (message.threadPHID != thread_phid) {
|
|
// Message event for some thread other than the visible one.
|
|
return;
|
|
}
|
|
|
|
if (message.messageID <= latest_id) {
|
|
// Message event for something we already know about.
|
|
return;
|
|
}
|
|
|
|
var params = {
|
|
action: 'load',
|
|
latest_transaction_id: latest_id
|
|
};
|
|
|
|
new JX.Workflow('/conpherence/update/' + thread_id + '/')
|
|
.setData(params)
|
|
.setHandler(function(r) {
|
|
var messages = JX.DOM.find(document, 'div', 'conpherence-messages');
|
|
JX.DOM.appendContent(messages, JX.$H(r.transactions));
|
|
messages.scrollTop = messages.scrollHeight;
|
|
|
|
// TODO: Continued grossness from above.
|
|
infonode.value = r.latest_transaction_id;
|
|
})
|
|
.start();
|
|
});
|
|
|
|
|
|
var onsubmit = function(e) {
|
|
e.kill();
|
|
|
|
var form = e.getNode('tag:form');
|
|
|
|
var root = e.getNode('conpherence-layout');
|
|
var messages_root = JX.DOM.find(root, 'div', 'conpherence-message-pane');
|
|
var header_root = JX.DOM.find(root, 'div', 'conpherence-header-pane');
|
|
var form_root = JX.DOM.find(root, 'div', 'conpherence-form');
|
|
var messages = JX.DOM.find(messages_root, 'div', 'conpherence-messages');
|
|
var fileWidget = null;
|
|
try {
|
|
fileWidget = JX.DOM.find(root, 'div', 'widgets-files');
|
|
} catch (ex) {
|
|
// Ignore; maybe no files widget
|
|
}
|
|
JX.DOM.alterClass(form_root, 'loading', true);
|
|
|
|
JX.Workflow.newFromForm(form)
|
|
.setHandler(JX.bind(this, function(r) {
|
|
JX.DOM.appendContent(messages, JX.$H(r.transactions));
|
|
messages.scrollTop = messages.scrollHeight;
|
|
|
|
if (fileWidget) {
|
|
JX.DOM.setContent(
|
|
fileWidget,
|
|
JX.$H(r.file_widget)
|
|
);
|
|
}
|
|
|
|
var latest_transaction_dom = JX.DOM.find(
|
|
root,
|
|
'input',
|
|
'latest-transaction-id');
|
|
latest_transaction_dom.value = r.latest_transaction_id;
|
|
|
|
var textarea = JX.DOM.find(form, 'textarea');
|
|
textarea.value = '';
|
|
|
|
JX.Stratcom.invoke(
|
|
'conpherence-selectthread',
|
|
null,
|
|
{ id : r.conpherence_phid + '-nav-item' }
|
|
);
|
|
|
|
JX.DOM.alterClass(form_root, 'loading', false);
|
|
}))
|
|
.start();
|
|
};
|
|
|
|
JX.Stratcom.listen(
|
|
['submit', 'didSyntheticSubmit'],
|
|
'conpherence-pontificate',
|
|
onsubmit);
|
|
|
|
});
|