<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.m2pool.chat.mapper.ChatMessageHistoryMapper">


    <select id="findHistoryMessage" resultType="com.m2pool.chat.dto.ChatMessageDto">
        SELECT id,
               type,
               send_email as sendEmail,
               content,
               create_time as createTime,
                room_id as roomId,
                case when send_email = #{email} then 1
                else 0
                end as isSelf
        FROM chat_message_history
        <where>
            room_id = #{roomId}
            <if test="id != null">
                AND id <![CDATA[ < ]]> #{id}
            </if>
        </where>
        ORDER BY id DESC
        LIMIT #{pageNum}
    </select>
</mapper>