 
     @on 'MemberAdded', (member) ->
       @constructor.emit 'MemberAdded', { group: this, member }
-      unless @slug is 'guests'
-
-        @prepareNewlyAddedMember member, ({ memberData }) =>
-
-          @sendNotification 'GroupJoined',
-            actionType : 'groupJoined'
-            actorType  : 'member'
-            subject    : ObjectRef(this).data
-            member     : ObjectRef(member).data
-            memberData : memberData
+
+      return  if @slug is 'guests'
+
+      @prepareNewlyAddedMember member, ({err, memberData }) =>
+
+        return @sendNotification 'GroupJoined', {}  if err
+
+        member = _.extend {}, ObjectRef(member).data
+        member = _.extend member, memberData
+
+        @sendNotification 'GroupJoined',
+          actionType : 'groupJoined'
+          actorType  : 'member'
+          subject    : ObjectRef(this).data
+          member     : member
 
     @on 'MemberRemoved', (member, requester) ->
+
       requester ?= member
       @constructor.emit 'MemberRemoved', { group: this, member, requester }
-      unless @slug is 'guests'
-        username = member.data.profile.nickname
-        @sendNotification 'GroupLeft',
-          actionType : 'groupLeft'
-          actorType  : 'member'
-          subject    : ObjectRef(this).data
-          member     : ObjectRef(member).data
-          username   : username
+
+      return  if @slug is 'guests'
+
+      username = member.data.profile.nickname
+      member = _.extend {}, ObjectRef(member).data
+      member = _.extend member, { username }
+      @sendNotification 'GroupLeft',
+        actionType : 'groupLeft'
+        actorType  : 'member'
+        subject    : ObjectRef(this).data
+        member     : member
 
   @render        :
     loggedIn     :


    memberData = {}
    @fetchRolesByAccount member, (err, roles = []) ->
      memberData.roles = roles  unless err
      member.fetchEmail (err, email) ->
        memberData.email = email  unless err
        memberData.username = member.data.profile.nickname
        callback { memberData }


  @create = (client, groupData, owner, callback) ->

async          = require 'async'
{ Module }     = require 'jraphical'
{ difference } = require 'underscore'
_ = require 'lodash'


module.exports = class JGroup extends Module
