-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES6: migrated "entity" (part 2) #1195
Conversation
app/script/entity/Conversation.js
Outdated
window.z = window.z || {}; | ||
window.z.entity = z.entity || {}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One too many
app/script/entity/Conversation.js
Outdated
this.name = ko.observable(); | ||
this.input = ko.observable(z.util.StorageUtil.get_value(`${z.storage.StorageKey.CONVERSATION.INPUT}|${this.id}`) || ''); | ||
this.input.subscribe((text) => { | ||
return z.util.StorageUtil.set_value(`${z.storage.StorageKey.CONVERSATION.INPUT}|${this.id}`, text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can keep simply things like this in a single line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/script/entity/Conversation.js
Outdated
this.participating_user_ids = ko.observableArray([]); | ||
this.self = undefined; | ||
this.number_of_participants = ko.pureComputed(() => { | ||
return this.participating_user_ids().length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
app/script/entity/Conversation.js
Outdated
return this.participating_user_ets()[0].name(); | ||
} | ||
return '…'; | ||
} else if (this.is_group()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for else. You always return in the above if
app/script/entity/Conversation.js
Outdated
add_message(message_et) { | ||
amplify.publish(z.event.WebApp.CONVERSATION.MESSAGE.ADDED, message_et); | ||
this._update_last_read_from_message(message_et); | ||
return this.messages_unordered.push(this._check_for_duplicate_nonce(message_et, this.get_last_message())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't return if you return undefined
app/script/entity/Conversation.js
Outdated
} | ||
} | ||
|
||
return z.util.ko_array_push_all(this.messages_unordered, message_ets); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to return this?
app/script/entity/Conversation.js
Outdated
message_et = this._check_for_duplicate_nonce(message_ets[index - 1], message_et); | ||
} | ||
|
||
return z.util.ko_array_unshift_all(this.messages_unordered, message_ets); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return?
app/script/entity/Conversation.js
Outdated
* @returns {undefined} No return value | ||
*/ | ||
remove_message(message_et) { | ||
return this.messages_unordered.remove(message_et); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure we want to return this?
app/script/entity/Conversation.js
Outdated
* @returns {undefined} No return value | ||
*/ | ||
remove_messages() { | ||
return this.messages_unordered.removeAll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
* @note If a message is send to the backend multiple times by a client they will be in the conversation multiple times | ||
* @param {z.entity.Message} message_et - Message entity to be added to the conversation | ||
* @param {z.entity.Message} other_message_et - Other message entity to compare with | ||
* @returns {undefined} No return value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You return a message entity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not anymore 🗡
* Creates the placeholder message after clearing a conversation. | ||
* @private | ||
* @note Only create the message if the group participants have been set | ||
* @returns {undefined} No return value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You return a message entity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not anymore 🗡
app/script/entity/Conversation.js
Outdated
*/ | ||
update_latest_from_message(message_et) { | ||
if ((message_et != null) && message_et.visible() && message_et.should_effect_conversation_timestamp) { | ||
return this.set_timestamp(message_et.timestamp(), z.conversation.ConversationUpdateType.LAST_EVENT_TIMESTAMP); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return?
app/script/entity/Conversation.js
Outdated
const has_timestamp = message_et.timestamp(); | ||
|
||
if (is_me && has_timestamp && message_et.should_effect_conversation_timestamp) { | ||
return this.set_timestamp(message_et.timestamp(), z.conversation.ConversationUpdateType.LAST_READ_TIMESTAMP); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return?
app/script/entity/Conversation.js
Outdated
return [this.self] | ||
.concat(this.participating_user_ets()) | ||
.filter((user_et) => !user_et.is_verified()) | ||
.map((user_et) => user_et); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check JSDoc returns and your actual returns
app/script/entity/Conversation.js
Outdated
// Conversation states for view | ||
this.is_muted = ko.pureComputed(() => { | ||
return this.muted_state(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest
this.is_muted = ko.pureComputed(() => this.muted_state());
everywhere where functions consist only of one return
line.
@gregor & @ffflorian: I fixed all of your requests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more one-liner functions missing which can/should be shortened.
Just replace \) => \{\n +return (.*);\n +\}\);
with \) => $1\);
🙂
app/script/entity/Conversation.js
Outdated
this.verification_state, | ||
].forEach((property) => { | ||
return property.subscribe(this.persist_state); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
].forEach((property) => property.subscribe(this.persist_state));
app/script/entity/User.js
Outdated
this.name = ko.observable(''); | ||
this.first_name = ko.pureComputed(() => { | ||
return this.name().split(' ')[0]; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.first_name = ko.pureComputed(() => this.name().split(' ')[0]);
Type of change
Screenshot