diff --git a/application/Conversation.cpp b/application/Conversation.cpp index fbba3bc..4579942 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -103,6 +103,7 @@ Conversation::ImMessage(BMessage* msg) int32 disabledFlags; if (msg->FindInt32("room_disallowed_flags", &disabledFlags) == B_OK) fDisallowedFlags = disabledFlags; + _CacheRoomFlags(); break; } case IM_ROOM_PARTICIPANT_JOINED: @@ -205,6 +206,7 @@ void Conversation::SetProtocolLooper(ProtocolLooper* looper) { fLooper = looper; + _LoadRoomFlags(); } @@ -384,6 +386,30 @@ Conversation::_GetChatLogs(BMessage* msg) } +void +Conversation::_CacheRoomFlags() +{ + _EnsureCachePath(); + BFile cacheFile(fCachePath.Path(), B_READ_WRITE | B_CREATE_FILE); + if (cacheFile.InitCheck() != B_OK) + return; + + cacheFile.WriteAttr("Caya:flags", B_INT32_TYPE, 0, &fRoomFlags, sizeof(int32)); +} + + +void +Conversation::_LoadRoomFlags() +{ + _EnsureCachePath(); + BFile cacheFile(fCachePath.Path(), B_READ_ONLY); + if (cacheFile.InitCheck() != B_OK) + return; + + cacheFile.ReadAttr("Caya:flags", B_INT32_TYPE, 0, &fRoomFlags, sizeof(int32)); +} + + void Conversation::_EnsureCachePath() { diff --git a/application/Conversation.h b/application/Conversation.h index bf4c017..0b8394a 100644 --- a/application/Conversation.h +++ b/application/Conversation.h @@ -68,10 +68,15 @@ public: void SetRole(BString id, Role* role); Role* GetRole(BString id); + int32 GetFlags(int32 flags) { return fRoomFlags; } + private: void _LogChatMessage(BMessage* msg); status_t _GetChatLogs(BMessage* msg); + void _CacheRoomFlags(); + void _LoadRoomFlags(); + void _EnsureCachePath(); User* _EnsureUser(BMessage* msg); diff --git a/application/Server.cpp b/application/Server.cpp index 94b0392..4ca3bd8 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -30,6 +30,7 @@ #include "InviteDialogue.h" #include "ProtocolLooper.h" #include "ProtocolManager.h" +#include "RoomFlags.h" #include "RosterItem.h" #include "Server.h" @@ -489,8 +490,25 @@ Server::ImMessage(BMessage* msg) while (dir.GetNextEntry(&entry, true) == B_OK) if (entry.GetName(fileName) == B_OK) { + int32 flags; + BFile file(&entry, B_READ_ONLY); + if (file.InitCheck() != B_OK) + continue; + + if (file.ReadAttr("Caya:flags", B_INT32_TYPE, 0, &flags, + sizeof(int32)) < 0) + continue; + + if (!(flags & ROOM_AUTOJOIN) && !(flags & ROOM_AUTOCREATE)) + continue; + BMessage join(IM_MESSAGE); - join.AddInt32("im_what", IM_JOIN_ROOM); + int32 im_what = IM_JOIN_ROOM; + if (flags & ROOM_AUTOCREATE) { + im_what = IM_CREATE_CHAT; + join.AddString("user_id", fileName); + } + join.AddInt32("im_what", im_what); join.AddString("chat_id", fileName); looper->PostMessage(&join); } diff --git a/protocols/xmpp/JabberHandler.cpp b/protocols/xmpp/JabberHandler.cpp index 8b91c32..d6671be 100644 --- a/protocols/xmpp/JabberHandler.cpp +++ b/protocols/xmpp/JabberHandler.cpp @@ -136,14 +136,15 @@ JabberHandler::Process(BMessage* msg) } case IM_CREATE_CHAT: { - const char* invite_id = msg->FindString("user_id"); + const char* user_id = msg->FindString("user_id"); // TODO: Contact validation, make sure permssion is granted - if (!invite_id) + if (!user_id) return B_ERROR; - _ChatCreatedMsg(invite_id); + _EnsureUserChat(user_id); + _ChatCreatedMsg(user_id); break; } @@ -213,14 +214,14 @@ JabberHandler::Process(BMessage* msg) gloox::MUCRoom* room = fRooms.ValueFor(chat_id); if (room != NULL) room->getRoomInfo(); - else if (fUserChats.HasString(chat_id) == true) + if (fUserChats.HasString(chat_id) == true) { BMessage metadata(IM_MESSAGE); metadata.AddInt32("im_what", IM_ROOM_METADATA); metadata.AddString("chat_id", chat_id); - metadata.AddInt32("room_default_flags", - 0 | ROOM_AUTOCREATE | ROOM_LOG_LOCALLY | ROOM_POPULATE_LOGS); - metadata.AddInt32("room_disallowed_flags", 0 | ROOM_AUTOJOIN); + metadata.AddInt32("room_default_flags", 0 | ROOM_LOG_LOCALLY | ROOM_POPULATE_LOGS); + metadata.AddInt32("room_disallowed_flags", 0 | ROOM_AUTOJOIN | ROOM_AUTOCREATE); + _SendMessage(&metadata); } break; }