import{a as b}from"./chunk-UB5P4QTT.mjs";import{d as h}from"./chunk-QM7X6D7F.mjs";import{a as M,b as I,c as P}from"./chunk-XEHBQAFR.mjs";var S={};I(S,{default:()=>x});var C,x,K=M(()=>{"use strict";C=function(){var y={defaultValue:null,kind:"LocalArgument",name:"connections"},s={defaultValue:null,kind:"LocalArgument",name:"profileId"},m=[{kind:"Variable",name:"profileId",variableName:"profileId"}],n={alias:null,args:null,kind:"ScalarField",name:"id",storageKey:null},o={alias:null,args:null,kind:"ScalarField",name:"isArchived",storageKey:null},c={alias:null,args:null,kind:"ScalarField",name:"participantsCount",storageKey:null},d={alias:null,args:null,kind:"ScalarField",name:"title",storageKey:null},g={alias:null,args:null,concreteType:"Profile",kind:"LinkedField",name:"profile",plural:!1,selections:[n],storageKey:null},f=[{alias:null,args:null,kind:"ScalarField",name:"url",storageKey:null}];return{fragment:{argumentDefinitions:[y,s],kind:"Fragment",metadata:null,name:"useRoomListSubscription",selections:[{alias:null,args:m,concreteType:"ChatRoomOnRoomUpdate",kind:"LinkedField",name:"chatRoomOnRoomUpdate",plural:!1,selections:[{alias:null,args:null,concreteType:"ChatRoomEdge",kind:"LinkedField",name:"room",plural:!1,selections:[{alias:null,args:null,concreteType:"ChatRoom",kind:"LinkedField",name:"node",plural:!1,selections:[n,o,c,d,{args:null,kind:"FragmentSpread",name:"LastMessageFragment"},{args:null,kind:"FragmentSpread",name:"TitleFragment"},{args:null,kind:"FragmentSpread",name:"UnreadMessagesCountFragment"}],storageKey:null}],storageKey:null},{alias:null,args:null,concreteType:"ChatRoomParticipant",kind:"LinkedField",name:"removedParticipants",plural:!0,selections:[n,g],storageKey:null}],storageKey:null}],type:"Subscription",abstractKey:null},kind:"Request",operation:{argumentDefinitions:[s,y],kind:"Operation",name:"useRoomListSubscription",selections:[{alias:null,args:m,concreteType:"ChatRoomOnRoomUpdate",kind:"LinkedField",name:"chatRoomOnRoomUpdate",plural:!1,selections:[{alias:null,args:null,concreteType:"ChatRoomEdge",kind:"LinkedField",name:"room",plural:!1,selections:[{alias:null,args:null,concreteType:"ChatRoom",kind:"LinkedField",name:"node",plural:!1,selections:[n,o,c,d,{alias:null,args:null,kind:"ScalarField",name:"lastMessageTime",storageKey:null},{alias:null,args:null,concreteType:"Message",kind:"LinkedField",name:"lastMessage",plural:!1,selections:[n,{alias:null,args:null,kind:"ScalarField",name:"content",storageKey:null}],storageKey:null},{alias:null,args:null,kind:"ScalarField",name:"isGroup",storageKey:null},{alias:null,args:[{kind:"Literal",name:"first",value:2}],concreteType:"ChatRoomParticipantConnection",kind:"LinkedField",name:"participants",plural:!1,selections:[{alias:null,args:null,concreteType:"ChatRoomParticipantEdge",kind:"LinkedField",name:"edges",plural:!0,selections:[{alias:null,args:null,concreteType:"ChatRoomParticipant",kind:"LinkedField",name:"node",plural:!1,selections:[{alias:null,args:null,concreteType:"Profile",kind:"LinkedField",name:"profile",plural:!1,selections:[n,{alias:null,args:null,kind:"ScalarField",name:"name",storageKey:null},{alias:null,args:[{kind:"Literal",name:"height",value:100},{kind:"Literal",name:"width",value:100}],concreteType:"File",kind:"LinkedField",name:"image",plural:!1,selections:f,storageKey:"image(height:100,width:100)"}],storageKey:null},n],storageKey:null}],storageKey:null}],storageKey:"participants(first:2)"},{alias:null,args:[{kind:"Literal",name:"height",value:144},{kind:"Literal",name:"width",value:144}],concreteType:"File",kind:"LinkedField",name:"image",plural:!1,selections:f,storageKey:"image(height:144,width:144)"},{alias:null,args:null,concreteType:"UnreadMessageCount",kind:"LinkedField",name:"unreadMessages",plural:!1,selections:[{alias:null,args:null,kind:"ScalarField",name:"count",storageKey:null},{alias:null,args:null,kind:"ScalarField",name:"markedUnread",storageKey:null},n],storageKey:null}],storageKey:null}],storageKey:null},{alias:null,args:null,concreteType:"ChatRoomParticipant",kind:"LinkedField",name:"removedParticipants",plural:!0,selections:[n,{alias:null,args:null,filters:null,handle:"deleteEdge",key:"",kind:"ScalarHandle",name:"id",handleArgs:[{kind:"Variable",name:"connections",variableName:"connections"}]},g],storageKey:null}],storageKey:null}]},params:{cacheID:"b33e570c1e964cbbf0ebdbe2cf54b30b",id:null,metadata:{},name:"useRoomListSubscription",operationKind:"subscription",text:`subscription useRoomListSubscription(
  $profileId: ID!
) {
  chatRoomOnRoomUpdate(profileId: $profileId) {
    room {
      node {
        id
        isArchived
        participantsCount
        title
        ...LastMessageFragment
        ...TitleFragment
        ...UnreadMessagesCountFragment
      }
    }
    removedParticipants {
      id
      profile {
        id
      }
    }
  }
}

fragment GroupTitleFragment on ChatRoom {
  id
  image(width: 144, height: 144) {
    url
  }
  title
}

fragment LastMessageFragment on ChatRoom {
  id
  lastMessageTime
  lastMessage {
    id
    content
  }
}

fragment RoomTitleFragment on ChatRoom {
  id
  participants(first: 2) {
    edges {
      node {
        profile {
          id
          name
          image(width: 100, height: 100) {
            url
          }
        }
        id
      }
    }
  }
}

fragment TitleFragment on ChatRoom {
  id
  isGroup
  ...RoomTitleFragment
  ...GroupTitleFragment
}

fragment UnreadMessagesCountFragment on ChatRoom {
  id
  unreadMessages {
    count
    markedUnread
    id
  }
}
`}}}();C.hash="1a6290e220a68b34641d01ea3ab017a1";x=C});import{useMemo as E}from"react";import{ConnectionHandler as v,useSubscription as A}from"react-relay";var u,w=(u!==void 0||(u=(K(),P(S)),u.hash&&u.hash!=="1a6290e220a68b34641d01ea3ab017a1"&&console.error("The definition of 'useRoomListSubscription' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data.")),u),V=function(s){var m=s.connections,n=s.profileId,o=s.onRemoval,c=b(),d=c.id,g=c.resetChatRoom,f=E(function(){var F=function(l){var e;return l==null||(e=l.chatRoomOnRoomUpdate)===null||e===void 0||(e=e.removedParticipants)===null||e===void 0?void 0:e.some(function(a){var t;return(a==null||(t=a.profile)===null||t===void 0?void 0:t.id)===n})};return{subscription:w,onError:console.error,variables:{profileId:n,connections:m},updater:function(l,e){var a,t=e==null||(a=e.chatRoomOnRoomUpdate)===null||a===void 0||(a=a.room)===null||a===void 0||(a=a.node)===null||a===void 0?void 0:a.id;if(t)if(F(e))h(l,n).forEach(function(r){return v.deleteNode(r,t)});else{var i,T=e==null||(i=e.chatRoomOnRoomUpdate)===null||i===void 0||(i=i.room)===null||i===void 0||(i=i.node)===null||i===void 0?void 0:i.isArchived;h(l,n,function(r){var p=r.q,k=r.archived;return p===""&&k===T}).forEach(function(r){var p;v.deleteNode(r,t);var k=(p=l.getRootField("chatRoomOnRoomUpdate"))===null||p===void 0?void 0:p.getLinkedRecord("room"),L=v.buildConnectionEdge(l,r,k);L&&v.insertEdgeBefore(r,L)})}},onNext:function(l){if(F(l)){var e;d&&(l==null||(e=l.chatRoomOnRoomUpdate)===null||e===void 0||(e=e.room)===null||e===void 0||(e=e.node)===null||e===void 0?void 0:e.id)===d&&g(),o?.()}}}},[n,m,o,d,g]);return A(f)};export{w as a,V as b};
//# sourceMappingURL=chunk-U2QNMZ5J.mjs.map