fix accept/decline friend request from conversationListItem
This commit is contained in:
parent
c9000c3f26
commit
05bbc43b22
|
@ -231,7 +231,28 @@
|
|||
this.trigger('change');
|
||||
this.messageCollection.forEach(m => m.trigger('change'));
|
||||
},
|
||||
async acceptFriendRequest() {
|
||||
const messages = await window.Signal.Data.getMessagesByConversation(
|
||||
this.id,
|
||||
{ limit: 1, MessageCollection: Whisper.MessageCollection }
|
||||
);
|
||||
|
||||
const lastMessageModel = messages.at(0);
|
||||
if (lastMessageModel) {
|
||||
lastMessageModel.acceptFriendRequest();
|
||||
}
|
||||
},
|
||||
async declineFriendRequest() {
|
||||
const messages = await window.Signal.Data.getMessagesByConversation(
|
||||
this.id,
|
||||
{ limit: 1, MessageCollection: Whisper.MessageCollection }
|
||||
);
|
||||
|
||||
const lastMessageModel = messages.at(0);
|
||||
if (lastMessageModel) {
|
||||
lastMessageModel.declineFriendRequest();
|
||||
}
|
||||
},
|
||||
setMessageSelectionBackdrop() {
|
||||
const messageSelected = this.selectedMessages.size > 0;
|
||||
|
||||
|
@ -571,6 +592,8 @@
|
|||
onDeleteContact: () => this.deleteContact(),
|
||||
onDeleteMessages: () => this.deleteMessages(),
|
||||
onCloseOverlay: () => this.resetMessageSelection(),
|
||||
acceptFriendRequest: () => this.acceptFriendRequest(),
|
||||
declineFriendRequest: () => this.declineFriendRequest(),
|
||||
};
|
||||
|
||||
this.updateAsyncPropsCache();
|
||||
|
@ -962,6 +985,7 @@
|
|||
}
|
||||
if (this.hasReceivedFriendRequest()) {
|
||||
this.setFriendRequestStatus(FriendRequestStatusEnum.friends, options);
|
||||
|
||||
await this.respondToAllFriendRequests({
|
||||
response: 'accepted',
|
||||
direction: 'incoming',
|
||||
|
|
|
@ -398,7 +398,6 @@
|
|||
return;
|
||||
}
|
||||
const conversation = await this.getSourceDeviceConversation();
|
||||
|
||||
// If we somehow received an old friend request (e.g. after having restored
|
||||
// from seed, we won't be able to accept it, we should initiate our own
|
||||
// friend request to reset the session:
|
||||
|
@ -408,7 +407,6 @@
|
|||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.set({ friendStatus: 'accepted' });
|
||||
await window.Signal.Data.saveMessage(this.attributes, {
|
||||
Message: Whisper.Message,
|
||||
|
|
|
@ -57,6 +57,8 @@ type PropsHousekeeping = {
|
|||
onClearNickname?: () => void;
|
||||
onCopyPublicKey?: () => void;
|
||||
onUnblockContact?: () => void;
|
||||
acceptFriendRequest?: () => void;
|
||||
declineFriendRequest?: () => void;
|
||||
};
|
||||
|
||||
type Props = PropsData & PropsHousekeeping;
|
||||
|
@ -280,10 +282,11 @@ export class ConversationListItem extends React.PureComponent<Props> {
|
|||
|
||||
public renderFriendRequestButtons() {
|
||||
|
||||
const { acceptFriendRequest, declineFriendRequest } = this.props;
|
||||
return (
|
||||
<div className="module-conversation-list-item__buttons">
|
||||
<SessionButton text={window.i18n('decline')} buttonColor={SessionButtonColor.None}/>
|
||||
<SessionButton text={window.i18n('accept')} />
|
||||
<SessionButton text={window.i18n('decline')} buttonColor={SessionButtonColor.None} onClick={declineFriendRequest}/>
|
||||
<SessionButton text={window.i18n('accept')} onClick={acceptFriendRequest}/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -201,9 +201,14 @@ export class ActionsPanel extends React.Component<Props, State> {
|
|||
static getFriendRequestsCount(conversations: Array<ConversationListItemPropsType> | undefined): number {
|
||||
let friendRequestCount = 0;
|
||||
if (conversations !== undefined) {
|
||||
// We assume a friend request already read is no longer a friend request (has been ignored)
|
||||
// We assume a friend request already read is still a friend valid request
|
||||
conversations.some(function (conversation) {
|
||||
friendRequestCount += conversation.showFriendRequestIndicator ? 1 : 0;
|
||||
// Ignore friend request with lastmessage status as sent as this is a friend request we made ourself
|
||||
const isValidFriendRequest = conversation.showFriendRequestIndicator
|
||||
&& conversation.lastMessage
|
||||
&& conversation.lastMessage.status !== 'sent'
|
||||
&& conversation.lastMessage.status !== 'sending';
|
||||
friendRequestCount += isValidFriendRequest ? 1 : 0;
|
||||
if (friendRequestCount > 9) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -185,8 +185,9 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
|
|||
let conversationsList = conversations;
|
||||
console.log('conversations:', conversationsList);
|
||||
if (conversationsList !== undefined) {
|
||||
// ignore friend request we made ourself
|
||||
conversationsList = conversationsList.filter(
|
||||
conversation => conversation.showFriendRequestIndicator
|
||||
conversation => conversation.showFriendRequestIndicator && conversation.lastMessage && conversation.lastMessage.status !== 'sent' && conversation.lastMessage.status !== 'sending'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -202,8 +203,7 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
|
|||
'render: must provided friends if no search results are provided'
|
||||
);
|
||||
}
|
||||
const length = friends.length + (friendsRequest?friendsRequest.length:0);
|
||||
|
||||
const length = friends.length + (friendsRequest ? friendsRequest.length : 0);
|
||||
// Note: conversations is not a known prop for List, but it is required to ensure that
|
||||
// it re-renders when our conversation data changes. Otherwise it would just render
|
||||
// on startup and scroll.
|
||||
|
|
Loading…
Reference in New Issue