Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #32 from Holochain/3-Mentions
Browse files Browse the repository at this point in the history
[WorkInProgress] initial create mentions links
  • Loading branch information
philipbeadle authored Jan 21, 2018
2 parents a8828ad + fde2ba3 commit 20c5ae7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
37 changes: 37 additions & 0 deletions dna/clutter/clutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ function post(post) {
// On the DHT, puts a link on my hash to the new post
commit("post_links",{Links:[{Base:me,Link:key,Tag:"post"}]});

// MENTIONS
// detect mentions
// for each mention, write that mention as a link
var mentions = detectMentions(post.message)
for (var i = 0; i <= mentions.length; i++) {
// get the userhash for this handle
var userHash = getAgent(handle)
if (userHash) {
createMention(userHash, key)
}
}

debug("meta: "+JSON.stringify(getLinks(me,"post",{Load:true})));
debug(key);
return key; // Returns the hash key of the new post to the calling function
Expand Down Expand Up @@ -169,11 +181,36 @@ function getAgent(handle) {
}
return "";
}

function getMentions() {
var links = getLinks(getMe(), "mentioned");
// map the array of "links" into simple postHashes
// return an array of postHashes
return [];
}

// ==============================================================================
// HELPERS: unexposed functions
// ==============================================================================

function detectMentions(postString) {
var regexp = /\B\@\w\w+\b/g;
var matches = postString.match(regexp);
return matches;
// returns something like ["bob"]
}

function createMention(userHash,postHash) {
var commit_hash = commit("userMention_links",{
Links:[
{Base: userHash, Link: postHash, Tag: "mentioned"},
{Base: postHash, Link: userHash, Tag: "mentions"}
]
});
debug('create a mention');
debug(commit_hash);
return commit_hash;
}

// helper function to resolve which has will be used as "me"
function getMe() {return App.Key.Hash;}
Expand Down
9 changes: 9 additions & 0 deletions dna/dna.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"Name": "directory_links",
"DataFormat": "links"
},
{
"Name": "userMention_links",
"DataFormat": "links"
},
{
"Name": "follow",
"DataFormat": "links"
Expand Down Expand Up @@ -130,6 +134,11 @@
"Name": "getHandles",
"CallingType": "json",
"Exposure":"public"
},
{
"Name": "getMentions",
"CallingType": "json",
"Exposure":"public"
}
]
}
Expand Down

0 comments on commit 20c5ae7

Please sign in to comment.