Skip to content

Commit

Permalink
Merge pull request #20 from dragouf/bugfix_11
Browse files Browse the repository at this point in the history
bugfix #11
  • Loading branch information
dragouf authored Jun 15, 2016
2 parents 57f0cf5 + c3edfc2 commit ba27285
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 41 deletions.
42 changes: 22 additions & 20 deletions extension/chrome/src/js/injector_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,35 @@ function injectBitbucketDetector() {
// it's a bitbucket page
isBitbucket = true;
// inject main script
attachListener();
injectEngine();
}
});
}

injectBitbucketDetector();


// message sent from background.js
chrome.runtime.onMessage.addListener(function(message) {
// transfert it to injected page script
if (message && message.action === 'ActivitiesRetrieved') {
var data = { 'detail': {
identifier: 'ActivitiesRetrieved',
activities: message.activities,
desktopNotification: message.desktopNotification } };

// chrome
var event = new CustomEvent('ActivitiesRetrieved', data);
document.dispatchEvent(event);
// ff
window.postMessage(data, '*');
}
else if(message && message.action === 'ping') {
chrome.runtime.sendMessage({ action: 'pong', url: getSiteBaseURl() });
}
});
function attachListener() {
// message sent from background.js
chrome.runtime.onMessage.addListener(function(message) {
// transfert it to injected page script
if (message && message.action === 'ActivitiesRetrieved') {
var data = { 'detail': {
identifier: 'ActivitiesRetrieved',
activities: message.activities,
desktopNotification: message.desktopNotification } };

// chrome
var event = new CustomEvent('ActivitiesRetrieved', data);
document.dispatchEvent(event);
// ff
window.postMessage(data, '*');
}
else if(message && message.action === 'ping') {
chrome.runtime.sendMessage({ action: 'pong', url: getSiteBaseURl() });
}
});
}

// transfert message from webpage to background (firefox add on)
window.addEventListener("message", function(ev) {
Expand Down
43 changes: 24 additions & 19 deletions extension/chrome/src/js/stash_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}

function buildSlug(pageState) {
if(pageState.link && pageState.link.url) {
if(pageState && pageState.link && pageState.link.url) {
return pageState.link.url;
}
else return '';
Expand Down Expand Up @@ -851,7 +851,7 @@
}
});

return _.sortBy(returnedActivities, 'activityDate').reverse();;
return _.sortBy(returnedActivities, 'activityDate').reverse();
}

function getLastPRCommentsAsync() {
Expand Down Expand Up @@ -910,11 +910,11 @@
function getMostRecentActivityDate(comment) {
var date = comment.createdDate;

comment.tasks.forEach(function(task){
(comment.tasks || []).forEach(function(task){
date = task.createdDate > date ? task.createdDate : date;
});

comment.comments.forEach(function(subcomment){
(comment.comments || []).forEach(function(subcomment){
var newDate = getMostRecentActivityDate(subcomment);
date = newDate > date ? newDate : date;
});
Expand All @@ -938,7 +938,7 @@
count.total += subCommentsFromOthers.length;
count.unread += _.filter(subCommentsFromOthers, function(c){ return !c.isPanelRead }).length;

comment.comments.forEach(function(subcomment){
(comment.comments || []).forEach(function(subcomment){
var result = countSubComments(subcomment);
count.total += result.total;
count.unread += result.unread;
Expand All @@ -953,7 +953,7 @@
count.total += taskFromOthers.length;
count.unread += _.filter(taskFromOthers, function(t){ return !t.isPanelRead }).length;

comment.comments.forEach(function(subcomment){
(comment.comments || []).forEach(function(subcomment){
var result = countTasks(subcomment);
count.total += result.total;
count.unread += result.unread;
Expand All @@ -978,10 +978,11 @@
jQuery.extend(activity.comment, {isBadgeRead: isCommentRead });
}

count +=isCommentRead ? 0 : activity.comment.author.name !== user.name ? 1 : 0;
var authorName = activity.comment && activity.comment.author && activity.comment.author.name ? activity.comment.author.name : '';
count +=isCommentRead ? 0 : authorName !== user.name ? 1 : 0;

// sub comments
activity.comment.comments.forEach(function(subComment){
(activity.comment.comments || []).forEach(function(subComment){
// count sub sub comments
count += countUnreadActivities([{ comment: subComment }], prefix);
});
Expand Down Expand Up @@ -1040,11 +1041,11 @@
activities.forEach(function(activity){
localStorage.setItem(prefix + 'comment_' + activity.comment.id, true);

activity.comment.comments.forEach(function(subComment){
(activity.comment.comments || []).forEach(function(subComment){
markActivitiesAsRead([{ comment:subComment }], prefix);
});

activity.comment.tasks.forEach(function(task){
(activity.comment.tasks || []).forEach(function(task){
localStorage.setItem(prefix + 'task_' + task.id, true);
});
});
Expand All @@ -1067,10 +1068,12 @@
// body
var $tbody = $table.append('<tbody>').find('tbody');
activities.forEach(function(activity) {
var commentAuthorName = activity.comment && activity.comment.author && activity.comment.author.name ? activity.comment.author.name : '';
var prAuthorName = activity.pullrequest && activity.pullrequest.author && activity.pullrequest.author.user && activity.pullrequest.author.user.name ? activity.pullrequest.author.user.name : '';
var $msgRow = jQuery('<td class="comment message markup">'+activity.comment.text+'</td>');
var $userRow = jQuery('<td class="author">'+activity.comment.author.name+'</td>');
var $userRow = jQuery('<td class="author">'+ commentAuthorName +'</td>');
var $countRow = jQuery('<td class="comment-count"></td>');
var $prRow = jQuery('<td class="title"><a href="' + urlUtil.buildSlug(activity.pullrequest) + '/overview?commentId='+activity.comment.id+'" title="{'+activity.pullrequest.author.user.name+'} '+activity.pullrequest.title+'">'+activity.pullrequest.title+'</a></td>');
var $prRow = jQuery('<td class="title"><a href="' + urlUtil.buildSlug(activity.pullrequest) + '/overview?commentId='+activity.comment.id+'" title="{'+ prAuthorName +'} '+ (activity.pullrequest || {title:''}).title +'">'+ (activity.pullrequest || {title:''}).title +'</a></td>');
var $updatedRow = jQuery('<td class="comment-count"></td>').html(moment(activity.activityDate).fromNow());

var isLineUnread = hasUnreadActivities(activity, NotificationType.panel);
Expand All @@ -1082,10 +1085,12 @@
});

// avatar
activity.comment.author = activity.comment.author || {};
activity.comment.author.avatarUrl = activity.comment.author.avatarUrl || '';
var $avatar = jQuery(stash.widget.avatar({
size: 'small',
person: activity.comment.author,
tooltip: activity.comment.author.displayName
tooltip: (activity.comment.author || {displayName:''}).displayName
}));
$userRow.html($avatar);
$avatar.find('img').tooltip();
Expand Down Expand Up @@ -1287,12 +1292,12 @@
if(window.notificationType.toString() === '0') { // prAndMentioned only (also include answer)
var isIncluded = false;
// filter PR which are not from current user
if(activity.pullrequest.author.user.name === user.name) {
if(activity.pullrequest && activity.pullrequest.author && activity.pullrequest.author.user.name === user.name) {
isIncluded = true;
}

// filter mentioned
if(activity.comment.text.indexOf('@"'+user.name+'"') > -1) {
if(activity.comment && (activity.comment.text || '').indexOf('@"'+user.name+'"') > -1) {
isIncluded = true;
}

Expand All @@ -1319,7 +1324,7 @@
}

// notification for subcomments (answers)
activity.comment.comments.forEach(function(subComment){
(activity.comment.comments || []).forEach(function(subComment){
displayDesktopNotification([{
comment: subComment,
pullrequest: activity.pullrequest,
Expand All @@ -1328,7 +1333,7 @@
});

// notification for task
activity.comment.tasks.forEach(function(task){
(activity.comment.tasks || []).forEach(function(task){
var taskKey = prefix + 'task_' + task.id;
var taskState = localStorage.getItem(taskKey);
localStorage.setItem(taskKey, true);
Expand Down Expand Up @@ -1402,7 +1407,7 @@
var pr = pageState.getPullRequest();
if (pr) {
getLastPRCommentsOnceAsync().done(function(activities){
activities = _.filter(activities, function(a){ return a.pullrequest.id === pr.id; });
activities = _.filter(activities, function(a){ return (a.pullrequest || {id:''}).id === pr.id; });
markActivitiesAsRead(activities, NotificationType.badge);
markActivitiesAsRead(activities, NotificationType.panel);
});
Expand Down Expand Up @@ -1941,7 +1946,7 @@
return {
filter: function(list, fct) {
//native filter
return list.filter(fct);
return (list || []).filter(fct);
},
sortBy:function (list){
// no order
Expand Down
2 changes: 1 addition & 1 deletion extension/chrome/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Stash Extension",
"description": "Allow to add group of reviewers for pull request in stash + other features",
"version": "1.6.5",
"version": "1.6.6",
"permissions": [
"storage",
"alarms",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions history
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.6.6
===================
- bug fix: extension was not loading on stash 3.2
- bug fix: loop in event message may result in some tab crash

1.6.5
===================
- better aui/flag polyfill
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.5
1.6.6

0 comments on commit ba27285

Please sign in to comment.