Skip to content

Commit

Permalink
Merge pull request #4367 from tloncorp/po/tlon-3407-add-currentUserIs…
Browse files Browse the repository at this point in the history
…Host-to-channel-model

add currentUserIsHost to channel model
  • Loading branch information
patosullivan authored Jan 23, 2025
2 parents 35e9d46 + ac94a30 commit b4ca39a
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
6 changes: 5 additions & 1 deletion packages/shared/src/api/groupsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getChannelType,
getJoinStatusFromGang,
} from '../urbit';
import { parseGroupId, toClientMeta } from './apiUtils';
import { parseGroupChannelId, parseGroupId, toClientMeta } from './apiUtils';
import { StructuredChannelDescriptionPayload } from './channelContentConfig';
import {
getCurrentUserId,
Expand Down Expand Up @@ -1539,6 +1539,9 @@ function toClientChannel({
roleId,
}));

const currentUserId = getCurrentUserId();
const { host: hostUserId } = parseGroupChannelId(id);

return {
id,
groupId,
Expand All @@ -1548,6 +1551,7 @@ function toClientChannel({
coverImage: omitEmpty(channel.meta.cover),
description,
contentConfiguration: channelContentConfiguration,
currentUserIsHost: hostUserId === currentUserId,
readerRoles,
writerRoles,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ CREATE TABLE `channels` (
`contact_id` text,
`added_to_group_at` integer,
`current_user_is_member` integer,
`current_user_is_host` integer,
`post_count` integer,
`unread_count` integer,
`first_unread_post_id` text,
Expand All @@ -74,7 +75,6 @@ CREATE TABLE `channels` (
`synced_at` integer,
`remote_updated_at` integer,
`last_viewed_at` integer,
`is_default_welcome_channel` integer,
`content_configuration` text,
FOREIGN KEY (`group_id`) REFERENCES `groups`(`id`) ON UPDATE no action ON DELETE cascade
);
Expand Down
16 changes: 8 additions & 8 deletions packages/shared/src/db/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "6",
"dialect": "sqlite",
"id": "faa3b44e-123d-4ff7-88c8-5e2a6fefa25b",
"id": "a317605a-b303-4b87-b2e9-0f210564fcce",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"activity_event_contact_group_pins": {
Expand Down Expand Up @@ -424,6 +424,13 @@
"notNull": false,
"autoincrement": false
},
"current_user_is_host": {
"name": "current_user_is_host",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"post_count": {
"name": "post_count",
"type": "integer",
Expand Down Expand Up @@ -495,13 +502,6 @@
"notNull": false,
"autoincrement": false
},
"is_default_welcome_channel": {
"name": "is_default_welcome_channel",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"content_configuration": {
"name": "content_configuration",
"type": "text",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/db/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "6",
"when": 1733961238109,
"tag": "0000_safe_zarda",
"when": 1737658544532,
"tag": "0000_unusual_christian_walker",
"breakpoints": true
}
]
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/db/migrations/migrations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is required for Expo/React Native SQLite migrations - https://orm.drizzle.team/quick-sqlite/expo

import journal from './meta/_journal.json';
import m0000 from './0000_safe_zarda.sql';
import m0000 from './0000_unusual_christian_walker.sql';

export default {
journal,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/db/modelBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export function buildChannel(
coverImage: null,
coverImageColor: null,
currentUserIsMember: null,
currentUserIsHost: null,
description: null,
firstUnreadPostId: null,
groupId: null,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ export const channels = sqliteTable(
contactId: text('contact_id'),
addedToGroupAt: timestamp('added_to_group_at'),
currentUserIsMember: boolean('current_user_is_member'),
currentUserIsHost: boolean('current_user_is_host'),
postCount: integer('post_count'),
unreadCount: integer('unread_count'),
firstUnreadPostId: text('first_unread_post_id'),
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/ChatOptionsSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ function ChannelOptionsSheetContent({
const { data: hooksPreview } = store.useChannelHooksPreview(channel.id);

const currentUser = useCurrentUserId();
const currentUserIsHost = group?.currentUserIsHost ?? false;
const currentUserIsHost = channel?.currentUserIsHost ?? false;
const currentUserIsAdmin = useIsAdmin(channel.groupId ?? '', currentUser);
const groupTitle = utils.useGroupTitle(group) ?? 'group';
const isSingleChannelGroup = group?.channels?.length === 1;
Expand Down

0 comments on commit b4ca39a

Please sign in to comment.