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; 021 022import org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension; 023import org.jivesoftware.smackx.mam.element.MamQueryIQ; 024 025/** 026 * MAM result filter class. 027 * 028 * @see <a href="http://xmpp.org/extensions/xep-0313.html">XEP-0313: Message 029 * Archive Management</a> 030 * @author Fernando Ramirez and Florian Schmaus 031 * 032 */ 033public class MamResultFilter extends FlexibleStanzaTypeFilter<Message> { 034 035 private final String queryId; 036 037 public MamResultFilter(MamQueryIQ mamQueryIQ) { 038 super(Message.class); 039 this.queryId = mamQueryIQ.getQueryId(); 040 } 041 042 @Override 043 protected boolean acceptSpecific(Message message) { 044 MamResultExtension mamResultExtension = MamResultExtension.from(message); 045 046 if (mamResultExtension == null) { 047 return false; 048 } 049 050 String resultQueryId = mamResultExtension.getQueryId(); 051 return (queryId == null && resultQueryId == null) || (queryId != null && queryId.equals(resultQueryId)); 052 } 053 054}