import { ApiCall } from "tsrpc";
import { ReqDelPrivate, ResDelPrivate } from "../../shared/protocols/chat/PtlDelPrivate";

export default async function (call: ApiCall<ReqDelPrivate, ResDelPrivate>) {

    G.redis.get('chatPrivate', call.uid).then(v => {
        if (v?.includes(call.req.privateId)) {
            G.redis.arrPop('chatPrivate', call.uid, v.findIndex(id => id == call.req.privateId));
        }
    });

    G.mongodb.collection('chat').deleteOne({ type: call.req.privateId });

    call.succ({});
}