<template>
    <div>
        会话设置 {{ targetId}}
        <div @click="setStatus">免打扰开关 {{status}}</div>
        <div @click="setTop">置顶会话 {{isTop}}</div>
        
        <u-button @click="toIndex">会首页</u-button>
    </div>
</template>

<script>
    import * as RongIMLib from '@rongcloud/imlib-uni'

    export default {
        data() {
            return {
                targetId: '',
                conversationType: 1,
                isTop: false,
                status: 0 // 0 是免打扰，1是正常通知
            }
        },
        onLoad(e) {
            this.targetId = e.targetId
            this.conversationType = e.conversationType

            RongIMLib.getConversation(this.conversationType, this.targetId, ({
                conversation
            }) => {
                this.isTop = conversation.isTop
            })

            RongIMLib.getConversationNotificationStatus(this.conversationType, this.targetId, ({
                status
            }) => {
                this.status = status
            })
        },
        methods: {
            toIndex() {
                uni.switchTab({
                    url: '/pages/im/index'
                })
            },
            setStatus() {
                RongIMLib.setConversationNotificationStatus(this.conversationType, this.targetId, this.status, ({
                    status
                }) => {
                    this.status = status
                })
            },
            setTop() {
                RongIMLib.setConversationToTop(this.conversationType, this.targetId, !this.isTop, (res) => {
                    console.log(res);
                    RongIMLib.getConversation(this.conversationType, this.targetId, ({
                        conversation
                    }) => {
                        console.log(conversation.isTop);
                        this.isTop = conversation.isTop
                    })
                })
            }
        }
    }
</script>

<style>
</style>
