Skip to content

Commit

Permalink
Searching through chat with TextSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
JadedCtrl committed Sep 1, 2021
1 parent e2d801b commit 3689f6c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions application/AppMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const uint32 APP_USER_INFO = 'CYuw';
//! Display a "room info" window
const uint32 APP_ROOM_INFO = 'CYrw';

//! Open the room's logs with TextSearch
const uint32 APP_ROOM_SEARCH = 'CYrs';

//! Toggle a specific flag for a room
const uint32 APP_ROOM_FLAG = 'Rlag';

Expand Down
4 changes: 4 additions & 0 deletions application/Conversation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@ Conversation::_LogChatMessage(BMessage* msg)
BFile logFile(fCachePath.Path(), B_READ_WRITE | B_OPEN_AT_END | B_CREATE_FILE);
WriteAttributeMessage(&logFile, "Chat:logs", &logMsg);

BString mime = BString("text/plain");
logFile.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0, mime.String(),
mime.CountChars() + 1);

// Plain-text logs
// Gotta make sure the formatting's pretty!
BString date;
Expand Down
2 changes: 2 additions & 0 deletions application/Conversation.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class Conversation : public Notifier, public Observer {
void SetFlags(int32 flags);
int32 DisallowedFlags() { return fDisallowedFlags; }

BPath CachePath() { return fCachePath; }

private:
void _WarnUser(BString message);

Expand Down
25 changes: 22 additions & 3 deletions application/windows/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
/*
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
Expand All @@ -16,6 +17,7 @@
#include <Catalog.h>
#include <LayoutBuilder.h>
#include <MenuBar.h>
#include <Roster.h>
#include <ScrollView.h>
#include <TranslationUtils.h>

Expand Down Expand Up @@ -211,6 +213,21 @@ MainWindow::MessageReceived(BMessage* message)
RoomListWindow::Get(fServer)->Show();
break;
}
case APP_ROOM_SEARCH:
{
if (fConversation != NULL) {
entry_ref ref;
BEntry entry(fConversation->CachePath().Path());
if (entry.GetRef(&ref) != B_OK)
break;

BMessage msg(B_REFS_RECEIVED);
msg.AddRef("refs", &ref);
BRoster roster;
roster.Launch("application/x-vnd.Haiku.TextSearch", &msg);
}
break;
}
case APP_EDIT_ROSTER:
{
RosterEditWindow::Get(fServer)->Show();
Expand Down Expand Up @@ -518,15 +535,17 @@ MainWindow::_CreateMenuBar()
BMenu* chatMenu = new BMenu(B_TRANSLATE("Chat"));
chatMenu->AddItem(new BMenuItem(B_TRANSLATE("Join room" B_UTF8_ELLIPSIS),
new BMessage(APP_JOIN_ROOM), 'J', B_COMMAND_KEY));
chatMenu->AddItem(new BMenuItem(B_TRANSLATE("Room directory" B_UTF8_ELLIPSIS),
new BMessage(APP_ROOM_DIRECTORY)));
chatMenu->SetTargetForItems(this);
chatMenu->AddSeparatorItem();
chatMenu->AddItem(new BMenuItem(B_TRANSLATE("New room" B_UTF8_ELLIPSIS),
new BMessage(APP_NEW_ROOM), 'N', B_COMMAND_KEY));
chatMenu->AddItem(new BMenuItem(B_TRANSLATE("New chat" B_UTF8_ELLIPSIS),
new BMessage(APP_NEW_CHAT), 'M', B_COMMAND_KEY));
chatMenu->AddSeparatorItem();
chatMenu->AddItem(new BMenuItem(B_TRANSLATE("Room directory" B_UTF8_ELLIPSIS),
new BMessage(APP_ROOM_DIRECTORY)));
chatMenu->SetTargetForItems(this);
chatMenu->AddItem(new BMenuItem(B_TRANSLATE("Find" B_UTF8_ELLIPSIS),
new BMessage(APP_ROOM_SEARCH), 'F', B_COMMAND_KEY));

// Roster
BMenu* rosterMenu = new BMenu(B_TRANSLATE("Roster"));
Expand Down

0 comments on commit 3689f6c

Please # to comment.