Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RoomMessageEvent: refactored boilerplate code; added support of HTML-formatted messages #17

Closed

Conversation

KitsuneRal
Copy link
Member

This breaks compatibility and is massive in itself, hence a PR.

While a lot of code has been moved around, it boils down to the following 5 things:

  • {Type}EventContent classes have moved to a dedicated namespace (MessageEventContent), to save on typestrokes.
  • The contents of these classes have been deduplicated by moving out common data into common parents; a trick with a template inheriting from its own parameter allowed to make a factory for event media content types
  • Parsing JSON has been deduplicated respectively. Fortunately, the spec is (almost) systematic in keys naming for different message types.
  • body member variable is now plainBody and lives in RoomMessageEvent, right next to msgtype. A primitive client can use these two and live in plain text - without looking at RoomMessageEvent::content() at all.
  • A separate class for text messages has been made, to store formatted text from formatted_body. The same class also can read from body and try to deduce the content type using Qt facilities. This may look controversial but in the end you always have RoomMessageEvent::plainBody() for fallback.

@KitsuneRal
Copy link
Member Author

To follow up with necessary updates on the client side (actually, the second item can be covered be a "compatibility" addition to RoomMessageEvent if you consider necessary - but I'd rather push clients to the new lib interface):

  • for plain text messages, just use RoomMessageEvent::body(), as you should have been doing by now;
  • for media content, instead of MessageEventContent derivatives, use respective classes from MessageEventContent namespace (such as Image);
  • to get HTML text messages (in particular, those produced by Vector), use MessageEventContent::Text and its body field (with an accessor in RoomMessageEvent being a fallback).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant