Some months ago I started walking my path towards replacing all proprietary software with free, open-source software. Some of my older posts cover how I embraced Jekyll to get rid of Medium, and how I stopped using GitHub in favor of Gitea. Those projects were fun, but I still had a strong dependency on instant-messaging applications like WhatsApp.

Using Matrix as communication protocol

I started hearing of matrix many years ago, but I never gave it a real chance. I guess I was not so into free software as I am now. When I started looking for alternatives to WhatsApp, I was looking for two main things:

  1. Using free software both in the server and the client
  2. Using a decentralized architecture where a single actor (company, organization, etc.) cannot maintain control.

After investing some afternoons on this project, I managed to host a Synapse server. I could have used a public instance, but I also wanted to prove myself I could host this service myself. Despite some reluctance to install yet another app just to chat with me, I convinced my close family and friends to start using Element as well. The more my friends started using Element, the less I used WhatsApp.

Upgrading to Element X

When Element X (a successor of the Element app) became production-ready, I couldn’t wait to try it. To my surprise, my server was not compatible with something called Sliding Sync, which apparently was required to use the recently launched version 2 of the Matrix protocol. I dedicated some time here and there to install a sliding sync proxy, and only then I was able to connect to my account from Element X.

I liked the UI of Element X much more than that of Element. There are a few features that were (and still are!) missing like message threading, but all in all, I decided to uninstall Element and use Element X only.

There was something that didn’t look quite right in my setup, as after switching to Element X, notifications had stopped working for me. Other colleagues who had also moved into the new app were not experiencing this issue, so I assumed it had to do with my device.

Discovering push notifications

I had a rough idea of what push notifications are, but I never needed to dig deeper into how they actually work. I think I still don’t get 100% of it, so please take this section with a grain of salt. Since I’m using Graphene OS in my phone, and I don’t have any of Google Services installed, some things that are generally available in most Android devices are not in mine. There is no Firebase SDK installed, and my Synapse server was not connected to Google’s Firebase backend either.

So there were two pieces I had to replace to make the system work. UnifiedPush looked like a promising specification for the task, so I started looking into it. Since I already host a NextCloud instance, I tried to set up the NextPush application for Nextcloud, along with the homonym Android app. I didn’t manage to make it work (probably because I didn’t dedicate enough time) so I decided to try ntfy for the backend and the client app.

Installing the backend was fairly straightforward. I just needed to configure a DNS entry, start a new container, and set up nginx to route traffic to it. The client application also worked like a charm. Once installed, I configured the Element X app to use ntfy as the push server.

I would be lying to you if I said this setup didn’t take my whole morning, but after long hours of debugging I found out I had misconfigured ntfy’s BASE_URL, putting http instead of https as the protocol. The mistake was insignificant, but I had to change log levels ntfy and customize nginx logging until I got to the actual error message. My Synapse server was still messing around with the Nextcloud instance, which made things even more confusing.

Learnings

I feel very satisfied with the outcome of this morning. I got to know a bit more about how push notifications work, and what is Google’s role in this all. Even though handy for developers, I find it pretty scary that so much information flows through Google servers by default just to use something as common as push notifications.

While setting up ntfy, I also found it pretty cool that you can send push notifications to your phone with a simple HTTP request to a topic’s endpoint in your ntfy server. This opens a world of opportunities that I may explore one day.

Happy coding!