Document protocol API

This commit is contained in:
Jaidyn Ann 2021-06-07 11:45:30 -05:00
parent 503c196d4f
commit 26e99477fc
4 changed files with 87 additions and 37 deletions

View File

@ -51,7 +51,7 @@ AccountManager::SetNickname(BString nick)
// Create message
BMessage* msg = new BMessage(IM_MESSAGE);
msg->AddInt32("im_what", IM_SET_OWN_NICKNAME);
msg->AddString("nick", nick);
msg->AddString("user_name", nick);
// Send message
TheApp* theApp = reinterpret_cast<TheApp*>(be_app);

View File

@ -32,12 +32,15 @@ enum im_what_code {
IM_GET_CONTACT_LIST = 1,
//! Server-side contact list received
// Requires: Stringlist "user_id"
IM_CONTACT_LIST = 2,
//! Contact(s) was added to the server-side list
// Requires: String "user_id"
IM_CONTACT_LIST_ADD_CONTACT = 3,
//! Contact(s) removed from the server-side list
// Requires: String "user_id"
IM_CONTACT_LIST_REMOVED_CONTACT = 4,
@ -45,32 +48,33 @@ enum im_what_code {
* Messages related to text chat.
*/
//! Send a chat message
//! Send a chat message to the protocol
// Requires: String "user_id", String "body"
IM_SEND_MESSAGE = 20,
//! Chat message has been sent
// Requires: String "chat_id", String "user_id", String "body"
// Accepts: String "subject"
IM_MESSAGE_SENT = 21,
//! Chat message received
// Requires: String "chat_id", String "user_id", String "body"
// Accepts: String "subject"
IM_MESSAGE_RECEIVED = 22,
//! Contact started typing
IM_CONTACT_STARTED_TYPING = 23,
//! Contact stopped typing
IM_CONTACT_STOPPED_TYPING = 24,
//! Contact gone
IM_CONTACT_GONE = 25,
//! Logs received
// Requires: String "chat_id", String "user_id", String "body"
// Accepts: String "subject"
IM_LOGS_RECEIVED = 23,
//! User started typing
IM_USER_STARTED_TYPING = 26,
// Requires: String "chat_id", String "user_id"
IM_USER_STARTED_TYPING = 24,
//! User stopped typing
IM_USER_STOPPED_TYPING = 27,
// Requires: String "chat_id", String "user_id"
IM_USER_STOPPED_TYPING = 25,
//! Logs received
IM_LOGS_RECEIVED = 28,
/*
@ -89,21 +93,27 @@ enum im_what_code {
*/
//! Received contact new status
// Requires: String "user_id", int32/CayaStatus "status"
IM_STATUS_SET = 60,
//! Contact's avatar icon was changed
// Requires: String "user_id", Ref "ref"
IM_AVATAR_SET = 61,
//! Get contact information
IM_GET_CONTACT_INFO = 62,
//! Received contact information
// Requires: String "user_id"
// Accepts: String "user_name", String "message", int32/CayaStatus "status"
IM_CONTACT_INFO = 63,
//! Get extended contact information
IM_GET_EXTENDED_CONTACT_INFO = 64,
//! Received extended contact information
// Requires: String "user_id"
// Accepts: String "user_name", String "full_name"
IM_EXTENDED_CONTACT_INFO = 65,
@ -112,24 +122,29 @@ enum im_what_code {
*/
//! Change own nickname
// Requires: String "user_name"
IM_SET_OWN_NICKNAME = 80,
//! Own nickname was changed
IM_OWN_NICKNAME_SET = 81,
//! Change own status
// Requires: int32/CayaStatus "status"
IM_SET_OWN_STATUS = 82,
// Own status was chagned
// Requires: int32/CayaStatus "status"
IM_OWN_STATUS_SET = 83,
//! Get own contact information
// Requires: String "user_id"
IM_OWN_CONTACT_INFO = 84,
//! Change own avatar icon
IM_SET_OWN_AVATAR = 85,
//! Own avatar icon was changed
// Requires: Ref "ref"
IM_OWN_AVATAR_SET = 86,
@ -180,30 +195,42 @@ enum im_what_code {
*/
//! Create an individual chat
// Requires: String "user_id"
IM_CREATE_CHAT = 150,
//! Chat has been created
// Requires: String "chat_id", String "user_id"
IM_CHAT_CREATED = 151,
//! Join a room
// Requires: String "chat_id"
IM_JOIN_ROOM = 152,
//! Confirm the room's been joined
// Requires: String "chat_id"
IM_ROOM_JOINED = 153,
//! User left the room
//! User wants to leave the room
// Requires: String "chat_id"
IM_LEAVE_ROOM = 154,
//! User left the room
// Requires: String "chat_id"
IM_ROOM_LEFT = 155,
//! Quietly add a user(s) to the chat
// Requires: String "chat_id", StringList "user_id"
// Accepts: StringList "user_name"
IM_ROOM_PARTICIPANTS = 156,
//! User has newly and explicitly joined
// Requires: String "chat_id", String "user_id"
// Accepts: String "body"
IM_ROOM_PARTICIPANT_JOINED = 157,
//! A user left the room
// Requires: String "chat_id", String "user_id"
// Accepts: String "user_name", String "body"
IM_ROOM_PARTICIPANT_LEFT = 158,
@ -211,11 +238,21 @@ enum im_what_code {
* Room metadata
*/
//! Room name
IM_ROOM_NAME = 160,
//! Set the room name
// Requires: String "chat_id", String "chat_name"
IM_SET_ROOM_NAME = 160,
//! Room subject
IM_ROOM_SUBJECT = 161,
//! Room name
// Requires: String "chat_id", String "chat_name"
IM_ROOM_NAME_SET = 161,
//! Set the room subject
// Requires: String "chat_id", String "subject"
IM_SET_ROOM_SUBJECT = 162,
//! Room has been set
// Requires: String "chat_id", String "subject"
IM_ROOM_SUBJECT_SET = 163,
/*
@ -223,33 +260,44 @@ enum im_what_code {
*/
//! A user's role has been changed
IM_ROOM_ROLECHANGE = 170,
// Requires: String "role_title", int32 "role_perms", int32 "role_priority"
IM_ROOM_ROLECHANGED = 170,
//! Kick user
// Requires: String "chat_id", String "user_id"
IM_ROOM_KICK_PARTICIPANT = 171,
//! A user was kicked
// Requires: String "chat_id", String "user_id"
// Accepts: String "user_name", String "body"
IM_ROOM_PARTICIPANT_KICKED = 172,
//! Ban user
// Requires: String "chat_id", String "user_id"
IM_ROOM_BAN_PARTICIPANT = 173,
//! A user was banned
// Requires: String "chat_id", String "user_id"
// Accepts: String "user_name", String "body"
IM_ROOM_PARTICIPANT_BANNED = 174,
//! Unban user
IM_ROOM_UNBAN_PARTICIPANT = 175,
//! Mute user
// Requires: String "chat_id", String "user_id"
IM_ROOM_MUTE_PARTICIPANT = 176,
//! Unmute user
// Requires: String "chat_id", String "user_id"
IM_ROOM_UNMUTE_PARTICIPANT = 177,
//! Deafen
// Requires: String "chat_id", String "user_id"
IM_ROOM_DEAFEN_PARTICIPANT = 178,
//! Allow to read messages
// Requires: String "chat_id", String "user_id"
IM_ROOM_UNDEAFEN_PARTICIPANT = 179,

View File

@ -181,7 +181,7 @@ Server::ImMessage(BMessage* msg)
const char* name = NULL;
if ((msg->FindString("name", &name) == B_OK)
if ((msg->FindString("user_name", &name) == B_OK)
&& (strcmp(name, "") != 0))
contact->SetNotifyName(name);
@ -201,9 +201,12 @@ Server::ImMessage(BMessage* msg)
const char* name = NULL;
if ((msg->FindString("full name", &name) == B_OK)
if ((msg->FindString("full_name", &name) == B_OK)
&& (strcmp(name, "") != 0))
contact->SetNotifyName(name);
else if ((msg->FindString("user_name", &name) == B_OK)
&& (strcmp(name, "") != 0))
contact->SetNotifyName(name);
break;
}
case IM_AVATAR_SET:
@ -285,7 +288,7 @@ Server::ImMessage(BMessage* msg)
chat->ImMessage(msg);
break;
}
case IM_ROOM_ROLECHANGE:
case IM_ROOM_ROLECHANGED:
{
Conversation* chat = _EnsureConversation(msg);
BString user_id;
@ -298,7 +301,7 @@ Server::ImMessage(BMessage* msg)
chat->SetRole(user_id, role);
break;
}
case IM_ROOM_NAME:
case IM_ROOM_NAME_SET:
{
BString name;
Conversation* chat = _EnsureConversation(msg);
@ -308,7 +311,7 @@ Server::ImMessage(BMessage* msg)
chat->SetNotifyName(name.String());
break;
}
case IM_ROOM_SUBJECT:
case IM_ROOM_SUBJECT_SET:
{
BString subject;
Conversation* chat = _EnsureConversation(msg);

View File

@ -720,7 +720,7 @@ JabberHandler::_RoleChangedMsg(BString chat_id, BString user_id,
gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff)
{
BMessage roleMsg(IM_MESSAGE);
roleMsg.AddInt32("im_what", IM_ROOM_ROLECHANGE);
roleMsg.AddInt32("im_what", IM_ROOM_ROLECHANGED);
roleMsg.AddString("user_id", user_id);
roleMsg.AddString("chat_id", chat_id);
roleMsg.AddString("role_title", _RoleTitle(role, aff));
@ -1170,8 +1170,7 @@ JabberHandler::handleRoster(const gloox::Roster& roster)
BMessage infoMsg(IM_MESSAGE);
infoMsg.AddInt32("im_what", IM_CONTACT_INFO);
infoMsg.AddString("user_id", jid);
infoMsg.AddString("name", name);
infoMsg.AddInt32("subscription", subscription);
infoMsg.AddString("user_name", name);
infoMsg.AddInt32("status", CAYA_OFFLINE);
// Groups
@ -1270,10 +1269,10 @@ printf("------ %d\n", state);
switch (state) {
case gloox::ChatStateComposing:
msg.AddInt32("im_what", IM_CONTACT_STARTED_TYPING);
msg.AddInt32("im_what", IM_USER_STARTED_TYPING);
break;
case gloox::ChatStatePaused:
msg.AddInt32("im_what", IM_CONTACT_STOPPED_TYPING);
msg.AddInt32("im_what", IM_USER_STOPPED_TYPING);
break;
case gloox::ChatStateGone:
// TODO
@ -1395,7 +1394,7 @@ JabberHandler::handleMUCSubject(gloox::MUCRoom *room, const std::string &nick,
return;
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_ROOM_SUBJECT);
msg.AddInt32("im_what", IM_ROOM_SUBJECT_SET);
msg.AddString("subject", subject.c_str());
msg.AddString("chat_id", chat_id);
if (user_id.IsEmpty() == false)
@ -1537,7 +1536,7 @@ JabberHandler::handleSelfPresence(const gloox::RosterItem& item, const std::stri
msg.AddInt32("im_what", IM_OWN_CONTACT_INFO);
msg.AddString("protocol", Signature());
msg.AddString("user_id", item.jidJID().full().c_str());
msg.AddString("name", item.name().c_str());
msg.AddString("user_name", item.name().c_str());
msg.AddInt32("subscription", item.subscription());
msg.AddInt32("status", _GlooxStatusToCaya(type));
msg.AddString("message", presenceMsg.c_str());
@ -1607,13 +1606,13 @@ JabberHandler::handleVCard(const gloox::JID& jid, const gloox::VCard* card)
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_EXTENDED_CONTACT_INFO);
msg.AddString("user_id", jid.bare().c_str());
msg.AddString("nick", card->nickname().c_str());
msg.AddString("family name", name.family.c_str());
msg.AddString("given name", name.given.c_str());
msg.AddString("middle name", name.middle.c_str());
msg.AddString("user_name", card->nickname().c_str());
msg.AddString("family_name", name.family.c_str());
msg.AddString("given_name", name.given.c_str());
msg.AddString("middle_name", name.middle.c_str());
msg.AddString("prefix", name.prefix.c_str());
msg.AddString("suffix", name.suffix.c_str());
msg.AddString("full name", fullName.c_str());
msg.AddString("full_name", fullName.c_str());
_SendMessage(&msg);
// Return if there's no avatar icon