Skip to content

Commit

Permalink
Merge pull request #2493 from Bilb/disable-write-based-on-sogs-caps
Browse files Browse the repository at this point in the history
fix: disable typing and message request on sogs without `write`
  • Loading branch information
Bilb authored Sep 15, 2022
2 parents b008e9d + 1774253 commit cecf1ba
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion stylesheets/_session.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ textarea {
overflow: hidden;
outline: none;
color: $textAndBorderColor;
border: 2px solid $textAndBorderColor;
border: 1px solid $textAndBorderColor;
}

width: auto;
Expand Down
2 changes: 1 addition & 1 deletion ts/components/conversation/TypingAnimation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const StyledTypingContainer = styled.div`

const StyledTypingDot = styled.div<{ index: number }>`
border-radius: 50%;
background-color: var(--color-text-subtle); // TODO Theming update
background-color: var(--color-text-subtle); // TODO Theming update
height: 6px;
width: 6px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { PubKey } from '../../../../session/types';
import { openConversationWithMessages } from '../../../../state/ducks/conversations';
import { updateUserDetailsModal } from '../../../../state/ducks/modalDialog';
import {
getIsTypingEnabled,
getMessageAvatarProps,
getSelectedConversationKey,
} from '../../../../state/selectors/conversations';
Expand Down Expand Up @@ -37,6 +38,8 @@ export const MessageAvatar = (props: Props) => {
const avatarProps = useSelector(state => getMessageAvatarProps(state as any, messageId));
const selectedConvoKey = useSelector(getSelectedConversationKey);

const isTypingEnabled = useSelector(getIsTypingEnabled);

if (!avatarProps) {
return null;
}
Expand Down Expand Up @@ -75,6 +78,11 @@ export const MessageAvatar = (props: Props) => {
}
}

if (isPublic && !isTypingEnabled) {
window.log.info('onMessageAvatarClick: no typing enabled. Dropping...');
return;
}

if (isPublic && selectedConvoKey) {
const convoOpen = getConversationController().get(selectedConvoKey);
const room = OpenGroupData.getV2OpenGroupRoom(convoOpen.id);
Expand Down
17 changes: 17 additions & 0 deletions ts/models/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,23 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
toRet.currentNotificationSetting = currentNotificationSetting;
}

if (this.isOpenGroupV2()) {
const room = OpenGroupData.getV2OpenGroupRoom(this.id);
if (room && isArray(room.capabilities) && room.capabilities.length) {
toRet.capabilities = room.capabilities;
}

if (this.get('writeCapability')) {
toRet.writeCapability = this.get('writeCapability');
}
if (this.get('readCapability')) {
toRet.readCapability = this.get('readCapability');
}
if (this.get('uploadCapability')) {
toRet.uploadCapability = this.get('uploadCapability');
}
}

const lastMessageText = this.get('lastMessage');
if (lastMessageText && lastMessageText.length) {
const lastMessageStatus = this.get('lastMessageStatus');
Expand Down
7 changes: 5 additions & 2 deletions ts/state/ducks/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,11 @@ export interface ReduxConversationType {
isApproved?: boolean;
didApproveMe?: boolean;

/** Should only be present on open groups - the key (stored as hex) that should be used when sending messages to an open group */
blindedPublicKey?: string;
// Should only be present on opengroups - the capabilities we have on this room.
capabilities?: Array<string>;
readCapability?: boolean;
writeCapability?: boolean;
uploadCapability?: boolean;
}

export interface NotificationForConvoOption {
Expand Down
4 changes: 2 additions & 2 deletions ts/state/selectors/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export const getIsTypingEnabled = createSelector(
if (!selectedConvo) {
return false;
}
const { isBlocked, isKickedFromGroup, left } = selectedConvo;
const { isBlocked, isKickedFromGroup, left, isPublic, writeCapability } = selectedConvo;

return !(isBlocked || isKickedFromGroup || left);
return !(isBlocked || isKickedFromGroup || left || (isPublic && !writeCapability));
}
);
/**
Expand Down

0 comments on commit cecf1ba

Please sign in to comment.