Auto-join cached rooms on log-in
Rooms are now cached in ~/config/settings/Caya/Cache/$account/Rooms/, with each file representing a seperate room. The filename is used as the identifier, and these files now also serve as log files. The log attribute name has also changed from "logs" to "Caya:logs". When a protocol has succesfuly connected, all cached rooms are automatically joined.
This commit is contained in:
parent
9cd4ce18e1
commit
07350b3a0a
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
||||
* Copyright 2014, Funky Idea Software
|
||||
* Copyright 2021, Jaidyn Levesque
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#include <memory.h>
|
||||
|
@ -126,18 +127,40 @@ CayaCachePath()
|
|||
|
||||
|
||||
const char*
|
||||
CayaLogPath(const char* accountName)
|
||||
CayaAccountCachePath(const char* accountName)
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||
BPath path(CayaCachePath());
|
||||
if (path.InitCheck() != B_OK)
|
||||
return NULL;
|
||||
|
||||
path.Append("Caya/Logs");
|
||||
path.Append(accountName);
|
||||
|
||||
if (create_directory(path.Path(), 0755) != B_OK)
|
||||
return NULL;
|
||||
return path.Path();
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
CayaRoomsCachePath(const char* accountName)
|
||||
{
|
||||
BPath path(CayaAccountCachePath(accountName));
|
||||
if (path.InitCheck() != B_OK)
|
||||
return NULL;
|
||||
path.Append("Rooms");
|
||||
|
||||
if (create_directory(path.Path(), 0755) != B_OK)
|
||||
return NULL;
|
||||
return path.Path();
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
CayaRoomCachePath(const char* accountName, const char* roomIdentifier)
|
||||
{
|
||||
BPath path(CayaRoomsCachePath(accountName));
|
||||
if (path.InitCheck() != B_OK)
|
||||
return NULL;
|
||||
path.Append(roomIdentifier);
|
||||
return path.Path();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/*
|
||||
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
||||
* Copyright 2014, Funky Idea Software
|
||||
* Copyright 2021, Jaidyn Levesque
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _CAYA_UTILS_H
|
||||
|
@ -22,7 +24,9 @@ const char* CayaAccountPath(const char* signature);
|
|||
const char* CayaAccountPath(const char* signature, const char* subsignature);
|
||||
|
||||
const char* CayaCachePath();
|
||||
const char* CayaLogPath(const char* accountName);
|
||||
const char* CayaAccountCachePath(const char* accountName);
|
||||
const char* CayaRoomsCachePath(const char* accountName);
|
||||
const char* CayaRoomCachePath(const char* accountName, const char* roomIdentifier);
|
||||
|
||||
rgb_color CayaTintColor(rgb_color color, int severity);
|
||||
rgb_color CayaForegroundColor(rgb_color background);
|
||||
|
|
|
@ -334,8 +334,8 @@ Conversation::_LogChatMessage(BMessage* msg)
|
|||
newLogMsg.AddStrings("body", bodies);
|
||||
newLogMsg.AddStrings("user_id", users);
|
||||
|
||||
BFile logFile(fLogPath.Path(), B_READ_WRITE | B_OPEN_AT_END | B_CREATE_FILE);
|
||||
WriteAttributeMessage(&logFile, "logs", &newLogMsg);
|
||||
BFile logFile(fCachePath.Path(), B_READ_WRITE | B_OPEN_AT_END | B_CREATE_FILE);
|
||||
WriteAttributeMessage(&logFile, "Caya:logs", &newLogMsg);
|
||||
|
||||
// Plain-text logs
|
||||
BString uname;
|
||||
|
@ -354,22 +354,22 @@ Conversation::_LogChatMessage(BMessage* msg)
|
|||
status_t
|
||||
Conversation::_GetChatLogs(BMessage* msg)
|
||||
{
|
||||
_EnsureLogPath();
|
||||
_EnsureCachePath();
|
||||
|
||||
BFile logFile(fLogPath.Path(), B_READ_WRITE | B_CREATE_FILE);
|
||||
BFile logFile(fCachePath.Path(), B_READ_WRITE | B_CREATE_FILE);
|
||||
|
||||
return ReadAttributeMessage(&logFile, "logs", msg);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Conversation::_EnsureLogPath()
|
||||
Conversation::_EnsureCachePath()
|
||||
{
|
||||
if (fLogPath.InitCheck() == B_OK)
|
||||
if (fCachePath.InitCheck() == B_OK)
|
||||
return;
|
||||
|
||||
fLogPath.SetTo(CayaLogPath(fLooper->Protocol()->GetName()));
|
||||
fLogPath.Append(fID);
|
||||
fCachePath.SetTo(CayaRoomCachePath(fLooper->Protocol()->GetName(),
|
||||
fID.String()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@ public:
|
|||
private:
|
||||
void _LogChatMessage(BMessage* msg);
|
||||
status_t _GetChatLogs(BMessage* msg);
|
||||
void _EnsureLogPath();
|
||||
|
||||
void _EnsureCachePath();
|
||||
|
||||
User* _EnsureUser(BMessage* msg);
|
||||
|
||||
|
@ -86,7 +87,7 @@ private:
|
|||
|
||||
BBitmap* fIcon;
|
||||
|
||||
BPath fLogPath;
|
||||
BPath fCachePath;
|
||||
BDateTimeFormat fDateFormatter;
|
||||
|
||||
UserMap fUsers;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "CayaProtocol.h"
|
||||
#include "CayaPreferences.h"
|
||||
#include "CayaProtocolMessages.h"
|
||||
#include "CayaUtils.h"
|
||||
#include "ImageCache.h"
|
||||
#include "InviteDialogue.h"
|
||||
#include "ProtocolLooper.h"
|
||||
|
@ -43,18 +44,8 @@ Server::Server()
|
|||
void
|
||||
Server::Quit()
|
||||
{
|
||||
Contact* contact = NULL;
|
||||
Conversation* conversation = NULL;
|
||||
|
||||
// while (contact = fRosterMap.ValueAt(0)) {
|
||||
// contact->DeletePopUp();
|
||||
// fRosterMap.RemoveItemAt(0);
|
||||
// }
|
||||
|
||||
// while (conversation = fChatMap.ValueAt(0)) {
|
||||
// fChatMap.RemoveItemAt(0);
|
||||
// delete conversation;
|
||||
// }
|
||||
for (int i = 0; i < fLoopers.CountItems(); i++)
|
||||
RemoveProtocolLooper(fLoopers.KeyAt(i));
|
||||
}
|
||||
|
||||
|
||||
|
@ -468,9 +459,11 @@ Server::ImMessage(BMessage* msg)
|
|||
}
|
||||
case IM_PROTOCOL_READY:
|
||||
{
|
||||
// Ready notification
|
||||
ProtocolLooper* looper = _LooperFromMessage(msg);
|
||||
if (looper == NULL)
|
||||
break;
|
||||
CayaProtocol* proto = looper->Protocol();
|
||||
|
||||
BString content("%user% has connected!");
|
||||
content.ReplaceAll("%user%", looper->Protocol()->GetName());
|
||||
|
@ -479,8 +472,21 @@ Server::ImMessage(BMessage* msg)
|
|||
notification.SetGroup(BString("Caya"));
|
||||
notification.SetTitle("Connected");
|
||||
notification.SetContent(content);
|
||||
notification.SetIcon(looper->Protocol()->Icon());
|
||||
notification.SetIcon(proto->Icon());
|
||||
notification.Send();
|
||||
|
||||
// Join cached rooms
|
||||
BEntry entry;
|
||||
char fileName[B_FILE_NAME_LENGTH] = {'\0'};
|
||||
BDirectory dir(CayaRoomsCachePath(proto->GetName()));
|
||||
|
||||
while (dir.GetNextEntry(&entry, true) == B_OK)
|
||||
if (entry.GetName(fileName) == B_OK) {
|
||||
BMessage join(IM_MESSAGE);
|
||||
join.AddInt32("im_what", IM_JOIN_ROOM);
|
||||
join.AddString("chat_id", fileName);
|
||||
looper->PostMessage(&join);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue