Display subscriber count for open chats

pull/741/head
Maxim Shishmarev 5 years ago
parent dc519ac606
commit 8ce066b802

@ -2534,6 +2534,10 @@
}); });
} }
}, },
async setSubscriberCount(count) {
this.set({ subscriberCount: count });
// Not sure if we care about updating the database
},
async setGroupNameAndAvatar(name, avatarPath) { async setGroupNameAndAvatar(name, avatarPath) {
const currentName = this.get('name'); const currentName = this.get('name');
const profileAvatar = this.get('profileAvatar'); const profileAvatar = this.get('profileAvatar');

@ -889,14 +889,16 @@ class LokiPublicChannelAPI {
include_annotations: 1, include_annotations: 1,
}, },
}); });
if (
!res.err && if (res.err || !res.response || !res.response.data) {
res.response && return;
res.response.data.annotations && }
res.response.data.annotations.length
) { const { data } = res.response;
if (data.annotations && data.annotations.length) {
// get our setting note // get our setting note
const settingNotes = res.response.data.annotations.filter( const settingNotes = data.annotations.filter(
note => note.type === SETTINGS_CHANNEL_ANNOTATION_TYPE note => note.type === SETTINGS_CHANNEL_ANNOTATION_TYPE
); );
const note = settingNotes && settingNotes.length ? settingNotes[0] : {}; const note = settingNotes && settingNotes.length ? settingNotes[0] : {};
@ -911,6 +913,10 @@ class LokiPublicChannelAPI {
// who are the moderators? // who are the moderators?
// else could set a default in case of server problems... // else could set a default in case of server problems...
} }
if (data.counts && Number.isInteger(data.counts.subscribers)) {
this.conversation.setSubscriberCount(data.counts.subscribers);
}
} }
// get moderation actions // get moderation actions

@ -189,6 +189,7 @@
window.storage.get('primaryDevicePubKey') window.storage.get('primaryDevicePubKey')
), ),
members, members,
subscriberCount: this.model.get('subscriberCount'),
selectedMessages: this.model.selectedMessages, selectedMessages: this.model.selectedMessages,
expirationSettingName, expirationSettingName,
showBackButton: Boolean(this.panels && this.panels.length), showBackButton: Boolean(this.panels && this.panels.length),

@ -44,8 +44,14 @@ interface Props {
isRss: boolean; isRss: boolean;
amMod: boolean; amMod: boolean;
// We might not always have the full list of members,
// e.g. for open groups where we could have thousands
// of members. We'll keep this for now (for closed chats)
members: Array<any>; members: Array<any>;
// not equal members.length (see above)
subscriberCount?: number;
expirationSettingName?: string; expirationSettingName?: string;
showBackButton: boolean; showBackButton: boolean;
timerOptions: Array<TimerOption>; timerOptions: Array<TimerOption>;
@ -134,8 +140,10 @@ export class ConversationHeader extends React.Component<Props> {
profileName, profileName,
isFriend, isFriend,
isGroup, isGroup,
isPublic,
isRss, isRss,
members, members,
subscriberCount,
isFriendRequestPending, isFriendRequestPending,
isMe, isMe,
name, name,
@ -149,13 +157,25 @@ export class ConversationHeader extends React.Component<Props> {
); );
} }
const memberCount: number = (() => {
if (!isGroup || isRss) {
return 0;
}
if (isPublic) {
return subscriberCount || 0;
} else {
return members.length;
}
})();
let text = ''; let text = '';
if (isFriendRequestPending) { if (isFriendRequestPending) {
text = i18n('pendingAcceptance'); text = i18n('pendingAcceptance');
} else if (!isFriend && !isGroup) { } else if (!isFriend && !isGroup) {
text = i18n('notFriends'); text = i18n('notFriends');
} else if (isGroup && !isRss && members.length > 0) { } else if (memberCount > 0) {
const count = String(members.length); const count = String(memberCount);
text = i18n('members', [count]); text = i18n('members', [count]);
} }
@ -373,6 +393,7 @@ export class ConversationHeader extends React.Component<Props> {
<div className="module-conversation-header__title-flex"> <div className="module-conversation-header__title-flex">
{this.renderOptions(triggerId)} {this.renderOptions(triggerId)}
{this.renderTitle()} {this.renderTitle()}
{/* This might be redundant as we show the title in the title: */}
{isPrivateGroup ? this.renderMemberCount() : null} {isPrivateGroup ? this.renderMemberCount() : null}
</div> </div>
</div> </div>
@ -392,7 +413,9 @@ export class ConversationHeader extends React.Component<Props> {
} }
private renderMemberCount() { private renderMemberCount() {
const memberCount = this.props.members.length; const memberCount = this.props.isPublic
? this.props.subscriberCount
: this.props.members.length;
if (memberCount === 0) { if (memberCount === 0) {
return null; return null;

Loading…
Cancel
Save