[jitsi-dev] [PATCH] Initial implementation of XMPP message correction


#1

Hi,

I've attached a patch for XMPP message correction as defined in XEP-308.
Here is a very high-level overview of the changes:

New classes:
- MessageCorrectionExtension - represents the XMPP extension,
- ...Provider - parses an XML extension and creates a MCE from it,
- OperationSetMessageCorrection with a single method correctMessage.

Changes:
The received XMPP messages are now created with the ID of the packet; and
the ID of the packet when sending messages is set to the ID of the message.
There are a bunch of changes in various places in order to propagate the
ID's from the UI to the network and vice versa - they are needed when
identifying which message to edit.
This implementation only has UI for editing the last sent message.

In ChatPanel.java: the ID of the last sent message (in order to be able to
edit it) and the currently corrected message, if any, are stored.

In ChatConversationPanel:

- The message ID is added to the HTML in order to be able to find the old
message when trying to replace it.

- A tag with the format <cite id="messageID-editedAt"></cite> is added for
every message as a placeholder for an "Edited at …" message. If it is
corrected, it's replaced with <cite id="newMessageID-editedAt">Edited at
…</cite>. A cite tag is used because an inline one is needed in order for
the text not to wrap on a newline, and most of the other inline tags are
problematic when used in setOuterHTML.

In ChatWritePanel:

- If UP arrow is pressed when the write area is empty and the protocol
supports message corrections, starts editing last message.

- If DOWN arrow is pressed, currently editing a message and cursor is
after the last position of the text in the write area, stop editing.

Test plan:

Tested with multiple XMPP accounts in Jitsi - message corrections are shown
on both the sending and receiving side correctly.

Tested with the latest version of Swift - works fine. (The official Beta
sends and receives correction packages with their own namespace, but that's
fixed in dev.)

Gmail shows corrections as new messages - as expected.

That's my first patch here, and it got a bit long, so I hope I got
everything (or, at least, most of the things) right :slight_smile: Let me know if you
need more info on the code.

Cheers,

Ivan

messageCorrection.txt (64.3 KB)


#2

This is a really neat feature! Thanks Ivan!

I know Yana has a few comments that she'll probably be making later but,
until then, I just wanted to make a quick comment:

It seems that this is only working for messages that have been sent
since a chat window was opened. Pressing the "up" arrow no longer has an
effect once you've closed and reopened a window.

I suppose you are simply not querying the history there, but we'd need
to address this at some point (not urgent).

Cheers,
Emil

···

On 11.07.12 04:53, Ivan Vergiliev wrote:

Hi,

I've attached a patch for XMPP message correction as defined in XEP-308.
Here is a very high-level overview of the changes:

New classes:
- MessageCorrectionExtension - represents the XMPP extension,
- ...Provider - parses an XML extension and creates a MCE from it,
- OperationSetMessageCorrection with a single method correctMessage.

Changes:
The received XMPP messages are now created with the ID of the packet;
and the ID of the packet when sending messages is set to the ID of the
message.
There are a bunch of changes in various places in order to propagate the
ID's from the UI to the network and vice versa - they are needed when
identifying which message to edit.
This implementation only has UI for editing the last sent message.

In ChatPanel.java: the ID of the last sent message (in order to be able
to edit it) and the currently corrected message, if any, are stored.

In ChatConversationPanel:

- The message ID is added to the HTML in order to be able to find the
old message when trying to replace it.

- A tag with the format <cite id="messageID-editedAt"></cite> is added
for every message as a placeholder for an "Edited at …" message. If it
is corrected, it's replaced with <cite id="newMessageID-editedAt">Edited
at …</cite>. A cite tag is used because an inline one is needed in order
for the text not to wrap on a newline, and most of the other inline tags
are problematic when used in setOuterHTML.

In ChatWritePanel:

- If UP arrow is pressed when the write area is empty and the protocol
supports message corrections, starts editing last message.

- If DOWN arrow is pressed, currently editing a message and cursor is
after the last position of the text in the write area, stop editing.

Test plan:

Tested with multiple XMPP accounts in Jitsi - message corrections are
shown on both the sending and receiving side correctly.

Tested with the latest version of Swift - works fine. (The official Beta
sends and receives correction packages with their own namespace, but
that's fixed in dev.)

Gmail shows corrections as new messages - as expected.

That's my first patch here, and it got a bit long, so I hope I got
everything (or, at least, most of the things) right :slight_smile: Let me know if
you need more info on the code.

Cheers,

Ivan

--
Emil Ivov, Ph.D. 67000 Strasbourg,
Project Lead France
Jitsi
emcho@jitsi.org PHONE: +33.1.77.62.43.30
http://jitsi.org FAX: +33.1.77.62.47.31


#3

Hi Ivan,

Very nice feature indeed!

Your patch is now applied and ack-ed on our contributors page!

You have done really good work! It made it's way to the repository with very few corrections. Among the things I had to change are the following:

* there were some missing resources (colors and texts) - I think you've forgot to include the resources in the patch actually. I had to add the chat correction color and the "edited at" text. If you think of something else, please tell me.

* I've changed the behavior of the up-arrow, by allowing the user to enter correction mode even if it's not supported by the provider. Once the message is ready to be re-send it will be send as a new message if the feature is not supported.

* I've made some minor formatting corrections :slight_smile:

Thanks again for the great work!

Cheers,
Yana

···

On Jul 12, 2012, at 11:39 PM, Emil Ivov wrote:

This is a really neat feature! Thanks Ivan!

I know Yana has a few comments that she'll probably be making later but,
until then, I just wanted to make a quick comment:

It seems that this is only working for messages that have been sent
since a chat window was opened. Pressing the "up" arrow no longer has an
effect once you've closed and reopened a window.

I suppose you are simply not querying the history there, but we'd need
to address this at some point (not urgent).

Cheers,
Emil

On 11.07.12 04:53, Ivan Vergiliev wrote:

Hi,

I've attached a patch for XMPP message correction as defined in XEP-308.
Here is a very high-level overview of the changes:

New classes:
- MessageCorrectionExtension - represents the XMPP extension,
- ...Provider - parses an XML extension and creates a MCE from it,
- OperationSetMessageCorrection with a single method correctMessage.

Changes:
The received XMPP messages are now created with the ID of the packet;
and the ID of the packet when sending messages is set to the ID of the
message.
There are a bunch of changes in various places in order to propagate the
ID's from the UI to the network and vice versa - they are needed when
identifying which message to edit.
This implementation only has UI for editing the last sent message.

In ChatPanel.java: the ID of the last sent message (in order to be able
to edit it) and the currently corrected message, if any, are stored.

In ChatConversationPanel:

- The message ID is added to the HTML in order to be able to find the
old message when trying to replace it.

- A tag with the format <cite id="messageID-editedAt"></cite> is added
for every message as a placeholder for an "Edited at …" message. If it
is corrected, it's replaced with <cite id="newMessageID-editedAt">Edited
at …</cite>. A cite tag is used because an inline one is needed in order
for the text not to wrap on a newline, and most of the other inline tags
are problematic when used in setOuterHTML.

In ChatWritePanel:

- If UP arrow is pressed when the write area is empty and the protocol
supports message corrections, starts editing last message.

- If DOWN arrow is pressed, currently editing a message and cursor is
after the last position of the text in the write area, stop editing.

Test plan:

Tested with multiple XMPP accounts in Jitsi - message corrections are
shown on both the sending and receiving side correctly.

Tested with the latest version of Swift - works fine. (The official Beta
sends and receives correction packages with their own namespace, but
that's fixed in dev.)

Gmail shows corrections as new messages - as expected.

That's my first patch here, and it got a bit long, so I hope I got
everything (or, at least, most of the things) right :slight_smile: Let me know if
you need more info on the code.

Cheers,

Ivan

--
Emil Ivov, Ph.D. 67000 Strasbourg,
Project Lead France
Jitsi
emcho@jitsi.org PHONE: +33.1.77.62.43.30
http://jitsi.org FAX: +33.1.77.62.47.31