GSoC Coding Phase 2: Challenge Is an Understatement
Tags: opensource, typescript, webdev, programming
Published: 2021-08-26 16:54:12

> **It was all going smooth. And then this happened.**

**[Google Summer of Code](https://summerofcode.withgoogle.com/)** is a 10 week global open-source program for students.

It has been in the running for 16 years! In case you're new here, I recommend checking out my first blog in this series.

**[How I Got Selected into Google Summer of Code](https://dev.to/rohanlekhwani/how-i-got-selected-into-google-summer-of-code-27)**

I'm revamping the **[most downloaded app](https://rocket.chat/blog/product/top-8-the-most-popular-rocket-chat-apps/)** on Rocket.Chat - the **[Poll App](https://github.com/RocketChat/rocket.chat.app-poll)**. 

**Bonus:** While it's been a smooth ride, there's one thing that happened that made all of us scratch our heads. Hang tight!

## Recap

Here’s a recap of the features I built in **[Coding Phase 1](https://dev.to/rohanlekhwani/commit-push-merge-gsoc-coding-phase-1-51i0)**:

- **Improved Response Visualizations:** Previously the Poll App displayed simple grayscale reponses. This was dull and boring. Moreover, there wasn’t a way to distinguish winners and total votes cast. **[Here’s](https://github.com/RocketChat/rocket.chat.app-poll/pull/2)** how we changed this.

<br>

- **Mixed Visibility Mode:** The Poll App allowed only two modes — open where voter identities were visible and closed where they were not. What about something in the middle? Introducing **[Mixed Visibility Mode](https://github.com/RocketChat/rocket.chat.app-poll/pull/5)**.

<br>

- **Word Clouds:** Bar graphs are simple. Bar graphs do the job. And bar graphs are just _“okay”_. Word Clouds are lit! Visualize responses in word clouds **[here](https://github.com/RocketChat/rocket.chat.app-poll/pull/6)**.

## What Did I Add to the Poll App?

While planning my timeline within my GSoC proposal, my strategy was to take up easier features at the start. This would allow me to have more time to explore the **[Rocket.Chat Apps Engine](https://rocketchat.github.io/Rocket.Chat.Apps-engine/)** while still shipping out features consistently.

Coding Phase 1 was a success. It was time to bring out the **big guns**.

### User-defined Options

Until now the Poll App only allowed the Poll Creator to add options. Once they posted the poll no changes to the options could be made. **What if users have an idea not covered within the options?**

Now if you’ve ever used Facebook polls within groups you might’ve noticed a subtle feature. All group members can add options after the poll is posted. Allowing group members to vote not only involves the community better but also evokes ideas and opinions from the entire group, not just limited to the poll creator.

We decided to give the Poll Creator an option — allow or disallow users from adding choices. Here’s how the poll message looks when the poll creator allowed users to add options.

![Allow Users to Add Options After Poll Creation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v8t99e9zogzfw03tnpjl.png)

See that Add option button? That becomes available to all the users within the room. Let’s click on it and see what happens.

![Adding German as a new option. I don’t speak German. (yet :P)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chgq3b6crsj46s5ej3hk.png)
 
It opens up a modal that allows users to add an option. On clicking Add the option gets added to the existing Poll message with both vote quantity and voters set to 0.

![Germans in the house!](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ygbsm3u1v8vpw9q54463.png)

The Poll message updates for everyone within the room with the new option. Yay!

The PR for this feature along with a video demo can be found here.

### Additional Poll Modes

Adding options to Poll was kind of repetitive. Especially if you’re doing a 1 to 10 poll typing 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 was what you had to do (_okay I just did that_). I thought:

![Why not?](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdz8qcgoasq9ghulpaih.png)

The Poll App only had two modes — Mutliple Choice and Single Choice. That. Is. It. **What if I could add more modes that would auto-fill all the options?**

Over the next few days (and nights) I added the following modes:

- **Overrated/Underrated Polls** (Options: Overrated, Appropriately Rated, Never Tried, Underrated)

- **1-to-5 Polls** (Options: 1–5)

- **1-to-10 Polls** (Options: 1–10)

- **Agree/Disagree Polls** (Options: Agree/Disagree)

- **Emoji Rank Polls** (Options: Watch the demo! 🚀)

<img alt="Emoji Rank Polls in Action!" src="https://miro.medium.com/max/700/1*sPhvVXxvC7wogIUc869mZg.gif" style="width: 100%"/>

The best part is that the modal is completely interactive. This means that as soon as you select one of the additional poll modes the Options fields automatically disappear. Not to mention that Additional Poll modes support Mixed Visibility. How cool is that?

To view other additional poll modes, checkout the **[PR](https://github.com/RocketChat/rocket.chat.app-poll/pull/11)** for Additional Poll Modes.

### Live Polls
 
If you’ve attempted an online quiz before. Well this it!

Introducing Live Polls. To be honest about it, the effort and thought that went into this feature qualifies it as a **mini-GSoC project** itself.

Live Polls are an array of regular Polls with additional functionality of having a time limit to vote upon after which the current Poll ends and the next one is posted. Poll creators can also click on a new “Next Poll” button to trigger a pre-scheduled finish of the current Poll.

The scheduling magic happens using the **[Scheduler API](https://developer.rocket.chat/apps-development/fundamentals-of-apps/scheduler-api)**. Every time a Poll within a Live Poll is posted, a processor is scheduled to end it after the user-specified time to vote.

![Time to vote on the Poll along with a “Next Poll” button.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r6s865itd4d0ji4vezg3.png)

Live Polls are triggered using the command `/poll live <number of polls>`.
An excellent use-case for the Live Poll are stand-up and retro meetings. An additional use case is by teachers wanting to conduct **timed quizzes** on Rocket.Chat.

**Late Retrieval**

My mentor suggested that in addition to having the Polls timed, the user should also be able to create a Live Poll at a time and retrieve or play it at a later time.

I created a subcommand `/poll live save <number of polls>`. It saves all the Poll states in the Poll App’s persistent storage. A unique **Live Poll ID** is provided to the user.

![Live Poll ID generated after saving Live Poll within persistent storage.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/puw7nh6isld1w95ixc76.png)

The created Live Poll can be subsequently retrieved using the `/poll live load <Live Poll ID>`. In case the user enters a wrong or non-existent Live Poll ID they’re shown a notification. On executing the above command with a correct Poll ID the Live Poll can be retrieved at any time.

<img alt="Retrieving a pre-created Live Poll." src="https://miro.medium.com/max/700/1*vA5bEwLTDGNTnMBS7LL_fQ.gif" style="width: 100%"/>

Speaking of teachers using Rocket.Chat for exams, the Live Poll Late Retrieval features proves an excellent tool for teachers to create quizzes even weeks before and then schedule the quiz on D-day with ease. All this while having control over the time limit to answer each question.

The PR for Live Poll and Live Poll Late Retrieval features can be found **[here](https://github.com/RocketChat/rocket.chat.app-poll/pull/13)**.

### Bonus: An Unexpected Problem!

If you’ve been through my **[Coding Phase 1 article](https://dev.to/rohanlekhwani/commit-push-merge-gsoc-coding-phase-1-51i0)** you would remember us using the **[Quickchart Wordcloud API](http://quickchart.io/documentation/word-cloud-api/)** to generate wordclouds.

While this API works well when your Rocket.Chat server is connected to the Internet, a lot of organizations (my mentors org Credit Suisse, US Defence) use Rocket.Chat in an isolated environment. That means no Internet access. What then?

We thought why not host Quickchart locally using their **[open-sourced codebase](https://github.com/typpo/quickchart)**? But…Wait-for-it. Quickchart has all APIs **except** wordcloud open-sourced. Ha!

Another problem was rate-limits. Quickchart has a rate-limit of `60 requests per minute per IP` on their free tier. This means it is totally unsuitable for rooms with more than 60 members. My mentor Murtaza shared a perfect explaination. Quoting him from the **[PR](https://github.com/RocketChat/rocket.chat.app-poll/pull/6)** comment:

> if all the users are accessing the room from a different network then the limit is fair enough, however if all the users are on a private network behind a (Router + NAT) then although each of them will have a different local IP, but the same public IP — In that case if there is a single room with more than 60 users, they all would be identified as a single entity/IP and the rate limit will come into picture.

**I thought, why can’t I build my own API and remove Quickchart out of the equation altogether? And:**

<img src="https://miro.medium.com/max/349/1*PHq45ZJJ4ibMrl8yI2e0zQ.gif" style="width: 100%"/>

Within a few days I had our own in-house developed Wordcloud API. The best thing about it? It offered **more** customizations than Quickchart Enterprise, worked without an Internet connection, had practically no rate-limits and was free.

I have open-sourced the word-cloud API **[here](https://github.com/RonLek/wordcloud-api)**. Feel free to use it in your own projects or raise a PR for further customizations.

My API also factors in the number of votes cast per option. For example, if English received twice as many votes as Hindi on a Poll then “English” would appear twice as big as “Hindi” within the word-cloud.

I provided the repository link within the Poll App settings page for users to self-host the API. This solved our Wordcloud frenzy forever.

**Have you faced an unexpected problem while coding a project? How did you solve it? Could you find a solution or did you just leave it for the future? Let me know in the comments section below!**

I write biweekly about my GSoC journey at Rocket.Chat and this was the fifth blog in this series. Follow my voyage on [DEV](https://dev.to/rohanlekhwani) and [Medium](https://rohanlekhwani.medium.com/about) ⭐️

In case you haven’t checked out my previous blog about GSoC First Evaluations, go check it out now —it covers in detail how a GSoC student is evaluated.

**[GSoC First Evaluations: All You Need to Know](https://dev.to/rohanlekhwani/gsoc-first-evaluations-all-you-need-to-know-2pjf)**

---

Like what I do? Help me pull my next all-nighter. Consider [buying me a coffee](https://www.buymeacoffee.com/rohanlekhwani).🥤

Rohan Lekhwani is an open source contributor and enthusiast. You can connect with him on [LinkedIn](https://www.linkedin.com/in/rohanlekhwani/), [GitHub](http://github.com/RonLek), [Twitter](https://twitter.com/Rohanlekhwani), and his [website](https://ronlek.github.io/).