Full-text search within conversation

This commit is contained in:
Scott Nonnenberg 2019-08-09 16:12:29 -07:00
parent 6292019d30
commit c39d5a811a
26 changed files with 697 additions and 134 deletions

View file

@ -520,6 +520,10 @@
Signal.State.Ducks.user.actions,
store.dispatch
);
actions.search = Signal.State.bindActionCreators(
Signal.State.Ducks.search.actions,
store.dispatch
);
actions.stickers = Signal.State.bindActionCreators(
Signal.State.Ducks.stickers.actions,
store.dispatch

View file

@ -1,5 +1,9 @@
export function searchMessages(query: string): Promise<Array<any>>;
export function searchConversations(query: string): Promise<Array<any>>;
export function searchMessagesInConversation(
query: string,
conversationId: string
): Promise<Array<any>>;
export function updateStickerLastUsed(
packId: string,

View file

@ -655,9 +655,16 @@ async function searchConversations(query) {
return conversations;
}
function handleSearchMessageJSON(messages) {
return messages.map(message => ({
...JSON.parse(message.json),
snippet: message.snippet,
}));
}
async function searchMessages(query, { limit } = {}) {
const messages = await channels.searchMessages(query, { limit });
return messages;
return handleSearchMessageJSON(messages);
}
async function searchMessagesInConversation(
@ -670,7 +677,7 @@ async function searchMessagesInConversation(
conversationId,
{ limit }
);
return messages;
return handleSearchMessageJSON(messages);
}
// Message
@ -784,6 +791,10 @@ async function getUnreadByConversation(conversationId, { MessageCollection }) {
return new MessageCollection(messages);
}
function handleMessageJSON(messages) {
return messages.map(message => JSON.parse(message.json));
}
async function getOlderMessagesByConversation(
conversationId,
{ limit = 100, receivedAt = Number.MAX_VALUE, MessageCollection }
@ -796,7 +807,7 @@ async function getOlderMessagesByConversation(
}
);
return new MessageCollection(messages);
return new MessageCollection(handleMessageJSON(messages));
}
async function getNewerMessagesByConversation(
conversationId,
@ -810,7 +821,7 @@ async function getNewerMessagesByConversation(
}
);
return new MessageCollection(messages);
return new MessageCollection(handleMessageJSON(messages));
}
async function getMessageMetricsForConversation(conversationId) {
const result = await channels.getMessageMetricsForConversation(

View file

@ -62,6 +62,7 @@ const { createStore } = require('../../ts/state/createStore');
const conversationsDuck = require('../../ts/state/ducks/conversations');
const emojisDuck = require('../../ts/state/ducks/emojis');
const itemsDuck = require('../../ts/state/ducks/items');
const searchDuck = require('../../ts/state/ducks/search');
const stickersDuck = require('../../ts/state/ducks/stickers');
const userDuck = require('../../ts/state/ducks/user');
@ -274,6 +275,7 @@ exports.setup = (options = {}) => {
emojis: emojisDuck,
items: itemsDuck,
user: userDuck,
search: searchDuck,
stickers: stickersDuck,
};
const State = {

View file

@ -257,6 +257,13 @@
this.setDisappearingMessages(seconds),
onDeleteMessages: () => this.destroyMessages(),
onResetSession: () => this.endSession(),
onSearchInConversation: () => {
const { searchInConversation } = window.reduxActions.search;
const name = this.model.isMe()
? i18n('noteToSelf')
: this.model.getTitle();
searchInConversation(this.model.id, name);
},
// These are view only and don't update the Conversation model, so they
// need a manual update call.
@ -1490,8 +1497,6 @@
this.focusMessageField();
this.model.updateLastMessage();
const statusPromise = this.throttledGetProfiles();
// eslint-disable-next-line more/no-then
this.statusFetch = statusPromise.then(() =>
@ -1522,6 +1527,8 @@
if (quotedMessageId) {
this.setQuoteMessage(quotedMessageId);
}
this.model.updateLastMessage();
},
async retrySend(messageId) {