fix group updates outgoing message status in left pane

pull/2154/head
Audric Ackermann 3 years ago
parent 912d6b36dc
commit a3eb80abcf
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -49,7 +49,7 @@ export const SearchResults = (props: SearchResultsProps) => {
<SearchResultsContainer>
{noResults ? <NoResults>{window.i18n('noSearchResults', [searchTerm])}</NoResults> : null}
{haveContactsAndGroup ? (
<div>
<>
<StyledSeparatorSection>{window.i18n('conversationsHeader')}</StyledSeparatorSection>
{contactsAndGroups.map(contactOrGroup => (
<MemoConversationListItemWithDetails
@ -59,18 +59,18 @@ export const SearchResults = (props: SearchResultsProps) => {
key={`search-result-convo-${contactOrGroup.id}`}
/>
))}
</div>
</>
) : null}
{haveMessages && (
<div>
<>
<StyledSeparatorSection>
{`${window.i18n('messagesHeader')}: ${messages.length}`}
</StyledSeparatorSection>
{messages.map(message => (
<MessageSearchResult key={`search-result-message-${message.id}`} {...message} />
))}
</div>
</>
)}
</SearchResultsContainer>
);

@ -1094,29 +1094,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const groupAdmins = this.getGroupAdmins();
return Array.isArray(groupAdmins) && groupAdmins.includes(pubKey);
}
// SIGNAL PROFILES
public async getProfiles() {
// request all conversation members' keys
let ids = [];
if (this.isPrivate()) {
ids = [this.id];
} else {
ids = this.get('members');
}
return Promise.all(_.map(ids, this.getProfile));
}
// This function is wrongly named by signal
// This is basically an `update` function and thus we have overwritten it with such
public async getProfile(id: string) {
const c = await getConversationController().getOrCreateAndWait(
id,
ConversationTypeEnum.PRIVATE
);
// We only need to update the profile as they are all stored inside the conversation
await c.updateProfileName();
}
public async setProfileName(name: string) {
const profileName = this.get('profileName');
if (profileName !== name) {

@ -285,7 +285,7 @@ export async function handleNewClosedGroup(
await ClosedGroup.addUpdateMessage(
convo,
{ newName: name, joiningMembers: members },
'incoming',
envelope.senderIdentity || envelope.source, // new group message are coming as session messages
envelopeTimestamp
);
@ -560,7 +560,7 @@ async function handleClosedGroupNameChanged(
await ClosedGroup.addUpdateMessage(
convo,
groupDiff,
'incoming',
envelope.senderIdentity,
_.toNumber(envelope.timestamp)
);
convo.set({ name: newName });
@ -613,7 +613,12 @@ async function handleClosedGroupMembersAdded(
const groupDiff: ClosedGroup.GroupDiff = {
joiningMembers: membersNotAlreadyPresent,
};
await ClosedGroup.addUpdateMessage(convo, groupDiff, 'incoming', _.toNumber(envelope.timestamp));
await ClosedGroup.addUpdateMessage(
convo,
groupDiff,
envelope.senderIdentity,
_.toNumber(envelope.timestamp)
);
convo.set({ members });
@ -686,7 +691,7 @@ async function handleClosedGroupMembersRemoved(
await ClosedGroup.addUpdateMessage(
convo,
groupDiff,
'incoming',
envelope.senderIdentity,
_.toNumber(envelope.timestamp)
);
convo.updateLastMessage();
@ -763,7 +768,12 @@ async function handleClosedGroupAdminMemberLeft(
};
convo.set('members', []);
await ClosedGroup.addUpdateMessage(convo, groupDiff, 'incoming', _.toNumber(envelope.timestamp));
await ClosedGroup.addUpdateMessage(
convo,
groupDiff,
envelope.senderIdentity,
_.toNumber(envelope.timestamp)
);
convo.updateLastMessage();
await convo.commit();
@ -779,7 +789,12 @@ async function handleClosedGroupLeftOurself(
const groupDiff: ClosedGroup.GroupDiff = {
leavingMembers: [envelope.senderIdentity],
};
await ClosedGroup.addUpdateMessage(convo, groupDiff, 'incoming', _.toNumber(envelope.timestamp));
await ClosedGroup.addUpdateMessage(
convo,
groupDiff,
envelope.senderIdentity,
_.toNumber(envelope.timestamp)
);
convo.updateLastMessage();
// remove ourself from the list of members
convo.set(
@ -828,7 +843,12 @@ async function handleClosedGroupMemberLeft(envelope: EnvelopePlus, convo: Conver
leavingMembers: [sender],
};
await ClosedGroup.addUpdateMessage(convo, groupDiff, 'incoming', _.toNumber(envelope.timestamp));
await ClosedGroup.addUpdateMessage(
convo,
groupDiff,
envelope.senderIdentity,
_.toNumber(envelope.timestamp)
);
convo.updateLastMessage();
// if a user just left and we are the admin, we remove him right away for everyone by sending a MEMBERS_REMOVED message so no need to add him as a zombie
if (oldMembers.includes(sender)) {
@ -918,7 +938,12 @@ export async function createClosedGroup(groupName: string, members: Array<string
joiningMembers: listOfMembers,
};
const dbMessage = await ClosedGroup.addUpdateMessage(convo, groupDiff, 'outgoing', Date.now());
const dbMessage = await ClosedGroup.addUpdateMessage(
convo,
groupDiff,
UserUtils.getOurPubKeyStrFromCache(),
Date.now()
);
// be sure to call this before sending the message.
// the sending pipeline needs to know from GroupUtils when a message is for a medium group

@ -15,7 +15,6 @@ import { UserUtils } from '../utils';
import { ClosedGroupMemberLeftMessage } from '../messages/outgoing/controlMessage/group/ClosedGroupMemberLeftMessage';
import { ConversationModel, ConversationTypeEnum } from '../../models/conversation';
import { MessageModel } from '../../models/message';
import { MessageModelType } from '../../models/messageType';
import {
addKeyPairToCacheAndDBIfNeeded,
distributingClosedGroupEncryptionKeyPairs,
@ -107,20 +106,35 @@ export async function initiateClosedGroupUpdate(
if (diff.newName?.length) {
const nameOnlyDiff: GroupDiff = _.pick(diff, 'newName');
const dbMessageName = await addUpdateMessage(convo, nameOnlyDiff, 'outgoing', Date.now());
const dbMessageName = await addUpdateMessage(
convo,
nameOnlyDiff,
UserUtils.getOurPubKeyStrFromCache(),
Date.now()
);
await sendNewName(convo, diff.newName, dbMessageName.id as string);
}
if (diff.joiningMembers?.length) {
const joiningOnlyDiff: GroupDiff = _.pick(diff, 'joiningMembers');
const dbMessageAdded = await addUpdateMessage(convo, joiningOnlyDiff, 'outgoing', Date.now());
const dbMessageAdded = await addUpdateMessage(
convo,
joiningOnlyDiff,
UserUtils.getOurPubKeyStrFromCache(),
Date.now()
);
await sendAddedMembers(convo, diff.joiningMembers, dbMessageAdded.id as string, updateObj);
}
if (diff.leavingMembers?.length) {
const leavingOnlyDiff: GroupDiff = { kickedMembers: diff.leavingMembers };
const dbMessageLeaving = await addUpdateMessage(convo, leavingOnlyDiff, 'outgoing', Date.now());
const dbMessageLeaving = await addUpdateMessage(
convo,
leavingOnlyDiff,
UserUtils.getOurPubKeyStrFromCache(),
Date.now()
);
const stillMembers = members;
await sendRemovedMembers(
convo,
@ -135,7 +149,7 @@ export async function initiateClosedGroupUpdate(
export async function addUpdateMessage(
convo: ConversationModel,
diff: GroupDiff,
type: MessageModelType,
sender: string,
sentAt: number
): Promise<MessageModel> {
const groupUpdate: any = {};
@ -156,25 +170,28 @@ export async function addUpdateMessage(
groupUpdate.kicked = diff.kickedMembers;
}
const unread = type === 'incoming';
const message = await convo.addSingleOutgoingMessage({
if (UserUtils.isUsFromCache(sender)) {
const outgoingMessage = await convo.addSingleOutgoingMessage({
sent_at: sentAt,
group_update: groupUpdate,
unread: 1,
expireTimer: 0,
});
return outgoingMessage;
}
const incomingMessage = await convo.addSingleIncomingMessage({
sent_at: sentAt,
group_update: groupUpdate,
unread: unread ? 1 : 0,
expireTimer: 0,
source: sender,
});
if (unread) {
// update the unreadCount for this convo
const unreadCount = await convo.getUnreadCount();
convo.set({
unreadCount,
});
await convo.commit();
}
return message;
// update the unreadCount for this convo
const unreadCount = await convo.getUnreadCount();
convo.set({
unreadCount,
});
await convo.commit();
return incomingMessage;
}
function buildGroupDiff(convo: ConversationModel, update: GroupInfo): GroupDiff {

Loading…
Cancel
Save