@Autowired
private PushApi pushApi;
@Override
public Page<Message> findUserMessage(Long userId, MessageState state, Pageable pageable) {
Searchable searchable = Searchable.newSearchable();
searchable.setPage(pageable);
switch (state) {
//sender的
case draft_box:
case out_box:
searchable.addSearchFilter("senderId", SearchOperator.eq, userId);
searchable.addSearchFilter("senderState", SearchOperator.eq, state);
break;
//receiver的
case in_box:
searchable.addSearchFilter("receiverId", SearchOperator.eq, userId);
searchable.addSearchFilter("receiverState", SearchOperator.eq, state);
break;
//sender or receiver的
case store_box:
case trash_box:
//sender
SearchFilter senderFilter = SearchFilterHelper.newCondition("senderId", SearchOperator.eq, userId);
SearchFilter senderStateFilter = SearchFilterHelper.newCondition("senderState", SearchOperator.eq, state);
SearchFilter and1 = SearchFilterHelper.and(senderFilter, senderStateFilter);
//receiver
SearchFilter receiverFilter = SearchFilterHelper.newCondition("receiverId", SearchOperator.eq, userId);
SearchFilter receiverStateFilter = SearchFilterHelper.newCondition("receiverState", SearchOperator.eq, state);
SearchFilter and2 = SearchFilterHelper.and(receiverFilter, receiverStateFilter);
searchable.or(and1, and2);
}
return messageService.findAll(searchable);
}