forked from sadhack/spcrud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spcrud.social.js
221 lines (203 loc) · 6.47 KB
/
spcrud.social.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/**
* Library with AngularJS operations for SharePoint 2013 Newsfeed operations over REST api
*
*
* @spjeff
* http://spjeff.com
*
* version 0.1.20
* last updated 06-06-2017
*
*/
//namespace
'use strict';
var spsocial = spsocial || {};
//----------SHAREPOINT SOCIAL NEWSFEED----------
//Returns newsfeed thread info
spsocial.getNewsFeed = function ($http, utc) {
var url = "";
if (utc) {
url = spcrud.baseUrl + '/_api/social.feed/my/news(MaxThreadCount=100,OlderThan=@v)?@v=datetime' + "%27" + utc + "%27";
} else {
url = spcrud.baseUrl + '/_api/social.feed/my/news';
}
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Gets the feed of activity by the current user and by people and content the user is following, sorted by created date
spsocial.getTimeLineFeed = function ($http, olderThan) {
var url = "";
if (olderThan) {
url = spcrud.baseUrl + "/_api/social.feed/my/timelinefeed(MaxThreadCount=25,SortOrder=0,NewerThan=@v)?@v=datetime'2016-03-11T21:48:45.000Z'";
} else {
url = spcrud.baseUrl + '/_api/social.feed/my/timelinefeed';
}
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Get feed of personal activity
spsocial.getPersonalActivityFeed = function ($http) {
var url = spcrud.baseUrl + '/_api/social.feed/my/feed';
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Get feed of like activity
spsocial.getLikesFeed = function ($http) {
var url = spcrud.baseUrl + '/_api/social.feed/my/likes';
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Get list of followers
spsocial.getFollowers = function ($http) {
var url = spcrud.baseUrl + '/_api/social.following/my/followed(types=1)';
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Gets the feed of activity by the current user and by people and content the user is following, sorted by created date
spsocial.getMentionsFeed = function ($http) {
var url = spcrud.baseUrl + '/_api/social.feed/my/mentionfeed';
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Get all replies for a given post ID
spsocial.getAllReplies = function ($http, id) {
var data = {
ID: id
};
var url = spcrud.baseUrl + "/_api/social.feed/post";
var config = {
method: 'POST',
data: data,
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Social data counts
//1 - Users
//2 - Documents
//4 - Sites
//8 - Tags
//value enum: https://msdn.microsoft.com/en-us/library/office/dn194080.aspx#bk_FollowedCount
spsocial.getSocialCounts = function ($http, types) {
var url = spcrud.baseUrl + '/_api/social.following/my/followedcount(types=' + types + ')';
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Returns sites being followed by the user
spsocial.getFollowedSites = function ($http) {
var url = spcrud.baseUrl + '/_api/social.following/my/followed(types=4)';
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Return Trending Tags Data
spsocial.getTrendingTags = function ($http, utc) {
var url = spcrud.baseUrl + "/_api/search/query?querytext='ContentTypeId:0x01FD* write>=\"" + utc + "\" -ContentClass=urn:content-class:SPSPeople'&refiners='Tags'";
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Get all social tags used
spsocial.getAllTags = function ($http) {
var url = spcrud.baseUrl + "/_api/search/query?querytext='ContentTypeId:0x01FD* -ContentClass=urn:content-class:SPSPeople'&refiners='Tags'&rowlimit=500";
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Get list of recent documents
spsocial.getRecentDocs = function ($http) {
var url = spcrud.baseUrl + "/_api/search/query?querytext='*'&querytemplate='(AuthorOwsUser:{User.AccountName} OR EditorOwsUser:{User.AccountName}) AND ContentType:Document AND IsDocument:1 AND -Title:OneNote_DeletedPages AND -Title:OneNote_RecycleBin NOT(FileExtension:mht OR FileExtension:aspx OR FileExtension:html OR FileExtension:htm OR FileExtension:one OR FileExtension:bin)'&rowlimit=100&bypassresulttypes=false&selectproperties='Title,Path,Filename,FileExtension,Created,Author,LastModifiedTime,ModifiedBy,LinkingUrl,SiteTitle,ParentLink,DocumentPreviewMetadata,ListID,ListItemID,SPSiteURL,SiteID,WebId,UniqueID,SPWebUrl'&sortlist='LastModifiedTime:descending'&enablesorting=true";
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Follow another user
spsocial.follow = function ($http, account) {
var data = {
'actor': {
'__metadata': { "type": "SP.Social.SocialActorInfo" },
'ActorType': 0,
'AccountName': account,
'Id': null
}
};
var url = spcrud.baseUrl + "/_api/social.following/follow";
var config = {
method: 'POST',
data: data,
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Unfollow another user
spsocial.unfollow = function ($http, account) {
var data = {
'actor': {
'__metadata': { "type": "SP.Social.SocialActorInfo" },
'ActorType': 0,
'AccountName': account,
'Id': null
}
};
var url = spcrud.baseUrl + "/_api/social.following/stopfollowing";
var config = {
method: 'POST',
data: data,
url: url,
headers: spcrud.headers
};
return $http(config);
};
//Get list of community sites
spsocial.getCommunitySites = function ($http) {
var url = spcrud.baseUrl + "/_api/search/query?querytext='WebTemplate=COMMUNITY OR WebTemplate=STS OR WebTemplate=PROJECTSITE'&rowlimit=1000&sortlist='LastModifiedTime:descending'&trimduplicates=false";
var config = {
method: 'GET',
url: url,
headers: spcrud.headers
};
return $http(config);
};