Skip to content

Commit

Permalink
Summarization of messages for newsfeed (RocketChat#70)
Browse files Browse the repository at this point in the history
* Initial commit for newsfeed

* Create server setting for Newsfeed

* Solve linting

* Callback for initializing and deinitializing newsfeed

* Solve liniting

* Access all users in initialize function

* Check if newsfeed for a user already exists

* Partial progress upload
Declaring Newsfeed URL
Declaring Newsfeed as new roomType
Displaying the correct Newsfeed for the owner

* Add deinitialize newsfeed function

* set newsfeed_enabled default as false

* Delete createNewsfeed.js

* Delete createNewsfeed.graphqls

* Delete newsfeed.graphql

* Delete no-use file created by me

* Display newsfeed channel name as Newsfeed in UI

* Create Newsfeed when a new user registers on the server

* Newsfeed creation using username instead of name

* Few Improvement:
-Change newsfeed icon to star
-change channel type to n in canSendMessage function

* Initial commit for follow user and follow button

* Initialize follow user method

* Follow Meteor method initialized

* Follwers and following update in database and creation of toastr

* solve linting

* Change follow button to unfollow if already followed

* Create unfollow user method

* Update followUser method to store followers as object with _id as the key

* Update hasAlreadyFollowed method in respond to change in storage scheme

* Update unfollowUser to new scheme

* Add to deInitialize newsfeed to remove following and followers from database

* based newsfeed type room on private group

* Mid progress for displaying messages in newsfeed

* Publish followers and following from server to client

* Relaying of first messge successful

* Relay of first message

* Solve linting

* partial improvements

* Revert "Solve linting"

This reverts commit 14d4a73.

* Revert "partial improvements"

This reverts commit 1bcc673.

* Solve linting

* Partial progress with bug and without lint

* Relay with identified bug

* getLastMessage method added

* Add getFollowers and getFollowing method

* Display of original channel name in newsfeed

* Revert "Display of original channel name in newsfeed"

This reverts commit b94ae9c.

* Add posted_in in front of sender in newsfeed

* Change isSequential for newsfeed

* Update followUser method to new schema

* Update hasAlreadyFollowed for new schema

* Update unfollowUser method to new schema

* Update getFollowers to new schema

* Update getFollowing and getFollowers

* removed test code

* Mid progress to new schema

* remove default user fields in accordance with new schema

* Migrate ChatMessage UI to new schema

* Only rooms which can be viewed by user can show messages in newsfeed

* Partial progress

* Crude time and channel based summarization system for newsfeed

* Eslint fix

* seperation of summarization

* Referesh in follow/unfollow button state

* summarization on client for newsfeed
  • Loading branch information
fliptrail authored and Kailash0311 committed Aug 19, 2019
1 parent 363428d commit 769cfd3
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/lib/server/functions/loadNewsfeedHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ export const loadNewsfeedHistory = function loadNewsfeedHistory({ userId, end, l
},
});

firstUnread = unreadMessages.fetch()[0];
unreadNotLoaded = unreadMessages.count();
if (Object.keys(unreadMessages).length === 0 && unreadMessages.constructor === Object) {
firstUnread = {};
unreadNotLoaded = 0;
} else {
firstUnread = unreadMessages.fetch()[0];
unreadNotLoaded = unreadMessages.count();
}

}
}

Expand Down
69 changes: 69 additions & 0 deletions app/models/server/models/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,21 @@ export class Messages extends Base {
{ $or: listOfAccessibleRoomsObject },
],
};


if (Match.test(types, [String]) && (types.length > 0)) {
query.t = { $nin: types };
}
const msgIndex = this.summarization(query);
query = {
$or: msgIndex,

};

if (Match.test(types, [String]) && (types.length > 0)) {
query.t = { $nin: types };
}

return this.find(query, options);
}

Expand Down Expand Up @@ -445,6 +457,19 @@ export class Messages extends Base {
query.t = { $nin: types };
}

const msgIndex = this.summarization(query);

query = {
$or: msgIndex,

};


if (Match.test(types, [String]) && (types.length > 0)) {
query.t = { $nin: types };
}


return this.find(query, options);
}

Expand Down Expand Up @@ -495,6 +520,11 @@ export class Messages extends Base {

const listOfAccessibleRoomsObject = listOfAccessibleRooms.map((rid) => ({ rid }));


if (!following || !following.length || !listOfAccessibleRoomsObject || !listOfAccessibleRoomsObject.length) {
return {};
}

query = {
_hidden: {
$ne: true,
Expand All @@ -511,9 +541,48 @@ export class Messages extends Base {
if (Match.test(types, [String]) && (types.length > 0)) {
query.t = { $nin: types };
}

const msgIndex = this.summarization(query);

if (!msgIndex || !msgIndex.length) {
return {};
}

query = {
$or: msgIndex,

};
if (Match.test(types, [String]) && (types.length > 0)) {
query.t = { $nin: types };
}
return this.find(query, options);
}

summarization(query) {
const msg = this.find(query, { sort: { rid: 1, 'u._id': 1, ts: -1 }, fields: { _id: 1, 'u._id': 1, ts: 1, rid: 1 } }).fetch();
const msgIndex = [];
for (let i = 0; i < msg.length - 1; i++) {
if (msg[i].rid === msg[i + 1].rid) {
if (msg[i]['u._id'] === msg[i + 1]['u._id']) {
if ((msg[i].ts - msg[i + 1].ts) > 20e3) {
const temp = new Object();
temp._id = msg[i]._id;
msgIndex.push(temp);
}
} else {
const temp = new Object();
temp._id = msg[i]._id;
msgIndex.push(temp);
}
} else {
const temp = new Object();
temp._id = msg[i]._id;
msgIndex.push(temp);
}
}
return msgIndex;
}

findVisibleCreatedOrEditedAfterTimestamp(timestamp, options) {
const query = {
_hidden: { $ne: true },
Expand Down
38 changes: 38 additions & 0 deletions app/ui-flextab/client/tabs/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,44 @@ export const getActions = ({ user, directActions, hideAdminControls }) => {
};
},

function() {
if (isSelf(this.username) || !directActions) {
return;
}
hasAlreadyFollowed(this.username);

if (Session.get('hasFollowed')) {
return {
icon: 'plus',
name: t('Unfollow'),
action: prevent(getUser, ({ username }) =>
Meteor.call('unfollowUser', username, success(() => {
toastr.success(TAPi18n.__('You_have_unfollowed__username_', { username }));
Session.set('hasFollowed', false);
}))
),
condition() {
return settings.get('Newsfeed_enabled');
},
};
}


return {
icon: 'plus',
name: t('Follow'),
action: prevent(getUser, ({ username }) =>
Meteor.call('followUser', username, success(() => {
toastr.success(TAPi18n.__('You_have_followed__username_', { username }));
Session.set('hasFollowed', true);
}))
),
condition() {
return settings.get('Newsfeed_enabled');
},
};
},

function() {
if (isSelf(this.username) || !directActions) {
return;
Expand Down
2 changes: 2 additions & 0 deletions app/ui-message/client/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
<span class = "user color-secondary-font-color">{{_ "posted_in"}}</span>
<span class = "user color-secondary-font-color">{{originalRoomNameForNewsfeed}}</span>
{{/if}}

<span class="info border-component-color color-info-font-color"></span>

{{#each role in roleTags}}
<span class="role-tag color-secondary-color border-component-color" data-role="{{role.description}}">{{role.description}}</span>
{{/each}}
Expand Down
32 changes: 31 additions & 1 deletion app/ui/client/views/app/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,41 @@ Template.room.helpers({
},
};
if (Template.instance().room.t === 'n') {
const query = {

let query = {

$or: Template.instance().followingUsers.get(),
_hidden: { $ne: true },
...(ignoreReplies || modes[viewMode] === 'compact') && { tmid: { $exists: 0 } },
};

const msg = ChatMessage.find(query, { sort: { rid: 1, 'u._id': 1, ts: -1 }, fields: { _id: 1, 'u._id': 1, ts: 1, rid: 1 } }).fetch();
const msgIndex = [];
for (let i = 0; i < msg.length - 1; i++) {
if (msg[i].rid === msg[i + 1].rid) {
if (msg[i]['u._id'] === msg[i + 1]['u._id']) {
if ((msg[i].ts - msg[i + 1].ts) > 20e3) {
const temp = new Object();
temp._id = msg[i]._id;
msgIndex.push(temp);
}
} else {
const temp = new Object();
temp._id = msg[i]._id;
msgIndex.push(temp);
}
} else {
const temp = new Object();
temp._id = msg[i]._id;
msgIndex.push(temp);
}
}
query = {
$or: msgIndex,
_hidden: { $ne: true },
...(ignoreReplies || modes[viewMode] === 'compact') && { tmid: { $exists: 0 } },
};

return ChatMessage.find(query, options);
}
return ChatMessage.find(query, options);
Expand Down

0 comments on commit 769cfd3

Please sign in to comment.