chatById variable
Home > @cbnsndwch/zrocket-contracts > chatById
chatById variable
Query to retrieve a specific chat by ID for the authenticated user.
Signature:
chatById: _rocicorp_zero.SyncedQuery<
'chatById',
JwtPayload,
true,
[string],
_rocicorp_zero.Query<
{
tables: {
readonly chats: {
name: 'chats';
columns: {
readonly t: {
type: 'string';
optional: false;
customType: RoomType.DirectMessages;
};
readonly systemMessageTypes: Omit<
{
type: 'json';
optional: false;
customType: SystemMessageType[];
},
'optional'
> & {
optional: true;
};
readonly memberIds: {
type: 'json';
optional: false;
customType: string[];
};
readonly usernames: {
type: 'json';
optional: false;
customType: string[];
};
readonly messageCount: {
type: 'number';
optional: false;
customType: number;
};
readonly lastMessage: Omit<
{
type: 'json';
optional: false;
customType: Readonly<IMessageBase>;
},
'optional'
> & {
optional: true;
};
readonly lastMessageAt: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly _id: {
type: 'string';
optional: false;
customType: string;
};
readonly createdAt: {
type: 'string';
optional: false;
customType: string;
};
readonly updatedAt: {
type: 'string';
optional: false;
customType: string;
};
};
primaryKey: readonly [string, ...string[]];
} & {
primaryKey: ['_id'];
};
readonly groups: {
name: 'groups';
columns: {
readonly t: {
type: 'string';
optional: false;
customType: RoomType.PrivateGroup;
};
readonly name: {
type: 'string';
optional: false;
customType: string;
};
readonly topic: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly description: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly readOnly: Omit<
{
type: 'boolean';
optional: false;
customType: boolean;
},
'optional'
> & {
optional: true;
};
readonly archived: Omit<
{
type: 'boolean';
optional: false;
customType: boolean;
},
'optional'
> & {
optional: true;
};
readonly systemMessageTypes: Omit<
{
type: 'json';
optional: false;
customType: SystemMessageType[];
},
'optional'
> & {
optional: true;
};
readonly memberIds: {
type: 'json';
optional: false;
customType: string[];
};
readonly usernames: {
type: 'json';
optional: false;
customType: string[];
};
readonly messageCount: {
type: 'number';
optional: false;
customType: number;
};
readonly lastMessage: Omit<
{
type: 'json';
optional: false;
customType: Readonly<IMessageBase>;
},
'optional'
> & {
optional: true;
};
readonly lastMessageAt: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly _id: {
type: 'string';
optional: false;
customType: string;
};
readonly createdAt: {
type: 'string';
optional: false;
customType: string;
};
readonly updatedAt: {
type: 'string';
optional: false;
customType: string;
};
};
primaryKey: readonly [string, ...string[]];
} & {
primaryKey: ['_id'];
};
readonly channels: {
name: 'channels';
columns: {
readonly t: {
type: 'string';
optional: false;
customType: RoomType.PublicChannel;
};
readonly default: Omit<
{
type: 'boolean';
optional: false;
customType: boolean;
},
'optional'
> & {
optional: true;
};
readonly featured: Omit<
{
type: 'boolean';
optional: false;
customType: boolean;
},
'optional'
> & {
optional: true;
};
readonly name: {
type: 'string';
optional: false;
customType: string;
};
readonly topic: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly description: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly readOnly: Omit<
{
type: 'boolean';
optional: false;
customType: boolean;
},
'optional'
> & {
optional: true;
};
readonly archived: Omit<
{
type: 'boolean';
optional: false;
customType: boolean;
},
'optional'
> & {
optional: true;
};
readonly systemMessageTypes: Omit<
{
type: 'json';
optional: false;
customType: SystemMessageType[];
},
'optional'
> & {
optional: true;
};
readonly memberIds: {
type: 'json';
optional: false;
customType: string[];
};
readonly usernames: {
type: 'json';
optional: false;
customType: string[];
};
readonly messageCount: {
type: 'number';
optional: false;
customType: number;
};
readonly lastMessage: Omit<
{
type: 'json';
optional: false;
customType: Readonly<IMessageBase>;
},
'optional'
> & {
optional: true;
};
readonly lastMessageAt: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly _id: {
type: 'string';
optional: false;
customType: string;
};
readonly createdAt: {
type: 'string';
optional: false;
customType: string;
};
readonly updatedAt: {
type: 'string';
optional: false;
customType: string;
};
};
primaryKey: readonly [string, ...string[]];
} & {
primaryKey: ['_id'];
};
readonly userMessages: {
name: 'userMessages';
columns: {
readonly sender: {
type: 'json';
optional: false;
customType: Required<IUserSummary> &
Partial<IHasName>;
};
readonly contents: {
type: 'json';
optional: false;
customType: lexical.SerializedEditorState<lexical.SerializedLexicalNode>;
};
readonly groupable: Omit<
{
type: 'boolean';
optional: false;
customType: boolean;
},
'optional'
> & {
optional: true;
};
readonly repliedBy: Omit<
{
type: 'json';
optional: false;
customType: string[];
},
'optional'
> & {
optional: true;
};
readonly starredBy: Omit<
{
type: 'json';
optional: false;
customType: string[];
},
'optional'
> & {
optional: true;
};
readonly pinned: Omit<
{
type: 'boolean';
optional: false;
customType: boolean;
},
'optional'
> & {
optional: true;
};
readonly pinnedAt: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly pinnedBy: Omit<
{
type: 'json';
optional: false;
customType: IUserSummary;
},
'optional'
> & {
optional: true;
};
readonly attachments: Omit<
{
type: 'json';
optional: false;
customType: readonly MessageAttachment[];
},
'optional'
> & {
optional: true;
};
readonly reactions: Omit<
{
type: 'json';
optional: false;
customType: Readonly<
Record<string, IMessageReaction>
>;
},
'optional'
> & {
optional: true;
};
readonly roomId: {
type: 'string';
optional: false;
customType: string;
};
readonly hidden: Omit<
{
type: 'boolean';
optional: false;
customType: boolean;
},
'optional'
> & {
optional: true;
};
readonly _id: {
type: 'string';
optional: false;
customType: string;
};
readonly createdAt: {
type: 'string';
optional: false;
customType: string;
};
readonly updatedAt: {
type: 'string';
optional: false;
customType: string;
};
};
primaryKey: readonly [string, ...string[]];
} & {
primaryKey: ['_id'];
};
readonly systemMessages: {
name: 'systemMessages';
columns: {
readonly t: {
type: 'string';
optional: false;
customType: SystemMessageType;
};
readonly data: Omit<
{
type: 'json';
optional: false;
customType: _cbnsndwch_zero_contracts.Dict;
},
'optional'
> & {
optional: true;
};
readonly roomId: {
type: 'string';
optional: false;
customType: string;
};
readonly hidden: Omit<
{
type: 'boolean';
optional: false;
customType: boolean;
},
'optional'
> & {
optional: true;
};
readonly _id: {
type: 'string';
optional: false;
customType: string;
};
readonly createdAt: {
type: 'string';
optional: false;
customType: string;
};
readonly updatedAt: {
type: 'string';
optional: false;
customType: string;
};
};
primaryKey: readonly [string, ...string[]];
} & {
primaryKey: ['_id'];
};
readonly users: {
name: 'users';
columns: {
readonly name: {
type: 'string';
optional: false;
customType: string;
};
readonly username: {
type: 'string';
optional: false;
customType: string;
};
readonly email: {
type: 'string';
optional: false;
customType: string;
};
readonly additionalEmails: Omit<
{
type: 'json';
optional: false;
customType: string[];
},
'optional'
> & {
optional: true;
};
readonly active: {
type: 'boolean';
optional: false;
customType: boolean;
};
readonly bio: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly avatarUrl: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly externalId: Omit<
{
type: 'string';
optional: false;
customType: `${string}/${string}`;
},
'optional'
> & {
optional: true;
};
readonly defaultPresence: Omit<
{
type: 'string';
optional: false;
customType: UserPresenceStatus;
},
'optional'
> & {
optional: true;
};
readonly presence: Omit<
{
type: 'string';
optional: false;
customType: UserPresenceStatus;
},
'optional'
> & {
optional: true;
};
readonly presenceText: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly defaultRoom: Omit<
{
type: 'string';
optional: false;
customType: string;
},
'optional'
> & {
optional: true;
};
readonly profile: Omit<
{
type: 'json';
optional: false;
customType: _cbnsndwch_zero_contracts.Dict;
},
'optional'
> & {
optional: true;
};
readonly preferences: Omit<
{
type: 'json';
optional: false;
customType: _cbnsndwch_zero_contracts.Dict;
},
'optional'
> & {
optional: true;
};
readonly _id: {
type: 'string';
optional: false;
customType: string;
};
readonly createdAt: {
type: 'string';
optional: false;
customType: string;
};
readonly updatedAt: {
type: 'string';
optional: false;
customType: string;
};
};
primaryKey: readonly [string, ...string[]];
} & {
primaryKey: ['_id'];
};
};
relationships: {
readonly chats: {
messages: [
{
readonly sourceField: string[];
readonly destField: (
| '_id'
| 'createdAt'
| 'updatedAt'
| 'roomId'
| 'hidden'
| 'sender'
| 'contents'
| 'groupable'
| 'repliedBy'
| 'starredBy'
| 'pinned'
| 'pinnedAt'
| 'pinnedBy'
| 'attachments'
| 'reactions'
)[];
readonly destSchema: 'userMessages';
readonly cardinality: 'many';
}
];
systemMessages: [
{
readonly sourceField: string[];
readonly destField: (
| '_id'
| 'createdAt'
| 'updatedAt'
| 't'
| 'roomId'
| 'hidden'
| 'data'
)[];
readonly destSchema: 'systemMessages';
readonly cardinality: 'many';
}
];
};
readonly groups: {
messages: [
{
readonly sourceField: string[];
readonly destField: (
| '_id'
| 'createdAt'
| 'updatedAt'
| 'roomId'
| 'hidden'
| 'sender'
| 'contents'
| 'groupable'
| 'repliedBy'
| 'starredBy'
| 'pinned'
| 'pinnedAt'
| 'pinnedBy'
| 'attachments'
| 'reactions'
)[];
readonly destSchema: 'userMessages';
readonly cardinality: 'many';
}
];
systemMessages: [
{
readonly sourceField: string[];
readonly destField: (
| '_id'
| 'createdAt'
| 'updatedAt'
| 't'
| 'roomId'
| 'hidden'
| 'data'
)[];
readonly destSchema: 'systemMessages';
readonly cardinality: 'many';
}
];
};
readonly channels: {
messages: [
{
readonly sourceField: string[];
readonly destField: (
| '_id'
| 'createdAt'
| 'updatedAt'
| 'roomId'
| 'hidden'
| 'sender'
| 'contents'
| 'groupable'
| 'repliedBy'
| 'starredBy'
| 'pinned'
| 'pinnedAt'
| 'pinnedBy'
| 'attachments'
| 'reactions'
)[];
readonly destSchema: 'userMessages';
readonly cardinality: 'many';
}
];
systemMessages: [
{
readonly sourceField: string[];
readonly destField: (
| '_id'
| 'createdAt'
| 'updatedAt'
| 't'
| 'roomId'
| 'hidden'
| 'data'
)[];
readonly destSchema: 'systemMessages';
readonly cardinality: 'many';
}
];
};
readonly userMessages: {
replies: [
{
readonly sourceField: string[];
readonly destField: (
| '_id'
| 'createdAt'
| 'updatedAt'
| 'roomId'
| 'hidden'
| 'sender'
| 'contents'
| 'groupable'
| 'repliedBy'
| 'starredBy'
| 'pinned'
| 'pinnedAt'
| 'pinnedBy'
| 'attachments'
| 'reactions'
)[];
readonly destSchema: 'userMessages';
readonly cardinality: 'many';
}
];
};
readonly users: {};
};
enableLegacyQueries: boolean | undefined;
enableLegacyMutators: boolean | undefined;
},
'chats',
{
readonly t: RoomType.DirectMessages;
readonly systemMessageTypes: SystemMessageType[] | null;
readonly memberIds: string[];
readonly usernames: string[];
readonly messageCount: number;
readonly lastMessage: Readonly<IMessageBase> | null;
readonly lastMessageAt: string | null;
readonly _id: string;
readonly createdAt: string;
readonly updatedAt: string;
} & {
readonly messages: readonly {
readonly sender: Required<IUserSummary> & Partial<IHasName>;
readonly contents: lexical.SerializedEditorState<lexical.SerializedLexicalNode>;
readonly groupable: boolean | null;
readonly repliedBy: string[] | null;
readonly starredBy: string[] | null;
readonly pinned: boolean | null;
readonly pinnedAt: string | null;
readonly pinnedBy: IUserSummary | null;
readonly attachments: readonly MessageAttachment[] | null;
readonly reactions: Readonly<
Record<string, IMessageReaction>
> | null;
readonly roomId: string;
readonly hidden: boolean | null;
readonly _id: string;
readonly createdAt: string;
readonly updatedAt: string;
}[];
} & {
readonly systemMessages: readonly {
readonly t: SystemMessageType;
readonly data: _cbnsndwch_zero_contracts.Dict | null;
readonly roomId: string;
readonly hidden: boolean | null;
readonly _id: string;
readonly createdAt: string;
readonly updatedAt: string;
}[];
}
>
>;Remarks
**Client-side**: Returns the chat with all messages if found **Server-side**: Returns the chat only if user is a member (implemented in get-queries endpoint)
Anonymous users or non-members receive empty results on the server. Includes related user messages and system messages ordered by creation time.
Example
// In a React component:
import { useQuery } from '@rocicorp/zero/react';
import { chatById } from '@cbnsndwch/zrocket-contracts/queries/rooms';
const [chat] = useQuery(chatById(chatId));How was this page?