|
|
@ -22,7 +22,6 @@ import {
|
|
|
|
MessageAttributes,
|
|
|
|
MessageAttributes,
|
|
|
|
MessageAttributesOptionals,
|
|
|
|
MessageAttributesOptionals,
|
|
|
|
MessageGroupUpdate,
|
|
|
|
MessageGroupUpdate,
|
|
|
|
MessageModelType,
|
|
|
|
|
|
|
|
fillMessageAttributesWithDefaults,
|
|
|
|
fillMessageAttributesWithDefaults,
|
|
|
|
type DataExtractionNotificationMsg,
|
|
|
|
type DataExtractionNotificationMsg,
|
|
|
|
} from './messageType';
|
|
|
|
} from './messageType';
|
|
|
@ -55,7 +54,6 @@ import {
|
|
|
|
MessageModelPropsWithoutConvoProps,
|
|
|
|
MessageModelPropsWithoutConvoProps,
|
|
|
|
PropsForAttachment,
|
|
|
|
PropsForAttachment,
|
|
|
|
PropsForExpirationTimer,
|
|
|
|
PropsForExpirationTimer,
|
|
|
|
PropsForExpiringMessage,
|
|
|
|
|
|
|
|
PropsForGroupInvitation,
|
|
|
|
PropsForGroupInvitation,
|
|
|
|
PropsForGroupUpdate,
|
|
|
|
PropsForGroupUpdate,
|
|
|
|
PropsForGroupUpdateAdd,
|
|
|
|
PropsForGroupUpdateAdd,
|
|
|
@ -196,7 +194,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public isIncoming() {
|
|
|
|
public isIncoming() {
|
|
|
|
return this.get('type') === 'incoming';
|
|
|
|
return this.get('type') === 'incoming' || this.get('direction') === 'incoming';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public isUnread() {
|
|
|
|
public isUnread() {
|
|
|
@ -429,34 +427,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private getPropsForExpiringMessage(): PropsForExpiringMessage {
|
|
|
|
|
|
|
|
const expirationType = this.getExpirationType();
|
|
|
|
|
|
|
|
const expirationDurationMs = this.getExpireTimerSeconds()
|
|
|
|
|
|
|
|
? this.getExpireTimerSeconds() * DURATION.SECONDS
|
|
|
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expireTimerStart = this.getExpirationStartTimestamp() || null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expirationTimestamp =
|
|
|
|
|
|
|
|
expirationType && expireTimerStart && expirationDurationMs
|
|
|
|
|
|
|
|
? expireTimerStart + expirationDurationMs
|
|
|
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const direction =
|
|
|
|
|
|
|
|
this.get('direction') === 'outgoing' || this.get('type') === 'outgoing'
|
|
|
|
|
|
|
|
? 'outgoing'
|
|
|
|
|
|
|
|
: 'incoming';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
convoId: this.get('conversationId'),
|
|
|
|
|
|
|
|
messageId: this.get('id'),
|
|
|
|
|
|
|
|
direction,
|
|
|
|
|
|
|
|
expirationDurationMs,
|
|
|
|
|
|
|
|
expirationTimestamp,
|
|
|
|
|
|
|
|
isExpired: this.isExpired(),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private getPropsForTimerNotification(): PropsForExpirationTimer | null {
|
|
|
|
private getPropsForTimerNotification(): PropsForExpirationTimer | null {
|
|
|
|
if (!this.isExpirationTimerUpdate()) {
|
|
|
|
if (!this.isExpirationTimerUpdate()) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -513,19 +483,13 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const sharedProps = {
|
|
|
|
|
|
|
|
isUnread: this.isUnread(),
|
|
|
|
|
|
|
|
receivedAt: this.get('received_at'),
|
|
|
|
|
|
|
|
...this.getPropsForExpiringMessage(),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (groupUpdate.joined?.length) {
|
|
|
|
if (groupUpdate.joined?.length) {
|
|
|
|
const change: PropsForGroupUpdateAdd = {
|
|
|
|
const change: PropsForGroupUpdateAdd = {
|
|
|
|
type: 'add',
|
|
|
|
type: 'add',
|
|
|
|
added: groupUpdate.joined as Array<PubkeyType>,
|
|
|
|
added: groupUpdate.joined as Array<PubkeyType>,
|
|
|
|
withHistory: false,
|
|
|
|
withHistory: false,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return { change, ...sharedProps };
|
|
|
|
return { change };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (groupUpdate.joinedWithHistory?.length) {
|
|
|
|
if (groupUpdate.joinedWithHistory?.length) {
|
|
|
|
const change: PropsForGroupUpdateAdd = {
|
|
|
|
const change: PropsForGroupUpdateAdd = {
|
|
|
@ -533,7 +497,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|
|
|
added: groupUpdate.joinedWithHistory as Array<PubkeyType>,
|
|
|
|
added: groupUpdate.joinedWithHistory as Array<PubkeyType>,
|
|
|
|
withHistory: true,
|
|
|
|
withHistory: true,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return { change, ...sharedProps };
|
|
|
|
return { change };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (groupUpdate.kicked?.length) {
|
|
|
|
if (groupUpdate.kicked?.length) {
|
|
|
@ -541,7 +505,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|
|
|
type: 'kicked',
|
|
|
|
type: 'kicked',
|
|
|
|
kicked: groupUpdate.kicked as Array<PubkeyType>,
|
|
|
|
kicked: groupUpdate.kicked as Array<PubkeyType>,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return { change, ...sharedProps };
|
|
|
|
return { change };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (groupUpdate.left?.length) {
|
|
|
|
if (groupUpdate.left?.length) {
|
|
|
@ -549,7 +513,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|
|
|
type: 'left',
|
|
|
|
type: 'left',
|
|
|
|
left: groupUpdate.left as Array<PubkeyType>,
|
|
|
|
left: groupUpdate.left as Array<PubkeyType>,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return { change, ...sharedProps };
|
|
|
|
return { change };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (groupUpdate.promoted?.length) {
|
|
|
|
if (groupUpdate.promoted?.length) {
|
|
|
@ -557,20 +521,20 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|
|
|
type: 'promoted',
|
|
|
|
type: 'promoted',
|
|
|
|
promoted: groupUpdate.promoted as Array<PubkeyType>,
|
|
|
|
promoted: groupUpdate.promoted as Array<PubkeyType>,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return { change, ...sharedProps };
|
|
|
|
return { change };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (groupUpdate.name) {
|
|
|
|
if (groupUpdate.name) {
|
|
|
|
const change: PropsForGroupUpdateName = {
|
|
|
|
const change: PropsForGroupUpdateName = {
|
|
|
|
type: 'name',
|
|
|
|
type: 'name',
|
|
|
|
newName: groupUpdate.name,
|
|
|
|
newName: groupUpdate.name,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return { change, ...sharedProps };
|
|
|
|
return { change };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (groupUpdate.avatarChange) {
|
|
|
|
if (groupUpdate.avatarChange) {
|
|
|
|
const change: PropsForGroupUpdateAvatarChange = {
|
|
|
|
const change: PropsForGroupUpdateAvatarChange = {
|
|
|
|
type: 'avatarChange',
|
|
|
|
type: 'avatarChange',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return { change, ...sharedProps };
|
|
|
|
return { change };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -624,8 +588,12 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|
|
|
public getPropsForMessage(): PropsForMessageWithoutConvoProps {
|
|
|
|
public getPropsForMessage(): PropsForMessageWithoutConvoProps {
|
|
|
|
const sender = this.getSource();
|
|
|
|
const sender = this.getSource();
|
|
|
|
const expirationType = this.getExpirationType();
|
|
|
|
const expirationType = this.getExpirationType();
|
|
|
|
const expirationDurationMs = this.getExpireTimerSeconds() * DURATION.SECONDS;
|
|
|
|
const expirationDurationMs = this.getExpireTimerSeconds()
|
|
|
|
const expireTimerStart = this.getExpirationStartTimestamp();
|
|
|
|
? this.getExpireTimerSeconds() * DURATION.SECONDS
|
|
|
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expireTimerStart = this.getExpirationStartTimestamp() || null;
|
|
|
|
|
|
|
|
|
|
|
|
const expirationTimestamp =
|
|
|
|
const expirationTimestamp =
|
|
|
|
expirationType && expireTimerStart && expirationDurationMs
|
|
|
|
expirationType && expireTimerStart && expirationDurationMs
|
|
|
|
? expireTimerStart + expirationDurationMs
|
|
|
|
? expireTimerStart + expirationDurationMs
|
|
|
@ -636,7 +604,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|
|
|
const body = this.get('body');
|
|
|
|
const body = this.get('body');
|
|
|
|
const props: PropsForMessageWithoutConvoProps = {
|
|
|
|
const props: PropsForMessageWithoutConvoProps = {
|
|
|
|
id: this.id,
|
|
|
|
id: this.id,
|
|
|
|
direction: (this.isIncoming() ? 'incoming' : 'outgoing') as MessageModelType,
|
|
|
|
direction: this.isIncoming() ? 'incoming' : 'outgoing',
|
|
|
|
timestamp: this.get('sent_at') || 0,
|
|
|
|
timestamp: this.get('sent_at') || 0,
|
|
|
|
sender,
|
|
|
|
sender,
|
|
|
|
convoId: this.get('conversationId'),
|
|
|
|
convoId: this.get('conversationId'),
|
|
|
|