mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
27a60bdb3c
Summary: Ref T7014. This hooks up the durable column such that when you open it up it loads your most recent Conpherence. You can then switch amongst the various widgets and stuff and everything works nicely. Except... - scroll bar does not work - also doesn't work at HEAD when I add a ton of text to the UI with no changes? (wrapped $copy in array_fill(0, 1000, $copy)) - "widget selector" does not collapse when you select something else - this part wasn't really specified so I used the aphlict dropdown stuff. didn't want to keep working on that if this was the wrong UI choice - can not edit title - do we still want that to be done by clicking on the title, which pops a dialogue? - can not add participants or calendar events - what should this UI be? maybe just a button on the top for "participants" and a button on the bottom for calendar? both on top? - this is not pixel perfect to the mock or two I've seen around. Aside from generally being bad at that, I definitely didn't get the name + timestamps formatting correctly, because the standard DOM of that has timestamp FIRST which appears second due to a "float right". Seemed like a lot of special-casing for what might not even be that important in the UI so I punted. (And again, there's likely many unknown ways in which this isn't pixel perfect) There's also code quality issues - `ConpherenceWidgetConfigConstants` is hopefully temporary or at least gets more sleek as we keep progressing here - copied some CSS from main Conpherence app - DOM structure is pretty different - there's some minor CSS tweaks too given the different width (not to mention the DOM structure being different) - copied some JS from behavior-pontificate.js to sync threads relative to aphlict updates - JS in general is like a better version of existing JS; these should collapse I'd hope? - maybe the aphlict-behavior-dropdown change was badsauce? ...but all that said, this definitely feels really nice and I feel like adding stuff is going to be really easy compared to how normal Conpherence is. Also includes a bonus bug fix - we now correctly update participation. The user would encounter this issue if they were in a conpherence that got some updates and then they went to a different page; they would have unread status for the messages that were ajax'd in. This patch fixes that by making sure we mark participation up to date with the proper transaction in all cases. Test Plan: hit "\" to invoke the column and saw nice loading UI and my latest conpherence load. sent messages and verified they received A-OK by looking in DOM console. toggled various widges and verified they rendered correctly. opened up a second browser with a second user on the thread, sent a message, and it was received in a nice asynchronous fashion Reviewers: chad, epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T7014 Differential Revision: https://secure.phabricator.com/D11968
270 lines
7.4 KiB
JavaScript
270 lines
7.4 KiB
JavaScript
/**
|
|
* @provides javelin-behavior-durable-column
|
|
* @requires javelin-behavior
|
|
* javelin-dom
|
|
* javelin-stratcom
|
|
* javelin-scrollbar
|
|
* javelin-quicksand
|
|
* phabricator-keyboard-shortcut
|
|
* javelin-behavior-conpherence-widget-pane
|
|
*/
|
|
|
|
JX.behavior('durable-column', function() {
|
|
|
|
var shouldInit = true;
|
|
var loadThreadID = null;
|
|
var loadedThreadID = null;
|
|
var loadedThreadPHID = null;
|
|
var latestTransactionID = null;
|
|
|
|
var frame = JX.$('phabricator-standard-page');
|
|
var quick = JX.$('phabricator-standard-page-body');
|
|
var show = false;
|
|
|
|
|
|
// TODO - this "upating" stuff is a copy from behavior-pontificate
|
|
// TODO: This isn't very clean. When you submit a message, you may get a
|
|
// notification about it back before you get the rendered message back. To
|
|
// prevent this, we keep track of whether we're currently updating the
|
|
// thread. If we are, we hold further updates until the response comes
|
|
// back.
|
|
|
|
// After the response returns, we'll do another update if we know about
|
|
// a transaction newer than the one we got back from the server.
|
|
var updating = null;
|
|
// Copy continues with slight modifications for how we store data now
|
|
JX.Stratcom.listen('aphlict-server-message', null, function(e) {
|
|
var message = e.getData();
|
|
|
|
if (message.type != 'message') {
|
|
// Not a message event.
|
|
return;
|
|
}
|
|
|
|
if (message.threadPHID != loadedThreadPHID) {
|
|
// Message event for some thread other than the visible one.
|
|
return;
|
|
}
|
|
|
|
if (message.messageID <= latestTransactionID) {
|
|
// Message event for something we already know about.
|
|
return;
|
|
}
|
|
|
|
// If we're currently updating, wait for the update to complete.
|
|
// If this notification tells us about a message which is newer than the
|
|
// newest one we know to exist, keep track of it so we can update once
|
|
// the in-flight update finishes.
|
|
if (updating && updating.threadPHID == loadedThreadPHID) {
|
|
if (message.messageID > updating.knownID) {
|
|
updating.knownID = message.messageID;
|
|
return;
|
|
}
|
|
}
|
|
|
|
update_thread();
|
|
});
|
|
function update_thread() {
|
|
var params = {
|
|
action: 'load',
|
|
latest_transaction_id: latestTransactionID,
|
|
minimal_display: true
|
|
};
|
|
|
|
var uri = '/conpherence/update/' + loadedThreadID + '/';
|
|
|
|
var workflow = new JX.Workflow(uri)
|
|
.setData(params)
|
|
.setHandler(function(r) {
|
|
var messages = _getColumnMessagesNode();
|
|
JX.DOM.appendContent(messages, JX.$H(r.transactions));
|
|
messages.scrollTop = messages.scrollHeight;
|
|
|
|
latestTransactionID = r.latest_transaction_id;
|
|
});
|
|
|
|
sync_workflow(workflow);
|
|
}
|
|
function sync_workflow(workflow) {
|
|
updating = {
|
|
threadPHID: loadedThreadPHID,
|
|
knownID: latestTransactionID
|
|
};
|
|
workflow.listen('finally', function() {
|
|
var need_sync = (updating.knownID > latestTransactionID);
|
|
updating = null;
|
|
if (need_sync) {
|
|
update_thread();
|
|
}
|
|
});
|
|
workflow.start();
|
|
}
|
|
// end copy / hack of stuff with big ole TODO on it
|
|
|
|
|
|
new JX.KeyboardShortcut('\\', 'Toggle Conpherence Column')
|
|
.setHandler(function() {
|
|
show = !show;
|
|
JX.DOM.alterClass(frame, 'with-durable-column', show);
|
|
var column = JX.$('conpherence-durable-column');
|
|
if (show) {
|
|
JX.DOM.show(column);
|
|
loadThreadContent(loadThreadID);
|
|
} else {
|
|
JX.DOM.hide(column);
|
|
}
|
|
JX.Stratcom.invoke('resize');
|
|
JX.Quicksand.setFrame(show ? quick : null);
|
|
})
|
|
.register();
|
|
|
|
new JX.Scrollbar(JX.$('conpherence-durable-column-content'));
|
|
|
|
JX.Quicksand.start();
|
|
|
|
JX.Stratcom.listen(
|
|
'click',
|
|
'conpherence-durable-column-widget-selected',
|
|
function (e) {
|
|
e.kill();
|
|
var data = e.getNodeData('conpherence-durable-column-widget-selected');
|
|
var widget = data.widget;
|
|
if (widget == 'conpherence-message-pane') {
|
|
return loadThreadContent(loadThreadID);
|
|
}
|
|
|
|
_markLoading(true);
|
|
var uri = '/conpherence/widget/' + loadThreadID + '/';
|
|
loadedThreadID = null;
|
|
|
|
var params = { widget : widget };
|
|
new JX.Workflow(uri)
|
|
.setData(params)
|
|
.setHandler(function(r) {
|
|
var body = _getColumnBodyNode();
|
|
JX.DOM.setContent(body, JX.$H(r));
|
|
new JX.Scrollbar(JX.$('conpherence-durable-column-content'));
|
|
_markLoading(false);
|
|
})
|
|
.start();
|
|
});
|
|
|
|
function _getColumnNode() {
|
|
return JX.$('conpherence-durable-column');
|
|
}
|
|
|
|
function _getColumnBodyNode() {
|
|
var column = JX.$('conpherence-durable-column');
|
|
return JX.DOM.find(
|
|
column,
|
|
'div',
|
|
'conpherence-durable-column-body');
|
|
}
|
|
|
|
function _getColumnMessagesNode() {
|
|
var column = JX.$('conpherence-durable-column');
|
|
return JX.DOM.find(
|
|
column,
|
|
'div',
|
|
'conpherence-durable-column-transactions');
|
|
}
|
|
|
|
function _getColumnFormNode() {
|
|
var column = JX.$('conpherence-durable-column');
|
|
return JX.DOM.find(
|
|
column,
|
|
'form',
|
|
'conpherence-message-form');
|
|
}
|
|
|
|
function _getColumnTextareaNode() {
|
|
var column = JX.$('conpherence-durable-column');
|
|
return JX.DOM.find(
|
|
column,
|
|
'textarea',
|
|
'conpherence-durable-column-textarea');
|
|
}
|
|
|
|
function _focusColumnTextareaNode() {
|
|
var textarea = _getColumnTextareaNode();
|
|
setTimeout(function() { JX.DOM.focus(textarea); }, 1);
|
|
}
|
|
|
|
function _markLoading(loading) {
|
|
var column = _getColumnNode();
|
|
JX.DOM.alterClass(column, 'loading', loading);
|
|
}
|
|
|
|
function loadThreadContent(thread_id) {
|
|
// loaded this thread already
|
|
if (loadedThreadID !== null && loadedThreadID == thread_id) {
|
|
return;
|
|
}
|
|
_markLoading(true);
|
|
|
|
var uri = '/conpherence/columnview/';
|
|
var params = null;
|
|
// We can pick a thread from the server the first time
|
|
if (shouldInit) {
|
|
shouldInit = false;
|
|
params = { shouldInit : true };
|
|
} else {
|
|
params = { id : thread_id };
|
|
}
|
|
var handler = function(r) {
|
|
var column = _getColumnNode();
|
|
var new_column = JX.$H(r.content);
|
|
loadedThreadID = r.threadID;
|
|
loadedThreadPHID = r.threadPHID;
|
|
loadThreadID = r.threadID;
|
|
latestTransactionID = r.latestTransactionID;
|
|
JX.DOM.replace(column, new_column);
|
|
JX.DOM.show(_getColumnNode());
|
|
new JX.Scrollbar(JX.$('conpherence-durable-column-content'));
|
|
_markLoading(false);
|
|
};
|
|
|
|
new JX.Workflow(uri)
|
|
.setData(params)
|
|
.setHandler(handler)
|
|
.start();
|
|
}
|
|
|
|
function _sendMessage(e) {
|
|
e.kill();
|
|
_markLoading(true);
|
|
|
|
var form = _getColumnFormNode();
|
|
var params = {
|
|
latest_transaction_id : latestTransactionID,
|
|
minimal_display : true
|
|
};
|
|
var workflow = JX.Workflow.newFromForm(form, params)
|
|
.setHandler(function(r) {
|
|
var messages = _getColumnMessagesNode();
|
|
JX.DOM.appendContent(messages, JX.$H(r.transactions));
|
|
messages.scrollTop = messages.scrollHeight;
|
|
|
|
var textarea = _getColumnTextareaNode();
|
|
textarea.value = '';
|
|
|
|
latestTransactionID = r.latest_transaction_id;
|
|
|
|
_markLoading(false);
|
|
|
|
_focusColumnTextareaNode();
|
|
});
|
|
sync_workflow(workflow);
|
|
}
|
|
|
|
JX.Stratcom.listen(
|
|
'click',
|
|
'conpherence-send-message',
|
|
_sendMessage);
|
|
|
|
JX.Stratcom.listen(
|
|
['submit', 'didSyntheticSubmit'],
|
|
'conpherence-message-form',
|
|
_sendMessage);
|
|
|
|
});
|