GSoC Final Report – Rocket Chat TUI
Tags: go, opensource, gsoc, tui
Published: 2022-11-20 15:58:50

## 👨🏻‍💻&nbsp;Introduction
Hello Guys, my summers were full of learning for me and I had a great learning experience in contributing to open source under Google Summer of Code in Rocket.Chat. This blog post contains the report of all the work done by me during my GSoC period for developing a Terminal User Interface Client for Rocket.Chat.

Project link - https://github.com/RocketChat/rocketchat-tui <br/><br/>
## 🔭&nbsp;Project Abstract
The aim of my project is to develop an attractive, lightweight and easy to use client for Rocket.Chat which is specially made for geeks. It is developed in golang using bubbletea and lipgloss package provided by charm. By using bubbletea we can make attractive terminal user interfaces using it’s different packages. 

To communicate with rocketchat apis and database using Rocket chat go SDK for all the rest and real time APIs needed in the TUI. Developing separate api’s in the SDK for TUI specific use cases or adding new versions of some APIs. <br/><br/>
## 🎯&nbsp;Implementation
1. Firstly After discussing with my mentors I started working on designing a basic TUI in terminal with some of the basic functionalities from the Rocket Chat web client. Firstly I designed the main chat TUI. I designed them on Canva. It can be viewed [here.](https://www.canva.com/design/DAFDgpHhJfc/pAQO4BYD_FN2r7yohtpGIA/view?utm_content=DAFDgpHhJfc&utm_campaign=designshare&utm_medium=link&utm_source=publishsharelink)
2. To understand the working of Rocket.Chat server and Go SDK so that I can use it in the TUI I read its main server code and developer docs. I came to know that some part of the Rocket.Chat server uses Meteorjs so I read about it to know how it works. You can read about meteorjs from [here.](https://www.tutorialspoint.com/meteor/index.htm) Reading from rocket chat developer docs about REST and Realtime APIs which I need and trying them in Postman. 
3. To develop TUI using bubbletea I read about it’s usage from its original github [repo.](https://github.com/charmbracelet/bubbletea)  I also read the codebase of different TUIs made using bubbletea to get a better understanding of its usage and understand how I can use it to add my required functionality in the TUI. Reading the codebase of different projects made using it helped me the most to understand it.
4. I first developed the Terminal UI as per the design. I made it in golang using bubbletea and lipgloss with some placeholder text. So that after it I can work on the specific APIs required for the TUI from the Go SDK.
5. I learned how to use the local Go package in my project so that I can test the local APIs which I developed in Go SDK in the TUI.
6. I Added listing of channels in the sidebar of the TUI, added message sending, switching between channels and loading previous message history.
7. I added realtime sending and receiving of messages in the chat.
8. I added user login screen, added caching of user token, login using cached token and token expiration.
9. I added listing, filtering, sending of slash command and @ mentioning of channel members while sending messages.
10. I added a flag to give server url value at the time of starting TUI, so that we can chat from any server so that all Requests will be sent to it.
11. Removing some of the bugs which I encountered during adding different features, cleaning up code, adding comments and updating readme with instructions of how to run TUI.
<br/><br/>

## ⚙️&nbsp;Demo Video

[![Rocket Chat Terminal User interface Demo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rz564jxlb8nwb0fkzx7v.png)](https://drive.google.com/file/d/1zlYEVr4K5rllz4UcKEk6DJjyaxZIdIc1/view?usp=sharing)

## 🛠️&nbsp;Tools and Technologies used
* Golang 
* Bubbletea Go package 
* Lipgloss Go package
* Meteorjs 
* BoltDb Go package
* Postman 
* Canva 

<br/><br/>
## ⚠️&nbsp;Challenges
* __How to manage the complete flow and state of the TUI__ - It's the most challenging part to keep everything in sync. I'm new with the framework used so learning more about it, how it's being used in other projects and keeping things simple.
* __Adding realtime message sending and receiving__ - Making some POC applications. Reading developer documentation of bubbletea and Rocket.chat. Understanding the codebase of projects made using bubbletea.
* __To show past message history__ - Searching and trying how it's implemented on other rocket.chat platforms. Examining their endpoints, reading about different endpoints from developer documentation and then adding it in the SDK. 
* __Adding slash commands and @ user mentioning__ - Covering edge cases when to show list, when to hide it, when to filter it and when to select it. Debugging some unexpected bugs which arise during its development.
<br/><br/>

## 💻&nbsp;Contributions
### - PR's
Topic | Link
--- | --- 
*[NEW] Complete TUI V1 [MERGED]* | https://github.com/RocketChat/rocketchat-tui/pull/5 
*[NEW] Added rest function to list all slash commands [MERGED]* | https://github.com/RocketChat/Rocket.Chat.Go.SDK/pull/61
*[NEW] Rest function to fetch list of members of a group [MERGED]* | https://github.com/RocketChat/Rocket.Chat.Go.SDK/pull/66
*[NEW] Added function to search users and rooms while mentioning in message [MERGED]* | https://github.com/RocketChat/Rocket.Chat.Go.SDK/pull/69
*Added Name field mapping in User [MERGED]* | https://github.com/RocketChat/Rocket.Chat.Go.SDK/pull/63
*Modified dm, group, channel history functions [MERGED]* | https://github.com/RocketChat/Rocket.Chat.Go.SDK/pull/65
*Changed the format of time so that it get parsed properly [MERGED]* | https://github.com/RocketChat/Rocket.Chat.Go.SDK/pull/67 <br/>

### - ISSUES OPENED
Issue | Link
--- | ---
*Implement basic services in TUI [CLOSED]* | https://github.com/RocketChat/rocketchat-tui/issues/2 
*To Figure out How to Handle User Navigation in Different Sections and Interaction with different bubbletea elements through keys [CLOSED]* | https://github.com/RocketChat/rocketchat-tui/issues/4 
*Fix: authentication issue [CLOSED]* | https://github.com/RocketChat/rocketchat-tui/issues/3 
*Adding rest function to get list of group members [CLOSED]* | https://github.com/RocketChat/Rocket.Chat.Go.SDK/issues/64
*To get name of user in realtime loadhistory function [CLOSED]* | https://github.com/RocketChat/Rocket.Chat.Go.SDK/issues/62
*To add functions for listing and making slash commands [CLOSED]* | https://github.com/RocketChat/Rocket.Chat.Go.SDK/issues/60 
*Adding caching of past messages in cache* | https://github.com/RocketChat/rocketchat-tui/issues/7
*Adding users search functions while mentioning users using @ instead of searching them in group members* | https://github.com/RocketChat/rocketchat-tui/issues/6
*Adding functionality to update message in the messages list* | https://github.com/RocketChat/rocketchat-tui/issues/9
*Adding a go linter for consistent linting and formatting of code* | https://github.com/RocketChat/rocketchat-tui/issues/8 
<br/>
**TUI COMMITS** - https://github.com/RocketChat/rocketchat-tui/commits/main <br/><br/>
## 🙏&nbsp;Mentors
My superbly amazing mentors for this project are Aaron Ogle([@geekgonecrazy](https://github.com/geekgonecrazy)) and Debdut Chakraborty([@debdutdeb](https://github.com/debdutdeb)). I really want to thank them very very much for supporting, helping and guiding me throughout these weeks, without them this project wouldn't have been possible. They are so kind and understanding. I learned many things from them. I extended my project to add some more features in it but due to some personal circumstances I was not able to work much on them and they supported me in my tough time. I’ll forever cherish the bond I made with them and will never forget the time I spent with them during Gsoc. <br/><br/>
## 🤖&nbsp;Features to Implement
* Caching of messages
* Editing and updating a message
* Adding formatting of message
* Adding threaded conversations
* Creating public and private channels 
* Making TUI responsive
* Adding support for emoji detection and sending.

<br/><br/>
## 🔗&nbsp;Important Links
Topic | Link
--- | ---
*Developer Documentation* | https://developer.rocket.chat/
*Rocket Chat Server Code* | https://github.com/RocketChat/Rocket.Chat
*TUI Code* | https://github.com/RocketChat/rocketchat-tui
*Go SDK Code* | https://github.com/RocketChat/Rocket.Chat.Go.SDK
*Bubbletea by Charm* | https://github.com/charmbracelet/bubbletea
*TUI public communication channel* | https://open.rocket.chat/channel/rocket-chat-text-terminal-client-tui
*Meteorjs* | https://www.tutorialspoint.com/meteor/index.htm
*TUI design* | https://bit.ly/3hWR6VE
*Demo presentation* | https://bit.ly/3EN5N6J
*GSoC Proposal* | https://bit.ly/3tLOE7a
*Demo presentation video* | [![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/n7tdkNhivtY/0.jpg)](https://www.youtube.com/watch?v=n7tdkNhivtY)

<br/><br/>
## 🚀&nbsp;Open for Contributions
Give it a try and share your feedback with me. I'd love to hear back from you all. Please open bug reports/issues on github for any new features that you'd like to see or problems you might've been facing.

**MAY THE SOURCE BE WITH YOU !**

*Go check it out and if you liked it please star it ⭐* <br/><br/>
## 😄&nbsp;About Me
I’m Sitaram Rathi, a Full-stack Developer focused on back-end development. I'm pursuing my B.Tech in CSE from Nit Hamirpur. I love working on projects and problems which make me push my limits and learn something new. You can connect with me here. <br/>

Social | Link
--- | ---
![srrathi github](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white) | https://github.com/srrathi
![Sitaram Rathi Linkedin](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white) | https://www.linkedin.com/in/sitaram-rathi-519152197/
![Sitaram Rathi email](https://img.shields.io/badge/Gmail-D14836?style=for-the-badge&logo=gmail&logoColor=white) | srrathi2000@gmail.com
![Sitaram Rathi twitter](https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white) | https://twitter.com/SitaramRathi5