address PR reviews

pull/1178/head
Audric Ackermann 5 years ago
parent 4d2b08f4a2
commit 28fb1dd12a
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -834,109 +834,6 @@ async function updateToLokiSchemaVersion1(currentVersion, instance) {
);`
);
const initConversation = async data => {
// eslint-disable-next-line camelcase
const { id, active_at, type, name } = data;
await instance.run(
`INSERT INTO conversations (
id,
json,
active_at,
type,
members,
name
) values (
$id,
$json,
$active_at,
$type,
$members,
$name,
);`,
{
$id: id,
$json: objectToJSON(data),
$active_at: active_at,
$type: type,
$members: null,
$name: name,
}
);
};
const lokiPublicServerData = {
// make sure we don't have a trailing slash just in case
serverUrl: config.get('defaultPublicChatServer').replace(/\/*$/, ''),
token: null,
};
console.log('lokiPublicServerData', lokiPublicServerData);
const baseData = {
active_at: Date.now(),
sealedSender: 0,
sessionResetStatus: 0,
swarmNodes: [],
type: 'group',
unlockTimestamp: null,
unreadCount: 0,
verified: 0,
version: 2,
};
const publicChatData = {
...baseData,
id: `publicChat:1@${lokiPublicServerData.serverUrl.replace(
/^https?:\/\//i,
''
)}`,
server: lokiPublicServerData.serverUrl,
name: 'Loki Public Chat',
channelId: '1',
};
const { serverUrl, token } = lokiPublicServerData;
await instance.run(
`INSERT INTO servers (
serverUrl,
token
) values (
$serverUrl,
$token
);`,
{
$serverUrl: serverUrl,
$token: token,
}
);
const newsRssFeedData = {
...baseData,
id: 'rss://loki.network/feed/',
rssFeed: 'https://loki.network/feed/',
closable: true,
name: 'Loki News',
profileAvatar: 'images/session/session_chat_icon.png',
};
const updatesRssFeedData = {
...baseData,
id: 'rss://loki.network/category/messenger-updates/feed/',
rssFeed: 'https://loki.network/category/messenger-updates/feed/',
closable: false,
name: 'Session Updates',
profileAvatar: 'images/session/session_chat_icon.png',
};
const autoJoinLokiChats = false;
if (autoJoinLokiChats) {
await initConversation(publicChatData);
}
await initConversation(newsRssFeedData);
await initConversation(updatesRssFeedData);
await instance.run(
`INSERT INTO loki_schema (
version
@ -2483,7 +2380,7 @@ async function getMessageBySender({ source, sourceDevice, sent_at }) {
async function getAllUnsentMessages() {
const rows = await db.all(`
SELECT json FROM messages WHERE
type IN ('outgoing', 'session-request') AND
type IN ('outgoing') AND
NOT sent
ORDER BY sent_at DESC;
`);

@ -507,7 +507,7 @@
<script type='text/javascript' src='js/views/create_group_dialog_view.js'></script>
<script type='text/javascript' src='js/views/confirm_session_reset_view.js'></script>
<script type='text/javascript' src='js/views/edit_profile_dialog_view.js'></script>
<script type='text/javascript' src='js/views/invite_friends_dialog_view.js'></script>
<script type='text/javascript' src='js/views/invite_contacts_dialog_view.js'></script>
<script type='text/javascript' src='js/views/moderators_add_dialog_view.js'></script>
<script type='text/javascript' src='js/views/moderators_remove_dialog_view.js'></script>
<script type='text/javascript' src='js/views/user_details_dialog_view.js'></script>

@ -507,7 +507,7 @@
<script type='text/javascript' src='js/views/create_group_dialog_view.js'></script>
<script type='text/javascript' src='js/views/confirm_session_reset_view.js'></script>
<script type='text/javascript' src='js/views/edit_profile_dialog_view.js'></script>
<script type='text/javascript' src='js/views/invite_friends_dialog_view.js'></script>
<script type='text/javascript' src='js/views/invite_contacts_dialog_view.js'></script>
<script type='text/javascript' src='js/views/moderators_add_dialog_view.js'></script>
<script type='text/javascript' src='js/views/moderators_remove_dialog_view.js'></script>
<script type='text/javascript' src='js/views/user_details_dialog_view.js'></script>

@ -504,9 +504,6 @@
window.Signal.Data.getOutgoingWithoutExpiresAt({
MessageCollection: Whisper.MessageCollection,
}),
window.Signal.Data.getAllUnsentMessages({
MessageCollection: Whisper.MessageCollection,
}),
]);
// Combine the models
@ -526,11 +523,6 @@
'expirationStartTimestamp'
);
// Make sure we only target outgoing messages
if (message.isEndSession() && message.get('direction') === 'incoming') {
return;
}
if (message.isEndSession()) {
return;
}
@ -1160,12 +1152,6 @@
});
};
Whisper.events.on('createNewGroup', async () => {
if (appView) {
appView.showCreateGroup();
}
});
Whisper.events.on('updateGroupName', async groupConvo => {
if (appView) {
appView.showUpdateGroupNameDialog(groupConvo);

@ -2014,7 +2014,7 @@
const hasSession = await libsession.Protocols.SessionProtocol.hasSession(
devicePubkey
);
if (hasSession) {
if (!hasSession) {
return;
}

@ -277,9 +277,6 @@
isKeyChange() {
return this.get('type') === 'keychange';
},
isSessionRequest() {
return this.get('type') === 'session-request';
},
isGroupInvitation() {
return !!this.get('groupInvitation');
},
@ -523,10 +520,8 @@
return 'error';
}
const isOutgoing = this.isOutgoing();
// Only return the status on outgoing messages
if (!isOutgoing) {
if (!this.isOutgoing()) {
return null;
}

@ -95,8 +95,8 @@ const {
UpdateGroupMembersDialog,
} = require('../../ts/components/conversation/UpdateGroupMembersDialog');
const {
InviteFriendsDialog,
} = require('../../ts/components/conversation/InviteFriendsDialog');
InviteContactsDialog,
} = require('../../ts/components/conversation/InviteContactsDialog');
const {
AddModeratorsDialog,
@ -295,7 +295,7 @@ exports.setup = (options = {}) => {
ConfirmDialog,
UpdateGroupNameDialog,
UpdateGroupMembersDialog,
InviteFriendsDialog,
InviteContactsDialog,
AddModeratorsDialog,
RemoveModeratorsDialog,
GroupInvitation,

@ -93,9 +93,13 @@
let iconUrl;
// The number of notifications excluding session request
const messagesNotificationCount = this.models.filter(
n => !n.get('isSessionRequest')
).length;
// FIXME do we need to filter out session request?
// I don't think the filter below might work also add this.models
// is created by Whisper.Notifications.add which as not this field
const messagesNotificationCount = this.models.length;
// const messagesNotificationCount = this.models.filter(
// n => !n.get('isSessionRequest')
// ).length;
// NOTE: i18n has more complex rules for pluralization than just
// distinguishing between zero (0) and other (non-zero),

@ -221,13 +221,6 @@
const dialog = new Whisper.DevicePairingWordsDialogView();
this.el.prepend(dialog.el);
},
showCreateGroup() {
// TODO: make it impossible to open 2 dialogs as once
// Currently, if the button is in focus, it is possible to
// create a new dialog by pressing 'Enter'
const dialog = new Whisper.CreateGroupDialogView();
this.el.append(dialog.el);
},
showUpdateGroupNameDialog(groupConvo) {
const dialog = new Whisper.UpdateGroupNameDialogView(groupConvo);
this.el.append(dialog.el);
@ -236,7 +229,6 @@
const dialog = new Whisper.UpdateGroupMembersDialogView(groupConvo);
this.el.append(dialog.el);
},
showSessionRestoreConfirmation(options) {
const dialog = new Whisper.ConfirmSessionResetView(options);
this.el.append(dialog.el);

@ -6,108 +6,6 @@
window.Whisper = window.Whisper || {};
Whisper.CreateGroupDialogView = Whisper.View.extend({
className: 'loki-dialog modal',
initialize() {
this.titleText = i18n('createGroupDialogTitle');
this.okText = i18n('ok');
this.cancelText = i18n('cancel');
this.close = this.close.bind(this);
const convos = window.getConversations().models;
let allMembers = convos.filter(d => !!d && d.isPrivate() && !d.isMe());
allMembers = _.uniq(allMembers, true, d => d.id);
this.membersToShow = allMembers;
this.$el.focus();
this.render();
},
render() {
this.dialogView = new Whisper.ReactWrapperView({
className: 'create-group-dialog',
Component: window.Signal.Components.CreateGroupDialog,
props: {
titleText: this.titleText,
okText: this.okText,
cancelText: this.cancelText,
contactList: this.membersToShow,
onClose: this.close,
},
});
this.$el.append(this.dialogView.el);
return this;
},
close() {
this.remove();
},
});
Whisper.UpdateGroupNameDialogView = Whisper.View.extend({
className: 'loki-dialog modal',
initialize(groupConvo) {
this.groupName = groupConvo.get('name');
this.conversation = groupConvo;
this.titleText = i18n('updateGroupDialogTitle');
this.close = this.close.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.isPublic = groupConvo.isPublic();
this.groupId = groupConvo.id;
this.members = groupConvo.get('members') || [];
this.avatarPath = groupConvo.getAvatarPath();
const ourPK = textsecure.storage.user.getNumber();
this.isAdmin = groupConvo.get('groupAdmins').includes(ourPK);
// public chat settings overrides
if (this.isPublic) {
// fix the title
this.titleText = `${i18n('updatePublicGroupDialogTitle')}: ${
this.groupName
}`;
// I'd much prefer to integrate mods with groupAdmins
// but lets discuss first...
this.isAdmin = groupConvo.isModerator(
window.storage.get('primaryDevicePubKey')
);
}
this.$el.focus();
this.render();
},
render() {
this.dialogView = new Whisper.ReactWrapperView({
className: 'create-group-dialog',
Component: window.Signal.Components.UpdateGroupNameDialog,
props: {
titleText: this.titleText,
isPublic: this.isPublic,
groupName: this.groupName,
okText: i18n('ok'),
cancelText: i18n('cancel'),
isAdmin: this.isAdmin,
i18n,
onSubmit: this.onSubmit,
onClose: this.close,
avatarPath: this.avatarPath,
},
});
this.$el.append(this.dialogView.el);
return this;
},
onSubmit(groupName, avatar) {
window.doUpdateGroup(this.groupId, groupName, this.members, avatar);
},
close() {
this.remove();
},
});
Whisper.UpdateGroupMembersDialogView = Whisper.View.extend({
className: 'loki-dialog modal',
initialize(groupConvo) {

@ -14,7 +14,9 @@
const convos = window.getConversations().models;
this.contacts = convos.filter(d => !!d && d.isPrivate() && !d.isMe());
this.contacts = convos.filter(
d => !!d && !d.isBlocked() && d.isPrivate() && !d.isMe()
);
if (!convo.isPublic()) {
const members = convo.get('members') || [];
this.contacts = this.contacts.filter(d => !members.includes(d.id));
@ -32,7 +34,7 @@
render() {
const view = new Whisper.ReactWrapperView({
className: 'invite-friends-dialog',
Component: window.Signal.Components.InviteFriendsDialog,
Component: window.Signal.Components.InviteContactsDialog,
props: {
contactList: this.contacts,
onSubmit: this.submit,

@ -21,9 +21,14 @@
const modPubKeys = await this.channelAPI.getModerators();
const convos = window.getConversations().models;
// private friends (not you) that aren't already moderators
// private contacts (not you) that aren't already moderators
const contacts = convos.filter(
d => !!d && d.isPrivate() && !d.isMe() && !modPubKeys.includes(d.id)
d =>
!!d &&
d.isPrivate() &&
!d.isBlocked() &&
!d.isMe() &&
!modPubKeys.includes(d.id)
);
this.contacts = contacts;

@ -48,12 +48,6 @@
}
}
function logSessionRequest(...args) {
if (debugFlags & DebugFlagsEnum.SESSION_REQUEST_MESSAGES) {
debugLogFn(...args);
}
}
function logBackgroundMessage(...args) {
if (debugFlags & DebugFlagsEnum.SESSION_BACKGROUND_MESSAGE) {
debugLogFn(...args);
@ -290,7 +284,6 @@
const debug = {
logContactSync,
logGroupSync,
logSessionRequest,
logSessionMessageSending,
logBackgroundMessage,
logGroupRequestInfo,

@ -14,8 +14,6 @@ const NUM_SEND_CONNECTIONS = 3;
const getTTLForType = type => {
switch (type) {
case 'session-request':
return 4 * 24 * 60 * 60 * 1000; // 4 days for session request message
case 'device-unpairing':
return 4 * 24 * 60 * 60 * 1000; // 4 days for device unpairing
case 'onlineBroadcast':
@ -106,15 +104,9 @@ function getStaleDeviceIdsForNumber(number) {
}
const DebugMessageType = {
SESSION_REQUEST: 'session-request',
SESSION_REQUEST_ACCEPT: 'session-request-accepted',
SESSION_RESET: 'session-reset',
SESSION_RESET_RECV: 'session-reset-received',
OUTGOING_FR_ACCEPTED: 'outgoing-friend-request-accepted',
INCOMING_FR_ACCEPTED: 'incoming-friend-request-accept',
REQUEST_SYNC_SEND: 'request-sync-send',
CONTACT_SYNC_SEND: 'contact-sync-send',
CLOSED_GROUP_SYNC_SEND: 'closed-group-sync-send',
@ -355,8 +347,7 @@ OutgoingMessage.prototype = {
const keysFound = await this.getKeysForNumber(devicePubKey, updatedDevices);
// Check if we need to attach the preKeys
const enableFallBackEncryption =
!keysFound || this.messageType === 'session-request';
const enableFallBackEncryption = !keysFound;
const flags = this.message.dataMessage
? this.message.dataMessage.get_flags()
: null;
@ -414,7 +405,6 @@ OutgoingMessage.prototype = {
sourceDevice: 1,
plaintext,
pubKey: devicePubKey,
isFriendRequest: enableFallBackEncryption,
isSessionRequest,
enableFallBackEncryption,
};
@ -434,7 +424,6 @@ OutgoingMessage.prototype = {
plaintext,
pubKey,
isSessionRequest,
isFriendRequest,
enableFallBackEncryption,
} = clearMessage;
// Session doesn't use the deviceId scheme, it's always 1.
@ -480,7 +469,6 @@ OutgoingMessage.prototype = {
sourceDevice,
content,
pubKey,
isFriendRequest,
isSessionRequest,
};
},
@ -551,8 +539,6 @@ OutgoingMessage.prototype = {
ourKey: ourIdentity,
sourceDevice: 1,
content: contentOuter.encode().toArrayBuffer(),
isFriendRequest: false,
isSessionRequest: false,
};
// TODO: Rather than using sealed sender, we just generate a key pair, perform an ECDH against
@ -672,10 +658,7 @@ OutgoingMessage.buildSessionRequestMessage = function buildSessionRequestMessage
dataMessage,
});
const options = {
messageType: 'session-request',
debugMessageType: DebugMessageType.SESSION_REQUEST,
};
const options = {};
// Send a empty message with information about how to contact us directly
return new OutgoingMessage(
null, // server

@ -439,8 +439,7 @@ MessageSender.prototype = {
haveSession ||
keysFound ||
options.isPublic ||
options.isMediumGroup ||
options.messageType === 'session-request'
options.isMediumGroup
) {
const outgoing = new OutgoingMessage(
this.server,

@ -555,7 +555,7 @@
<script type="text/javascript" src="../js/views/create_group_dialog_view.js"></script>
<script type="text/javascript" src="../js/views/confirm_session_reset_view.js"></script>
<script type="text/javascript" src="../js/views/edit_profile_dialog_view.js"></script>
<script type="text/javascript" src="../js/views/invite_friends_dialog_view.js"></script>
<script type="text/javascript" src="../js/views/invite_contacts_dialog_view.js"></script>
<script type="text/javascript" src="../js/views/moderators_add_dialog_view.js"></script>
<script type="text/javascript" src="../js/views/moderators_remove_dialog_view.js"></script>
<script type="text/javascript" src="../js/views/user_details_dialog_view.js"></script>

@ -18,7 +18,7 @@ interface State {
contactList: Array<ContactType>;
}
export class InviteFriendsDialog extends React.Component<Props, State> {
export class InviteContactsDialog extends React.Component<Props, State> {
constructor(props: any) {
super(props);

@ -72,7 +72,8 @@ export class SessionClosableOverlay extends React.Component<Props, State> {
return (
!conversation.isMe() &&
conversation.isPrivate() &&
!conversation.isSecondaryDevice()
!conversation.isSecondaryDevice() &&
!conversation.isBlocked()
);
});

@ -437,7 +437,7 @@ async function handleRegularMessage(
handleMentions(message, conversation, ourNumber);
if (type === 'incoming' || message.isEndSession()) {
if (type === 'incoming') {
updateReadStatus(message, conversation);
}

@ -26,7 +26,6 @@ interface MessageCreationData {
receivedAt: number;
sourceDevice: number; // always 1 isn't it?
unidentifiedDeliveryReceived: any; // ???
isSessionRequest: boolean;
isRss: boolean;
source: boolean;
serverId: string;
@ -534,7 +533,6 @@ export async function handleDataMessage(
ev.confirm = () => removeFromCache(envelope);
ev.data = {
isSessionRequest: envelope.type === SESSION_REQUEST,
source,
sourceDevice: envelope.sourceDevice,
timestamp: toNumber(envelope.timestamp),
@ -593,8 +591,6 @@ export async function handleMessageEvent(event: any): Promise<void> {
const isDuplicate = await isMessageDuplicate(data);
const testNb: number = 3.1545;
if (isDuplicate) {
// RSS expects duplicates, so squelch log
if (!source.match(/^rss:/)) {
@ -604,11 +600,9 @@ export async function handleMessageEvent(event: any): Promise<void> {
return;
}
// Note(LOKI): don't send receipt for FR as we don't have a session yet
const shouldSendReceipt =
isIncoming &&
data.unidentifiedDeliveryReceived &&
!data.isSessionRequest &&
!isGroupMessage;
if (shouldSendReceipt) {

@ -174,8 +174,6 @@ export class SessionProtocol {
if (!SessionProtocol.dbLoaded) {
const sentItem = await getItemById('sentSessionsTimestamp');
if (sentItem) {
// FIXME we must update the existing map with those items
// or empty the existing map, not create a new one
SessionProtocol.sentSessionsTimestamp = sentItem.value;
} else {
SessionProtocol.sentSessionsTimestamp = {};

Loading…
Cancel
Save