001/** 002 * 003 * Copyright © 2016 Florian Schmaus and Fernando Ramirez 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.mam.filter; 018 019import org.jivesoftware.smack.filter.FlexibleStanzaTypeFilter; 020import org.jivesoftware.smack.packet.Message; 021import org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension; 022import org.jivesoftware.smackx.mam.element.MamQueryIQ; 023 024/** 025 * MAM result filter class. 026 * 027 * @see <a href="http://xmpp.org/extensions/xep-0313.html">XEP-0313: Message 028 * Archive Management</a> 029 * @author Fernando Ramirez and Florian Schmaus 030 * 031 */ 032public class MamResultFilter extends FlexibleStanzaTypeFilter<Message> { 033 034 private final String queryId; 035 036 public MamResultFilter(MamQueryIQ mamQueryIQ) { 037 super(Message.class); 038 this.queryId = mamQueryIQ.getQueryId(); 039 } 040 041 @Override 042 protected boolean acceptSpecific(Message message) { 043 MamResultExtension mamResultExtension = MamResultExtension.from(message); 044 045 if (mamResultExtension == null) { 046 return false; 047 } 048 049 String resultQueryId = mamResultExtension.getQueryId(); 050 return ((queryId == null && resultQueryId == null) || (queryId != null && queryId.equals(resultQueryId))); 051 } 052 053}