First cut of Conversation Search #518
|
@ -220,6 +220,7 @@ const (
|
|||
|
||||
// Conversation Search
|
||||
SearchResult = Type("SearchResult")
|
||||
SearchCancelled = Type("SearchCancelled")
|
||||
)
|
||||
|
||||
// Field defines common event attributes
|
||||
|
|
|
@ -806,6 +806,11 @@ func (cp *cwtchPeer) GetChannelMessage(conversation int, channel int, id int) (s
|
|||
|
||||
func (cp *cwtchPeer) doSearch(ctx context.Context, searchID string, pattern string) {
|
||||
|
||||
// do not allow trivial searches that would match a wide variety of messages...
|
||||
if len(pattern) <=5 {
|
||||
return
|
||||
}
|
||||
|
||||
conversations, _ := cp.FetchConversations()
|
||||
maxCount := 0
|
||||
conversationCount := map[int]int{}
|
||||
|
@ -824,8 +829,9 @@ func (cp *cwtchPeer) doSearch(ctx context.Context, searchID string, pattern stri
|
|||
for offset := 0; offset < (maxCount + 10); offset += 10 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
cp.PublishEvent(event.NewEvent(event.SearchCancelled, map[event.Field]string{event.SearchID: searchID}))
|
||||
return
|
||||
case <-time.After(time.Millisecond):
|
||||
case <-time.After(time.Millisecond*100):
|
||||
for _, conversation := range conversations {
|
||||
ccount := conversationCount[conversation.ID]
|
||||
if offset > ccount {
|
||||
|
|
|
@ -344,10 +344,11 @@ func (e *engine) Shutdown() {
|
|||
log.Infof("shutting down ephemeral service")
|
||||
// work around: service.shutdown() can block for a long time if it is Open()ing a new connection, putting it in a
|
||||
// goroutine means we can perform this operation and let the per service shutdown in their own time or until the app exits
|
||||
conn := connection; // don't capture loop variable
|
||||
go func() {
|
||||
connection.connectingLock.Lock()
|
||||
connection.service.Shutdown()
|
||||
connection.connectingLock.Unlock()
|
||||
conn.connectingLock.Lock()
|
||||
conn.service.Shutdown()
|
||||
conn.connectingLock.Unlock()
|
||||
|
||||
}()
|
||||
}
|
||||
|
@ -380,6 +381,7 @@ func (e *engine) peerWithOnion(onion string) {
|
|||
}
|
||||
}
|
||||
}
|
||||
e.ignoreOnShutdown(e.peerDisconnected)(onion)
|
||||
}
|
||||
|
||||
func (e *engine) makeAntispamPayment(onion string) {
|
||||
|
|
Loading…
Reference in New Issue