Commit Graph

65 Commits

Author SHA1 Message Date
Badri Sunderarajan 18d8fbdd69
Bump ConverseJS from 9.1.1 to 10.1.7 and *make it work*
This was somewhat harder than you'd imagine, because ConverseJS
and Strophe have changed a bit in the meantime. Nothing major, but
a small change had unintended consequences.

Some backstory: we use Rollup for bundling Convo into a format
that KaiOS' ageing engine can understand. The bad news: due to
a weird bug/issue/something, Rollup doesn't like the UMD format
that ConverseJS dependency Strophe bundles into. This bug has
been affecting a lot of people and has been extensively documented
in issues like this one:

https://github.com/rollup/rollup-plugin-commonjs/issues/139

(I think Strophe also bundles into other formats, but for some
reason the default one picked by Rollup is dist/strophe.umd.js
that it then immediately raises a complaint about).

The good news was that @converse/headless was inadvertently
sidestepping this issue because it imported the Strophe object
from a specific file in Strophe's src like this:

    import { Strophe } from 'strophe.js/src/strophe';

which completely bypassed the problematic dist folder. Since
Rollup eventually bundled everything anyway, reading from source
to start with wasn't a problem.

The bad news was that, at some point, ConverseJS was updated to
use a newer version of Strophe. Unfortunately, the new Strophe
had renamed its src/strophe.js to src/index.js:

26f94b15f0

That is in itself a good practice, but it broke the import in
@converse/headless, which was still looking for the old file
instead of the new one.

Not a big problem either; a few days later @converse/headless
implemented the best practice of importing straight from
'strophe' instead of trying to specify where exacly to import
from, allowing the Strophe package to take on that job:

72f659cd1a

The only problem is, that "take it from wherever the package
decides" proved disastrous for Convo's Rollup setup, because
Rollup stopped looking in src/ at all. Instead, it went straight
to the dist/ folder like any sensible bundler would do. Except
that the first option in the dist/ folder happened to be the
strophe.umd.js file that Rollup had issues with as mentioned in
the beginning of this commit message!

I didn't know all this backstory at the time. All I knew was that
Rollup was producing the somewhat cryptic error:

    'Strophe' is not exported by node_modules/strophe.js/dist/strophe.umd.js

which made no sense to me because of course it was!

With some DuckDuckGo'ing I realised that this is a not uncommon
problem with UMD packages in Rollup when using the commonjs
plugin. But though the problem was quite common, the workarounds
weren't. None of the workarounds (I wouldn't deign to call them
solutions) that were described, semi-described, or hinted-at
worked for me.

After sleeping over it, I decided to inspect the ConverseJS code
and see what exacly changed, which is when I realised the whole
setup described above.

The hacky solution implemented here is to override the clean

    import { ... } from 'strophe.js';

statements with the more explicit

    import { ... } from 'strophe.js/src';

...which is at least somewhat cleaner, given that 'strophe.js/src'
automatically resolves to 'strophe.js/src/index.js'.

In conclusion: bumping to a newer version of a JavaScript
dependency, despite being a seemingly innocous task, can be way
more complicated than you'd expect!
2024-03-26 17:14:21 +05:30
Badri Sunderarajan be8d93e946
Style tweak: make all but selected list icons rounded
In our case, "list icons" usually means "avatars" so think
"rounded avatars, except the currently selected one which remains
square". This makes things look a bit more polished, but still
allow you to properly see the full avatar when you actually need
to.
2024-03-24 23:12:50 +05:30
Badri Sunderarajan 4379de12df
Catch back button keypress in options menu
By default, the back button exits the entire chat, which is an
overkill if we're just in the menu. This commit makes the options
menu catch the backspace event and simply close the menu instead
of letting it go all the way to closing the conversation.

Along the way, the function was also neatened a bit to use breaks
instead of returns.
2024-03-24 23:11:14 +05:30
Badri Sunderarajan 073176a9c9
Allow the options menu to toggle itself
Earlier, the toggle was only happening from the outside, but now
we can toggle the options menu from the menu itself. This is
useful when we want to close the menu from inside, for example
when an option has been selected or the back button has been
pressed.
2024-03-24 23:10:22 +05:30
Badri Sunderarajan d36fd1afe8
Bugfix: options menu nav broken with new ListItem classes
The autofocus and nav functions were still using the old class
name .list-item-indicator instead of .list-item which it actually
is now.
2024-03-24 23:09:45 +05:30
Badri Sunderarajan c4cd385cfe
Make ListItem image optional
It was supposed to be optional anyway, but setting it as undefined
to begin with makes it explicitly optional so Svelte doesn't start
giving warnings and stuff.
2024-03-24 23:06:37 +05:30
Badri Sunderarajan 4d58d0f1c0
Display image attachments
We optimise memory usage by only downloading the resolution of
image that needs to be displayed, rather than the full image. This
is described in a bit more detail on the kaios.dev blog:

    https://kaios.dev/2023/04/kaios-app-optimization-tips/#media-fragments--moz-samplesize

However, images are loaded immediately without confirmation. We
might want to change that in future to check the file size, etc.
before attempting to display an image, which is what many XMPP
apps default to doing.

This commit implements #16, albeit minimally.
2024-03-24 22:23:04 +05:30
Badri Sunderarajan 5e986b0ae1
Display avatars in contacts and message list
An enhancement that will seal tight the already closed #15!
2024-03-24 21:48:36 +05:30
Badri Sunderarajan e63d9978bb
Update ListItem to support full features (including images)
There are actually three kinds of list-item classes in the
kaios-native-ui stylesheet: ordinary, with indicator (a little
caret pointing to the side), and with icon (which lets you set an
image such as a profile picture, hint hint). Till now the ListItem
implementation had mixed it up a little, using the indicator
styles for an ordinary non-indicator list. Now, the code has been
revamped to properly support all three.
2024-03-24 21:46:31 +05:30
Badri Sunderarajan be74fc8e43
Tweak chat bubble selection and metadata colours
I can do this confidently now that I've figured out how to test
them live on the phone! (Colours there render pretty differently
from the ones on my laptop screen, so I've got to view it directly
to make it work.)
2024-03-24 21:44:39 +05:30
Badri Sunderarajan 237c185933
Use vcard avatar images instead of contact placeholder ones
I don't know what the placeholder ones are all about, but the
vcards work well – including for own avatars! (You won't be in
your own contact list, but you will have your own vcard.)

With this, we close #15, the very freshly created issue.
2024-03-24 21:43:49 +05:30
Badri Sunderarajan ce4cd60fe0
Display avatar images, if available
I'm still not sure how to make them available, so it's all
placeholder images for now, but still: progress!
2024-03-24 19:35:04 +05:30
Badri Sunderarajan 6c95cf3586
Remove an extra semicolon
I usually don't use semicolons for terminating JavaScript
statements, but this time I got nervous. (There are a few times
when it's needed to resolve ambiguity; if you look hard in the
last few commits I think you'll find one example.)
2024-03-24 19:35:04 +05:30
Badri Sunderarajan f49eb12dff
Display initial letter in avatar
Just to make it not-blank! In future we should be displaying the
actual XMPP avatars here

This is the final feature on the to-do list for and therefore
closes #2
2024-03-24 19:35:00 +05:30
Badri Sunderarajan 50f85789d8
Computer message sender name once instead of every time
Those or-chains were going all over the place :P
2024-03-24 18:54:54 +05:30
Badri Sunderarajan 525cdd0c58
Add support for the /me command!
This addresses one more point in #2
2024-03-24 18:54:54 +05:30
Badri Sunderarajan 9ad87dc248
Remove margin for bare chat items
They're innocuous enough anyway, and making larger margins means
they end up taking more lines and therefore more attention
2024-03-24 18:54:53 +05:30
Badri Sunderarajan 8faeca0ea0
Reduce font size in chat bubbles
This allows more text to be shown in the same limited amount of
space, as described in #2
2024-03-24 18:54:19 +05:30
Badri Sunderarajan 41bc583b06
Customise style for own and system chat bubbles
Partially addresses the concerns in #2! Own messages are now on
the opposite side in their own colour, and system messages (such
as "* is online", detected by having no "from" attribute) are
displayed without any bubble at all.

Along the way, we also fixed bug #14 where own messages would
show the other person's name underneath. That was because we were
looking at the nickname attribute, which, as it turns out, gives
the nickname for the entire conversation or something, not for the
chat itself. I think it wasn't a problem in groupchats, but anyway,
that's something to tackle another day...
2024-03-24 18:04:50 +05:30
Badri Sunderarajan 86c5489f19
Allow user to close a conversation (chatbox)
One step ahead in the memory game! This commit closes #12 (closes,
get it? :P)
2024-03-24 16:51:18 +05:30
Badri Sunderarajan 26e344e28c
Set up OptionsMenu component with its own navigation
This navigation overrides the main navigation, making it act as a
modal. This is complicated, so let's not try to do it again
anywhere else besides these options menus :P

Well actually not that complicated, but it is a bit of duplicated
work and feels a little hacky so I'm not entirely comfortable with
it. Maybe there's a DRYer way to get it working though?
2024-03-24 16:44:57 +05:30
Badri Sunderarajan ec007df1e6
Make softkey height into a variable
Not that we'll need to change the height, but we need to refer to
it in some places and variables makes it more clear what exactly
we're referring to (as opposed to bare numbers).
2024-03-24 16:39:33 +05:30
Badri Sunderarajan e92e76ad8f
Resize icons to add a bit of margin
This makes them look better on the KaiOS app menu. Come to think
of it, maybe I should add *even* more margin but ehh I'm done for
now
2024-03-24 13:04:51 +05:30
Badri Sunderarajan f79289e5fc
Customise system statusbar colour when this app is open
Explanation for what exactly happened: I added a margin to the
header, made the app fullscreen, and activated a magic setting in
the manifest to render the system statusbar on *top of* the app.
Thanks to the following blog post for teaching me how:

  https://kaios.dev/2023/03/complete-manifest.webapp-guide/
2024-03-23 19:14:19 +05:30
Badri Sunderarajan d69179fa9d
Don't capitalise the first letter of a list item
This "feature" of capitalising the first letter came from the
kaios-native-ui project, but in this case it's more like a bug
than a feature because case is important in things like usernames
and JIDs (as well as conversation titles, since people deserve the
right to be fancy).
2024-03-23 17:50:04 +05:30
Badri Sunderarajan f24483df3a
A little formatting for the import
If we decide to import more things in future, it'll be neater to
change it. (Full disclosure: I did in fact attempt to import an
arrowsStore; when that was abandoned I decided to retain the
formatting anyway so I didn't have to do it next time. The time
thus saved has been utilised in the composition of this commit
message.)
2024-03-23 17:38:16 +05:30
Badri Sunderarajan c8f5240332
Add roster screen
This allows you to view and start new conversations with contacts,
although it doesn't let implement a sliding window or allow you to
search through then.
2024-03-23 17:36:53 +05:30
Badri Sunderarajan 1f7ad1408c
Keep 5-second delay between renders to withstand message floods
Instead of rendering the message list every time a message comes
in, we give a delay of 5 seconds. If more messages have arrived in
the meantime, those messages will also get included in the render.

5 seconds is selected to offer the best performance; if it ends
up being too long we could later make it configurable or bring it
down to something like 1 second. Another option is to intelligently
ramp up the delays as messages flood in, and then ramp it down when
the flow reduces to just 1-2 messages. But all that is for another
day ;)

This commit hopefully addresses #10; it should theoretically work
but I haven't been able to fully test it yet due to not yet
receiving a full flood of messages :P
2024-03-23 13:55:01 +05:30
Badri Sunderarajan 8d1ca787fa
Set message limits and disable group autojoin
All this is in order to solve the big problem with Convo, which
was that a large number of messages coming in (as is the case with
highly active groupchats) would overload the entire app and cause
it to crash.

To fix this, I've taken the somewhat draconian measure of not
auto-joining any groupchats at all. Of course, this should be
better optimised in future, starting with an option to join
specific groupchats, and later perhaps allowing the user to "pin"
one or two important groupchats, or have some kind of cyclical
function that catches up on one groupchat at a time, checks for
important mentions, and then closes it to save memory.

Another option would be to load the groupchat data but offload it
from the working memory; unfortunately that'd require a greater
knowledge of the internal workings of ConverseJS than I currently
posess.
2024-03-23 13:05:57 +05:30
Badri Sunderarajan 15bfc1599b
Lighten rendering function in conversation list
Instead of running the entire toArray of the chatboxes object, we
only render the information we need (id, title, last message text)
which will (hopefully) make for a less resource-hungry function
2024-03-23 13:04:25 +05:30
Badri Sunderarajan f76bb30987 Scroll through entire element before moving to next
This is primarily so that we can read the entire chat message that
comes in, not just the beginning part that fits on the screen. The
implementation is still a bit jumpy and needs some work, but at
least you can now use it to have a functional conversation.

Addresses #3 but maybe needs more work.
2022-09-27 21:56:22 +05:30
Badri Sunderarajan aa0f1c5641 Fix checkbox styling
The original kaios-native-ui was using a fancy mask-image property,
which was unfortunately a bit *too* fancy for KaiOS to handle.
Instead, we've fallen back to good ol' conditions and a number of
new SVGs for the selected version of the checkbox. The drawback is,
of course, that selected checkboxes will perforce be white (which
can be easily overridden to black if so desired, but not so easily
to any other colour: Inkscape is your friend though).
2022-09-27 19:17:32 +05:30
Badri Sunderarajan c8c5d3178c Fix styling for selected elements
KaiOS 2 doesn't support :focus-within, so we're replacing it with
a (resurrected) wee bit of JavaScript.

Closes #8
2022-09-27 19:15:16 +05:30
Badri Sunderarajan 356911ed52 Update Inkscape export info for white icon
Should've done this earlier but :P
2022-09-27 18:09:54 +05:30
Badri Sunderarajan 1dbe3183c0 Add splash screen
This gives us something prettier than a blank page while the app
is loading (although, of course, it could also prove a bit more
cryptic to debug if something goes wrong).

Closes #5
2022-09-27 17:54:25 +05:30
Badri Sunderarajan 301b72b488 Use left softkey to send a message
Earlier, we were using the centre softkey but this is a bit too
easy to trigger by mistake. Now, we use the centre softkey for
the more mundane but arguably equally important "Enter"...which
doesn't actually work because we're using a single-line input and
not a multi-line textarea, but we'll get to that sometime. Or,
maybe the centre key can become something more funky such as...
an emoji selector?

Fixes #4
2022-09-27 17:32:43 +05:30
Badri Sunderarajan e5a9ea5905 Smarten chatbox styling
They now can take on any width (for example when the message is
shorter), and the font is larger for emoji-only messages
2022-09-17 22:28:23 +05:30
Badri Sunderarajan cf926cd5b6 Dynamicaly update/blank-out "Send" softkey
I perhaps spent an inordinate amount of time getting this to work
to my satisfaction :P
2022-09-17 22:16:37 +05:30
Badri Sunderarajan ca92f79d7a Use event bubbling intead of hacky workaround
I'm not going to describe what the hacky workaround was, but you
can see for yourself if you're so interested.
2022-09-17 22:15:58 +05:30
Badri Sunderarajan e7bed614c9 Persist login details
We should have done this long ago! Think of all the seconds that
would have been saved logging in and re-logging in while testing!
2022-09-17 22:14:43 +05:30
Badri Sunderarajan 9e72f32ac4 Move converse and a rollup plugin to devDependencies
They were in the main dependencies, which is not really necessary.
Come to think of it, *no* dependencies should be necessary once
the thing is compiled, but the template which this project is
based on kept `sirv` as a main dependency, so I'm keeping it there.
I guess you could argue that sirv is necessary for runtime if
you're going to be running this application on a desktop for some
reason and need someway to serve the app to you.
2022-09-17 21:02:19 +05:30
Badri Sunderarajan ce3f8254b1 Add missing helpers: unescapeHTML and escapeHTML
These helpers are there in the main ConverseJS utils but not in
the headless one; unfortunately they are used in some cases
(while parsing inline emoji) so not having them causes an error.
Ideally we'd patch ConverseJS to include this in the headless
version too, but for now as a quick-fix we're just defining
everything directly in our converse.js itself.
2022-09-17 20:51:43 +05:30
Badri Sunderarajan a5593a22ca Simplify autoscroll mechanism
This is the mechanism to automatically scroll to the bottom of
the page when a new message comes in. This is now done by
listening for a change on the "mesages" element and acting upon
that. It's still a bit hacky like the earlier one, but at least
the hack is all in one place.
2022-09-17 20:50:19 +05:30
Badri Sunderarajan d671932569 Implement conversation view!
This has a few hacks and is a bit buggy, but at least it's usable
and you can begin texting people now :D
2022-09-17 14:43:23 +05:30
Badri Sunderarajan db067d14fb Shorten "Connecting..." label to prevent overflow
It now says "Connect..." which is less grammatical but at least
you can see all of it
2022-09-17 14:42:25 +05:30
Badri Sunderarajan e9145a46b8 Add Messages route
Now you can see a list of all your messages (including chats and
groupchats)!
2022-09-16 19:04:35 +05:30
Badri Sunderarajan b74dbf5212 Add advanced settings (BOSH and WebSocket URL)
These settings are now present under a checkbox-toggle on the
login screen.
2022-09-16 19:04:00 +05:30
Badri Sunderarajan 8ce50c90cc Update softkey label while connecting 2022-09-16 19:00:19 +05:30
Badri Sunderarajan 1c6cdece7f Start using the message plugin
This is instead of using the stanza directly. To get this to work,
we had to import a couple of other util libraries just so that
they assign their respective utils to Converse's `u` object. This
is probably supposed to happen by itself when the respective
plugins are loaded, but for whatever reason it wasn't happening so
here we are.
2022-09-16 18:55:16 +05:30
Badri Sunderarajan d2f6414980 Remove extra _converse global assignment
We already defined window._converse earlier in the file. (In any
case, both these are temporary globals for debugging; once done
we ideally won't have a floating public _converse like that. Come
to think of it, we won't have a floating converse without the
underscore either!)
2022-09-16 18:52:39 +05:30