pencil / rechat

Adds chat messages from the past to your favorite Twitch VODs
https://www.rechat.org/
MIT License
66 stars 11 forks source link

Server Side Ideas #9

Closed goldbattle closed 10 years ago

goldbattle commented 10 years ago

I am not sure how you are compiling messages server side but I have been looking into IRC clients. It seems that when a user joins a channel the join message also displays their emoticon allows groups. So it would be possible to keep track of users, and their respective emoticon groups, and their username color.

Color IRC jtv PRIVMSG goldbattle :USERCOLOR goldbattle2 #421ED2 Emote Sets jtv PRIVMSG goldbattle :EMOTESET goldbattle2 [42,793,21,932]

So this could be easily tied into a user table of some sort (not sure how things are structured), and then served again through the api tagged with the the message. Easy way to get the users color, so each time you see that user again it has the same color, and that user has the color matching what is used on the site. The extension would then have the easy job of just seeing if the possible emote use is in the array of emotes that the user has privilege to.

pencil commented 10 years ago

Thanks for your suggestion.

It is important to note that ReChat is (for performance reasons) not powered by a relational database but by an Elasticsearch cluster. Storing additional user data would either require a relational database (in addition to the existing Elasticsearch instances) or additional Elasticsearch indexes. Unfortunately both solutions would require additional server resources that I currently do not have at hand.

goldbattle commented 10 years ago

I was thinking of handling the colors, and emote during runtime. I just did a proof of concept in java with two hashmaps.

private HashMap<String, String> users_color;
private HashMap<String, String> users_emotes;

From there, I just kept track of the user color hex, and the emote array. When I added a row into the database I just used those hashmaps to fill in the missing data. So for example if the program does not know the persons color or permissions, a null value is inserted. On the client side, it can be simply changed if there is a null color value, then do what is currently made, and create a random color. With the emotes, if the user has the permission for the group they can get the emote. If they have null, or don't have permission then don't parse! This both captures the user's current color and emotes permission, but would also allow for the visible change of the user's color if they change it or gain an emote permission.

// Create a row
Map<String, Object> json = new HashMap<String, Object>();
json.put("channel", channel);
json.put("user_name", sender);
json.put("user_color", users_color.get(sender));
json.put("user_emotes", users_emotes.get(sender));
json.put("user_message", message);
json.put("date_created", new Date());

// Debug output
System.out.println(json.toString());

// Append, to db
client.prepareIndex("channels", channel).setSource(json).execute().actionGet(); 
{
  "_index": "channels",
  "_type": "lirik",
  "_id": "DxeeM2PyRo-Hzs8594Omnw",
  "_score": 1,
  "_source": {
    "user_color": "#008000",
    "user_name": "astronautsir",
    "date_created": "2014-09-27T17:52:43.370Z",
    "channel": "lirik",
    "user_emotes": "[2416,615,21,27]",
    "user_message": "And by thank you kind sir... I mean GTFO of your CAR! Kappa"
  }
}

Just a proof of concept, it would allow for a great feature to be added.