 
     dynamic var fromFriend: User?
     dynamic var conversation: Conversation?
+
+
+    func deleteAttachmentInRealm(realm: Realm) {
+
+        if let mediaMetaData = mediaMetaData {
+            realm.delete(mediaMetaData)
+        }
+
+        switch mediaType {
+
+        case MessageMediaType.Image.rawValue:
+            NSFileManager.removeMessageImageFileWithName(localAttachmentName)
+
+        case MessageMediaType.Video.rawValue:
+            NSFileManager.removeMessageVideoFilesWithName(localAttachmentName, thumbnailName: localThumbnailName)
+
+        case MessageMediaType.Audio.rawValue:
+            NSFileManager.removeMessageAudioFileWithName(localAttachmentName)
+
+        case MessageMediaType.Location.rawValue:
+            NSFileManager.removeMessageImageFileWithName(localAttachmentName)
+
+        case MessageMediaType.SocialWork.rawValue:
+
+            if let socialWork = socialWork {
+
+                if let githubRepo = socialWork.githubRepo {
+                    realm.delete(githubRepo)
+                }
+
+                if let dribbbleShot = socialWork.dribbbleShot {
+                    realm.delete(dribbbleShot)
+                }
+
+                if let instagramMedia = socialWork.instagramMedia {
+                    realm.delete(instagramMedia)
+                }
+                
+                realm.delete(socialWork)
+            }
+            
+        default:
+            break // TODO: if have other message media need to delete
+        }
+    }
 }
 
 class Draft: Object {


    let messages = conversation.messages

    // delete all media files of messages

    messages.forEach { deleteMediaFilesOfMessage($0) }

    // delete all mediaMetaDatas


    return messages.first
}

func avatarWithAvatarURLString(avatarURLString: String, inRealm realm: Realm) -> Avatar? {
    let predicate = NSPredicate(format: "avatarURLString = %@", avatarURLString)
    return realm.objects(Avatar).filter(predicate).first
